draft tags and portlets

This commit is contained in:
Dennis Eichhorn 2020-03-01 15:00:33 +01:00
parent 6a5b355df9
commit 43dd58324a
17 changed files with 596 additions and 19 deletions

View File

@ -0,0 +1,48 @@
[
{
"id": 1007501001,
"pid": "/",
"type": 2,
"subtype": 1,
"name": "Tag",
"uri": "{/prefix}tag/list?{?}",
"target": "self",
"icon": null,
"order": 75,
"from": "Tag",
"permission": { "permission": 2, "type": null, "element": null },
"parent": 1003301001,
"children": [
{
"id": 1007502001,
"pid": "/tag",
"type": 3,
"subtype": 1,
"name": "List",
"uri": "{/prefix}tag/list?{?}",
"target": "self",
"icon": null,
"order": 1,
"from": "Tag",
"permission": { "permission": 2, "type": null, "element": null },
"parent": 1007501001,
"children": []
},
{
"id": 1007502101,
"pid": "/tag",
"type": 3,
"subtype": 5,
"name": "Create",
"uri": "{/prefix}tag/create?{?}",
"target": "self",
"icon": null,
"order": 15,
"from": "Tag",
"permission": { "permission": 4, "type": null, "element": null },
"parent": 1007501001,
"children": []
}
]
}
]

View File

@ -0,0 +1,43 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Tag\Admin\Install
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Tag\Admin\Install;
use phpOMS\DataStorage\Database\DatabasePool;
/**
* Navigation class.
*
* @package Modules\Tag\Admin\Install
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class Navigation
{
/**
* Install navigation providing
*
* @param string $path Module path
* @param DatabasePool $dbPool Database pool for database interaction
*
* @return void
*
* @since 1.0.0
*/
public static function install(string $path, DatabasePool $dbPool) : void
{
\Modules\Navigation\Admin\Installer::installExternal($dbPool, ['path' => __DIR__ . '/Navigation.install.json']);
}
}

View File

