Commit 99a3b8d3 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

fix: set episode numbers during import + remove all custom form_helpers + minor ui issues

parent b05d177f
<?php
declare(strict_types=1);
/**
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
//--------------------------------------------------------------------
if (! function_exists('form_dropdown')) {
/**
* Drop-down Menu (based on html select tag)
*
* @param array<string, mixed> $options
* @param array<string|int> $selected
* @param array<string, mixed> $customExtra
*/
function form_dropdown(
string $name = '',
array $options = [],
array $selected = [],
array $customExtra = []
): string {
$defaultExtra = [
'data-select-text' => lang('Common.forms.multiSelect.selectText'),
'data-loading-text' => lang('Common.forms.multiSelect.loadingText'),
'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'),
'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'),
'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'),
];
$extra = array_merge($defaultExtra, $customExtra);
$defaults = [
'name' => $name,
];
// standardize selected as strings, like the option keys will be.
foreach ($selected as $key => $item) {
$selected[$key] = $item;
}
$placeholderOption = '';
if (isset($extra['placeholder'])) {
$placeholderOption = '<option value="" disabled="disabled" hidden="hidden"' . (in_array(
'',
$selected,
true
) ? ' selected="selected"' : '') . '>' . $extra['placeholder'] . '</option>';
unset($extra['placeholder']);
}
$extra = stringify_attributes($extra);
$multiple = (count($selected) > 1 && stripos($extra, 'multiple') === false) ? ' multiple="multiple"' : '';
$form = '<select ' . rtrim(parse_form_attributes($name, $defaults)) . $extra . $multiple . ">\n";
$form .= $placeholderOption;
foreach ($options as $key => $val) {
if (is_array($val)) {
if ($val === []) {
continue;
}
$form .= '<optgroup label="' . $key . "\">\n";
foreach ($val as $optgroupKey => $optgroupVal) {
$sel = in_array($optgroupKey, $selected, true) ? ' selected="selected"' : '';
$form .= '<option value="' . htmlspecialchars($optgroupKey) . '"' . $sel . '>'
. $optgroupVal . "</option>\n";
}
$form .= "</optgroup>\n";
} else {
/** @noRector RecastingRemovalRector */
$form .= '<option value="' . htmlspecialchars((string) $key) . '"'
. (in_array($key, $selected, true) ? ' selected="selected"' : '') . '>'
. $val . "</option>\n";
}
}
return $form . "</select>\n";
}
}
......@@ -23,7 +23,7 @@ class Checkbox extends FormComponent
'name' => $this->name,
'class' => 'form-checkbox text-pine-500 border-black border-3 focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 w-6 h-6',
],
$this->value,
'yes',
old($this->name) ? old($this->name) === $this->value : $this->isChecked,
);
......
......@@ -10,16 +10,7 @@ class Input extends FormComponent
public function render(): string
{
$class = 'px-3 py-2 bg-white rounded-lg border-3 focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 ' . $this->class;
if (session()->has('errors')) {
$error = session('errors')[$this->name];
if ($error) {
$class .= ' border-red';
}
} else {
$class .= ' border-black focus:border-black';
}
$class = 'px-3 py-2 bg-white border-black rounded-lg focus:border-black border-3 focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 ' . $this->class;
$this->attributes['class'] = $class;
......
......@@ -31,6 +31,11 @@ class MultiSelect extends FormComponent
$defaultAttributes = [
'data-class' => $this->attributes['class'],
'multiple' => 'multiple',
'data-select-text' => lang('Common.forms.multiSelect.selectText'),
'data-loading-text' => lang('Common.forms.multiSelect.loadingText'),
'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'),
'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'),
'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'),
];
$extra = array_merge($defaultAttributes, $this->attributes);
......
......@@ -23,6 +23,11 @@ class Select extends FormComponent
$defaultAttributes = [
'class' => 'focus:border-black focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 border-3 rounded-lg border-black ' . $this->class,
'data-class' => $this->class,
'data-select-text' => lang('Common.forms.multiSelect.selectText'),
'data-loading-text' => lang('Common.forms.multiSelect.loadingText'),
'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'),
'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'),
'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'),
];
$extra = array_merge($this->attributes, $defaultAttributes);
......
......@@ -30,7 +30,7 @@ $pager->setSurroundCount(2);
<?php foreach ($pager->links() as $link): ?>
<li>
<?php if ($link['active']): ?>
<span class="block px-4 py-2 font-semibold text-white rounded-full bg-pine-600">
<span class="block px-4 py-2 font-semibold text-white rounded-full bg-pine-500">
<?= $link['title'] ?>
</span>
<?php else: ?>
......
......@@ -285,17 +285,17 @@ class PodcastImportController extends BaseController
}
}
$numberItems = $feed->channel[0]->item->count();
$itemsCount = $feed->channel[0]->item->count();
$lastItem =
$this->request->getPost('max_episodes') !== '' &&
$this->request->getPost('max_episodes') < $numberItems
$this->request->getPost('max_episodes') < $itemsCount
? (int) $this->request->getPost('max_episodes')
: $numberItems;
: $itemsCount;
$slugs = [];
for ($itemNumber = 1; $itemNumber <= $lastItem; ++$itemNumber) {
$item = $feed->channel[0]->item[$numberItems - $itemNumber];
$item = $feed->channel[0]->item[$itemsCount - $itemNumber];
$nsItunes = $item->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
$nsPodcast = $item->children(
......
<?php declare(strict_types=1);
if (session()->has('message')): ?>
<Alert variant="success"><?= session('message') ?></Alert>
<Alert variant="success" class="mb-4"><?= session('message') ?></Alert>
<?php endif; ?>
<?php if (session()->has('error')): ?>
<Alert variant="danger"><?= session('error') ?></Alert>
<Alert variant="danger" class="mb-4"><?= session('error') ?></Alert>
<?php endif; ?>
<?php if (session()->has('errors')): ?>
<Alert variant="danger">
<Alert variant="danger" class="mb-4">
<ul>
<?php foreach (session('errors') as $error): ?>
<li><?= $error ?></li>
......
......@@ -88,7 +88,7 @@
$podcast->id,
$episode->id,
) . '">' . lang(
'Episode.embeddable_player.add',
'Episode.embeddable_player.title',
) . '</a>' .
'<a class="px-4 py-1 hover:bg-gray-100" href="' . route_to(
'episode-persons-manage',
......
......@@ -50,7 +50,7 @@
[
'header' => lang('Common.actions'),
'cell' => function ($person): string {
return '<Button uri="' . route_to('episode-person-remove', $person->podcast_id, $person->episode_id, $person->id) . '" variant="danger" size="small">' . lang('Person.episode_form.remove') . '</Button>';
return '<Button uri="' . route_to('episode-person-remove', $person->podcast_id, $person->episode_id, $person->id) . '" variant="danger" size="small" iconLeft="delete-bin">' . lang('Person.episode_form.remove') . '</Button>';
},
],
],
......@@ -58,7 +58,7 @@
'max-w-xl'
) ?>
<form action="<?= route_to('episode-persons-manage', $episode->id) ?>" method="POST" class="mt-6">
<form action="<?= route_to('episode-persons-manage', $podcast->id, $episode->id) ?>" method="POST" class="mt-6">
<?= csrf_field() ?>
<Forms.Section
......
......@@ -68,7 +68,7 @@
$podcast->id,
$episode->id,
) ?>"><?= lang(
'Episode.embeddable_player.add',
'Episode.embeddable_player.title',
) ?></a>
<a class="px-4 py-1 hover:bg-gray-100" href="<?= route_to(
'episode-persons-manage',
......
<?php declare(strict_types=1);
if (session()->has('message')): ?>
<Alert variant="success"><?= session('message') ?></Alert>
<Alert variant="success" class="mb-4"><?= session('message') ?></Alert>
<?php endif; ?>
<?php if (session()->has('error')): ?>
<Alert variant="danger"><?= session('error') ?></Alert>
<Alert variant="danger" class="mb-4"><?= session('error') ?></Alert>
<?php endif; ?>
<?php if (session()->has('errors')): ?>
<Alert variant="danger">
<Alert variant="danger" class="mb-4">
<ul>
<?php foreach (session('errors') as $error): ?>
<li><?= $error ?></li>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment