- Added a context list (from picea-ui form) to the ControllerTrait
- Added some default i18n text - Moved some reusable widget into lean view
This commit is contained in:
parent
abafee0b30
commit
4bd68a74f8
|
@ -18,7 +18,6 @@
|
|||
"mcnd/picea": "dev-master",
|
||||
"mcnd/picea-ui": "dev-master",
|
||||
"mcnd/cronard": "dev-master",
|
||||
"mcnd/storage": "dev-master",
|
||||
"mcnd/tell": "dev-master",
|
||||
"mcnd/dump": "dev-master",
|
||||
"mcnd/notes": "dev-master",
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"copyright" : "All rights reserved © {$organisation} {$year}",
|
||||
"dashboard": "Dashboard"
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"copyright" : "Tout droits réservés © {$organisation} {$year}",
|
||||
"dashboard": "Tableau de bord"
|
||||
}
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
namespace Lean;
|
||||
|
||||
use Picea;
|
||||
use Picea,
|
||||
Picea\Ui\Method\FormContext;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Storage\Session;
|
||||
|
||||
use Laminas\Diactoros\Response\{ HtmlResponse, TextResponse, RedirectResponse, JsonResponse };
|
||||
|
@ -12,7 +14,7 @@ use Ulmus\EntityCollection;
|
|||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
# use TheBugs\Email\MailerInterface;
|
||||
use TheBugs\Email\MailerInterface;
|
||||
|
||||
use Notes\Route\Annotation\Object\Route as RouteParam,
|
||||
Notes\Route\Annotation\Method\Route,
|
||||
|
@ -31,12 +33,23 @@ trait ControllerTrait {
|
|||
|
||||
public ? Picea\Picea $picea;
|
||||
|
||||
public MailerInterface $mailer;
|
||||
|
||||
public function __construct(? Picea\Picea $picea, Session $session/*, MailerInterface $mailer*/) {
|
||||
public ? MailerInterface $mailer;
|
||||
|
||||
public array $contextList = [];
|
||||
|
||||
public function __construct(? Picea\Picea $picea, Session $session, ? MailerInterface $mailer = null) {
|
||||
$this->picea = $picea;
|
||||
$this->session = $session;
|
||||
// $this->mailer = $mailer;
|
||||
$this->mailer = $mailer;
|
||||
}
|
||||
|
||||
public function exportJson(ServerRequestInterface $request, string $entityClass, bool $includeRelations = true, ? callable $callback = null) : ResponseInterface
|
||||
{
|
||||
foreach($entityClass::repository()->filterServerRequest( $entityClass::searchRequest()->fromRequest($request->withQueryParams($request->getQueryParams() + ['limit' => PHP_INT_MAX,])) )->loadAll() as $entity) {
|
||||
$data[] = $callback ? call_user_func($callback, $entity->toArray($includeRelations)) : $entity->toArray($includeRelations);
|
||||
}
|
||||
|
||||
return $this->renderJson( array_filter($data ?? [], function($row) { return $row !== null; }));
|
||||
}
|
||||
|
||||
public function renderView(string $view, ?array $variables = null) : ResponseInterface
|
||||
|
@ -54,7 +67,7 @@ trait ControllerTrait {
|
|||
protected function redirect(string $url, int $code = 302, array $headers = []) {
|
||||
return new RedirectResponse($url, $code, $headers);
|
||||
}
|
||||
|
||||
|
||||
public static function renderText(string $html, int $code = 200, array $headers = []) : ResponseInterface
|
||||
{
|
||||
return new TextResponse($html, $code, $headers);
|
||||
|
@ -69,4 +82,16 @@ trait ControllerTrait {
|
|||
{
|
||||
return new JsonResponse($data, $code, $headers);
|
||||
}
|
||||
|
||||
public function pushContext(FormContext $context) : FormContext
|
||||
{
|
||||
$this->contextList[$context->formName ?? uniqid("context_")] = $context;
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
public function context(string $name) : FormContext
|
||||
{
|
||||
return $this->contextList[$name];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<ol class="breadcrumb ">
|
||||
<li class="breadcrumb-item"><a href="{% url '' %}"><i class="fas fa-fw fa-tachometer-alt"></i> Tableau de bord</a></li>
|
||||
|
||||
{% foreach $this->breadcrumb ?? [] as $crumb %}
|
||||
<li class="breadcrumb-item {{ ( $crumb['active'] ?? false ) ? 'active' : '' }}">
|
||||
{% if ! ($crumb['active'] ?? false) %}
|
||||
{? $last = $crumb ?}
|
||||
|
||||
<a href="{% url $crumb['url'] %}">
|
||||
{% if $crumb['icon'] ?? false %}
|
||||
<i class="fa fa-{{ $crumb['icon'] }}"></i>
|
||||
{% endif %}
|
||||
|
||||
{{ $crumb['title'] }}
|
||||
</a>
|
||||
{% else %}
|
||||
{% if $crumb['icon'] ?? false %}
|
||||
<i class="fa fa-{{ $crumb['icon'] }}"></i>
|
||||
{% endif %}
|
||||
<span>{{ $crumb['title'] }}</span>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endforeach %}
|
||||
|
||||
{% if $last ?? false %}
|
||||
<li class="breadcrumb-last-item ml-auto"><a href="{{ url( $last['url']) }}"><i class="fas fa-chevron-circle-left"></i> Retour</a></li>
|
||||
{% endif %}
|
||||
</ol>
|
|
@ -0,0 +1,7 @@
|
|||
<div class="message-wrapper">
|
||||
{% foreach array_filter(array_merge($this->contextList, [ $context ?? null ])) as $name => $context %}
|
||||
{% foreach $context->messages ?? [] as $message %}
|
||||
{{= $message->render() }}
|
||||
{% endforeach %}
|
||||
{% endforeach %}
|
||||
</div>
|
Loading…
Reference in New Issue