功能調整

API 收到包廂指令先押資料
加入 包廂列表
加入 包廂控制介面
加入 包廂記錄
補上正規劃
20250729
This commit is contained in:
allen.yan 2025-07-29 00:24:03 +08:00
parent e248359e98
commit 2769e82a37
35 changed files with 812 additions and 150 deletions

View File

@ -23,7 +23,7 @@ enum RoomType: string {
public function labels(): string
{
return match($this) {
self::Unset => __('enums.room.status.Unset'),
self::Unset => __('enums.Unset'),
self::PC => "PC",
self::SVR => "SVR",
};

View File

@ -80,8 +80,30 @@ class RoomControlController extends Controller
if (empty($branch->external_ip) ) {
return ApiResponse::error('分店未設定 外部URL');
}
$roomType = null;
$roomName = null;
// 從 room_name例如 PC101, SVR01中擷取 type 與 name
if (preg_match('/^([A-Za-z]+)(\d+)$/', $validated['room_name'], $matches)) {
$roomType = strtolower($matches[1]); // 'PC' → 'pc'
$roomName = $matches[2]; // '101'
}
$room = Room::where([
'branch_id' => $branch->id,
'name' => $roomName,
'type' => $roomType
])->first();
if (!$room) {
return ApiResponse::error('包廂不存在');
}
$command = $validated['command'];
$room->update([
'status' => $command,
'started_at' => $validated['started_at'] ?? null,
'ended_at' => $validated['ended_at'] ?? null,
]);
$payload = [
'branch_name' => $validated['branch_name'],
'room_name' => $validated['room_name'],
@ -89,8 +111,7 @@ class RoomControlController extends Controller
'started_at' => $validated['started_at'] ?? null,
'ended_at' => $validated['ended_at'] ?? null,
];
$user = \App\Models\User::find(2);
$token = $user->api_plain_token;
$token = \App\Models\User::find(2)->api_plain_token;
$api = new \App\Services\ApiClient($branch->external_ip,$token);
$response = $api->post('/api/room/sendSwitch', $payload);

View File

@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use WireUi\Traits\WireUiActions;
use Illuminate\Validation\Rules\Enum;
use App\Models\Artist;
use App\Enums\ArtistCategory;
@ -30,6 +31,15 @@ class ArtistForm extends Component
'name' =>'',
'enable' => true,
];
public function rules()
{
return [
'fields.category' => ['required', new Enum(ArtistCategory::class)],
'fields.name' => 'required|string|max:255',
'fields.enable' => 'required|boolean',
];
}
public $selectedCategory = []; // 表單中選到的權限
@ -66,6 +76,7 @@ class ArtistForm extends Component
public function save()
{
$validated = $this->validate($this->rules());
if ($this->artistId) {
if ($this->canEdit) {
$artist = Artist::findOrFail($this->artistId);

View File

@ -31,7 +31,15 @@ class BranchForm extends Component
'enable' => true,
'roomNotes' =>''
];
public function rules()
{
return [
'fields.name' => 'required|string|max:255',
'fields.external_ip' => 'required|string|max:255',
'fields.enable' => 'required|boolean', // 或 new Enum(...) 如果你用了 Enum
'fields.roomNotes' => 'nullable|string',
];
}
public function mount()
{
@ -61,6 +69,7 @@ class BranchForm extends Component
public function save()
{
$validated = $this->validate($this->rules());
if ($this->branchId) {
if ($this->canEdit) {
$branch = Branch::findOrFail($this->branchId);

View File

@ -0,0 +1,125 @@
<?php
namespace App\Livewire\Forms;
use Illuminate\Validation\Rule;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use WireUi\Traits\WireUiActions;
use App\Models\Room;
use App\Enums\RoomType;
class RoomForm extends Component
{
use WireUiActions;
protected $listeners = ['openModal','closeModal', 'deleteRoom'];
public bool $canCreate;
public bool $canEdit;
public bool $canDelect;
public bool $showModal = false;
public ?int $roomId = null;
public array $typeOptions =[];
public array $fields = [
'floor' =>'',
'type' =>'',
'name' =>''
];
public function mount()
{
$this->typeOptions = collect(RoomType::cases())->map(fn ($type) => [
'name' => $type->labels(),
'value' => $type->value,
])->toArray();
$this->canCreate = Auth::user()?->can('room-edit') ?? false;
$this->canEdit = Auth::user()?->can('room-edit') ?? false;
$this->canDelect = Auth::user()?->can('room-delete') ?? false;
}
public function openModal($id = null)
{
$this->resetFields();
if ($id) {
$room = Room::findOrFail($id);
$this->roomId = $room->id;
$this->fields = $room->only(array_keys($this->fields));
}
$this->showModal = true;
}
public function closeModal()
{
$this->resetFields();
$this->showModal = false;
}
public function save()
{
$description ="無權修改";
if ($this->roomId) {
if ($this->canEdit) {
$room = Room::findOrFail($this->roomId);
$room->update($this->fields);
$description='分店已更新';
}
} else {
if ($this->canCreate) {
$room = Room::create([
'floor' => $this->fields['floor'],
'type' => $this->fields['type'],
'name' => $this->fields['name'],
]);
$description='分店已新增';
}
}
$this->notification()->send([
'icon' => 'success',
'title' => '成功',
'description' => $description,
]);
$this->resetFields();
$this->showModal = false;
$this->dispatch('pg:eventRefresh-room-table');
}
public function deleteBranch($id)
{
if ($this->canDelect) {
Room::findOrFail($id)->delete();
$this->notification()->send([
'icon' => 'success',
'title' => '成功',
'description' => '分店已刪除',
]);
$this->dispatch('pg:eventRefresh-room-table');
}
}
public function resetFields()
{
foreach ($this->fields as $key => $value) {
if ($key == 'enable') {
$this->fields[$key] = true;
} else {
$this->fields[$key] = '';
}
}
$this->branchId = null;
}
public function render()
{
return view('livewire.forms.room-form');
}
}

View File

@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use WireUi\Traits\WireUiActions;
use Illuminate\Validation\Rules\Enum;
use App\Enums\SongLanguageType;
use App\Enums\SongSituation;
use App\Models\Song;
@ -52,10 +53,30 @@ class SongForm extends Component
];
//protected $rules = [
// 'name' => 'required|string|max:255',
//
//];
public function rules()
{
return [
'fields.name' => 'required|string|max:255',
'fields.adddate' => 'required|date', // 或 required, 依照你的需求
'fields.filename' => 'required|string|max:255',
'fields.language_type'=> ['required',new Enum(SongLanguageType::class)],
'fields.vocal' => 'required|boolean',
'fields.situation' => ['required',new Enum(SongSituation::class)],
'fields.copyright01' => 'nullable|string|max:255',
'fields.copyright02' => 'nullable|string|max:255',
'fields.note01' => 'nullable|string|max:255',
'fields.note02' => 'nullable|string|max:255',
'fields.note03' => 'nullable|string|max:255',
'fields.note04' => 'nullable|string|max:255',
'fields.enable' => 'required|boolean',
// 如果你在表單中也綁定了 selectedArtists / selectedCategories
'selectedArtists' => 'required|array',
'selectedArtists.*' => 'integer|exists:artists,id',
'selectedCategories' => 'nullable|array',
'selectedCategories.*'=> 'integer|exists:categories,id',
];
}
public function mount()
{
@ -95,7 +116,7 @@ class SongForm extends Component
public function save()
{
//$this->validate();
$validated = $this->validate($this->rules());
if ($this->songId) {
if ($this->canEdit) {

View File

@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use WireUi\Traits\WireUiActions;
use Illuminate\Validation\Rules\Enum;
use App\Models\TextAd;
use App\Enums\TextAdColors;
@ -31,7 +32,15 @@ class TextAdsForm extends Component
'duration' => 1,
'is_active' => 1,
];
public function rules()
{
return [
'fields.content' => 'required|string|max:255',
'fields.color' => ['required',new Enum(TextAdColors::class)],
'fields.duration' => 'required|integer|min:1|max:60',
'fields.is_active' => 'required|boolean',
];
}
public function mount()
@ -66,6 +75,7 @@ class TextAdsForm extends Component
public function save()
{
$validated = $this->validate($this->rules());
if ($this->textAdId) {
if ($this->canEdit) {
$textAd = TextAd::findOrFail($this->textAdId);

View File

@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use WireUi\Traits\WireUiActions;
use Illuminate\Validation\Rules\Enum;
use App\Models\User;
use App\Enums\UserGender;
use App\Enums\UserStatus;
@ -41,15 +42,17 @@ class UserForm extends Component
'password_confirmation' => '', // 新增
];
protected $rules = [
public function rules()
{
return [
'fields.name' => 'required|string|max:255',
'fields.email' => 'required|string|email|max:255',
'fields.phone' => 'nullable|regex:/^09\d{8}$/',
'fields.birthday' =>'nullable|date',
'fields.gender' => 'required|in:male,female,other,unset',
'fields.status' => 'required|integer|in:0,1,2',
'fields.gender' => ['required', new Enum(UserGender::class)],
'fields.status' => ['required', new Enum(UserStatus::class)],
];
}
public function mount()
{
@ -88,7 +91,8 @@ class UserForm extends Component
public function save()
{
$rules = $this->rules;
//dd($this->fields);
$rules = $this->rules();
// 加入 email / phone 唯一性驗證,排除自己(編輯時)
$rules['fields.email'] .= '|unique:users,email' . ($this->userId ? ",{$this->userId}" : '');
$rules['fields.phone'] .= '|unique:users,phone' . ($this->userId ? ",{$this->userId}" : '');

View File

@ -12,36 +12,35 @@ use Illuminate\Database\Eloquent\Collection;
class RoomGrid extends Component
{
protected $listeners = ['openModal','closeModal'];//,'refreshRooms' => '$refresh'
public bool $showModal = false;
public int $branch_id = 0;
public $branchName="";
public ?int $selectedBranchId = null;
public string $external_ip= "";
public array $roomTypes;
public function mount()
{
$this->roomTypes = ['all' => '全部'] + collect(RoomType::cases())->mapWithKeys(fn($e) => [$e->value => $e->labels()])->toArray();
$this->roomTypes = ['all' => '全部'] + collect(RoomType::cases())->mapWithKeys(
fn($e) => [$e->value => $e->labels()]
)->toArray();
$this->selectChanged(Branch::first()->id,"","");
}
public function openModal($branch_id = null)
public function selectChanged($value,$fieldName, $modelId): void
{
$this->branch_id = $branch_id;
$branch = Branch::find($branch_id);
$this->branchName = Branch::find($branch_id)?->name ?? '';
$this->showModal = true;
}
public function closeModal(){
$this->showModal = false;
$this->branch_id = 0;
$branch = $value ? Branch::find($value) : null;
$this->selectedBranchId=$branch?->id ?? '';
$this->external_ip = $branch?->external_ip ?? '';
}
public function render()
{
$rooms = Room::where('branch_id', $this->branch_id)->orderBy('name', 'asc')->get();
// 取得樓層
$rooms = Room::where('branch_id', $this->selectedBranchId)->orderBy('name')->get();
$floors = $rooms->pluck('floor')->unique()->sort()->values()->toArray();
return view('livewire.grids.room-grid',['rooms' =>$rooms,'floors' =>$floors]);
return view('livewire.grids.room-grid', [
'rooms' => $rooms,
'floors' => $floors,
]);
}
}

View File

@ -99,7 +99,7 @@ final class ArtistTable extends PowerGridComponent
->add('category_str', function (Artist $model) {
if ($this->canEdit) {
return Blade::render(
'<x-select-category type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
'<x-select-dropdown type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
[
'options' => ArtistCategory::options(),
'modelId' => intval($model->id),
@ -154,8 +154,8 @@ final class ArtistTable extends PowerGridComponent
}
}
}
#[On('categoryChanged')]
public function categoryChanged($value,$fieldName, $modelId): void
#[On('selectChanged')]
public function selectChanged($value,$fieldName, $modelId): void
{
// dd($value,$fieldName, $modelId);
if ($fieldName == 'category' && $this->canEdit) {

View File

@ -154,8 +154,8 @@ final class BranchTable extends PowerGridComponent
}
}
}
#[On('categoryChanged')]
public function categoryChanged($value,$fieldName, $modelId): void
#[On('selectChanged')]
public function selectChanged($value,$fieldName, $modelId): void
{
// dd($value,$fieldName, $modelId);
if ($fieldName == 'category' && $this->canEdit) {
@ -201,11 +201,6 @@ final class BranchTable extends PowerGridComponent
public function actions(Branch $row): array
{
$actions = [];
$actions[] = Button::add('room-settings')
->slot('包廂設定')
->icon('solid-cog')
->class('inline-flex items-center gap-1 px-3 py-1 rounded bg-amber-200 text-black')
->dispatchTo('grids.room-grid', 'openModal', ['branch_id' => $row->id]);
$actions[] = Button::add('room-synchronous')
->slot('包廂同步')
->icon('solid-cog')

View File

@ -0,0 +1,82 @@
<?php
namespace App\Livewire\Tables;
use App\Models\RoomStatusLog;
use Illuminate\Support\Carbon;
use Illuminate\Database\Eloquent\Builder;
use PowerComponents\LivewirePowerGrid\Button;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Facades\Filter;
use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridFields;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
final class RoomStatusLogTable extends PowerGridComponent
{
public string $tableName = 'room-status-log-table';
public bool $showFilters = false;
public function boot(): void
{
config(['livewire-powergrid.filter' => 'outside']);
}
public function setUp(): array
{
$actions = [];
$header = PowerGrid::header()
->withoutLoading()
->showToggleColumns();
$header->includeViewOnTop('livewire.forms.headers.room-status-log');
$actions[]=$header;
$actions[]=PowerGrid::footer()->showPerPage()->showRecordCount();
return $actions;
}
public function datasource(): Builder
{
return RoomStatusLog::query()->latest();;
}
public function relationSearch(): array
{
return [];
}
public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('id')
->add('room_name', function (RoomStatusLog $model) {
return $model->room?->type->labelPowergridFilter().$model->room?->name;
})
->add('user_name', function (RoomStatusLog $model){
return $model->user?->name;
})
->add('status_str',function (RoomStatusLog $model){
return $model->status->labelPowergridFilter();
})
->add('message')
->add('created_at');
}
public function columns(): array
{
$column=[];
$column[]=Column::make(__('room-status-log.id'), 'id');
$column[]=Column::make(__('room-status-log.room'), 'room_name');
$column[]=Column::make(__('room-status-log.user'), 'user_name');
$column[]=Column::make(__('room-status-log.status'), 'status_str');
$column[]=Column::make(__('room-status-log.message'), 'message');
$column[]=Column::make(__('room-status-log.created_at'), 'created_at');
return $column;
}
public function filters(): array
{
return [
];
}
}

View File

@ -0,0 +1,263 @@
<?php
namespace App\Livewire\Tables;
use App\Models\Branch;
use App\Models\Room;
use App\Enums\RoomType;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Blade;
use Illuminate\Database\Eloquent\Builder;
use PowerComponents\LivewirePowerGrid\Button;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Facades\Filter;
use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridFields;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\Traits\WithExport;
use PowerComponents\LivewirePowerGrid\Components\SetUp\Exportable;
use Livewire\Attributes\On;
use WireUi\Traits\WireUiActions;
final class RoomTable extends PowerGridComponent
{
use WithExport, WireUiActions;
public string $tableName = 'room-table';
public bool $canCreate;
public bool $canEdit;
public bool $canDownload;
public bool $canDelect;
public ?int $selectedBranchId = null;
public ?string $external_ip= "";
public bool $showFilters = false;
public function boot(): void
{
config(['livewire-powergrid.filter' => 'outside']);
//權限設定
$this->canCreate = Auth::user()?->can('room-edit') ?? false;
$this->canEdit = Auth::user()?->can('room-edit') ?? false;
$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;
}
public function setUp(): array
{
if($this->canDownload || $this->canDelect){
$this->showCheckBox();
}
$actions = [];
if($this->canDownload){
$actions[]=PowerGrid::exportable(fileName: $this->tableName.'-file')
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV);
}
$header = PowerGrid::header()
->withoutLoading()
->showToggleColumns();
if($this->canCreate){
$header->includeViewOnTop('livewire.forms.headers.room');
}
$actions[]=$header;
$actions[]=PowerGrid::footer()->showPerPage()->showRecordCount();
return $actions;
}
public function header(): array
{
$actions = [];
if ($this->canDelect) {
$actions[]=Button::add('bulk-delete')
->slot('Bulk delete (<span x-text="window.pgBulkActions.count(\'' . $this->tableName . '\')"></span>)')
->icon('solid-trash',['id' => 'my-custom-icon-id', 'class' => 'font-bold'])
->class('inline-flex items-center gap-1 px-3 py-1 rounded ')
->dispatch('bulkDelete.' . $this->tableName, []);
}
return $actions;
}
public function datasource(): Builder
{
$query = Room::query()->orderBy('name');
if ($this->selectedBranchId) {
$query->where('branch_id', $this->selectedBranchId);
}
return $query;
}
public function updatedSelectedBranchId($value)
{
$this->resetPage(); // 重設分頁
}
public function relationSearch(): array
{
return [];
}
public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('id')
->add('floor')
->add('type_str',function(Room $model){
if ($this->canEdit) {
return Blade::render(
'<x-select-dropdown type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
[
'options' => RoomType::options(),
'modelId' => intval($model->id),
'fieldName'=>'type',
'selected' => $model->type->value
]
);
}
return $model->type->labelPowergridFilter();
})
->add('name')
->add('is_online', fn ($model) => $model->is_online===true ? '在線' : '斷線')
->add('status_str',function (Room $model){
return $model->status->labelPowergridFilter();
})
->add('str_started_at', fn (Room $model) => $model->str_started_at())
->add('str_ended_at', fn (Room $model) => $model->str_ended_at())
->add('created_at');
}
public function columns(): array
{
$column=[];
$column[]=Column::make(__('rooms.id'), 'id');
$column[]=Column::make(__('rooms.floor'), 'floor')->sortable()->searchable()->editOnClick(
hasPermission: $this->canEdit,
dataField: 'floor',
fallback: 'N/A',
saveOnMouseOut: true
);
$column[]=Column::make(__('rooms.type'), 'type_str','room.type')->sortable()->searchable();
$column[]=Column::make(__('rooms.name'), 'name')->sortable()->searchable()
->editOnClick(
hasPermission: $this->canEdit,
dataField: 'name',
fallback: 'N/A',
saveOnMouseOut: true
);
$column[]=Column::make(__('rooms.isOnline'), 'is_online');
$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);
$column[]=Column::make(__('rooms.created_at'), 'created_at')->sortable()->searchable();
$column[]=Column::action('Action');
return $column;
}
public function filters(): array
{
return [
Filter::datetimepicker('started_at'),
Filter::datetimepicker('ended_at'),
Filter::boolean('is_online')
->label('在線', '斷線'),
];
}
#[On('bulkDelete.{tableName}')]
public function bulkDelete(): void
{
if ($this->canDelect) {
$this->js('alert(window.pgBulkActions.get(\'' . $this->tableName . '\'))');
if($this->checkboxValues){
Branch::destroy($this->checkboxValues);
$this->js('window.pgBulkActions.clearAll()'); // clear the count on the interface.
}
}
}
#[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;
}
if ($fieldName == 'type' && $this->canEdit) {
$this->noUpdated($modelId,$fieldName,$value);
}
}
#[On('onUpdatedEditable')]
public function onUpdatedEditable($id, $field, $value): void
{
if($field === 'floor' && $this->canEdit){
if (!is_numeric($value)) {
$this->notification()->send([
'icon' => 'error',
'title' => '無效輸入',
'description' => '樓層必須是數字',
]);
return;
}
$this->noUpdated($id,$field,$value);
}else if ($field === 'name' && $this->canEdit) {
$this->noUpdated($id,$field,$value);
}
}
private function noUpdated($id,$field,$value){
$room = Room::find($id);
if ($room) {
$room->{$field} = $value;
$room->save(); // 明確觸發 saving
}
$this->notification()->send([
'icon' => 'success',
'title' => $id.'.'.__('room.'.$field).':'.$value,
'description' => '已經寫入',
]);
}
public function actions(Room $row): array
{
$actions = [];
if ($this->canEdit) {
$actions[] =Button::add('edit')
->slot(__('rooms.edit'))
->icon('solid-pencil-square')
->class('inline-flex items-center gap-1 px-3 py-1 rounded ')
->dispatchTo('forms.room-form', 'openModal', ['id' => $row->id]);
}
if($this->canDelect){
$actions[] =Button::add('delete')
->slot(__('rooms.delete'))
->icon('solid-trash')
->class('inline-flex items-center gap-1 px-3 py-1 rounded ')
->dispatchTo('forms.room-form', 'deleteRoom', ['id' => $row->id]);
}
if ($row->type->value === 'pc') {
$actions[] = Button::add('room-settings')
->slot('包廂設定')
->icon('solid-cog')
->class('inline-flex items-center gap-1 px-3 py-1 rounded ')
->dispatchTo('forms.modals.room-detail-modal', 'openModal', ['roomId' => $row->id]);
}
return $actions;
}
/*
public function actionRules($row): array
{
return [
// Hide button edit for ID 1
Rule::button('edit')
->when(fn($row) => $row->id === 1)
->hide(),
];
}
*/
}

View File

@ -107,7 +107,7 @@ final class SongTable extends PowerGridComponent
//->add('language_type_str', fn (Song $model) => SongLanguageType::from($model->language_type->value)->labels())
->add('language_type_str', function (Song $model) {
return Blade::render(
'<x-select-category type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
'<x-select-dropdown type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
[
'options' => SongLanguageType::options(),
'modelId' => intval($model->id),
@ -120,7 +120,7 @@ final class SongTable extends PowerGridComponent
//->add('situation_str', fn (Song $model) => SongSituation::from($model->situation->value)->labels())
->add('situation_str', function (Song $model){
return Blade::render(
'<x-select-category type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
'<x-select-dropdown type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
[
'options' => SongSituation::options(),
'modelId' => intval($model->id),
@ -214,8 +214,8 @@ final class SongTable extends PowerGridComponent
$this->js('window.pgBulkActions.clearAll()'); // clear the count on the interface.
}
}
#[On('categoryChanged')]
public function categoryChanged($value,$fieldName, $modelId): void
#[On('selectChanged')]
public function selectChanged($value,$fieldName, $modelId): void
{
// dd($value,$fieldName, $modelId);
if (in_array($fieldName, ['language_type', 'situation'])) {

View File

@ -97,7 +97,7 @@ final class TextAdsTable extends PowerGridComponent
->add('color_str', function (TextAd $model) {
if ($this->canEdit) {
return Blade::render(
'<x-select-category type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
'<x-select-dropdown type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
[
'options' => TextAdColors::options(),
'modelId' => intval($model->id),
@ -148,8 +148,8 @@ final class TextAdsTable extends PowerGridComponent
$this->js('window.pgBulkActions.clearAll()'); // clear the count on the interface.
}
}
#[On('categoryChanged')]
public function categoryChanged($value,$fieldName, $modelId): void
#[On('selectChanged')]
public function selectChanged($value,$fieldName, $modelId): void
{
//dd($value,$fieldName, $modelId);
if (in_array($fieldName, ['color'])) {

View File

@ -96,7 +96,7 @@ final class UserTable extends PowerGridComponent
->add('gender_str', function (User $model) {
if ($this->canEdit) {
return Blade::render(
'<x-select-category type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
'<x-select-dropdown type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
[
'options' => UserGender::options(),
'modelId' => intval($model->id),
@ -112,7 +112,7 @@ final class UserTable extends PowerGridComponent
->add('status_str', function (User $model) {
if ($this->canEdit) {
return Blade::render(
'<x-select-category type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
'<x-select-dropdown type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
[
'options' => UserStatus::options(),
'modelId' => intval($model->id),
@ -180,8 +180,8 @@ final class UserTable extends PowerGridComponent
}
}
}
#[On('categoryChanged')]
public function categoryChanged($value,$fieldName, $modelId): void
#[On('selectChanged')]
public function selectChanged($value,$fieldName, $modelId): void
{
// dd($value,$fieldName, $modelId);
if (in_array($fieldName,['gender','status']) && $this->canEdit) {

View File

@ -1,27 +0,0 @@
<?php
namespace App\View\Components;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
use Illuminate\View\Component;
class SelectCategory extends Component
{
/**
* Create a new component instance.
*/
public function __construct(public Collection $options, public int $modelId,public string $fieldName, public string $selected)
{
//dd($options,$modelId,$fieldName,$selected);
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.select-category');
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace App\View\Components;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
use Illuminate\View\Component;
class SelectDropdown extends Component
{
public Collection $options;
public ?string $fieldName;
public ?int $modelId;
public string|int|null $selected;
/**
* Create a new component instance.
*/
public function __construct( Collection $options, int|null $modelId = null, string|null $fieldName = null, string|int|null $selected = null)
{
//dd($options,$modelId,$fieldName,$selected);
$this->options = $options;
$this->fieldName = $fieldName;
$this->modelId = $modelId;
$this->selected = $selected;
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.select-dropdown');
}
}

BIN
database/.DS_Store vendored

Binary file not shown.

View File

@ -0,0 +1,5 @@
<?php
return [
'list' => '操作記錄'
];

View File

@ -0,0 +1,13 @@
<?php
return [
'list' => '包廂狀態紀錄',
'id' => '編號',
'room' => '包廂',
'user' => '操成者',
'status' => '狀態',
'message' => '紀錄',
'created_at' => '建立於'
];

View File

@ -0,0 +1,29 @@
<?php
return [
'list' => '包廂列表',
'CreateNew' => '新增包廂',
'EditRoom' => '編輯包廂',
'create' => '新增',
'edit' => '編輯',
'delete' => '刪除',
'id' =>'編號',
'floor' =>'樓層',
'type' =>'型別',
'name' =>'名稱',
'isOnline' =>'在線',
'status' =>'狀態',
'started_at' =>'開始於',
'ended_at' =>'結束於',
'created_at' =>'建立於',
'active' => '正常',
'error' => '維修',
'select_type' =>'選擇型別',
'actions' => '操作',
'view' => '查看',
'submit' => '提交',
'cancel' => '取消',
];

View File

@ -0,0 +1,11 @@
<div class="flex items-center gap-2">
<x-select-dropdown
:options="App\Models\Branch::pluck('name', 'id')"
fieldName="selectedBranchId"
:modelId="0"
:selected="$selectedBranchId"
/>
@if ($selectedBranchId)
<span class="text-lg font-semibold whitespace-nowrap">- 包廂設定 ({{ $external_ip }})</span>
@endif
</div>

View File

@ -1,9 +1,9 @@
<div class="bg-white px-4 py-3 shadow-sm border rounded-md mb-4">
<div class="flex items-center justify-between">
{{-- 左邊標題 --}}
<h2 class="text-lg font-semibold text-gray-800">
{{ $title }}
</h2>
<div>
{!! $title !!}
</div>
{{-- 右邊 slot 注入按鈕群 --}}
<div class="flex gap-3">

View File

@ -1,6 +1,6 @@
@props(['selected','fieldName', 'modelId'])
@props(['options', 'modelId' , 'fieldName', 'selected' ])
<div>
<select wire:change="categoryChanged($event.target.value,'{{ $fieldName}}', {{ $modelId }})">
<select wire:change="selectChanged($event.target.value,'{{ $fieldName}}', {{ $modelId }})" class="border rounded">
@foreach ($options as $id => $name)
<option
value="{{ $id }}"

View File

@ -2,7 +2,6 @@
<x-layouts.admin>
<x-wireui:notifications/>
<livewire:tables.branch-table />
<livewire:grids.room-grid />
<livewire:forms.branch-form />
<livewire:forms.import-datas.branch />
</x-layouts.admin>

View File

@ -0,0 +1,4 @@
<x-layouts.admin>
<livewire:grids.room-grid />
</x-layouts.admin>

View File

@ -0,0 +1,3 @@
<x-layouts.admin>
<livewire:tables.room-status-log-table />
</x-layouts.admin>

View File

@ -0,0 +1,7 @@
<x-layouts.admin>
<x-wireui:notifications/>
<livewire:tables.room-table/>
<livewire:forms.room-form />
<livewire:grids.modals.room-detail-modal />
</x-layouts.admin>

View File

@ -0,0 +1,2 @@
<x-admin.section-header title="{{ __('room-status-log.list') }}">
</x-admin.section-header>

View File

@ -0,0 +1,10 @@
<x-admin.section-header :title="view('components.admin.branch-select', ['selectedBranchId' => $selectedBranchId,'external_ip' => $external_ip])">
@if ($canCreate)
<x-wireui:button
wire:click="$dispatchTo('forms.room-form', 'openModal')"
icon="plus"
label="{{ __('rooms.CreateNew') }}"
class="bg-blue-600 text-white"
/>
@endif
</x-admin.section-header>

View File

@ -0,0 +1,21 @@
<x-wireui:modal-card title="{{ $roomId ? __('rooms.EditRoom') : __('rooms.CreateNew') }}" blur wire:model.defer="showModal">
<div class="space-y-4">
<x-wireui:input type="number" label="{{__('rooms.floor')}}" wire:model.defer="fields.floor" />
<x-wireui:select
label="{{__('rooms.type')}}"
wire:model.defer="fields.type"
placeholder="{{__('rooms.select_type')}}"
:options="$typeOptions"
option-label="name"
option-value="value"
/>
<x-wireui:input label="{{__('rooms.name')}}" wire:model.defer="fields.name" />
</div>
<x-slot name="footer">
<div class="flex justify-between w-full">
<x-wireui:button flat label="{{__('rooms.cancel')}}" wire:click="closeModal" />
<x-wireui:button primary label="{{__('rooms.submit')}}" wire:click="save" />
</div>
</x-slot>
</x-wireui:modal-card>

View File

@ -1,11 +1,17 @@
<x-wireui:modal id="room-grid-modal" wire:model.defer="showModal" persistent>
<x-wireui:card class="border border-gray-200 w-full">
<x-slot name="action">
<button class="cursor-pointer p-1 rounded-full text-secondary-300 focus:ring-2 focus:ring-secondary-200" wire:click="closeModal">
<x-dynamic-component :component="WireUi::component('icon')" name="x-mark" class="w-5 h-5"/>
</button>
<x-wireui:card class="border border-gray-200 w-full">
<x-slot name="title">
<div class="flex items-center gap-2">
<x-select-dropdown
:options="App\Models\Branch::pluck('name', 'id')"
fieldName="selectedBranchId"
:modelId="0"
:selected="$selectedBranchId"
/>
<span class="text-lg font-semibold whitespace-nowrap">
{{ $selectedBranchId ? " - 包廂設定 ($external_ip)" : '' }}
</span>
</div>
</x-slot>
<x-slot name="title">{{ $branchName }} - 包廂設定</x-slot>
<div x-data="{ floor: '{{ $floors[0] ?? 1 }}', type: 'all' }">
{{-- 樓層 Tab --}}
@ -35,7 +41,7 @@
</div>
{{-- 房間卡片列表 --}}
<div @if($showModal) wire:poll.5s @endif>
<div >
<div class="grid grid-cols-3 md:grid-cols-4 lg:grid-cols-6 gap-4">
@forelse($rooms as $room)
<template x-if="floor == '{{ $room->floor }}' && (type == 'all' || type == '{{ $room->type }}')">
@ -55,5 +61,4 @@
</div>
<livewire:grids.modals.room-detail-modal />
</x-wireui:card>
</x-wireui:modal>
</x-wireui:card>

View File

@ -8,11 +8,14 @@ new class extends Component
public array $menus=[
['label' => 'Dashboard', 'route' => 'admin.dashboard', 'icon' => 'home', 'permission' => null],
['label' => 'ActivityLog', 'route' => 'admin.activity-log', 'icon' => 'clock', 'permission' => null],
['label' => 'RoomStatusLog', 'route' => 'admin.room-status-log', 'icon' => 'clock', 'permission' => null],
['label' => 'Role', 'route' => 'admin.roles', 'icon' => 'user-circle', 'permission' => 'role-list'],
['label' => 'User', 'route' => 'admin.users', 'icon' => 'user-circle', 'permission' => 'user-list'],
['label' => 'Artist', 'route' => 'admin.artists', 'icon' => 'musical-note', 'permission' => 'song-list'],
['label' => 'Song', 'route' => 'admin.songs', 'icon' => 'musical-note', 'permission' => 'song-list'],
['label' => 'Branche', 'route' => 'admin.branches', 'icon' => 'building-library', 'permission' => 'room-list'],
['label' => 'Room', 'route' => 'admin.rooms', 'icon' => 'building-library', 'permission' => 'room-list'],
['label' => 'RoomGrid', 'route' => 'admin.room-grids', 'icon' => 'film', 'permission' => 'room-list'],
['label' => 'TextAd', 'route' => 'admin.text-ads', 'icon' => 'megaphone', 'permission' => 'text-ad-list'],
];

View File

@ -22,11 +22,13 @@ require __DIR__.'/auth.php';
Route::middleware(['auth'])->prefix('admin')->name('admin.')->group(function () {
Route::get('/dashboard', AdminDashboard::class)->name('dashboard');
Route::get('/activity-log', function () {return view('livewire.admin.activity-log');})->name('activity-log');
Route::get('/room-status-log', function () {return view('livewire.admin.room-status-log');})->name('room-status-log');
Route::get('/roles', function () {return view('livewire.admin.roles');})->name('roles');
Route::get('/users', function () {return view('livewire.admin.users');})->name('users');
Route::get('/artists', function () {return view('livewire.admin.artists');})->name('artists');
Route::get('/songs', function () {return view('livewire.admin.songs');})->name('songs');
Route::get('/branches', function () {return view('livewire.admin.branches');})->name('branches');
Route::get('/rooms', function () {return view('livewire.admin.rooms');})->name('rooms');
Route::get('/room-grids', function () {return view('livewire.admin.room-grids');})->name('room-grids');
Route::get('/text-ads', function () {return view('livewire.admin.text-ads');})->name('text-ads');
});