Skip to content

Commit 5f4426e

Browse files
committed
Add import all option to series import
1 parent dd0521b commit 5f4426e

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

app/Filament/Resources/SeriesResource.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,17 @@ public static function getFormSteps(): array
468468
]),
469469
Forms\Components\Wizard\Step::make('Series to Import')
470470
->schema([
471+
Forms\Components\Toggle::make('import_all')
472+
->label('Import All Series')
473+
->live()
474+
->helperText('If enabled, all series in the selected category will be imported.')
475+
->default(false)
476+
->columnSpanFull()
477+
->afterStateUpdated(function (Get $get, $set) {
478+
if ($get('import_all')) {
479+
$set('series', []);
480+
}
481+
}),
471482
Forms\Components\CheckboxList::make('series')
472483
->label('Series to Import')
473484
->required()
@@ -486,8 +497,7 @@ public static function getFormSteps(): array
486497
$xtreamPass = $xtreamConfig['password'] ?? '';
487498
$cacheKey = 'xtream_category_series' . md5($xtremeUrl . $xtreamUser . $xtreamPass . $category);
488499
$cachedCategories = Cache::remember($cacheKey, 60 * 1, function () use ($xtremeUrl, $xtreamUser, $xtreamPass, $category) {
489-
$service = new XtreamService();
490-
$xtream = $service->init(xtream_config: [
500+
$xtream = XtreamService::make(xtream_config: [
491501
'url' => $xtremeUrl,
492502
'username' => $xtreamUser,
493503
'password' => $xtreamPass,
@@ -512,8 +522,8 @@ public static function getFormSteps(): array
512522
? 'Which series would you like to import.'
513523
: 'You must select a playlist and category first.'
514524
)
515-
->disabled(fn(Get $get): bool => ! $get('playlist') || ! $get('category'))
516-
->hidden(fn(Get $get): bool => ! $get('playlist') || ! $get('category')),
525+
->disabled(fn(Get $get): bool => ! $get('playlist') || ! $get('category') || $get('import_all'))
526+
->hidden(fn(Get $get): bool => ! $get('playlist') || ! $get('category') || $get('import_all')),
517527
])
518528
];
519529
}

app/Filament/Resources/SeriesResource/Pages/ListSeries.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ protected function getHeaderActions(): array
2828
playlist: $data['playlist'],
2929
catId: $data['category'],
3030
catName: $data['category_name'],
31-
series: $data['series'],
31+
series: $data['series'] ?? [],
32+
importAll: $data['import_all'] ?? false,
3233
));
3334
})->after(function () {
3435
Notification::make()

app/Jobs/SyncXtreamSeries.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function __construct(
2020
public int $catId,
2121
public string $catName,
2222
public array $series,
23+
public bool $importAll = false,
2324
) {}
2425

2526
/**
@@ -58,6 +59,12 @@ public function handle(XtreamService $xtream): void
5859
]);
5960
}
6061

62+
if ($this->importAll) {
63+
// If importAll is true, we need to import all series from the category
64+
$this->series = collect($xtream->getSeries($this->catId))
65+
->pluck('series_id')
66+
->toArray();
67+
}
6168
foreach ($this->series as $seriesId) {
6269
// Check if the series exists for the playlist
6370
$playlistSeries = $playlist->series()

app/Services/XtreamService.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,31 @@ class XtreamService
1515
protected Playlist|null $playlist;
1616
protected array|null $xtream_config;
1717

18+
/**
19+
* Factory method to create an instance of XtreamService.
20+
*
21+
* @param Playlist|null $playlist
22+
* @param array|null $xtream_config
23+
* @param int $retryLimit Number of retries for HTTP requests
24+
* @return XtreamService
25+
*/
26+
public static function make(
27+
Playlist|null $playlist = null,
28+
array|null $xtream_config = null,
29+
$retryLimit = 5
30+
): self {
31+
$instance = new self();
32+
return $instance->init($playlist, $xtream_config, $retryLimit);
33+
}
34+
35+
/**
36+
* Initialize the XtreamService with a Playlist or Xtream config.
37+
*
38+
* @param Playlist|null $playlist
39+
* @param array|null $xtream_config
40+
* @param int $retryLimit Number of retries for HTTP requests
41+
* @return bool|self Returns false if initialization fails, otherwise returns the instance.
42+
*/
1843
public function init(
1944
Playlist|null $playlist = null,
2045
array|null $xtream_config = null,

0 commit comments

Comments
 (0)