Optimized template draft

This commit is contained in:
Kevin Frantz 2019-02-25 12:50:26 +01:00
parent d0adc9b42a
commit 2cf9e019e8
22 changed files with 208 additions and 178 deletions

View File

@ -7,6 +7,7 @@ twig:
layer_action_map: "@Infinito\\Domain\\LayerManagement\\LayerActionMap"
requested_action_service: "@Infinito\\Domain\\RequestManagement\\Action\\RequestedActionService"
action_icon_class_map: "@Infinito\\Domain\\TwigManagement\\ActionIconClassMap"
layer_icon_class_map: "@Infinito\\Domain\\TwigManagement\\LayerIconClassMap"
action_template_name_service: "@Infinito\\Domain\\TemplateManagement\\ActionTemplateNameServiceInterface"
action_template_data_store_service: "@Infinito\\Domain\\TemplateManagement\\ActionTemplateDataStoreServiceInterface"
entity_dom_service: "@Infinito\\Domain\\DomManagement\\EntityDomServiceInterface"

View File

@ -10,6 +10,12 @@ use Infinito\Domain\RequestManagement\Entity\RequestedEntityServiceInterface;
use Infinito\Exception\NotCorrectInstanceException;
/**
* This class is not ready and not tested!
*
* @todo Implement tests!
* @todo finish class!
* @todo refactor class!
*
* @author kevinfrantz
*/
final class EntityDomService implements EntityDomServiceInterface

View File

