Skip to content

Commit 635a27c

Browse files
committed
feat: Add "Undo" options for EPG mapping for Live Channels
Allow resetting entire playlist, or via bulk actions.
1 parent 6451f16 commit 635a27c

File tree

2 files changed

+72
-30
lines changed

2 files changed

+72
-30
lines changed

app/Filament/Resources/Channels/ChannelResource.php

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
use Filament\Schemas\Components\Utilities\Set;
4242
use Filament\Schemas\Schema;
4343
use Filament\Support\Enums\Width;
44-
use Filament\Tables\Columns\IconColumn;
4544
use Filament\Tables\Columns\ImageColumn;
4645
use Filament\Tables\Columns\SelectColumn;
4746
use Filament\Tables\Columns\TextColumn;
@@ -279,10 +278,9 @@ public static function getTableColumns($showGroup = true, $showPlaylist = true):
279278
}
280279
})
281280
->sortable(),
282-
IconColumn::make('epg_map_enabled')
281+
ToggleColumn::make('epg_map_enabled')
283282
->label('Mapping Enabled')
284-
->sortable()
285-
->boolean(),
283+
->sortable(),
286284
TextColumn::make('epgChannel.name')
287285
->label('EPG Channel')
288286
->toggleable()
@@ -544,31 +542,6 @@ public static function getTableBulkActions($addToCustom = true): array
544542
->modalIcon('heroicon-o-arrows-right-left')
545543
->modalDescription('Move the selected channel(s) to the chosen group.')
546544
->modalSubmitActionLabel('Move now'),
547-
BulkAction::make('map')
548-
->label('Map EPG to selected')
549-
->schema(EpgMapResource::getForm(showPlaylist: false, showEpg: true))
550-
->action(function (Collection $records, array $data): void {
551-
app('Illuminate\Contracts\Bus\Dispatcher')
552-
->dispatch(new MapPlaylistChannelsToEpg(
553-
epg: (int) $data['epg_id'],
554-
channels: $records->pluck('id')->toArray(),
555-
force: $data['override'],
556-
settings: $data['settings'] ?? [],
557-
));
558-
})->after(function () {
559-
Notification::make()
560-
->success()
561-
->title('EPG to Channel mapping')
562-
->body('Mapping started, you will be notified when the process is complete.')
563-
->send();
564-
})
565-
->deselectRecordsAfterCompletion()
566-
->requiresConfirmation()
567-
->icon('heroicon-o-link')
568-
->modalIcon('heroicon-o-link')
569-
->modalWidth(Width::FourExtraLarge)
570-
->modalDescription('Map the selected EPG to the selected channel(s).')
571-
->modalSubmitActionLabel('Map now'),
572545
BulkAction::make('preferred_logo')
573546
->label('Update preferred icon')
574547
->schema([
@@ -696,6 +669,49 @@ public static function getTableBulkActions($addToCustom = true): array
696669
->modalIcon('heroicon-o-arrow-path-rounded-square')
697670
->modalDescription('Add the selected channel(s) to the chosen channel as failover sources.')
698671
->modalSubmitActionLabel('Add failovers now'),
672+
BulkAction::make('map')
673+
->label('Map EPG to selected')
674+
->schema(EpgMapResource::getForm(showPlaylist: false, showEpg: true))
675+
->action(function (Collection $records, array $data): void {
676+
app('Illuminate\Contracts\Bus\Dispatcher')
677+
->dispatch(new MapPlaylistChannelsToEpg(
678+
epg: (int) $data['epg_id'],
679+
channels: $records->pluck('id')->toArray(),
680+
force: $data['override'],
681+
settings: $data['settings'] ?? [],
682+
));
683+
})->after(function () {
684+
Notification::make()
685+
->success()
686+
->title('EPG to Channel mapping')
687+
->body('Mapping started, you will be notified when the process is complete.')
688+
->send();
689+
})
690+
->deselectRecordsAfterCompletion()
691+
->requiresConfirmation()
692+
->icon('heroicon-o-link')
693+
->modalIcon('heroicon-o-link')
694+
->modalWidth(Width::FourExtraLarge)
695+
->modalDescription('Map the selected EPG to the selected channel(s).')
696+
->modalSubmitActionLabel('Map now'),
697+
BulkAction::make('unmap')
698+
->label('Undo EPG Map')
699+
->action(function (Collection $records, array $data): void {
700+
Channel::whereIn('id', $records->pluck('id')->toArray())
701+
->update(['epg_channel_id' => null]);
702+
})->after(function () {
703+
Notification::make()
704+
->success()
705+
->title('EPG Channel mapping removed')
706+
->body('Channel mapping removed for the selected channels.')
707+
->send();
708+
})
709+
->requiresConfirmation()
710+
->icon('heroicon-o-arrow-uturn-left')
711+
->color('warning')
712+
->modalIcon('heroicon-o-arrow-uturn-left')
713+
->modalDescription('Clear EPG mappings for the selected channels.')
714+
->modalSubmitActionLabel('Reset now'),
699715
BulkAction::make('find-replace')
700716
->label('Find & Replace')
701717
->schema([

app/Filament/Resources/Channels/Pages/ListChannels.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,33 @@ protected function getHeaderActions(): array
179179
->modalWidth(Width::FourExtraLarge)
180180
->modalDescription('Map the selected EPG to the selected Playlist channels.')
181181
->modalSubmitActionLabel('Map now'),
182-
182+
Action::make('unmap')
183+
->label('Undo EPG Map')
184+
->schema([
185+
Select::make('playlist_id')
186+
->label('Playlist')
187+
->options(Playlist::where('user_id', auth()->id())->pluck('name', 'id'))
188+
->live()
189+
->required()
190+
->searchable()
191+
->helperText(text: 'Playlist to clear EPG mappings for.'),
192+
])
193+
->action(function (array $data): void {
194+
$playlist = Playlist::find($data['playlist_id']);
195+
$playlist->channels()->update(['epg_channel_id' => null]);
196+
})->after(function () {
197+
Notification::make()
198+
->success()
199+
->title('EPG Channel mapping removed')
200+
->body('Channel mapping removed for the selected Playlist.')
201+
->send();
202+
})
203+
->requiresConfirmation()
204+
->icon('heroicon-o-arrow-uturn-left')
205+
->color('warning')
206+
->modalIcon('heroicon-o-arrow-uturn-left')
207+
->modalDescription('Clear EPG mappings for all channels of the selected playlist.')
208+
->modalSubmitActionLabel('Reset now'),
183209
Action::make('find-replace')
184210
->label('Find & Replace')
185211
->schema([

0 commit comments

Comments
 (0)