mirror of
https://github.com/Karaka-Management/oms-Tag.git
synced 2026-01-11 15:48:42 +00:00
add list pagination
This commit is contained in:
parent
4945558980
commit
30c173e09c
|
|
@ -20,11 +20,13 @@ use Modules\Tag\Models\L11nTagMapper;
|
|||
use Modules\Tag\Models\Tag;
|
||||
use Modules\Tag\Models\TagMapper;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
use phpOMS\Message\Http\HttpRequest;
|
||||
use phpOMS\Message\NotificationLevel;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
use phpOMS\Model\Message\FormValidation;
|
||||
use phpOMS\System\MimeType;
|
||||
use phpOMS\Uri\HttpUri;
|
||||
|
||||
/**
|
||||
* Tag controller class.
|
||||
|
|
@ -53,7 +55,9 @@ final class ApiController extends Controller
|
|||
{
|
||||
$val = [];
|
||||
if (($val['title'] = empty($request->getData('title')))
|
||||
|| ($val['color'] = (!empty($request->getData('color')) && !\ctype_xdigit(\ltrim($request->getData('color'), '#'))))
|
||||
|| ($val['color'] = (!empty($request->getData('color'))
|
||||
&& (!\ctype_xdigit(\ltrim($request->getData('color'), '#'))
|
||||
|| \stripos($request->getData('color'), '#') !== 0)))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
|
@ -124,8 +128,13 @@ final class ApiController extends Controller
|
|||
$tag = $this->createTagFromRequest($request);
|
||||
$this->createModel($request->getHeader()->getAccount(), $tag, TagMapper::class, 'tag');
|
||||
|
||||
$request->setData('tag', $tag->getId(), true);
|
||||
$l11nTag = $this->createL11nTagFromRequest($request);
|
||||
$l11nRequest = new HttpRequest($request->getUri());
|
||||
$l11nRequest->setData('tag', $tag->getId());
|
||||
$l11nRequest->setData('title', $request->getData('title'));
|
||||
$l11nRequest->setData('color', $request->getData('color'));
|
||||
$l11nRequest->setData('language', $request->getData('language'));
|
||||
|
||||
$l11nTag = $this->createL11nTagFromRequest($l11nRequest);
|
||||
$this->createModel($request->getHeader()->getAccount(), $l11nTag, L11nTagMapper::class, 'tag_l11n');
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Tag', 'Tag successfully created', $tag);
|
||||
|
|
@ -170,7 +179,7 @@ final class ApiController extends Controller
|
|||
private function createTagFromRequest(RequestAbstract $request) : Tag
|
||||
{
|
||||
$tag = new Tag();
|
||||
$tag->setColor($request->getData('color') ?? '#00000000');
|
||||
$tag->setColor(\str_pad($request->getData('color') ?? '#000000ff', 9, 'f'));
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
|
@ -188,7 +197,9 @@ final class ApiController extends Controller
|
|||
{
|
||||
$l11nTag = new L11nTag();
|
||||
$l11nTag->setTag((int) ($request->getData('tag') ?? 0));
|
||||
$l11nTag->setLanguage((string) ($request->getData('language') ?? ISO639x1Enum::_EN));
|
||||
$l11nTag->setLanguage((string) (
|
||||
$request->getData('language') ?? $request->getHeader()->getL11n()->getLanguage()
|
||||
));
|
||||
$l11nTag->setTitle((string) ($request->getData('title') ?? ''));
|
||||
|
||||
return $l11nTag;
|
||||
|
|
|
|||
|
|
@ -73,8 +73,17 @@ final class BackendController extends Controller
|
|||
$view->setTemplate('/Modules/Tag/Theme/Backend/tag-list');
|
||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1007501001, $request, $response));
|
||||
|
||||
$tags = TagMapper::withConditional('language', $response->getHeader()->getL11n()->getLanguage())::getNewest(50);
|
||||
$view->addData('tags', $tags);
|
||||
if ($request->getData('ptype') === '-') {
|
||||
$view->setData('tags',
|
||||
TagMapper::withConditional('language', $response->getHeader()->getL11n()->getLanguage())
|
||||
::getBeforePivot((int) ($request->getData('id') ?? 0), null, 25)
|
||||
);
|
||||
} else {
|
||||
$view->setData('tags',
|
||||
TagMapper::withConditional('language', $response->getHeader()->getL11n()->getLanguage())
|
||||
::getAfterPivot((int) ($request->getData('id') ?? 0), null, 25)
|
||||
);
|
||||
}
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,12 +12,17 @@
|
|||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use phpOMS\Uri\UriFactory;
|
||||
|
||||
/**
|
||||
* @var \phpOMS\Views\View $this
|
||||
* @var \Modules\Tag\Models\Tag[] $tags
|
||||
*/
|
||||
$tags = $this->getData('tags');
|
||||
|
||||
$previous = empty($tags) ? '{/prefix}tag/list' : '{/prefix}tag/list?{?}&id=' . \reset($tags)->getId() . '&ptype=-';
|
||||
$next = empty($tags) ? '{/prefix}tag/list' : '{/prefix}tag/list?{?}&id=' . \end($tags)->getId() . '&ptype=+';
|
||||
|
||||
echo $this->getData('nav')->render(); ?>
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
|
|
@ -30,7 +35,7 @@ echo $this->getData('nav')->render(); ?>
|
|||
<td class="wf-100"><?= $this->getHtml('Color') ?>
|
||||
<tbody>
|
||||
<?php $count = 0; foreach ($tags as $key => $value) : ++$count;
|
||||
$url = \phpOMS\Uri\UriFactory::build('{/prefix}tag/single?{?}&id=' . $value->getId()); ?>
|
||||
$url = UriFactory::build('{/prefix}tag/single?{?}&id=' . $value->getId()); ?>
|
||||
<tr data-href="<?= $url; ?>">
|
||||
<td data-label="<?= $this->getHtml('Title') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getTitle()); ?></a>
|
||||
<td data-label="<?= $this->getHtml('Title') ?>"><a href="<?= $url; ?>"><span class="tag" style="background: <?= $this->printHtml($value->getColor()); ?>"> </span></a>
|
||||
|
|
@ -39,6 +44,9 @@ echo $this->getData('nav')->render(); ?>
|
|||
<tr><td colspan="3" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
<div class="portlet-foot"></div>
|
||||
<div class="portlet-foot">
|
||||
<a class="button" href="<?= UriFactory::build($previous); ?>"><?= $this->getHtml('Previous', '0', '0'); ?></a>
|
||||
<a class="button" href="<?= UriFactory::build($next); ?>"><?= $this->getHtml('Next', '0', '0'); ?></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user