table 可以修改 歌手類別,歌曲語別,歌曲情境 20250502
This commit is contained in:
parent
c2aaff1f30
commit
3a609e495f
@ -5,6 +5,8 @@ namespace App\Livewire\Admin;
|
||||
use App\Models\Artist;
|
||||
use App\Enums\ArtistCategory;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use PowerComponents\LivewirePowerGrid\Button;
|
||||
use PowerComponents\LivewirePowerGrid\Column;
|
||||
@ -72,9 +74,20 @@ final class ArtistTable extends PowerGridComponent
|
||||
|
||||
public function fields(): PowerGridFields
|
||||
{
|
||||
$options = $this->categorySelectOptions();
|
||||
|
||||
return PowerGrid::fields()
|
||||
->add('id')
|
||||
->add('category_str', fn (Artist $model) => ArtistCategory::from($model->category->value)->labels())
|
||||
->add('category_str', function (Artist $model) use ($options){
|
||||
return Blade::render(
|
||||
'<x-select-category type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
|
||||
[
|
||||
'options' => $options,
|
||||
'modelId' => intval($model->id),
|
||||
'fieldName'=>'category',
|
||||
'selected' => $model->category->value
|
||||
]);
|
||||
} )
|
||||
->add('name')
|
||||
->add('simplified')
|
||||
->add('phonetic_abbr')
|
||||
@ -116,6 +129,20 @@ final class ArtistTable extends PowerGridComponent
|
||||
];
|
||||
}
|
||||
|
||||
public function categorySelectOptions():Collection
|
||||
{
|
||||
return collect(ArtistCategory::cases())->mapWithKeys(function (ArtistCategory $case) {
|
||||
return [$case->value => $case->labels()];
|
||||
});
|
||||
}
|
||||
#[On('categoryChanged')]
|
||||
public function categoryChanged($value,$fieldName, $modelId): void
|
||||
{
|
||||
// dd($value,$fieldName, $modelId);
|
||||
if($fieldName=='category'){
|
||||
Artist::find($modelId)?->update([$fieldName => $value]);
|
||||
}
|
||||
}
|
||||
public function filters(): array
|
||||
{
|
||||
return [
|
||||
|
@ -6,6 +6,8 @@ use App\Models\Song;
|
||||
use App\Enums\SongLanguageType;
|
||||
use App\Enums\SongSituation;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use PowerComponents\LivewirePowerGrid\Button;
|
||||
use PowerComponents\LivewirePowerGrid\Column;
|
||||
@ -86,11 +88,31 @@ final class SongTable extends PowerGridComponent
|
||||
->add('filename')
|
||||
->add('adddate_formatted', fn (Song $model) => Carbon::parse($model->adddate)->format('Y-m-d'))
|
||||
->add('song_artists' ,fn(Song $model)=> $model->str_artists())
|
||||
->add('language_type_str', fn (Song $model) => SongLanguageType::from($model->language_type->value)->labels())
|
||||
//->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/>',
|
||||
[
|
||||
'options' => $this->languageTypeSelectOptions(),
|
||||
'modelId' => intval($model->id),
|
||||
'fieldName'=>'language_type',
|
||||
'selected' => $model->language_type->value
|
||||
]);
|
||||
} )
|
||||
->add('song_categories', fn(Song $model) => $model->str_categories())
|
||||
->add('db_change')
|
||||
->add('vocal')
|
||||
->add('situation_str', fn (Song $model) => SongSituation::from($model->situation->value)->labels())
|
||||
//->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/>',
|
||||
[
|
||||
'options' => $this->situationSelectOptions(),
|
||||
'modelId' => intval($model->id),
|
||||
'fieldName'=>'situation',
|
||||
'selected' => $model->situation->value
|
||||
]);
|
||||
} )
|
||||
->add('copyright01')
|
||||
->add('copyright02')
|
||||
->add('note01')
|
||||
@ -160,7 +182,8 @@ final class SongTable extends PowerGridComponent
|
||||
Column::make(__('songs.note02'), 'note02')
|
||||
->sortable()
|
||||
->searchable()
|
||||
->editOnClick(hasPermission: true, dataField: 'note02', fallback: 'N/A', saveOnMouseOut: true),
|
||||
->editOnClick(hasPermission: true, dataField: 'note02', fallback: 'N/A', saveOnMouseOut: true)
|
||||
->hidden(true, false),
|
||||
|
||||
Column::make(__('songs.note03'), 'note03')
|
||||
->sortable()
|
||||
@ -208,7 +231,26 @@ final class SongTable extends PowerGridComponent
|
||||
Filter::datetimepicker('created_at'),
|
||||
];
|
||||
}
|
||||
|
||||
public function languageTypeSelectOptions():Collection
|
||||
{
|
||||
return collect(SongLanguageType::cases())->mapWithKeys(function (SongLanguageType $case) {
|
||||
return [$case->value => $case->labels()];
|
||||
});
|
||||
}
|
||||
public function situationSelectOptions():Collection
|
||||
{
|
||||
return collect(SongSituation::cases())->mapWithKeys(function (SongSituation $case) {
|
||||
return [$case->value => $case->labels()];
|
||||
});
|
||||
}
|
||||
#[On('categoryChanged')]
|
||||
public function categoryChanged($value,$fieldName, $modelId): void
|
||||
{
|
||||
// dd($value,$fieldName, $modelId);
|
||||
if (in_array($fieldName, ['language_type', 'situation'])) {
|
||||
Artist::find($modelId)?->update([$fieldName => $value]);
|
||||
}
|
||||
}
|
||||
#[On('bulkDelete.{tableName}')]
|
||||
public function bulkDelete(): void
|
||||
{
|
||||
|
27
app/View/Components/SelectCategory.php
Normal file
27
app/View/Components/SelectCategory.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
16
resources/views/components/select-category.blade.php
Normal file
16
resources/views/components/select-category.blade.php
Normal file
@ -0,0 +1,16 @@
|
||||
@props(['selected','fieldName', 'modelId'])
|
||||
<div>
|
||||
<select wire:change="categoryChanged($event.target.value,'{{ $fieldName}}', {{ $modelId }})">
|
||||
@foreach ($options as $id => $name)
|
||||
<option
|
||||
value="{{ $id }}"
|
||||
@if ($id == $selected)
|
||||
selected="selected"
|
||||
@endif
|
||||
>
|
||||
{{ $name }}
|
||||
</option>
|
||||
@endforeach
|
||||
|
||||
</select>
|
||||
</div>
|
Loading…
x
Reference in New Issue
Block a user