Skip to content

Commit bdc02eb

Browse files
committed
combile import and export pages at "Package" page
1 parent 55923c3 commit bdc02eb

14 files changed

Lines changed: 422 additions & 97 deletions

File tree

config/inspirecms.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
],
8686
'pages' => [
8787
'dashboard' => \SolutionForest\InspireCms\Filament\Pages\Dashboard::class,
88+
'package' => \SolutionForest\InspireCms\Filament\Pages\Package::class,
8889
'health' => \SolutionForest\InspireCms\Filament\Pages\Health::class,
8990
],
9091
'clusters' => [
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
return [
4+
'title' => 'Package',
5+
'import_title' => 'Import',
6+
'export_title' => 'Export',
7+
];

resources/lang/en/resources/export.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
<?php
22

33
return [
4+
5+
'exporter' => [
6+
'label' => 'Exporter',
7+
],
8+
'message' => [
9+
'label' => 'Message',
10+
],
11+
'result' => [
12+
'label' => 'Result',
13+
],
14+
415
'notification' => [
516

617
'completed' => [
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
return [
4+
'title' => '套件',
5+
'import_title' => '匯入',
6+
'export_title' => '匯出',
7+
];

resources/lang/zh_TW/resources/export.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
<?php
22

33
return [
4+
5+
'exporter' => [
6+
'label' => '匯出器',
7+
],
8+
'message' => [
9+
'label' => '訊息',
10+
],
11+
'result' => [
12+
'label' => '結果',
13+
],
14+
415
'notification' => [
516

617
'completed' => [
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<x-filament-panels::page>
2+
@foreach ($this->getTableComponents() as $item)
3+
@livewire($item['component'], $item['data'])
4+
@endforeach
5+
</x-filament-panels::page>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
{{ $this->table }}
3+
</div>

src/CmsPanelProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use SolutionForest\InspireCms\Http\Middleware\CmsAuthenticate;
2828
use SolutionForest\InspireCms\Http\Middleware\CmsAuthenticateSession;
2929
use SolutionForest\InspireCms\Http\Middleware\UserPreference;
30+
use SolutionForest\InspireCms\Livewire\ListPackages;
3031
use SolutionForest\InspireCms\View\Components as ViewComponents;
3132

3233
class CmsPanelProvider extends PanelProvider
@@ -306,6 +307,7 @@ protected function registerLivewireComponents(Panel $panel): Panel
306307
{
307308
return $panel->livewireComponents([
308309
Pages\Auth\Install::class,
310+
ListPackages::class,
309311
]);
310312
}
311313

src/Filament/Clusters/Settings/Resources/ExportResource.php

Lines changed: 94 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
use Filament\Forms\Form;
77
use Filament\Infolists;
88
use Filament\Infolists\Infolist;
9+
use Filament\Notifications\Notification;
910
use Filament\Resources\Resource;
1011
use Filament\Tables;
1112
use Filament\Tables\Table;
1213
use Illuminate\Database\Eloquent\Builder;
1314
use Illuminate\Database\Eloquent\Model;
15+
use Illuminate\Support\Arr;
1416
use Illuminate\Support\Str;
17+
use SolutionForest\InspireCms\Exports\Exporters\BaseExporter;
1518
use SolutionForest\InspireCms\Filament\Clusters\Settings;
16-
use SolutionForest\InspireCms\Filament\Clusters\Settings\Resources\ExportResource\Pages;
1719
use SolutionForest\InspireCms\Filament\Concerns\ClusterSectionResourceTrait;
1820
use SolutionForest\InspireCms\Filament\Contracts\ClusterSectionResource;
1921
use SolutionForest\InspireCms\InspireCmsConfig;
@@ -29,6 +31,8 @@ class ExportResource extends Resource implements ClusterSectionResource
2931

3032
protected static ?string $cluster = Settings::class;
3133

34+
protected static bool $shouldRegisterNavigation = false;
35+
3236
public static function getPermissionPrefixes(): array
3337
{
3438
return [
@@ -109,28 +113,72 @@ public static function infolist(Infolist $infolist): Infolist
109113
Infolists\Components\TextEntry::make('author.email')->inlineLabel()->copyable(),
110114
]),
111115

112-
\SolutionForest\InspireCms\Filament\Infolists\Components\JsonEntry::make('payload')
113-
->label(__('inspirecms::resources/import.payload.label'))
116+
Infolists\Components\Section::make()
117+
->heading('Detail')
118+
->collapsible()
114119
->columnSpanFull()
115-
->darkTheme('tomorrow_night_eighties'),
120+
->columns(1)
121+
->schema([
122+
Infolists\Components\TextEntry::make('exporter')
123+
->label(__('inspirecms::resources/export.exporter.label'))
124+
->inlineLabel()
125+
->formatStateUsing(function ($state) {
126+
if (is_string($state) && class_exists($state)) {
127+
return $state::getLabel();
128+
}
129+
return $state;
130+
}),
131+
132+
\SolutionForest\InspireCms\Filament\Infolists\Components\JsonEntry::make('payload')
133+
->label(__('inspirecms::resources/export.message.label'))
134+
->columnSpanFull()
135+
->darkTheme('tomorrow_night_eighties')
136+
->getStateUsing(function ($record) {
137+
$payload = $record->payload;
138+
return collect($payload)->except('result')->all();
139+
}),
140+
141+
\SolutionForest\InspireCms\Filament\Infolists\Components\JsonEntry::make('payload.result')
142+
->label(__('inspirecms::resources/export.result.label'))
143+
->columnSpanFull()
144+
->darkTheme('tomorrow_night_eighties'),
145+
]),
116146
]);
117147
}
118148

119149
public static function form(Form $form): Form
120150
{
151+
$exporters = collect([
152+
\SolutionForest\InspireCms\Exports\Exporters\DocumentTypeExporter::class,
153+
\SolutionForest\InspireCms\Exports\Exporters\FieldGroupExporter::class,
154+
\SolutionForest\InspireCms\Exports\Exporters\TemplateExporter::class,
155+
])
156+
->mapWithKeys(fn ($exporter) => [$exporter => $exporter::getLabel()])
157+
->all();
158+
121159
return $form
160+
->columns(1)
122161
->schema([
123-
Forms\Components\ToggleButtons::make('exporter')
124-
->options(
125-
collect([
126-
\SolutionForest\InspireCms\Exporters\DocumentTypeExporter::class,
127-
\SolutionForest\InspireCms\Exporters\FieldGroupExporter::class,
128-
\SolutionForest\InspireCms\Exporters\TemplateExporter::class,
129-
])
130-
->mapWithKeys(fn ($exporter) => [$exporter => $exporter::getLabel()])
131-
->all()
132-
)
133-
->required(),
162+
Forms\Components\Select::make('exporter')
163+
->options($exporters)
164+
->required()
165+
->live(),
166+
167+
Forms\Components\Group::make()
168+
->statePath('payload.args')
169+
->dehydrated(true)
170+
->schema(function (Forms\Get $get) {
171+
172+
$exporter = $get('exporter');
173+
174+
if ($exporter && is_string($exporter) && class_exists($exporter) && is_a($exporter, BaseExporter::class, true)) {
175+
$fields = $exporter::getArgsFormFields();
176+
177+
return $fields;
178+
}
179+
180+
return [];
181+
}),
134182
]);
135183
}
136184

@@ -185,16 +233,44 @@ public static function table(Table $table): Table
185233
->label(__('inspirecms::inspirecms.created_at'))
186234
->sortable(),
187235
])
236+
->recordAction('view')
237+
->headerActions([
238+
Tables\Actions\CreateAction::make()
239+
->createAnother(false)
240+
->modalWidth('lg')
241+
->stickyModalHeader()->stickyModalHeader()
242+
->slideOver()
243+
->form(fn (Form $form) => static::form($form))
244+
// todo: add translations
245+
->label('Add')
246+
->modalSubmitActionLabel('Export')
247+
->successNotificationTitle('Queued for export, please wait for the download link.')
248+
->failureNotificationTitle('Missing required data, failed to export.')
249+
->failureNotification(fn (Notification $notification) => $notification->warning())
250+
->using(function (Tables\Actions\CreateAction $action, array $data, string $model) {
251+
252+
$user = auth()->user();
253+
$exporter = $data['exporter'] ?? null;
254+
255+
if (! $user || ! filled($exporter)) {
256+
$action->sendFailureNotification();
257+
return $action->cancel();
258+
}
259+
$export = app($model, ['attributes' => Arr::only($data, ['exporter', 'payload'])]);
260+
$export->author()->associate($user);
261+
$export->save();
262+
263+
return $export;
264+
}),
265+
])
188266
->actions([
189267
Tables\Actions\ViewAction::make()->iconButton()->slideOver()->authorize(null),
190268
]);
191269
}
192270

193271
public static function getPages(): array
194272
{
195-
return [
196-
'index' => Pages\ListExports::route('/'),
197-
];
273+
return [];
198274
}
199275

200276
public static function getModel(): string

src/Filament/Clusters/Settings/Resources/ExportResource/Pages/ListExports.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)