@ -10,9 +10,13 @@ use Infinito\Attribut\ActionTypeAttribut;
use Infinito\DBAL\Types\ActionType;
use Infinito\Domain\FormManagement\RequestedActionFormBuilderServiceInterface;
use Infinito\Domain\RequestManagement\Action\RequestedActionServiceInterface;
use Infinito\Domain\SecureManagement\SecureRequestedRightCheckerServiceInterface;
/**
* @author kevinfrantz
*
* @todo Refactor this class
* @todo Test this class
*/
final class MVCRoutineService implements MVCRoutineServiceInterface
{
@ -48,6 +52,11 @@ final class MVCRoutineService implements MVCRoutineServiceInterface
*/
private $requestedActionService;
/**
* @var SecureRequestedRightCheckerServiceInterface
*/
private $secureRequestedRightCheckerService;
/**
* @return View
*/
@ -62,13 +71,14 @@ final class MVCRoutineService implements MVCRoutineServiceInterface
/**
* @param ActionHandlerServiceInterface $actionHandlerService
*/
public function __construct(ActionHandlerServiceInterface $actionHandlerService, TemplateNameServiceInterface $templateNameService, ActionTemplateDataStoreServiceInterface $actionTemplateDataStore, RequestedActionFormBuilderServiceInterface $requestedActionFormBuilderService, RequestedActionServiceInterface $requestedActionService)
public function __construct(ActionHandlerServiceInterface $actionHandlerService, TemplateNameServiceInterface $templateNameService, ActionTemplateDataStoreServiceInterface $actionTemplateDataStore, RequestedActionFormBuilderServiceInterface $requestedActionFormBuilderService, RequestedActionServiceInterface $requestedActionService, SecureRequestedRightCheckerServiceInterface $secureRequestedRightCheckerService)
{
$this->actionHandlerService = $actionHandlerService;
$this->templateNameService = $templateNameService;
$this->actionTemplateDataStore = $actionTemplateDataStore;
$this->requestedActionFormBuilderService = $requestedActionFormBuilderService;
$this->requestedActionService = $requestedActionService;
$this->secureRequestedRightCheckerService = $secureRequestedRightCheckerService;
}
/**
@ -80,17 +90,29 @@ final class MVCRoutineService implements MVCRoutineServiceInterface
public function process(): View
{
if (!$this->actionType) {
//UPDATE
$this->requestedActionService->setActionType(ActionType::CREATE);
$updateForm = $this->requestedActionFormBuilderService->createByService()->getForm()->createView();
$this->actionTemplateDataStore->setData(ActionType::UPDATE, $updateForm);
//READ
$this->requestedActionService->setActionType(ActionType::READ);
$read = $this->actionHandlerService->handle();
$this->actionTemplateDataStore->setData(ActionType::READ, $read);
$view = $this->getView();
if ($this->requestedActionService->hasRequestedEntity()) {
//READ
$this->requestedActionService->setActionType(ActionType::READ);
if ($this->secureRequestedRightCheckerService->check($this->requestedActionService)) {
$read = $this->actionHandlerService->handle();
$this->actionTemplateDataStore->setData(ActionType::READ, $read);
}
$this->requestedActionService->setActionType(ActionType::UPDATE);
//UPDATE
if ($this->secureRequestedRightCheckerService->check($this->requestedActionService)) {
$updateForm = $this->requestedActionFormBuilderService->createByService()->getForm()->createView();
$this->actionTemplateDataStore->setData(ActionType::UPDATE, $updateForm);
}
//DELETE
//EXECUTE
} else {
//CREATE
$this->requestedActionService->setActionType(ActionType::CREATE);
$updateForm = $this->requestedActionFormBuilderService->createByService()->getForm()->createView();
$this->actionTemplateDataStore->setData(ActionType::CREATE, $updateForm);
}
return $view;
return $this->getView();
}
throw new \Exception('Not implemented yet!');
}

View File

@ -0,0 +1,37 @@
<?php
namespace Infinito\Domain\TwigManagement;
use Infinito\Exception\NotSetException;
use Infinito\DBAL\Types\Meta\Right\LayerType;
/**
* @author kevinfrantz
*/
final class LayerIconClassMap implements LayerIconClassMapInterface
{
/**
* @var array|string[]
*/
const LAYER_ICON_CLASS_MAP = [
LayerType::SOURCE => 'fas fa-tint',
LayerType::LAW => 'fas fa-gavel',
LayerType::RIGHT => 'fas fa-check',
LayerType::HEREDITY => 'fas fa-seedling',
LayerType::MEMBER => 'fas fa-users',
LayerType::CREATOR => 'fas fa-bed',
];
/**
* {@inheritdoc}
*
* @see \Infinito\Domain\TwigManagement\LayerIconClassMapInterface::getIconClass()
*/
public function getIconClass(string $layer): string
{
if (key_exists($layer, self::LAYER_ICON_CLASS_MAP)) {
return self::LAYER_ICON_CLASS_MAP[$layer];
}
throw new NotSetException("The key <<$layer>> is not defined in the map!");
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace Infinito\Domain\TwigManagement;
/**
* Maps actions to classes.
*
* @author kevinfrantz
*/
interface LayerIconClassMapInterface
{
/**
* @param string $layer
*
* @return string
*/
public function getIconClass(string $layer): string;
}

View File

@ -11,7 +11,7 @@ use Infinito\Entity\Source\Primitive\Text\TextSource;
/**
* @author kevinfrantz
*/
final class TextSourceCreateType extends SourceType
class TextSourceCreateType extends SourceType
{
/**
* {@inheritdoc}

View File

@ -0,0 +1,10 @@
<?php
namespace Infinito\Form\Source\Primitive\Text;
/**
* @author kevinfrantz
*/
final class TextSourceUpdateType extends TextSourceCreateType
{
}

View File

@ -21,27 +21,52 @@ class Menu
*/
private $factory;
/**
* @param FactoryInterface $factory
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(FactoryInterface $factory, EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
$this->factory = $factory;
}
/**
* @param RequestStack $request
*
* @return ItemInterface
*/
public function sourceNavbar(RequestStack $request): ItemInterface
{
return $this->createMenu(MenuEventType::SOURCE, $request);
}
/**
* @param RequestStack $request
*
* @return ItemInterface
*/
public function nodeSubbar(RequestStack $request): ItemInterface
{
return $this->createMenu(MenuEventType::NODE, $request);
}
/**
* @param RequestStack $request
*
* @return ItemInterface
*/
public function userTopbar(RequestStack $request): ItemInterface
{
return $this->createMenu(MenuEventType::USER, $request);
}
/**
* @param string $type
* @param RequestStack $request
*
* @return ItemInterface
*/
private function createMenu(string $type, RequestStack $request): ItemInterface
{
$menu = $this->createBasicMenuItem();
@ -50,6 +75,9 @@ class Menu
return $menu;
}
/**
* @return ItemInterface
*/
private function createBasicMenuItem(): ItemInterface
{
return $this->factory->createItem('root', [

View File

@ -10,6 +10,9 @@ use Infinito\Event\Menu\MenuEvent;
use Infinito\DBAL\Types\MenuEventType;
use Infinito\Domain\FixtureManagement\FixtureSource\ImpressumFixtureSource;
/**
* @author kevinfrantz
*/
class UserMenuSubscriber implements EventSubscriberInterface
{
/**
@ -22,6 +25,10 @@ class UserMenuSubscriber implements EventSubscriberInterface
*/
private $translator;
/**
* @param TokenStorageInterface $tokenStorage
* @param TranslatorInterface $translator
*/
public function __construct(TokenStorageInterface $tokenStorage, TranslatorInterface $translator)
{
$this->tokenStorage = $tokenStorage;
@ -42,7 +49,7 @@ class UserMenuSubscriber implements EventSubscriberInterface
]);
$menu->addChild($this->translator->trans('imprint'), [
'uri' => 'rest/api/source/'.strtolower(ImpressumFixtureSource::SLUG).'.html',
'uri' => '/api/rest/source/'.strtolower(ImpressumFixtureSource::SLUG).'.html',
'attributes' => [
'icon' => 'fas fa-address-card',
],
@ -50,6 +57,9 @@ class UserMenuSubscriber implements EventSubscriberInterface
$this->generateUserDropdown($menu);
}
/**
* @param ItemInterface $menu
*/
private function generateUserDropdown(ItemInterface $menu): void
{
$dropdown = $menu->addChild($this->tokenStorage->getToken()
@ -91,6 +101,9 @@ class UserMenuSubscriber implements EventSubscriberInterface
]);
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [

View File

@ -0,0 +1,12 @@
{% set icon_class = layer_icon_class_map.getIconClass(layer) %}
<i class="{{ icon_class }}"></i>
{# <a href="{{
path('infinito_api_rest_layer_read',{'layer':layer,'_format':'html'})}}">
#}
{{ layer|capitalize }}: {# </a>#}
{% if slug is defined and slug%}
<a
href="{{ path('infinito_api_rest_layer_read',{'identity':slug,'layer':layer,'_format':'html'}) }}">
{{ slug }}</a>{% endif %}<a
href="{{ path('infinito_api_rest_layer_read',{'identity':id,'layer':layer,'_format':'html'}) }}">#{{ id }}
</a>

View File

@ -12,7 +12,10 @@
<td>{{ name|trans }}</td>
<td>
{% if id and layer %}
<a href="{{ path('infinito_api_rest_layer_read',{'identity':id,'layer':layer,'_format':'html'}) }}">{{ content }}</a>
<a href="{{ path('infinito_api_rest_layer_read',{'identity':id,'layer':layer,'_format':'html'}) }}">
<i class="fas fa-link"></i>
{% if id == content %}#{% endif %}{{ content }}
</a>
{% else %}
{{ content }}
{% endif %}

View File

@ -1,115 +1,51 @@
{# @todo Refactor this template #}
{% extends "frames/default.html.twig" %}
{% set layer = requested_action_service.getLayer()%}
{% set entity = action_template_data_store_service.getData('read') %}
{% set headline = (layer|trans|capitalize)~':' %}
{% if entity.hasSlug %}
{% set headline = headline~entity.slug %}
{% set headline = (layer|trans|capitalize)~': ' %}
{% if requested_action_service.hasRequestedEntity()%}
{% set entity = requested_action_service.getRequestedEntity().getEntity() %}
{% if entity.hasSlug is defined and entity.hasSlug %}
{% set headline = headline~entity.slug %}
{% endif %}
{% set headline = headline~'#'~entity.id %}
{% endif %}
{% set headline = headline~'#'~entity.id %}
{% block title %}
{{ headline }}:
{{ headline }}
{% endblock %}
{% block content %}
<h1>
{{ headline }}
</h1>
<div id="accordion">
{% for action in layer_action_map.getActions(layer) %}
{% if action_template_data_store_service.isDataStored(action) %}
{{ action_template_name_service.setActionType(action) }}
<div class="card">
<div class="card-header" id="heading_{{ action }}">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse"
data-target="#collapse_{{ action }}" aria-expanded="false"
aria-controls="collapse_{{ action }}">
<i class="{{ action_icon_class_map.getIconClass(action) }}"></i> {{ action|trans }}
</button>
</h5>
</div>
<div id="collapse_{{ action }}" class="collapse"
aria-labelledby="heading_{{ action }}" data-parent="#accordion">
<div class="card-body">
{% include [action_template_name_service.getAtomTemplateName(),'entity/_entity_'~action~'.html.twig'] %}
</div>
</div>
</div>
{% endif %}
{% endfor %}
</div>
<hr />
<div id="accordion">
<div class="card">
<div class="card-header" id="headingThree">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse"
data-target="#collapseThree" aria-expanded="false"
aria-controls="collapseThree">
<i class="fas fa-wrench"></i> Manage
</button>
</h5>
</div>
<div id="collapseThree" class="collapse"
aria-labelledby="headingThree" data-parent="#accordion">
<div class="card-body">Anim pariatur cliche reprehenderit, enim
eiusmod high life accusamus terry richardson ad squid. 3 wolf moon
officia aute, non cupidatat skateboard dolor brunch. Food truck
quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt
aliqua put a bird on it squid single-origin coffee nulla assumenda
shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes
anderson cred nesciunt sapiente ea proident. Ad vegan excepteur
butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw
denim aesthetic synth nesciunt you probably haven't heard of them
accusamus labore sustainable VHS.</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingHistory">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse"
data-target="#collapseHistory" aria-expanded="false"
aria-controls="collapseHistory">
<i class="fas fa-history"></i> History
</button>
</h5>
</div>
<div id="collapseHistory" class="collapse"
aria-labelledby="headingHistory" data-parent="#accordion">
<div class="card-body">Anim pariatur cliche reprehenderit, enim
eiusmod high life accusamus terry richardson ad squid. 3 wolf moon
officia aute, non cupidatat skateboard dolor brunch. Food truck
quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt
aliqua put a bird on it squid single-origin coffee nulla assumenda
shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes
anderson cred nesciunt sapiente ea proident. Ad vegan excepteur
butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw
denim aesthetic synth nesciunt you probably haven't heard of them
accusamus labore sustainable VHS.</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingRelation">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse"
data-target="#collapseHistory" aria-expanded="false"
aria-controls="collapseRelation">
<i class="fas fa-map-marked-alt"></i> Map
</button>
</h5>
</div>
<div id="collapseRelation" class="collapse"
aria-labelledby="headingRelation" data-parent="#accordion">
<div class="card-body">Anim pariatur cliche reprehenderit, enim
eiusmod high life accusamus terry richardson ad squid. 3 wolf moon
officia aute, non cupidatat skateboard dolor brunch. Food truck
quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt
aliqua put a bird on it squid single-origin coffee nulla assumenda
shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes
anderson cred nesciunt sapiente ea proident. Ad vegan excepteur
butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw
denim aesthetic synth nesciunt you probably haven't heard of them
accusamus labore sustainable VHS.</div>
</div>
</div>
</div>
<h1>
{% include "element/link/_layer_link.html.twig" with {'id':entity.getId(),'layer':layer,'slug':((entity.hasSlug() is defined and entity.hasSlug())?entity.getSlug():null)} %}
</h1>
{% if action_template_data_store_service.getAllStoredData().count() > 0 %}
<div id="accordion">
{% set aria_expanded = 'true' %}
{% for action in layer_action_map.getActions(layer) %}
{% if action_template_data_store_service.isDataStored(action) %}
{{ action_template_name_service.setActionType(action) }}
<div class="card">
<div class="card-header" id="heading_{{ action }}">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse"
data-target="#collapse_{{ action }}" aria-expanded="{{ aria_expanded }}"
aria-controls="collapse_{{ action }}">
<i class="{{ action_icon_class_map.getIconClass(action) }}"></i> {{ action|trans }}
</button>
</h5>
</div>
<div id="collapse_{{ action }}" class="collapse {{ (aria_expanded == 'true')?'show':'' }}"
aria-labelledby="heading_{{ action }}" data-parent="#accordion">
<div class="card-body">
{% include [action_template_name_service.getAtomTemplateName(),'entity/_entity_'~action~'.html.twig'] %}
</div>
</div>
</div>
{% endif %}
{% set aria_expanded = 'false' %}
{% endfor %}
</div>
{% else %}
<div class="alert alert-warning" role="alert">
<i class="fas fa-exclamation-triangle"></i> {{ 'This entity doesn\'t offer you any options. It seems like you don\'t have any right to perform actions on this entity.'|trans }}
</div>
{% endif %}
{% endblock %}

View File

@ -1,6 +0,0 @@
{% extends "frames/default.html.twig" %}
{% block title %}
{% trans %}
Law
{% endtrans %}
{% endblock %}

View File

@ -1,17 +0,0 @@
{% extends "law/law.html.twig" %}
{% block content %}
<h1>
{% trans %}
Law
{% endtrans %}
#
{{ law.id }}
</h1>
{% trans %}
Responsible for:
{% endtrans %}
<a href="{{ path('app_node_show',{'id':law.node.id})}}"> {% trans with {'%law.node.id%':law.node.id}%}
node #%law.node.id% {% endtrans %}
</a>
.
{% endblock %}

View File

@ -1,3 +0,0 @@
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}

View File

@ -1,5 +0,0 @@
{% extends "source/form/source.html.twig" %}
{% block content %}
<h1>{% trans %} Name {% endtrans %}</h1>
{% include "source/form/content/name." ~ app.request.requestFormat ~ ".twig" %}
{% endblock %}

View File

@ -1,6 +0,0 @@
{% extends "source/source.html.twig" %}
{% block title %}
{% trans %}
Source edit
{% endtrans %}
{% endblock %}

View File

@ -1 +0,0 @@
{{ source.name }}

View File

@ -1 +0,0 @@
{% include "source/view/content/name." ~ app.request.requestFormat ~ ".twig" with {'source':source.nameSource}%}

View File

@ -1,5 +0,0 @@
{% extends "source/view/source.html.twig" %}
{% block content %}
<h1>{% trans %} Name {% endtrans %}</h1>
{% include "source/view/content/name." ~ app.request.requestFormat ~ ".twig" %}
{% endblock %}

View File

@ -1,7 +0,0 @@
{% extends "source/source.html.twig" %}
{% block title %}
{% trans %}
Source
{% endtrans %}
#{{ source.id }}
{% endblock %}

View File

@ -1,5 +0,0 @@
{% extends "source/view/source.html.twig" %}
{% block content %}
<h1>{% trans %} User {% endtrans %}</h1>
{% include "source/view/content/user." ~ app.request.requestFormat ~ ".twig" %}
{% endblock %}