@ -16,7 +16,7 @@
},
"tag_color": {
"name": "tag_color",
"type": "VARCHAR(8)",
"type": "VARCHAR(9)",
"null": false
},
"tag_type": {

View File

@ -6,7 +6,7 @@ use phpOMS\Account\PermissionType;
use phpOMS\Router\RouteVerb;
return [
'^.*/tag.*$' => [
'^.*/tag$' => [
[
'dest' => '\Modules\Tag\Controller\ApiController:apiTagCreate',
'verb' => RouteVerb::PUT,
@ -35,4 +35,15 @@ return [
],
],
],
'^.*/tag/find.*$' => [
[
'dest' => '\Modules\Tag\Controller\ApiController:apiTagFind',
'verb' => RouteVerb::GET,
'permission' => [
'module' => ApiController::MODULE_NAME,
'type' => PermissionType::READ,
'state' => PermissionState::TAG,
],
],
],
];

View File

@ -0,0 +1,42 @@
<?php declare(strict_types=1);
use Modules\Tag\Controller\BackendController;
use Modules\Tag\Models\PermissionState;
use phpOMS\Account\PermissionType;
use phpOMS\Router\RouteVerb;
return [
'^.*/tag/create.*$' => [
[
'dest' => '\Modules\Tag\Controller\BackendController:viewTagCreate',
'verb' => RouteVerb::GET,
'permission' => [
'module' => BackendController::MODULE_NAME,
'type' => PermissionType::CREATE,
'state' => PermissionState::TAG,
],
],
],
'^.*/tag/list.*$' => [
[
'dest' => '\Modules\Tag\Controller\BackendController:viewTagList',
'verb' => RouteVerb::GET,
'permission' => [
'module' => BackendController::MODULE_NAME,
'type' => PermissionType::READ,
'state' => PermissionState::TAG,
],
],
],
'^.*/tag/single.*$' => [
[
'dest' => '\Modules\Tag\Controller\BackendController:viewTagSingle',
'verb' => RouteVerb::GET,
'permission' => [
'module' => BackendController::MODULE_NAME,
'type' => PermissionType::READ,
'state' => PermissionState::TAG,
],
],
],
];

View File

@ -21,6 +21,7 @@ use phpOMS\Message\NotificationLevel;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\Model\Message\FormValidation;
use phpOMS\System\MimeType;
/**
* Tag controller class.
@ -49,7 +50,7 @@ final class ApiController extends Controller
{
$val = [];
if (($val['title'] = empty($request->getData('title')))
|| ($val['color'] = (!empty($request->getData('color')) && !\ctype_xdigit($request->getData('color'))))
|| ($val['color'] = (!empty($request->getData('color')) && !\ctype_xdigit(\ltrim($request->getData('color'), '#'))))
) {
return $val;
}
@ -135,7 +136,7 @@ final class ApiController extends Controller
{
$tag = new Tag();
$tag->setTitle((string) ($request->getData('title') ?? ''));
$tag->setColor($request->getData('color') ?? '00000000');
$tag->setColor($request->getData('color') ?? '#00000000');
return $tag;
}
@ -178,4 +179,29 @@ final class ApiController extends Controller
$this->deleteModel($request->getHeader()->getAccount(), $tag, TagMapper::class, 'tag');
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Tag', 'Tag successfully deleted', $tag);
}
/**
* Api method to find tags
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiTagFind(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
$response->getHeader()->set('Content-Type', MimeType::M_JSON, true);
$response->set(
$request->getUri()->__toString(),
\array_values(
TagMapper::find((string) ($request->getData('search') ?? ''))
)
);
}
}

View File

@ -0,0 +1,107 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Tag
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Tag\Controller;
use Modules\Tag\Models\TagMapper;
use Modules\Tag\Models\PermissionState;
use phpOMS\Account\PermissionType;
use phpOMS\Contract\RenderableInterface;
use phpOMS\Message\Http\RequestStatusCode;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\Views\View;
/**
* Calendar controller class.
*
* @package Modules\Tag
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class BackendController extends Controller
{
/**
* Routing end-point for application behaviour.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return RenderableInterface
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function viewTagCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface
{
$view = new View($this->app->l11nManager, $request, $response);
$view->setTemplate('/Modules/Tag/Theme/Backend/tag-create');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1007501001, $request, $response));
return $view;
}
/**
* Routing end-point for application behaviour.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return RenderableInterface
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function viewTagList(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface
{
$view = new View($this->app->l11nManager, $request, $response);
$view->setTemplate('/Modules/Tag/Theme/Backend/tag-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1007501001, $request, $response));
$tags = TagMapper::getNewest(50);
$view->addData('tags', $tags);
return $view;
}
/**
* Routing end-point for application behaviour.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return RenderableInterface
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function viewTagSingle(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface
{
$view = new View($this->app->l11nManager, $request, $response);
$tag = TagMapper::get((int) $request->getData('id'));
$view->setTemplate('/Modules/Tag/Theme/Backend/tag-single');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1007501001, $request, $response));
$view->addData('tag', $tag);
return $view;
}
}

View File

@ -17,7 +17,7 @@ namespace Modules\Tag\Models;
use phpOMS\Contract\ArrayableInterface;
/**
* Tag article class.
* Tag class.
*
* @package Modules\Tag\Models
* @license OMS License 1.0
@ -53,10 +53,10 @@ class Tag implements ArrayableInterface, \JsonSerializable
/**
* Creator.
*
* @var int
* @var null|int|\Modules\Admin\Models\Account
* @since 1.0.0
*/
protected $owner = 0;
protected $owner = null;
/**
* Tag type.
@ -69,7 +69,7 @@ class Tag implements ArrayableInterface, \JsonSerializable
/**
* Get created by
*
* @return null|int|\phpOMS\Account\Account
* @return null|int|\Modules\Admin\Models\Account
*
* @since 1.0.0
*/
@ -192,14 +192,6 @@ class Tag implements ArrayableInterface, \JsonSerializable
];
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return (string) \json_encode($this->toArray());
}
/**
* {@inheritdoc}
*/

View File

