@@ -398,6 +398,79 @@ public static function setupTable(Table $table, $relationId = null): Table
398
398
->modalIcon ('heroicon-o-photo ' )
399
399
->modalDescription ('Update the preferred icon for the selected channel(s). ' )
400
400
->modalSubmitActionLabel ('Update now ' ),
401
+
402
+ Tables \Actions \BulkAction::make ('failover ' )
403
+ ->label ('Add as failover ' )
404
+ ->form ([
405
+ Forms \Components \Select::make ('master_channel_id ' )
406
+ ->label ('Master Channel ' )
407
+ ->options (function ($ state ) {
408
+ // Get the current channel ID to exclude it from options
409
+ $ channels = \App \Models \Channel::query ()
410
+ ->withoutEagerLoads ()
411
+ ->with ('playlist ' )
412
+ ->when ($ state , function ($ query ) use ($ state ) {
413
+ return $ query ->where ('id ' , '= ' , $ state );
414
+ })->limit (100 )->get ();
415
+
416
+ // Create options array
417
+ $ options = [];
418
+ foreach ($ channels as $ channel ) {
419
+ $ displayTitle = $ channel ->title_custom ?: $ channel ->title ;
420
+ $ playlistName = $ channel ->playlist ->name ?? 'Unknown ' ;
421
+ $ options [$ channel ->id ] = "{$ displayTitle } [ {$ playlistName }] " ;
422
+ }
423
+
424
+ return $ options ;
425
+ })
426
+ ->searchable ()
427
+ ->getSearchResultsUsing (function (string $ search ) {
428
+ // Always include the selected value if it exists
429
+ $ channels = \App \Models \Channel::query ()
430
+ ->withoutEagerLoads ()
431
+ ->with ('playlist ' )
432
+ ->where (function ($ query ) use ($ search ) {
433
+ $ query ->where ('title ' , 'like ' , "% {$ search }% " )
434
+ ->orWhere ('title_custom ' , 'like ' , "% {$ search }% " )
435
+ ->orWhere ('name ' , 'like ' , "% {$ search }% " )
436
+ ->orWhere ('name_custom ' , 'like ' , "% {$ search }% " );
437
+ })
438
+ ->limit (50 ) // Reasonable limit for search results
439
+ ->get ();
440
+
441
+ // Create options array
442
+ $ options = [];
443
+ foreach ($ channels as $ channel ) {
444
+ $ displayTitle = $ channel ->title_custom ?: $ channel ->title ;
445
+ $ playlistName = $ channel ->playlist ->name ?? 'Unknown ' ;
446
+ $ options [$ channel ->id ] = "{$ displayTitle } [ {$ playlistName }] " ;
447
+ }
448
+
449
+ return $ options ;
450
+ })
451
+ ->required (),
452
+ ])
453
+ ->action (function (Collection $ records , array $ data ): void {
454
+ foreach ($ records as $ record ) {
455
+ ChannelFailover::updateOrCreate ([
456
+ 'channel_id ' => $ data ['master_channel_id ' ],
457
+ 'channel_failover_id ' => $ record ->id ,
458
+ ]);
459
+ }
460
+ })->after (function () {
461
+ Notification::make ()
462
+ ->success ()
463
+ ->title ('Channels as failover ' )
464
+ ->body ('The selected channels have been added as failovers. ' )
465
+ ->send ();
466
+ })
467
+ ->deselectRecordsAfterCompletion ()
468
+ ->requiresConfirmation ()
469
+ ->icon ('heroicon-o-arrow-path-rounded-square ' )
470
+ ->modalIcon ('heroicon-o-arrow-path-rounded-square ' )
471
+ ->modalDescription ('Add the selected channel(s) to the chosen channel as failover sources. ' )
472
+ ->modalSubmitActionLabel ('Add failovers now ' ),
473
+
401
474
Tables \Actions \BulkAction::make ('find-replace ' )
402
475
->label ('Find & Replace ' )
403
476
->form ([
0 commit comments