|
|
@@ -3,21 +3,15 @@
|
|
3
|
3
|
namespace App\Filament\Resources;
|
|
4
|
4
|
|
|
5
|
5
|
use App\Filament\Resources\AlbumResource\Pages;
|
|
6
|
|
-use App\Filament\Resources\AlbumResource\RelationManagers;
|
|
7
|
|
-use App\Service\DeepLService;
|
|
8
|
6
|
use App\Models\Album;
|
|
9
|
7
|
use App\Models\AlbumCategory;
|
|
10
|
|
-use App\Models\NewsCategory;
|
|
11
|
|
-use Filament\Forms;
|
|
12
|
|
-use Filament\Forms\Components\Actions\Action;
|
|
|
8
|
+use App\Service\DeepLService;
|
|
13
|
9
|
use Filament\Forms\Components\DatePicker;
|
|
14
|
|
-use Filament\Forms\Components\DateTimePicker;
|
|
15
|
10
|
use Filament\Forms\Components\FileUpload;
|
|
16
|
11
|
use Filament\Forms\Components\Group;
|
|
17
|
12
|
use Filament\Forms\Components\Radio;
|
|
18
|
13
|
use Filament\Forms\Components\Section;
|
|
19
|
14
|
use Filament\Forms\Components\Select;
|
|
20
|
|
-use Filament\Forms\Components\Textarea;
|
|
21
|
15
|
use Filament\Forms\Components\TextInput;
|
|
22
|
16
|
use Filament\Forms\Components\Toggle;
|
|
23
|
17
|
use Filament\Forms\Form;
|
|
|
@@ -26,81 +20,84 @@ use Filament\Resources\Resource;
|
|
26
|
20
|
use Filament\Tables;
|
|
27
|
21
|
use Filament\Tables\Columns\ImageColumn;
|
|
28
|
22
|
use Filament\Tables\Columns\TextColumn;
|
|
29
|
|
-use Filament\Tables\Filters\QueryBuilder;
|
|
30
|
|
-use Filament\Tables\Filters\QueryBuilder\Constraints\SelectConstraint;
|
|
31
|
|
-use Filament\Tables\Filters\QueryBuilder\Constraints\TextConstraint;
|
|
32
|
23
|
use Filament\Tables\Filters\SelectFilter;
|
|
33
|
24
|
use Filament\Tables\Table;
|
|
34
|
25
|
use Illuminate\Database\Eloquent\Builder;
|
|
35
|
|
-use Illuminate\Database\Eloquent\Collection;
|
|
36
|
|
-use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
37
|
26
|
use Illuminate\Support\Facades\DB;
|
|
38
|
27
|
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
|
|
39
|
28
|
|
|
40
|
29
|
class AlbumResource extends Resource
|
|
41
|
30
|
{
|
|
42
|
31
|
protected static ?string $model = Album::class;
|
|
43
|
|
- protected static ?string $modelLabel = "影音管理";
|
|
|
32
|
+
|
|
|
33
|
+ protected static ?string $modelLabel = '影音管理';
|
|
|
34
|
+
|
|
44
|
35
|
protected static ?string $navigationIcon = 'heroicon-o-photo';
|
|
|
36
|
+
|
|
45
|
37
|
protected static ?string $navigationGroup = '最新消息';
|
|
46
|
|
- protected static ?string $navigationLabel = "影音管理";
|
|
|
38
|
+
|
|
|
39
|
+ protected static ?string $navigationLabel = '影音管理';
|
|
47
|
40
|
|
|
48
|
41
|
public static function form(Form $form): Form
|
|
49
|
42
|
{
|
|
50
|
43
|
return $form
|
|
51
|
44
|
->schema([
|
|
52
|
|
- Section::make("新增 影音")->schema([
|
|
|
45
|
+ Section::make('新增 影音')->schema([
|
|
53
|
46
|
Group::make()->schema([
|
|
54
|
|
- Select::make("album_category_id")
|
|
55
|
|
- ->options(AlbumCategory::orderBy("order")->get()->pluck("name","id"))
|
|
56
|
|
- ->label("影音分類")
|
|
57
|
|
- ->required()
|
|
58
|
|
- ->columnSpan(1)
|
|
59
|
|
- ->native(false)
|
|
60
|
|
- ->Live(),
|
|
|
47
|
+ Select::make('album_category_id')
|
|
|
48
|
+ ->options(AlbumCategory::orderBy('order')->get()->pluck('name', 'id'))
|
|
|
49
|
+ ->label('影音分類')
|
|
|
50
|
+ ->required()
|
|
|
51
|
+ ->columnSpan(1)
|
|
|
52
|
+ ->native(false)
|
|
|
53
|
+ ->Live(),
|
|
61
|
54
|
])->columnSpanFull()->columns(2),
|
|
62
|
55
|
Group::make()->schema([
|
|
63
|
56
|
DatePicker::make('post_date')
|
|
64
|
|
- ->label("發布日期")
|
|
65
|
|
- ->closeOnDateSelection(),
|
|
|
57
|
+ ->label('發布日期')
|
|
|
58
|
+ ->closeOnDateSelection(),
|
|
66
|
59
|
])->columnSpanFull()->columns(2),
|
|
67
|
|
- FileUpload::make('news_banner')->label("列表大圖")
|
|
68
|
|
- ->directory("album/img")
|
|
69
|
|
- ->helperText('建議寬高限制為:2000*720px,出血寬度720px,主要圖像範圍為:1280*720px,檔案大小限制為1M以下')->maxSize('1024'),
|
|
70
|
|
- FileUpload::make('news_img_pc')->label("列表圖(desktop)")
|
|
71
|
|
- ->directory("album/img")
|
|
72
|
|
- ->helperText('建議寬高限制為:1280*720px,檔案大小限制為1M以下')->maxSize('1024'),
|
|
73
|
|
- FileUpload::make('news_img_mobile')->label("列表圖(mobile)")
|
|
74
|
|
- ->directory("album/img")
|
|
75
|
|
- ->helperText('建議寬高限制為:600x896px,檔案大小限制為1M以下')->maxSize('1024'),
|
|
|
60
|
+ FileUpload::make('news_banner')->label('列表大圖')
|
|
|
61
|
+ ->directory('album/img')
|
|
|
62
|
+ ->acceptedFileTypes(['image/jpeg', 'image/jpg', 'image/png', 'image/webp'])
|
|
|
63
|
+ ->helperText('建議寬高限制為:2000*720px,出血寬度720px,主要圖像範圍為:1280*720px,檔案大小限制為1M以下')->maxSize('1024'),
|
|
|
64
|
+ FileUpload::make('news_img_pc')->label('列表圖(desktop)')
|
|
|
65
|
+ ->directory('album/img')
|
|
|
66
|
+ ->acceptedFileTypes(['image/jpeg', 'image/jpg', 'image/png', 'image/webp'])
|
|
|
67
|
+ ->helperText('建議寬高限制為:1280*720px,檔案大小限制為1M以下')->maxSize('1024'),
|
|
|
68
|
+ FileUpload::make('news_img_mobile')->label('列表圖(mobile)')
|
|
|
69
|
+ ->directory('album/img')
|
|
|
70
|
+ ->acceptedFileTypes(['image/jpeg', 'image/jpg', 'image/png', 'image/webp'])
|
|
|
71
|
+ ->helperText('建議寬高限制為:600x896px,檔案大小限制為1M以下')->maxSize('1024'),
|
|
76
|
72
|
Translate::make()->schema(fn (string $locale) => [
|
|
77
|
73
|
TextInput::make('title')
|
|
78
|
|
- ->label("標題")
|
|
79
|
|
- ->columnSpan(1),
|
|
|
74
|
+ ->label('標題')
|
|
|
75
|
+ ->columnSpan(1),
|
|
80
|
76
|
])
|
|
81
|
|
- ->locales(["zh_TW", "en", "jp"])
|
|
82
|
|
- ->actions([
|
|
83
|
|
- app(DeepLService::class)->createTranslationAction("Main", ["title"])
|
|
84
|
|
- ])
|
|
85
|
|
- ->id("main")->columnSpanFull()->columns(3),
|
|
|
77
|
+ ->locales(['zh_TW', 'en', 'jp'])
|
|
|
78
|
+ ->actions([
|
|
|
79
|
+ app(DeepLService::class)->createTranslationAction('Main', ['title']),
|
|
|
80
|
+ ])
|
|
|
81
|
+ ->id('main')->columnSpanFull()->columns(3),
|
|
86
|
82
|
|
|
87
|
|
- Section::make("")->schema([
|
|
88
|
|
- Radio::make("upload_type")->label("")->options([
|
|
89
|
|
- 1 => "網址",
|
|
90
|
|
- 2 => "檔案"
|
|
|
83
|
+ Section::make('')->schema([
|
|
|
84
|
+ Radio::make('upload_type')->label('')->options([
|
|
|
85
|
+ 1 => '網址',
|
|
|
86
|
+ 2 => '檔案',
|
|
91
|
87
|
])->columnSpanFull()->default(1)->Live(),
|
|
92
|
88
|
Group::make()->schema([
|
|
93
|
|
- TextInput::make('link_video')->label("網址")->nullable(),
|
|
94
|
|
- ])->visible(fn (Get $get):bool => $get("upload_type") == 1)->columnSpanFull(),
|
|
|
89
|
+ TextInput::make('link_video')->label('網址')->nullable(),
|
|
|
90
|
+ ])->visible(fn (Get $get): bool => $get('upload_type') == 1)->columnSpanFull(),
|
|
95
|
91
|
Group::make()->schema([
|
|
96
|
|
- FileUpload::make('link_upload')->label("")->directory("album/video")
|
|
97
|
|
- ->helperText('建議影片寬高限制為:1920*1080px,出血寬度720px,大小限制為:100M以下')
|
|
98
|
|
- ->maxSize(102400)->nullable(),
|
|
99
|
|
- ])->visible(fn (Get $get):bool => $get("upload_type") == 2)->columnSpanFull(),
|
|
|
92
|
+ FileUpload::make('link_upload')->label('')->directory('album/video')
|
|
|
93
|
+ ->acceptedFileTypes(['video/mp4', 'video/mpeg', 'video/quicktime', 'video/x-msvideo', 'video/x-ms-wmv'])
|
|
|
94
|
+ ->helperText('建議影片寬高限制為:1920*1080px,出血寬度720px,大小限制為:100M以下')
|
|
|
95
|
+ ->maxSize(102400)->nullable(),
|
|
|
96
|
+ ])->visible(fn (Get $get): bool => $get('upload_type') == 2)->columnSpanFull(),
|
|
100
|
97
|
])->columnSpanFull(),
|
|
101
|
|
- Toggle::make("on_top")->inline()->label("置頂輪播")->columnSpanFull(),
|
|
102
|
|
- Toggle::make("homepage_top")->inline()->label("在首頁輪播")->columnSpanFull(),
|
|
103
|
|
- TextInput::make('order')->label("排序")->integer()->default(0),
|
|
|
98
|
+ Toggle::make('on_top')->inline()->label('置頂輪播')->columnSpanFull(),
|
|
|
99
|
+ Toggle::make('homepage_top')->inline()->label('在首頁輪播')->columnSpanFull(),
|
|
|
100
|
+ TextInput::make('order')->label('排序')->integer()->default(0),
|
|
104
|
101
|
])->columns(3),
|
|
105
|
102
|
]);
|
|
106
|
103
|
}
|
|
|
@@ -110,66 +107,64 @@ class AlbumResource extends Resource
|
|
110
|
107
|
return $table
|
|
111
|
108
|
->columns([
|
|
112
|
109
|
//
|
|
113
|
|
- TextColumn::make("albumCategory.name")->label("分類")->alignCenter(),
|
|
114
|
|
- TextColumn::make("title")->label("標題")->alignCenter(),
|
|
115
|
|
- TextColumn::make("post_date")->date()->alignCenter(),
|
|
116
|
|
- ImageColumn::make("news_img_pc")->alignCenter(),
|
|
117
|
|
- TextColumn::make("list_audit_state")->label("狀態")->badge()
|
|
118
|
|
- ->color(fn (string $state): string => match ($state) {
|
|
119
|
|
- '暫存' => 'warning',
|
|
120
|
|
- '已發佈' => 'success',
|
|
121
|
|
- }),
|
|
122
|
|
- TextColumn::make("created_at")->label("建立時間")->dateTime()->alignCenter(),
|
|
123
|
|
- TextColumn::make("updated_at")->label("更新時間")->dateTime()->alignCenter(),
|
|
|
110
|
+ TextColumn::make('albumCategory.name')->label('分類')->alignCenter(),
|
|
|
111
|
+ TextColumn::make('title')->label('標題')->alignCenter(),
|
|
|
112
|
+ TextColumn::make('post_date')->date()->alignCenter(),
|
|
|
113
|
+ ImageColumn::make('news_img_pc')->alignCenter(),
|
|
|
114
|
+ TextColumn::make('list_audit_state')->label('狀態')->badge()
|
|
|
115
|
+ ->color(fn (string $state): string => match ($state) {
|
|
|
116
|
+ '暫存' => 'warning',
|
|
|
117
|
+ '已發佈' => 'success',
|
|
|
118
|
+ }),
|
|
|
119
|
+ TextColumn::make('created_at')->label('建立時間')->dateTime()->alignCenter(),
|
|
|
120
|
+ TextColumn::make('updated_at')->label('更新時間')->dateTime()->alignCenter(),
|
|
124
|
121
|
])
|
|
125
|
122
|
->filters([
|
|
126
|
|
- SelectFilter::make('post_date')->label("年份")
|
|
127
|
|
- ->options(Album::select(DB::raw("DATE_FORMAT(post_date, '%Y') as year"))->whereNotNull("post_date")->distinct()->pluck("year","year")->toArray())
|
|
128
|
|
- ->query(
|
|
129
|
|
- fn (array $data, Builder $query): Builder =>
|
|
130
|
|
- $query->when(
|
|
131
|
|
- $data['value'],
|
|
132
|
|
- fn (Builder $query, $value): Builder => $query->where('post_date', 'like', $data['value']. "%")
|
|
133
|
|
- )
|
|
134
|
|
- ),
|
|
135
|
|
- SelectFilter::make('album_category_id')->label("分類")
|
|
136
|
|
- ->relationship('albumCategory', 'name')
|
|
137
|
|
- ->getOptionLabelFromRecordUsing(fn($record, $livewire) => $record->getTranslation('name', "zh_TW")),
|
|
138
|
|
- SelectFilter::make('visible')->label("狀態")
|
|
139
|
|
- ->options([
|
|
140
|
|
- 0 => "暫存",
|
|
141
|
|
- 1 => "已發佈",
|
|
142
|
|
- ])
|
|
143
|
|
- ->query(
|
|
144
|
|
- fn (array $data, Builder $query): Builder =>
|
|
145
|
|
- $query->when(
|
|
146
|
|
- $data['value'],
|
|
147
|
|
- fn (Builder $query, $value): Builder => $query->where('visible', $data['value'])
|
|
148
|
|
- )
|
|
149
|
|
- ),
|
|
|
123
|
+ SelectFilter::make('post_date')->label('年份')
|
|
|
124
|
+ ->options(Album::select(DB::raw("DATE_FORMAT(post_date, '%Y') as year"))->whereNotNull('post_date')->distinct()->pluck('year', 'year')->toArray())
|
|
|
125
|
+ ->query(
|
|
|
126
|
+ fn (array $data, Builder $query): Builder => $query->when(
|
|
|
127
|
+ $data['value'],
|
|
|
128
|
+ fn (Builder $query, $value): Builder => $query->where('post_date', 'like', $data['value'].'%')
|
|
|
129
|
+ )
|
|
|
130
|
+ ),
|
|
|
131
|
+ SelectFilter::make('album_category_id')->label('分類')
|
|
|
132
|
+ ->relationship('albumCategory', 'name')
|
|
|
133
|
+ ->getOptionLabelFromRecordUsing(fn ($record, $livewire) => $record->getTranslation('name', 'zh_TW')),
|
|
|
134
|
+ SelectFilter::make('visible')->label('狀態')
|
|
|
135
|
+ ->options([
|
|
|
136
|
+ 0 => '暫存',
|
|
|
137
|
+ 1 => '已發佈',
|
|
|
138
|
+ ])
|
|
|
139
|
+ ->query(
|
|
|
140
|
+ fn (array $data, Builder $query): Builder => $query->when(
|
|
|
141
|
+ $data['value'],
|
|
|
142
|
+ fn (Builder $query, $value): Builder => $query->where('visible', $data['value'])
|
|
|
143
|
+ )
|
|
|
144
|
+ ),
|
|
150
|
145
|
])
|
|
151
|
146
|
->actions([
|
|
152
|
147
|
Tables\Actions\EditAction::make(),
|
|
153
|
148
|
Tables\Actions\DeleteAction::make(),
|
|
154
|
|
- \Filament\Tables\Actions\Action::make("audit")
|
|
155
|
|
- ->label(fn ($record) => match ($record->visible) {
|
|
156
|
|
- 0 => '發佈',
|
|
157
|
|
- 1 => '下架',
|
|
158
|
|
- })
|
|
159
|
|
- ->color(fn ($record) => match ($record->visible) {
|
|
160
|
|
- 0 => 'warning',
|
|
161
|
|
- 1 => 'gray',
|
|
162
|
|
- })
|
|
163
|
|
- ->icon(fn ($record) => match ($record->visible) {
|
|
164
|
|
- 0 => 'heroicon-m-chevron-double-up',
|
|
165
|
|
- 1 => 'heroicon-m-chevron-double-down',
|
|
166
|
|
- })
|
|
167
|
|
- ->action(function ($record) {
|
|
168
|
|
- $record->visible = !$record->visible;
|
|
169
|
|
- $record->save();
|
|
170
|
|
- })
|
|
171
|
|
- ->outlined()
|
|
172
|
|
- ->requiresConfirmation(),
|
|
|
149
|
+ \Filament\Tables\Actions\Action::make('audit')
|
|
|
150
|
+ ->label(fn ($record) => match ($record->visible) {
|
|
|
151
|
+ 0 => '發佈',
|
|
|
152
|
+ 1 => '下架',
|
|
|
153
|
+ })
|
|
|
154
|
+ ->color(fn ($record) => match ($record->visible) {
|
|
|
155
|
+ 0 => 'warning',
|
|
|
156
|
+ 1 => 'gray',
|
|
|
157
|
+ })
|
|
|
158
|
+ ->icon(fn ($record) => match ($record->visible) {
|
|
|
159
|
+ 0 => 'heroicon-m-chevron-double-up',
|
|
|
160
|
+ 1 => 'heroicon-m-chevron-double-down',
|
|
|
161
|
+ })
|
|
|
162
|
+ ->action(function ($record) {
|
|
|
163
|
+ $record->visible = ! $record->visible;
|
|
|
164
|
+ $record->save();
|
|
|
165
|
+ })
|
|
|
166
|
+ ->outlined()
|
|
|
167
|
+ ->requiresConfirmation(),
|
|
173
|
168
|
])
|
|
174
|
169
|
->bulkActions([
|
|
175
|
170
|
Tables\Actions\BulkActionGroup::make([
|