@ -35,7 +35,7 @@ final class TagMapper extends DataMapperAbstract
*/
protected static array $columns = [
'tag_id' => ['name' => 'tag_id', 'type' => 'int', 'internal' => 'id'],
'tag_title' => ['name' => 'tag_title', 'type' => 'string', 'internal' => 'title'],
'tag_title' => ['name' => 'tag_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
'tag_color' => ['name' => 'tag_color', 'type' => 'string', 'internal' => 'color'],
'tag_type' => ['name' => 'tag_type', 'type' => 'int', 'internal' => 'type'],
'tag_owner' => ['name' => 'tag_owner', 'type' => 'int', 'internal' => 'owner'],

View File

@ -0,0 +1,92 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Tag
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Tag\Theme\Backend\Components\TagSelector;
use phpOMS\Localization\L11nManager;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\Views\View;
/**
* Component view.
*
* @package Modules\Tag
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
* @codeCoverageIgnore
*/
class BaseView extends View
{
private $id = '';
private $name = '';
private $isRequired = false;
/**
* {@inheritdoc}
*/
public function __construct(L11nManager $l11n = null, RequestAbstract $request, ResponseAbstract $response)
{
parent::__construct($l11n, $request, $response);
$this->setTemplate('/Modules/Tag/Theme/Backend/Components/TagSelector/base');
}
/**
* Get selector id
*
* @return string
*
* @since 1.0.0
*/
public function getId() : string
{
return $this->id;
}
/**
* Get name
*
* @return string
*
* @since 1.0.0
*/
public function getName() : string
{
return $this->name;
}
/**
* Is required?
*
* @return bool
*
* @since 1.0.0
*/
public function isRequired() : bool
{
return $this->isRequired;
}
/**
* {@inheritdoc}
*/
public function render(...$data) : string
{
$this->id = $data[0];
$this->name = $data[1];
$this->isRequired = $data[2] ?? false;
return parent::render();
}
}

View File

@ -0,0 +1,49 @@
<div class="ipt-wrap">
<div class="ipt-first">
<span class="input">
<button type="button" id="<?= $this->printHtml($this->getId()); ?>-book-button" data-action='[
{
"key": 1, "listener": "click", "action": [
{"key": 1, "type": "dom.popup", "selector": "#acc-grp-tpl", "aniIn": "fadeIn", "id": "<?= $this->printHtml($this->getId()); ?>"},
{"key": 2, "type": "message.request", "uri": "<?= \phpOMS\Uri\UriFactory::build('{/prefix}tag?filter=some&limit=10'); ?>", "method": "GET", "request_type": "json"},
{"key": 3, "type": "dom.table.append", "id": "acc-table", "aniIn": "fadeIn", "data": [], "bindings": {"id": "id", "name": "title"}, "position": -1},
{"key": 4, "type": "message.request", "uri": "<?= \phpOMS\Uri\UriFactory::build('{/prefix}tag?filter=some&limit=10'); ?>", "method": "GET", "request_type": "json"},
{"key": 5, "type": "dom.table.append", "id": "grp-table", "aniIn": "fadeIn", "data": [], "bindings": {"id": "id", "name": "title"}, "position": -1}
]
}
]' formaction=""><i class="fa fa-book"></i></button>
<div class="advancedInput wf-100" id="<?= $this->printHtml($this->getId()); ?>">
<input autocomplete="off" class="input" type="text" id="i<?= $this->printHtml($this->getId()); ?>" placeholder="&#xf007; Guest"
data-emptyAfter="true"
data-autocomplete="false"
data-src="api/tag/find?search={#i<?= $this->printHtml($this->getId()); ?>}">
<div id="<?= $this->printHtml($this->getId()); ?>-dropdown" class="dropdown" data-active="true">
<table class="default">
<thead>
<tr>
<td>ID<i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<td>Title<i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<tbody>
<template id="<?= $this->printHtml($this->getId()); ?>-rowElement" class="rowTemplate">
<tr tabindex="-1">
<td data-tpl-text="/id" data-tpl-value="/id" data-value=""></td>
<td data-tpl-text="/title" data-tpl-value="/title" data-value=""></td>
</tr>
</template>
</tbody>
</table>
</div>
</div>
</span>
</div>
<div class="ipt-second"><button><?= $this->getHtml('Select', '0', '0'); ?></button></div>
</div>
<div class="box" id="<?= $this->printHtml($this->getId()); ?>-tags" data-limit="0" data-active="true">
<template id="<?= $this->printHtml($this->getId()); ?>-tagTemplate">
<span class="tag red" data-tpl-value="/id" data-value="" data-uuid="" data-name="<?= $this->printHtml($this->getName()); ?>" style="background: {/color};">
<i class="fa fa-times"></i>
<span data-tpl-text="/id" data-name="id" data-tpl-value="/id" data-value=""></span>
<span data-tpl-text="/title" data-tpl-value="/title" data-value=""></span>
</span>
</template>
</div>

View File

@ -0,0 +1,19 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Tag
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
return ['Navigation' => [
'Create' => 'Create',
'List' => 'List',
'Tag' => 'Tag',
]];

View File

@ -13,6 +13,10 @@
declare(strict_types=1);
return ['Tag' => [
'Tag' => 'Tag',
'Tags' => 'Tags',
'Color' => 'Color',
'Create' => 'Create',
'List' => 'List',
'Tag' => 'Tag',
'Tags' => 'Tags',
'Title' => 'Title',
]];

View File

@ -0,0 +1,40 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Editor
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
use phpOMS\Uri\UriFactory;
/**
* @var \phpOMS\Views\View $this
*/
echo $this->getData('nav')->render(); ?>
<div class="row">
<div class="col-xs-12 col-md-6">
<div class="portlet">
<form id="fUnitCreate" method="put" action="<?= UriFactory::build('{/api}tag'); ?>">
<div class="portlet-head"><?= $this->getHtml('Tag') ?></div>
<div class="portlet-body">
<table class="layout wf-100" style="table-layout: fixed">
<tr><td><label for="iTitle"><?= $this->getHtml('Title') ?></label>
<tr><td><input type="text" name="title" id="iTitle" placeholder="&#xf040; oms" required>
<tr><td><label for="iColor"><?= $this->getHtml('Color') ?></label>
<tr><td><input type="text" name="color" id="iColor" placeholder="#ff0000ff" required>
</table>
</div>
<div class="portlet-foot">
<input id="iSubmit" name="submit" type="submit" value="<?= $this->getHtml('Create', '0', '0'); ?>">
</div>
</form>
</div>
</div>
</div>

View File

@ -0,0 +1,44 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Editor
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
/**
* @var \phpOMS\Views\View $this
* @var \Modules\Tag\Models\Tag[] $tags
*/
$tags = $this->getData('tags');
echo $this->getData('nav')->render(); ?>
<div class="row">
<div class="col-xs-12">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('Tags') ?><i class="fa fa-download floatRight download btn"></i></div>
<table class="default">
<thead>
<tr>
<td class="wf-100"><?= $this->getHtml('Title') ?>
<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()); ?>
<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()); ?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a>
<?php endforeach; ?>
<?php if ($count === 0) : ?>
<tr><td colspan="3" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?>
</table>
<div class="portlet-foot"></div>
</div>
</div>

