單機版 v.0.1.0 20250625
檔案搬移
This commit is contained in:
parent
5abc0c0d70
commit
35485bf3f8
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
namespace App\Livewire\Forms\Tables;
|
||||
|
||||
use App\Models\ActivityLog;
|
||||
use Illuminate\Support\Carbon;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
namespace App\Livewire\Forms\Tables;
|
||||
|
||||
use App\Models\Artist;
|
||||
use App\Enums\ArtistCategory;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
namespace App\Livewire\Forms\Tables;
|
||||
|
||||
use App\Models\Branch;
|
||||
use Illuminate\Support\Carbon;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
namespace App\Livewire\Forms\Tables;
|
||||
|
||||
use App\Models\MachineStatus;
|
||||
use Illuminate\Support\Carbon;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
namespace App\Livewire\Forms\Tables;
|
||||
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Spatie\Permission\Models\Permission;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
namespace App\Livewire\Forms\Tables;
|
||||
|
||||
use App\Models\RoomStatusLog;
|
||||
use Illuminate\Support\Carbon;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
namespace App\Livewire\Forms\Tables;
|
||||
|
||||
use App\Models\Room;
|
||||
use App\Enums\RoomType;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
namespace App\Livewire\Forms\Tables;
|
||||
|
||||
use App\Models\Song;
|
||||
use App\Models\SongLibraryCache;
|
208
app/Livewire/Forms/Tables/TextAdTable.php
Normal file
208
app/Livewire/Forms/Tables/TextAdTable.php
Normal file
@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Forms\Tables;
|
||||
|
||||
use App\Models\TextAd;
|
||||
use App\Enums\TextAdColors;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Carbon;
|
||||
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 TextAdTable extends PowerGridComponent
|
||||
{
|
||||
use WithExport, WireUiActions;
|
||||
public string $tableName = 'text-ad-table';
|
||||
|
||||
public bool $canCreate;
|
||||
public bool $canEdit;
|
||||
public bool $canDownload;
|
||||
public bool $canDelect;
|
||||
|
||||
public bool $showFilters = false;
|
||||
public function boot(): void
|
||||
{
|
||||
config(['livewire-powergrid.filter' => 'outside']);
|
||||
$this->canCreate = Auth::user()?->can('text-ad-create') ?? false;
|
||||
$this->canEdit = Auth::user()?->can('text-ad-edit') ?? false;
|
||||
$this->canDownload=Auth::user()?->can('text-ad-delete') ?? false;
|
||||
$this->canDelect = Auth::user()?->can('text-ad-delete') ?? false;
|
||||
}
|
||||
|
||||
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()->showSoftDeletes()->showToggleColumns();
|
||||
if($this->canCreate){
|
||||
$header->includeViewOnTop('livewire.header.text-ad');
|
||||
}
|
||||
$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
|
||||
{
|
||||
return TextAd::query();
|
||||
}
|
||||
|
||||
public function relationSearch(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function fields(): PowerGridFields
|
||||
{
|
||||
return PowerGrid::fields()
|
||||
->add('id')
|
||||
->add('content')
|
||||
->add(
|
||||
'content_short',
|
||||
fn (TextAd $model) =>
|
||||
'<span title="' . e($model->content) . '">' . e(Str::limit($model->content, 50)) . '</span>'
|
||||
)
|
||||
->add('color')
|
||||
->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/>',
|
||||
[
|
||||
'options' => TextAdColors::options(),
|
||||
'modelId' => intval($model->id),
|
||||
'fieldName'=>'color',
|
||||
'selected' => $model->color->value
|
||||
]
|
||||
);
|
||||
}
|
||||
// 沒有權限就顯示對應的文字
|
||||
|
||||
return $model->color->labelPowergridFilter(); // 假設 label() 會回傳顯示文字
|
||||
} )
|
||||
->add('duration')
|
||||
->add('is_active')
|
||||
->add('created_at');
|
||||
}
|
||||
|
||||
public function columns(): array
|
||||
{
|
||||
$column=[];
|
||||
$column[] = Column::make(__('text_ads.id'), 'id');
|
||||
$column[] = Column::make(__('text_ads.content'), 'content_short', 'text_ads.content')->sortable()->searchable();
|
||||
$column[] = Column::make(__('text_ads.color'),'color_str', 'text-ads.color')->searchable();
|
||||
$column[] = Column::make(__('text_ads.duration'), 'duration')->sortable()->searchable();
|
||||
$column[] = Column::make(__('text_ads.is_active'), 'is_active')->toggleable(hasPermission: $this->canEdit, trueLabel: 'yes', falseLabel: 'no');
|
||||
$column[] = Column::make(__('text_ads.created_at'), 'created_at')->sortable()->searchable();
|
||||
$column[] = Column::action(__('text_ads.actions'));
|
||||
return $column;
|
||||
}
|
||||
|
||||
public function filters(): array
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
#[On('bulkDelete.{tableName}')]
|
||||
public function bulkDelete(): void
|
||||
{
|
||||
$this->js('alert(window.pgBulkActions.get(\'' . $this->tableName . '\'))');
|
||||
if($this->checkboxValues){
|
||||
foreach ($this->checkboxValues as $id) {
|
||||
$textAd = TextAd::find($id);
|
||||
if ($textAd) {
|
||||
$textAd->delete();
|
||||
}
|
||||
}
|
||||
$this->js('window.pgBulkActions.clearAll()'); // clear the count on the interface.
|
||||
}
|
||||
}
|
||||
#[On('categoryChanged')]
|
||||
public function categoryChanged($value,$fieldName, $modelId): void
|
||||
{
|
||||
//dd($value,$fieldName, $modelId);
|
||||
if (in_array($fieldName, ['color'])) {
|
||||
$this->noUpdated($modelId,$fieldName,$value);
|
||||
}
|
||||
}
|
||||
#[On('onUpdatedEditable')]
|
||||
public function onUpdatedEditable($id, $field, $value): void
|
||||
{
|
||||
if (in_array($field,[
|
||||
''
|
||||
]) && $this->canEdit) {
|
||||
$this->noUpdated($id,$field,$value);
|
||||
}
|
||||
}
|
||||
#[On('onUpdatedToggleable')]
|
||||
public function onUpdatedToggleable($id, $field, $value): void
|
||||
{
|
||||
if (in_array($field,['is_active']) && $this->canEdit) {
|
||||
$this->noUpdated($id,$field,$value);
|
||||
}
|
||||
}
|
||||
private function noUpdated($id,$field,$value){
|
||||
$textAd = TextAd::find($id);
|
||||
if ($textAd) {
|
||||
$textAd->{$field} = $value;
|
||||
$textAd->save(); // 明確觸發 saving
|
||||
}
|
||||
$this->notification()->send([
|
||||
'icon' => 'success',
|
||||
'title' => $id.'.'.__('text_ads.'.$field).':'.$value,
|
||||
'description' => '已經寫入',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function actions(TextAd $row): array
|
||||
{
|
||||
$actions = [];
|
||||
if ($this->canEdit) {
|
||||
$actions[]=Button::add('edit')
|
||||
->slot(__('text_ads.edit'))
|
||||
->icon('solid-pencil-square')
|
||||
->class('inline-flex items-center gap-1 px-3 py-1 rounded ')
|
||||
->dispatchTo('forms.text-ads-form', 'openModal', ['id' => $row->id]);
|
||||
}
|
||||
if($this->canDelect){
|
||||
$actions[]=Button::add('delete')
|
||||
->slot(__('text_ads.delete'))
|
||||
->icon('solid-trash')
|
||||
->class('inline-flex items-center gap-1 px-3 py-1 rounded ')
|
||||
->dispatchTo('forms.text-ads-form', 'deleteTextAd', ['id' => $row->id]);
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
namespace App\Livewire\Forms\Tables;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Enums\UserGender;
|
@ -1,4 +1,4 @@
|
||||
|
||||
<x-layouts.admin>
|
||||
<livewire:forms.activity-log-table />
|
||||
<livewire:forms.tables.activity-log-table />
|
||||
</x-layouts.admin>
|
@ -1,7 +1,7 @@
|
||||
|
||||
<x-layouts.admin>
|
||||
<x-wireui:notifications/>
|
||||
<livewire:forms.artist-table />
|
||||
<livewire:forms.tables.artist-table />
|
||||
<livewire:forms.artist-form />
|
||||
<livewire:forms.artist-import-data />
|
||||
</x-layouts.admin>
|
@ -1,7 +1,7 @@
|
||||
|
||||
<x-layouts.admin>
|
||||
<x-wireui:notifications/>
|
||||
<livewire:forms.branch-table />
|
||||
<livewire:forms.tables.branch-table />
|
||||
<livewire:forms.room-grid />
|
||||
<livewire:forms.branch-form />
|
||||
<livewire:forms.branch-import-data />
|
||||
|
@ -1,3 +1,3 @@
|
||||
<x-layouts.admin>
|
||||
<livewire:forms.machine-status-table />
|
||||
<livewire:forms.tables.machine-status-table />
|
||||
</x-layouts.admin>
|
@ -1,6 +1,6 @@
|
||||
|
||||
<x-layouts.admin>
|
||||
<x-wireui:notifications/>
|
||||
<livewire:forms.role-table />
|
||||
<livewire:forms.tables.role-table />
|
||||
<livewire:forms.role-form />
|
||||
</x-layouts.admin>
|
@ -1,3 +1,3 @@
|
||||
<x-layouts.admin>
|
||||
<livewire:forms.room-status-log-table />
|
||||
<livewire:forms.tables.room-status-log-table />
|
||||
</x-layouts.admin>
|
@ -1,7 +1,7 @@
|
||||
|
||||
<x-layouts.admin>
|
||||
<x-wireui:notifications/>
|
||||
<livewire:forms.room-table/>
|
||||
<livewire:forms.tables.room-table/>
|
||||
<livewire:forms.room-form />
|
||||
<livewire:forms.modals.room-detail-modal />
|
||||
</x-layouts.admin>
|
@ -1,7 +1,7 @@
|
||||
|
||||
<x-layouts.admin>
|
||||
<x-wireui:notifications/>
|
||||
<livewire:forms.song-table />
|
||||
<livewire:forms.tables.song-table />
|
||||
<livewire:forms.song-form />
|
||||
<livewire:forms.song-import-data />
|
||||
</x-layouts.admin>
|
@ -1,6 +1,6 @@
|
||||
|
||||
<x-layouts.admin>
|
||||
<x-wireui:notifications/>
|
||||
<livewire:forms.user-table />
|
||||
<livewire:forms.tables.user-table />
|
||||
<livewire:forms.user-form />
|
||||
</x-layouts.admin>
|
Loading…
x
Reference in New Issue
Block a user