diff --git a/app/Jobs/ExportSqliteTextAdJob.php b/app/Jobs/ExportSqliteTextAdJob.php new file mode 100644 index 0000000..68fff43 --- /dev/null +++ b/app/Jobs/ExportSqliteTextAdJob.php @@ -0,0 +1,68 @@ +branchId = $branchId; + } + + public function handle() + { + $sqlitePath = storage_path('app/database/tempTextAd.sqlite'); + + if (!file_exists(dirname($sqlitePath))) { + mkdir(dirname($sqlitePath), 0755, true); + } + + if (!file_exists($sqlitePath)) { + file_put_contents($sqlitePath, ''); + } + $connectionName = 'tempsqlite_' . md5($sqlitePath . microtime()); + config(["database.connections.{$connectionName}" => [ + 'driver' => 'sqlite', + 'database' => $sqlitePath, + 'prefix' => '', + ]]); + + $exporter = new SqliteExportService($connectionName); + $exporter->exportMultiple([ + 'text_ads' => [ + 'query' => fn () => DB::table('text_ads'), + 'tableSchema' => function (Blueprint $table) { + $table->id(); + $table->string('content')->comment('廣告內容'); + $table->enum('color', ['black','white', 'red', 'green','blue'])->default('black')->comment('顯示顏色'); + $table->integer('duration')->default(1)->comment('播放間隔時間(分鐘)'); + $table->boolean('is_active')->default(true); // 啟用狀態 + $table->timestamps(); + }, + 'transformer' => fn ($row) => [ + 'content' => $row->content, + 'color' => $row->color, + 'duration' => $row->duration, + 'is_active' => $row->is_active, + 'created_at' => $row->created_at, + 'updated_at' => $row->updated_at, + ], + ], + ]); + SendSqliteFileJob::dispatch($sqlitePath, $this->branchId); + } +} diff --git a/app/Livewire/Modals/BranchSyncModal.php b/app/Livewire/Modals/BranchSyncModal.php new file mode 100644 index 0000000..64e034b --- /dev/null +++ b/app/Livewire/Modals/BranchSyncModal.php @@ -0,0 +1,76 @@ +branch_id = $branch_id; + $this->branch_name = Branch::find($branch_id)->name; + $this->reset('syncBranch', 'syncSong', 'syncFavorite', 'syncTextAds', 'syncUser'); + $this->showModal = true; + } + public function closeModal() + { + $this->showModal = false; + } + + public function save() + { + if ($this->syncBranch) { + ExportSqliteBranchJob::dispatch($this->branch_id); + } + if ($this->syncSong) { + ExportSqliteSongJob::dispatch($this->branch_id); + } + if ($this->syncFavorite) { + ExportSqliteFavoriteJob::dispatch($this->branch_id); + } + if($this->syncTextAds){ + ExportSqliteTextAdJob::dispatch($this->branch_id); + } + if ($this->syncUser) { + ExportSqliteUserJob::dispatch(true, $this->branch_id); + } + + $this->notification()->send([ + 'icon' => 'success', + 'title' => '同步任務', + 'description' => '已加入排程', + ]); + + $this->showModal = false; + + } + + public function render() + { + return view('livewire.modals.branch-sync-modal'); + } +} diff --git a/app/Livewire/Tables/BranchTable.php b/app/Livewire/Tables/BranchTable.php index e903b80..08de251 100644 --- a/app/Livewire/Tables/BranchTable.php +++ b/app/Livewire/Tables/BranchTable.php @@ -202,10 +202,10 @@ final class BranchTable extends PowerGridComponent { $actions = []; $actions[] = Button::add('room-synchronous') - ->slot('包廂同步') + ->slot('分店中控同步') ->icon('solid-cog') ->class('inline-flex items-center gap-1 px-3 py-1 rounded bg-amber-200 text-black') - ->dispatch('synchronous.' . $this->tableName, ['branch_id' => $row->id]); + ->dispatchTo('modals.branch-sync-modal','openModal', ['branch_id' => $row->id]); if ($this->canEdit) { $actions[] =Button::add('edit') ->slot(__('branches.edit')) diff --git a/app/Livewire/Tables/RoomStatusLogTable.php b/app/Livewire/Tables/RoomStatusLogTable.php index a5a2735..4252e8c 100644 --- a/app/Livewire/Tables/RoomStatusLogTable.php +++ b/app/Livewire/Tables/RoomStatusLogTable.php @@ -62,7 +62,12 @@ final class RoomStatusLogTable extends PowerGridComponent ->add('user_name', function (RoomStatusLog $model){ return $model->user?->name; }) - ->add('is_online') + ->add('is_online_img', fn ($model) => + [ + $model->is_online ? 'check-circle' : 'x-circle' => [ + 'text-color' => $model->is_online ? 'text-green-600' : 'text-red-600', + ], + ]) ->add('status_str',function (RoomStatusLog $model){ return $model->status->labelPowergridFilter(); }) @@ -80,7 +85,7 @@ final class RoomStatusLogTable extends PowerGridComponent $column[]=Column::make(__('room-status-log.branch'), 'branch_name'); $column[]=Column::make(__('room-status-log.room'), 'room_name'); $column[]=Column::make(__('room-status-log.user'), 'user_name'); - $column[]=Column::make(__('room-status-log.is_online'), 'is_online'); + $column[]=Column::make(__('room-status-log.is_online'), 'is_online_img')->template(); $column[]=Column::make(__('room-status-log.status'), 'status_str'); $column[]=Column::make(__('room-status-log.started_at'), 'started_at'); $column[]=Column::make(__('room-status-log.ended_at'), 'ended_at'); @@ -89,6 +94,17 @@ final class RoomStatusLogTable extends PowerGridComponent $column[]=Column::make(__('room-status-log.created_at'), 'created_at'); return $column; } + public function rowTemplates(): array + { + return [ + 'check-circle' => ' + + ', + 'x-circle' => ' + + ', + ]; + } public function filters(): array { diff --git a/app/Livewire/Tables/RoomTable.php b/app/Livewire/Tables/RoomTable.php index c8f4f41..183a464 100644 --- a/app/Livewire/Tables/RoomTable.php +++ b/app/Livewire/Tables/RoomTable.php @@ -18,6 +18,7 @@ use PowerComponents\LivewirePowerGrid\PowerGridComponent; use PowerComponents\LivewirePowerGrid\Traits\WithExport; use PowerComponents\LivewirePowerGrid\Components\SetUp\Exportable; use Livewire\Attributes\On; +use Livewire\Attributes\Url; use WireUi\Traits\WireUiActions; final class RoomTable extends PowerGridComponent @@ -26,7 +27,7 @@ final class RoomTable extends PowerGridComponent public string $tableName = 'room-table'; public bool $canDownload; public bool $canDelect; - + #[Url] public ?int $selectedBranchId = null; public ?string $external_ip= ""; @@ -38,8 +39,7 @@ final class RoomTable extends PowerGridComponent $this->canDownload=Auth::user()?->can('room-delete') ?? false; $this->canDelect = Auth::user()?->can('room-delete') ?? false; $branch = Branch::first(); - $this->selectedBranchId = $branch?->id; - $this->external_ip = $branch?->external_ip; + $this->selectChanged($branch?->id,"", ""); } public function setUp(): array @@ -57,7 +57,7 @@ final class RoomTable extends PowerGridComponent ->showToggleColumns(); $header->includeViewOnTop('livewire.headers.room'); $actions[]=$header; - $actions[]=PowerGrid::footer()->pageName('selectedBranchId')->showPerPage()->showRecordCount(); + $actions[]=PowerGrid::footer()->showPerPage()->showRecordCount(); return $actions; } public function header(): array @@ -83,10 +83,6 @@ final class RoomTable extends PowerGridComponent return $query; } - public function updatedSelectedBranchId($value) - { - $this->resetPage(); // 重設分頁 - } public function relationSearch(): array { @@ -102,7 +98,12 @@ final class RoomTable extends PowerGridComponent return $model->type->labelPowergridFilter(); }) ->add('name') - ->add('is_online', fn ($model) => $model->is_online===true ? '在線' : '斷線') + ->add('is_online_img', fn ($model) => [ + $model->is_online ? 'check-circle' : 'x-circle' => [ + 'text-color' => $model->is_online ? 'text-green-600' : 'text-red-600', + ], + ] + ) ->add('status_str',function (Room $model){ return $model->status->labelPowergridFilter(); }) @@ -118,7 +119,7 @@ final class RoomTable extends PowerGridComponent $column[]=Column::make(__('rooms.floor'), 'floor')->sortable()->searchable(); $column[]=Column::make(__('rooms.type'), 'type_str','room.type')->sortable()->searchable(); $column[]=Column::make(__('rooms.name'), 'name')->sortable()->searchable(); - $column[]=Column::make(__('rooms.isOnline'), 'is_online'); + $column[]=Column::make(__('rooms.isOnline'), 'is_online_img')->template(); $column[]=Column::make(__('rooms.status'), 'status_str','room.status')->sortable()->searchable()->hidden(true, false); $column[]=Column::make(__('rooms.started_at'), 'str_started_at', 'started_at')->sortable()->hidden(true, false); $column[]=Column::make(__('rooms.ended_at'), 'str_ended_at', 'ended_at')->sortable()->hidden(true, false); @@ -127,6 +128,17 @@ final class RoomTable extends PowerGridComponent return $column; } + public function rowTemplates(): array + { + return [ + 'check-circle' => ' + + ', + 'x-circle' => ' + + ', + ]; + } public function filters(): array { @@ -153,11 +165,12 @@ final class RoomTable extends PowerGridComponent #[On('selectChanged')] public function selectChanged($value,$fieldName, $modelId): void { - //dd($value,$fieldName, $modelId); + if($fieldName == 'selectedBranchId'){ $this->selectedBranchId=$value; $branch = Branch::find($this->selectedBranchId); $this->external_ip=$branch->external_ip; + $this->resetPage(); // 重設分頁 } } #[On('deleteRoom')] diff --git a/app/Models/Room.php b/app/Models/Room.php index 11edf97..68b7f24 100644 --- a/app/Models/Room.php +++ b/app/Models/Room.php @@ -42,6 +42,12 @@ class Room extends Model 'started_at', 'ended_at', ]; + protected $attributes = [ + 'type' => \App\Enums\RoomType::Unset, + 'floor' => 1, + 'is_online' => false, + 'status' => \App\Enums\RoomStatus::Error, + ]; protected $hidden = [ 'internal_ip', diff --git a/resources/views/livewire/admin/branches.blade.php b/resources/views/livewire/admin/branches.blade.php index f5d5c42..c0a3c01 100644 --- a/resources/views/livewire/admin/branches.blade.php +++ b/resources/views/livewire/admin/branches.blade.php @@ -3,5 +3,6 @@ + \ No newline at end of file diff --git a/resources/views/livewire/modals/branch-sync-modal.blade.php b/resources/views/livewire/modals/branch-sync-modal.blade.php new file mode 100644 index 0000000..59c1fa4 --- /dev/null +++ b/resources/views/livewire/modals/branch-sync-modal.blade.php @@ -0,0 +1,32 @@ + + + + + + + {{ $branch_name ?? '未選擇' }} 分店中控同步 + +
+ + + + + +
+ +
+ + +
+
+
+
\ No newline at end of file