View File

@ -0,0 +1,42 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Editor
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
use phpOMS\Uri\UriFactory;
$tag = $this->getData('tag');
/**
* @var \phpOMS\Views\View $this
*/
echo $this->getData('nav')->render(); ?>
<div class="row">
<div class="col-xs-12 col-md-6">
<div class="portlet">
<form id="fUnitCreate" method="put" action="<?= UriFactory::build('{/api}tag'); ?>">
<div class="portlet-head"><?= $this->getHtml('Tag') ?></div>
<div class="portlet-body">
<table class="layout wf-100" style="table-layout: fixed">
<tr><td><label for="iTitle"><?= $this->getHtml('Title') ?></label>
<tr><td><input type="text" name="title" id="iTitle" placeholder="&#xf040; oms" value="<?= $this->printHtml($tag->getTitle()); ?>" required>
<tr><td><label for="iColor"><?= $this->getHtml('Color') ?></label>
<tr><td><input type="text" name="color" id="iColor" placeholder="#ff0000ff" value="<?= $this->printHtml($tag->getColor()); ?>" required>
</table>
</div>
<div class="portlet-foot">
<input id="iSubmit" name="submit" type="submit" value="<?= $this->getHtml('Save', '0', '0'); ?>">
</div>
</form>
</div>
</div>
</div>

View File

@ -24,5 +24,23 @@
"Navigation": "*"
},
"load": [
{
"pid": [
"/tag"
],
"type": 4,
"for": "Tag",
"file": "Tag",
"from": "Tag"
},
{
"pid": [
"/"
],
"type": 5,
"from": "Tag",
"for": "Navigation",
"file": "Navigation"
}
]
}