Merge pull request #4472 from angelej/computed-property
Use computed property for timezones
This commit is contained in:
commit
089f48d495
4 changed files with 22 additions and 12 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
use App\Actions\Server\StartSentinel;
|
use App\Actions\Server\StartSentinel;
|
||||||
use App\Actions\Server\StopSentinel;
|
use App\Actions\Server\StopSentinel;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Livewire\Attributes\Locked;
|
use Livewire\Attributes\Computed;
|
||||||
use Livewire\Attributes\Validate;
|
use Livewire\Attributes\Validate;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
|
|
@ -79,9 +79,6 @@ class Show extends Component
|
||||||
#[Validate(['required'])]
|
#[Validate(['required'])]
|
||||||
public string $serverTimezone;
|
public string $serverTimezone;
|
||||||
|
|
||||||
#[Locked]
|
|
||||||
public array $timezones;
|
|
||||||
|
|
||||||
public function getListeners()
|
public function getListeners()
|
||||||
{
|
{
|
||||||
$teamId = auth()->user()->currentTeam()->id;
|
$teamId = auth()->user()->currentTeam()->id;
|
||||||
|
|
@ -96,13 +93,21 @@ public function mount(string $server_uuid)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->server = Server::ownedByCurrentTeam()->whereUuid($server_uuid)->firstOrFail();
|
$this->server = Server::ownedByCurrentTeam()->whereUuid($server_uuid)->firstOrFail();
|
||||||
$this->timezones = collect(timezone_identifiers_list())->sort()->values()->toArray();
|
|
||||||
$this->syncData();
|
$this->syncData();
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return handleError($e, $this);
|
return handleError($e, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Computed]
|
||||||
|
public function timezones(): array
|
||||||
|
{
|
||||||
|
return collect(timezone_identifiers_list())
|
||||||
|
->sort()
|
||||||
|
->values()
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
public function syncData(bool $toModel = false)
|
public function syncData(bool $toModel = false)
|
||||||
{
|
{
|
||||||
if ($toModel) {
|
if ($toModel) {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Livewire\Attributes\Locked;
|
use Livewire\Attributes\Computed;
|
||||||
use Livewire\Attributes\Validate;
|
use Livewire\Attributes\Validate;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
|
|
@ -17,9 +17,6 @@ class Index extends Component
|
||||||
|
|
||||||
protected Server $server;
|
protected Server $server;
|
||||||
|
|
||||||
#[Locked]
|
|
||||||
public $timezones;
|
|
||||||
|
|
||||||
#[Validate('boolean')]
|
#[Validate('boolean')]
|
||||||
public bool $is_auto_update_enabled;
|
public bool $is_auto_update_enabled;
|
||||||
|
|
||||||
|
|
@ -101,12 +98,20 @@ public function mount()
|
||||||
$this->is_api_enabled = $this->settings->is_api_enabled;
|
$this->is_api_enabled = $this->settings->is_api_enabled;
|
||||||
$this->auto_update_frequency = $this->settings->auto_update_frequency;
|
$this->auto_update_frequency = $this->settings->auto_update_frequency;
|
||||||
$this->update_check_frequency = $this->settings->update_check_frequency;
|
$this->update_check_frequency = $this->settings->update_check_frequency;
|
||||||
$this->timezones = collect(timezone_identifiers_list())->sort()->values()->toArray();
|
|
||||||
$this->instance_timezone = $this->settings->instance_timezone;
|
$this->instance_timezone = $this->settings->instance_timezone;
|
||||||
$this->disable_two_step_confirmation = $this->settings->disable_two_step_confirmation;
|
$this->disable_two_step_confirmation = $this->settings->disable_two_step_confirmation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Computed]
|
||||||
|
public function timezones(): array
|
||||||
|
{
|
||||||
|
return collect(timezone_identifiers_list())
|
||||||
|
->sort()
|
||||||
|
->values()
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
public function instantSave($isSave = true)
|
public function instantSave($isSave = true)
|
||||||
{
|
{
|
||||||
$this->validate();
|
$this->validate();
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ class="mt-8 mb-4 w-full font-bold box-without-bg bg-coollabs hover:bg-coollabs-1
|
||||||
<div class="w-full" x-data="{
|
<div class="w-full" x-data="{
|
||||||
open: false,
|
open: false,
|
||||||
search: '{{ $serverTimezone ?: '' }}',
|
search: '{{ $serverTimezone ?: '' }}',
|
||||||
timezones: @js($timezones),
|
timezones: @js($this->timezones),
|
||||||
placeholder: '{{ $serverTimezone ? 'Search timezone...' : 'Select Server Timezone' }}',
|
placeholder: '{{ $serverTimezone ? 'Search timezone...' : 'Select Server Timezone' }}',
|
||||||
init() {
|
init() {
|
||||||
this.$watch('search', value => {
|
this.$watch('search', value => {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
<div class="w-full" x-data="{
|
<div class="w-full" x-data="{
|
||||||
open: false,
|
open: false,
|
||||||
search: '{{ $settings->instance_timezone ?: '' }}',
|
search: '{{ $settings->instance_timezone ?: '' }}',
|
||||||
timezones: @js($timezones),
|
timezones: @js($this->timezones),
|
||||||
placeholder: '{{ $settings->instance_timezone ? 'Search timezone...' : 'Select Server Timezone' }}',
|
placeholder: '{{ $settings->instance_timezone ? 'Search timezone...' : 'Select Server Timezone' }}',
|
||||||
init() {
|
init() {
|
||||||
this.$watch('search', value => {
|
this.$watch('search', value => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue