diff --git a/app/Http/Controllers/Admin/BasicSettings/MachineSettingController.php b/app/Http/Controllers/Admin/BasicSettings/MachineSettingController.php index 8d20bf9..9d4f922 100644 --- a/app/Http/Controllers/Admin/BasicSettings/MachineSettingController.php +++ b/app/Http/Controllers/Admin/BasicSettings/MachineSettingController.php @@ -22,51 +22,83 @@ class MachineSettingController extends AdminController /** * 顯示機台與型號設定列表 (採用標籤頁整合) */ - public function index(Request $request): View + public function index(Request $request): View|\Illuminate\Http\Response { $tab = $request->input('tab', 'machines'); $per_page = $request->input('per_page', 10); $search = $request->input('search'); + $isAjax = $request->boolean('_ajax'); - // 1. 處理機台清單 (Machines Tab) - $machineQuery = Machine::query()->with(['machineModel', 'paymentConfig', 'company']); - if ($tab === 'machines' && $search) { - $machineQuery->where(function ($q) use ($search) { - $q->where('name', 'like', "%{$search}%") - ->orWhere('serial_no', 'like', "%{$search}%"); - }); - } - $machines = $machineQuery->latest()->paginate($per_page)->withQueryString(); + // AJAX 模式:只查當前 Tab 的搜尋/分頁結果 + if ($isAjax) { + $machines = null; + $models_list = null; + $users_list = null; - // 2. 處理型號清單 (Models Tab) - $modelQuery = MachineModel::query()->withCount('machines'); - if ($tab === 'models' && $search) { - $modelQuery->where('name', 'like', "%{$search}%"); - } - $models_list = $modelQuery->latest()->paginate($per_page)->withQueryString(); + switch ($tab) { + case 'machines': + $machineQuery = Machine::query()->with(['machineModel', 'paymentConfig', 'company']); + if ($search) { + $machineQuery->where(function ($q) use ($search) { + $q->where('name', 'like', "%{$search}%") + ->orWhere('serial_no', 'like', "%{$search}%"); + }); + } + $machines = $machineQuery->latest()->paginate($per_page)->withQueryString(); + break; - // 3. 處理機台權限 (Permissions Tab) - 僅顯示 is_admin 帳號 - $users_list = null; - if ($tab === 'permissions') { - $userQuery = \App\Models\System\User::query() - ->where('is_admin', true) - ->with(['company', 'machines']); - - if ($search) { - $userQuery->where(function($q) use ($search) { - $q->where('name', 'like', "%{$search}%") - ->orWhere('username', 'like', "%{$search}%"); - }); + case 'models': + $modelQuery = MachineModel::query()->withCount('machines'); + if ($search) { + $modelQuery->where('name', 'like', "%{$search}%"); + } + $models_list = $modelQuery->latest()->paginate($per_page)->withQueryString(); + break; + + case 'permissions': + $userQuery = \App\Models\System\User::query() + ->where('is_admin', true) + ->with(['company', 'machines']); + if ($search) { + $userQuery->where(function($q) use ($search) { + $q->where('name', 'like', "%{$search}%") + ->orWhere('username', 'like', "%{$search}%"); + }); + } + if ($request->filled('company_id')) { + $userQuery->where('company_id', $request->company_id); + } + $users_list = $userQuery->latest()->paginate($per_page)->withQueryString(); + break; } - if ($request->filled('company_id')) { - $userQuery->where('company_id', $request->company_id); - } + $companies = \App\Models\System\Company::select('id', 'name', 'code')->get(); - $users_list = $userQuery->latest()->paginate($per_page)->withQueryString(); + $tabView = match($tab) { + 'models' => 'admin.basic-settings.machines.partials.tab-models', + 'permissions' => 'admin.basic-settings.machines.partials.tab-permissions', + default => 'admin.basic-settings.machines.partials.tab-machines', + }; + return response()->view($tabView, compact( + 'machines', 'models_list', 'users_list', 'companies', 'tab' + )); } - // 4. 基礎下拉資料 (用於新增/編輯機台的彈窗) + // SSR 模式:一次查好全部三個 Tab 的首頁資料(供 x-show 即時切換) + $machines = Machine::query() + ->with(['machineModel', 'paymentConfig', 'company']) + ->latest()->paginate($per_page)->withQueryString(); + + $models_list = MachineModel::query() + ->withCount('machines') + ->latest()->paginate($per_page)->withQueryString(); + + $userQuery = \App\Models\System\User::query() + ->where('is_admin', true) + ->with(['company', 'machines']); + $users_list = $userQuery->latest()->paginate($per_page)->withQueryString(); + + // 基礎下拉資料 (用於新增/編輯機台的彈窗) $models = MachineModel::select('id', 'name')->get(); $paymentConfigs = PaymentConfig::select('id', 'name')->get(); $companies = \App\Models\System\Company::select('id', 'name', 'code')->get(); diff --git a/lang/en.json b/lang/en.json index b8ff430..b7dc3be 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1153,5 +1153,6 @@ "Waiting": "Waiting", "Publish Time": "Publish Time", "Expired Time": "Expired Time", - "Inventory synced with machine": "Inventory synced with machine" + "Inventory synced with machine": "Inventory synced with machine", + "Failed to load tab content": "Failed to load tab content" } \ No newline at end of file diff --git a/lang/ja.json b/lang/ja.json index b449490..3831844 100644 --- a/lang/ja.json +++ b/lang/ja.json @@ -1152,5 +1152,6 @@ "Waiting": "待機中", "Publish Time": "公開時間", "Expired Time": "終了時間", - "Inventory synced with machine": "在庫が機体と同期されました" + "Inventory synced with machine": "在庫が機体と同期されました", + "Failed to load tab content": "タブコンテンツの読み込みに失敗しました" } \ No newline at end of file diff --git a/lang/zh_TW.json b/lang/zh_TW.json index a0a0518..fbced3a 100644 --- a/lang/zh_TW.json +++ b/lang/zh_TW.json @@ -1158,5 +1158,6 @@ "Waiting": "等待中", "Publish Time": "發布時間", "Expired Time": "下架時間", - "Inventory synced with machine": "庫存已與機台同步" + "Inventory synced with machine": "庫存已與機台同步", + "Failed to load tab content": "載入分頁內容失敗" } \ No newline at end of file diff --git a/resources/views/admin/basic-settings/machines/index.blade.php b/resources/views/admin/basic-settings/machines/index.blade.php index 5bd1ef3..72b1cde 100644 --- a/resources/views/admin/basic-settings/machines/index.blade.php +++ b/resources/views/admin/basic-settings/machines/index.blade.php @@ -3,6 +3,11 @@ @section('content')
{{ __('Management of operational parameters and models') }}
{{ __('Loading Data') }}...
| - {{ __('Machine Info') }} | -- {{ __('Machine Model') }} | -- {{ __('Status') }} | -- {{ __('Card Reader') }} | -- {{ __('Owner') }} | -- {{ __('Action') }} | -
|---|---|---|---|---|---|
| toJson() }}, {{ $machine->id }}, "{{ $machine->serial_no }}")'>
-
-
-
- @if(isset($machine->image_urls[0]))
-
-
-
-
- {{ $machine->name }}
-
- {{
- $machine->serial_no }}
-
- |
- toJson() }}, {{ $machine->id }}, "{{ $machine->serial_no }}")'> - - {{ $machine->machineModel->name ?? '--' }} - - | -
- @php
- $isOnline = $machine->last_heartbeat_at && $machine->last_heartbeat_at->diffInSeconds() < 30;
- @endphp
-
-
- @if($isOnline)
-
-
- @else
-
- @endif
-
-
- {{ $isOnline ? __('Online') : __('Offline') }}
-
- |
-
-
- {{ $machine->card_reader_seconds ?? 0 }}s / No.{{
- $machine->card_reader_no ?? '--' }}
+
+
+
+
-
+ @include('admin.basic-settings.machines.partials.tab-machines')
+
|
- - - {{ $machine->company->name ?? __('System') }} - - | -
- |
-
| - {{ __('No data available') }} - | -|||||
| - {{ __('Account Info') }} | -- {{ __('Company Name') }} | -- {{ __('Authorized Machines') }} | -- {{ __('Action') }} | -
|---|---|---|---|
|
-
-
-
-
-
-
- {{
- $user->name }}
- {{
- $user->username }}
-
- |
- - - {{ $user->company->name ?? __('System') }} - - | -- - | -
- |
-
|
-
-
-
- {{ __('No accounts found') }} - |
- |||
| - {{ __('Model Name') }} | -- {{ __('Machine Count') }} | -- {{ __('Last Updated') }} | -- {{ __('Action') }} | -
|---|---|---|---|
|
-
-
-
-
-
-
- {{ $model->name }}
- |
- - - {{ $model->machines_count ?? 0 }} {{ __('Items') }} - - | -
-
- {{ $model->updated_at->format('Y/m/d H:i') }}
-
- |
-
-
-
- |
-
| - {{ __('No data available') }} - | -|||
| + {{ __('Machine Info') }} | ++ {{ __('Machine Model') }} | ++ {{ __('Status') }} | ++ {{ __('Card Reader') }} | ++ {{ __('Owner') }} | ++ {{ __('Action') }} | +
|---|---|---|---|---|---|
| toJson() }}, {{ $machine->id }}, "{{ $machine->serial_no }}")'>
+
+
+
+ @if(isset($machine->image_urls[0]))
+
+
+
+
+ {{ $machine->name }}
+
+ {{
+ $machine->serial_no }}
+
+ |
+ toJson() }}, {{ $machine->id }}, "{{ $machine->serial_no }}")'> + + {{ $machine->machineModel->name ?? '--' }} + + | +
+ @php
+ $isOnline = $machine->last_heartbeat_at && $machine->last_heartbeat_at->diffInSeconds() < 30;
+ @endphp
+
+
+ @if($isOnline)
+
+
+ @else
+
+ @endif
+
+
+ {{ $isOnline ? __('Online') : __('Offline') }}
+
+ |
+
+
+ {{ $machine->card_reader_seconds ?? 0 }}s / No.{{
+ $machine->card_reader_no ?? '--' }}
+
+ |
+ + + {{ $machine->company->name ?? __('System') }} + + | +
+ |
+
| + {{ __('No data available') }} + | +|||||
| + {{ __('Model Name') }} | ++ {{ __('Machine Count') }} | ++ {{ __('Last Updated') }} | ++ {{ __('Action') }} | +
|---|---|---|---|
|
+
+
+
+
+
+
+ {{ $model->name }}
+ |
+ + + {{ $model->machines_count ?? 0 }} {{ __('Items') }} + + | +
+
+ {{ $model->updated_at->format('Y/m/d H:i') }}
+
+ |
+
+
+
+ |
+
| + {{ __('No data available') }} + | +|||
| + {{ __('Account Info') }} | ++ {{ __('Company Name') }} | ++ {{ __('Authorized Machines') }} | ++ {{ __('Action') }} | +
|---|---|---|---|
|
+
+
+
+
+
+
+ {{
+ $user->name }}
+ {{
+ $user->username }}
+
+ |
+ + + {{ $user->company->name ?? __('System') }} + + | ++ + | +
+ |
+
|
+
+
+
+ {{ __('No accounts found') }} + |
+ |||