feat(admin): add search form in podcast episodes list

closes #26
This commit is contained in:
Yassine Doghri 2022-06-17 10:44:05 +00:00
parent 9f4a467ad4
commit 6be5d12877
7 changed files with 7214 additions and 7793 deletions

View File

@ -158,6 +158,14 @@ class AddEpisodes extends Migration
$this->forge->addForeignKey('created_by', 'users', 'id');
$this->forge->addForeignKey('updated_by', 'users', 'id');
$this->forge->createTable('episodes');
// Add Full-Text Search index on title and description_markdown
$prefix = $this->db->getPrefix();
$createQuery = <<<CODE_SAMPLE
ALTER TABLE {$prefix}episodes
ADD FULLTEXT(title, description_markdown);
CODE_SAMPLE;
$this->db->query($createQuery);
}
public function down(): void

View File

@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
<g>
<path fill="none" d="M0 0h24v24H0z"/>
<path d="M18.031 16.617l4.283 4.282-1.415 1.415-4.282-4.283A8.96 8.96 0 0 1 11 20c-4.968 0-9-4.032-9-9s4.032-9 9-9 9 4.032 9 9a8.96 8.96 0 0 1-1.969 5.617z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 320 B

View File

@ -33,7 +33,7 @@ class Button extends Component
$variantClass = [
'default' => 'text-black bg-gray-300 hover:bg-gray-400',
'primary' => 'text-accent-contrast bg-accent-base hover:bg-accent-hover',
'secondary' => 'border-2 border-accent-base text-accent-base bg-transparent hover:border-accent-hover hover:text-accent-hover',
'secondary' => 'border-2 border-accent-base text-accent-base bg-white hover:border-accent-hover hover:text-accent-hover',
'success' => 'text-white bg-pine-500 hover:bg-pine-800',
'danger' => 'text-white bg-red-600 hover:bg-red-700',
'warning' => 'text-black bg-yellow-500 hover:bg-yellow-600',

14710
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -63,14 +63,25 @@ class EpisodeController extends BaseController
public function list(): string
{
$episodes = (new EpisodeModel())
->where('podcast_id', $this->podcast->id)
->orderBy('created_at', 'desc');
/** @var ?string $query */
$query = $this->request->getGet('q');
if ($query !== null && $query !== '') {
$episodes = (new EpisodeModel())
->where('podcast_id', $this->podcast->id)
->where("MATCH (title, description_markdown) AGAINST ('{$query}')");
} else {
$episodes = (new EpisodeModel())
->where('podcast_id', $this->podcast->id)
->orderBy('created_at', 'desc');
}
helper('form');
$data = [
'podcast' => $this->podcast,
'episodes' => $episodes->paginate(10),
'pager' => $episodes->pager,
'query' => $query,
];
replace_breadcrumb_params([

View File

@ -38,6 +38,15 @@ return [
'not_published' => 'Not published',
],
'list' => [
'search' => [
'placeholder' => 'Search for an episode',
'clear' => 'Clear search',
'submit' => 'Search',
],
'number_of_episodes' => '{numberOfEpisodes, plural,
one {# episode}
other {# episodes}
}',
'episode' => 'Episode',
'visibility' => 'Visibility',
'comments' => 'Comments',

View File

@ -5,7 +5,7 @@
<?= $this->endSection() ?>
<?= $this->section('pageTitle') ?>
<?= lang('Episode.all_podcast_episodes') ?> (<?= $pager->getDetails()['total'] ?>)
<?= lang('Episode.all_podcast_episodes') ?>
<?= $this->endSection() ?>
<?= $this->section('headerRight') ?>
@ -15,128 +15,143 @@
<?= $this->section('content') ?>
<p class="mb-4 text-sm italic text-skin-muted">
<?= lang('Common.pageInfo', [
'currentPage' => $pager->getDetails()['currentPage'],
'pageCount' => $pager->getDetails()['pageCount'],
]) ?>
</p>
<div class="flex flex-wrap items-center justify-between">
<p class="text-sm italic text-skin-muted">
<span class="font-semibold"><?= lang('Episode.list.number_of_episodes', [
'numberOfEpisodes' => $pager->getDetails()['total'],
]) ?></span><br />
<?= lang('Common.pageInfo', [
'currentPage' => $pager->getDetails()['currentPage'],
'pageCount' => $pager->getDetails()['pageCount'],
]) ?>
</p>
<form class="relative flex">
<div class="relative">
<Forms.Input name="q" placeholder="<?= lang('Episode.list.search.placeholder') ?>" value="<?= $query ?>" class="<?= $query ? 'pr-8' : '' ?>" />
<?php if ($query): ?>
<a href="<?= route_to('episode-list', $podcast->id) ?>" class="absolute inset-y-0 right-0 inline-flex items-center justify-center px-2 opacity-75 focus:ring-accent hover:opacity-100 focus:opacity-100" title="<?= lang('Episode.list.search.clear') ?>" data-tooltip="bottom"><?= icon('close', 'text-lg') ?></a>
<?php endif; ?>
</div>
<Button type="submit" variant="secondary" class="px-3 ml-2 rounded-lg shadow-md" title="<?= lang('Episode.list.search.submit') ?>" data-tooltip="bottom" isSquared="true"><?= icon('search', 'text-xl') ?></Button>
</form>
</div>
<?= data_table(
<?=
data_table(
[
[
[
'header' => lang('Episode.list.episode'),
'cell' => function ($episode, $podcast) {
return '<div class="flex">' .
'<div class="relative flex-shrink-0 mr-2">' .
'<time class="absolute px-1 text-xs font-semibold text-white rounded bottom-2 right-2 bg-black/50" datetime="PT' . round($episode->audio->duration, 3) . 'S">' .
format_duration(
(int) $episode->audio->duration,
) .
'</time>' .
'<img src="' . $episode->cover->thumbnail_url . '" alt="' . esc($episode->title) . '" class="object-cover w-20 rounded-lg shadow-inner aspect-square" loading="lazy" />' .
'</div>' .
'<a class="overflow-x-hidden text-sm hover:underline" href="' . route_to(
'episode-view',
$podcast->id,
$episode->id,
) . '">' .
'<h2 class="inline-flex items-baseline w-full font-semibold leading-none gap-x-1 group">' .
episode_numbering(
$episode->number,
$episode->season_number,
'text-xs font-semibold text-skin-muted !no-underline border px-1 border-gray-500',
true,
) .
'<span class="mr-1 truncate group-hover:underline">' . esc($episode->title) . '</span>' .
'</h2>' .
'<p class="max-w-sm text-xs text-skin-muted line-clamp-2">' . $episode->description . '</p>' .
'</a>' .
'</div>';
},
],
[
'header' => lang('Episode.list.visibility'),
'cell' => function ($episode): string {
return publication_pill(
$episode->published_at,
$episode->publication_status,
);
},
],
[
'header' => lang('Episode.list.comments'),
'cell' => function ($episode): int {
return $episode->comments_count;
},
],
[
'header' => lang('Episode.list.actions'),
'cell' => function ($episode, $podcast) {
$items = [
[
'type' => 'link',
'title' => lang('Episode.go_to_page'),
'uri' => route_to('episode', esc($podcast->handle), esc($episode->slug)),
],
[
'type' => 'link',
'title' => lang('Episode.edit'),
'uri' => route_to('episode-edit', $podcast->id, $episode->id),
],
[
'type' => 'link',
'title' => lang('Episode.embed.title'),
'uri' => route_to('embed-add', $podcast->id, $episode->id),
],
[
'type' => 'link',
'title' => lang('Person.persons'),
'uri' => route_to('episode-persons-manage', $podcast->id, $episode->id),
],
[
'type' => 'link',
'title' => lang('VideoClip.list.title'),
'uri' => route_to('video-clips-list', $episode->podcast->id, $episode->id),
],
[
'type' => 'link',
'title' => lang('Soundbite.list.title'),
'uri' => route_to('soundbites-list', $podcast->id, $episode->id),
],
[
'type' => 'separator',
],
];
if ($episode->published_at === null) {
$items[] = [
'type' => 'link',
'title' => lang('Episode.delete'),
'uri' => route_to('episode-delete', $podcast->id, $episode->id),
'class' => 'font-semibold text-red-600',
];
} else {
$label = lang('Episode.delete');
$icon = icon('forbid');
$title = lang('Episode.messages.unpublishBeforeDeleteTip');
$items[] = [
'type' => 'html',
'content' => esc(<<<CODE_SAMPLE
<span class="inline-flex items-center px-4 py-1 font-semibold text-gray-400 cursor-not-allowed" data-tooltip="bottom" title="{$title}">{$icon}<span class="ml-2">{$label}</span></span>
CODE_SAMPLE),
];
}
return '<button id="more-dropdown-' . $episode->id . '" type="button" class="inline-flex items-center p-1 rounded-full focus:ring-accent" data-dropdown="button" data-dropdown-target="more-dropdown-' . $episode->id . '-menu" aria-haspopup="true" aria-expanded="false">' .
icon('more') .
'</button>' .
'<DropdownMenu id="more-dropdown-' . $episode->id . '-menu" labelledby="more-dropdown-' . $episode->id . '" offsetY="-24" items="' . esc(json_encode($items)) . '" />';
},
],
'header' => lang('Episode.list.episode'),
'cell' => function ($episode, $podcast) {
return '<div class="flex">' .
'<div class="relative flex-shrink-0 mr-2">' .
'<time class="absolute px-1 text-xs font-semibold text-white rounded bottom-2 right-2 bg-black/50" datetime="PT' . round($episode->audio->duration, 3) . 'S">' .
format_duration(
(int) $episode->audio->duration,
) .
'</time>' .
'<img src="' . $episode->cover->thumbnail_url . '" alt="' . esc($episode->title) . '" class="object-cover w-20 rounded-lg shadow-inner aspect-square" loading="lazy" />' .
'</div>' .
'<a class="overflow-x-hidden text-sm hover:underline" href="' . route_to(
'episode-view',
$podcast->id,
$episode->id,
) . '">' .
'<h2 class="inline-flex items-baseline w-full font-semibold leading-none gap-x-1 group">' .
episode_numbering(
$episode->number,
$episode->season_number,
'text-xs font-semibold text-skin-muted !no-underline border px-1 border-gray-500',
true,
) .
'<span class="mr-1 truncate group-hover:underline">' . esc($episode->title) . '</span>' .
'</h2>' .
'<p class="max-w-sm text-xs text-skin-muted line-clamp-2">' . $episode->description . '</p>' .
'</a>' .
'</div>';
},
],
$episodes,
'mb-6',
$podcast
) ?>
[
'header' => lang('Episode.list.visibility'),
'cell' => function ($episode): string {
return publication_pill(
$episode->published_at,
$episode->publication_status,
);
},
],
[
'header' => lang('Episode.list.comments'),
'cell' => function ($episode): int {
return $episode->comments_count;
},
],
[
'header' => lang('Episode.list.actions'),
'cell' => function ($episode, $podcast) {
$items = [
[
'type' => 'link',
'title' => lang('Episode.go_to_page'),
'uri' => route_to('episode', esc($podcast->handle), esc($episode->slug)),
],
[
'type' => 'link',
'title' => lang('Episode.edit'),
'uri' => route_to('episode-edit', $podcast->id, $episode->id),
],
[
'type' => 'link',
'title' => lang('Episode.embed.title'),
'uri' => route_to('embed-add', $podcast->id, $episode->id),
],
[
'type' => 'link',
'title' => lang('Person.persons'),
'uri' => route_to('episode-persons-manage', $podcast->id, $episode->id),
],
[
'type' => 'link',
'title' => lang('VideoClip.list.title'),
'uri' => route_to('video-clips-list', $episode->podcast->id, $episode->id),
],
[
'type' => 'link',
'title' => lang('Soundbite.list.title'),
'uri' => route_to('soundbites-list', $podcast->id, $episode->id),
],
[
'type' => 'separator',
],
];
if ($episode->published_at === null) {
$items[] = [
'type' => 'link',
'title' => lang('Episode.delete'),
'uri' => route_to('episode-delete', $podcast->id, $episode->id),
'class' => 'font-semibold text-red-600',
];
} else {
$label = lang('Episode.delete');
$icon = icon('forbid');
$title = lang('Episode.messages.unpublishBeforeDeleteTip');
$items[] = [
'type' => 'html',
'content' => esc(<<<CODE_SAMPLE
<span class="inline-flex items-center px-4 py-1 font-semibold text-gray-400 cursor-not-allowed" data-tooltip="bottom" title="{$title}">{$icon}<span class="ml-2">{$label}</span></span>
CODE_SAMPLE),
];
}
return '<button id="more-dropdown-' . $episode->id . '" type="button" class="inline-flex items-center p-1 rounded-full focus:ring-accent" data-dropdown="button" data-dropdown-target="more-dropdown-' . $episode->id . '-menu" aria-haspopup="true" aria-expanded="false">' .
icon('more') .
'</button>' .
'<DropdownMenu id="more-dropdown-' . $episode->id . '-menu" labelledby="more-dropdown-' . $episode->id . '" offsetY="-24" items="' . esc(json_encode($items)) . '" />';
},
],
],
$episodes,
'mb-6 mt-4',
$podcast
) ?>
<?= $pager->links() ?>