- Work done on the console to have at least some working functionality from every parts

This commit is contained in:
Dave M. 2022-11-29 19:29:15 +00:00
parent e78492d398
commit 24e5490c71
18 changed files with 352 additions and 27 deletions

View File

@ -5,9 +5,11 @@ use Lean\Console\Lib\DatabaseMigrations;
return [
'lean.console' => [
'picea' => [
'context' => "Lean\\Console\\View",
'view' => [
[
'path' => getenv("PROJECT_PATH") . "/vendor/mcnd/lean-console/view/",
'path' => getenv("PROJECT_PATH") . implode(DIRECTORY_SEPARATOR, [ "", "vendor", "mcnd" , "lean-console" , "view" ]),
'order' => 99,
],
],

View File

@ -0,0 +1,3 @@
{
"clear": "Clear"
}

View File

@ -20,6 +20,10 @@
"createAll": "Create all tables",
"query": "SQL Query"
}
},
"session": {
"header": "List of sessions",
"count": "{$count} session(s)"
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace Lean\Console\Controller;
use League\Route\Router;
use Picea\Caching\Opcache;
use Picea\FileFetcher;
use Picea\Picea;
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
use Notes\Route\Annotation\Object\Route as RouteParam,
Notes\Route\Annotation\Method\Route,
Notes\Security\Annotation\Security,
Notes\Tell\Annotation\Language;
use Lean\Console\{ Form, Lib };
use Picea\Extension\UrlExtension;
use function Home\View\{ _, lang, url, route, form };
/**
* @Language("lean.caching")
*/
class Caching extends Console {
use Lib\ConsoleControllerTrait;
/**
* @Route("/caching/picea", "name" => "lean.console:caching")
*/
public function picea(ServerRequestInterface $request, array $arguments) : ResponseInterface
{
$list = [];
if ( isset($this->picea) ) {
form(new Form\Caching\Picea($this->picea, $list), $this->pushContext(new Lib\FormContext($request, "caching.picea")));
}
return $this->renderView("lean-console/page/caching/picea", get_defined_vars());
}
}

View File

@ -28,10 +28,7 @@ class Storage extends Console {
use Lib\ConsoleControllerTrait;
/**
* @Route("/storage/database", "name" => "lean.console:request.route")
* @param ServerRequestInterface $request
* @param array $arguments
* @return ResponseInterface
* @Route("/storage/database", "name" => "lean.console:storage.database")
*/
public function database(ServerRequestInterface $request, array $arguments) : ResponseInterface
{
@ -45,6 +42,40 @@ class Storage extends Console {
return $this->renderView("lean-console/page/storage/database", get_defined_vars());
}
/**
* @Route("/storage/session", "name" => "lean.console:storage.session")
*/
public function session(ServerRequestInterface $request, array $arguments) : ResponseInterface
{
$path = ini_get("session.save_path");
$sessions = preg_grep("/^sess_/", scandir($path));
return $this->renderView("lean-console/page/storage/session", get_defined_vars());
}
/**
* #Taxus('admin')
* @Route("/storage/session/content/{hash}", "name" => "lean.console:storage.session_content")
*/
public function sessionContent(ServerRequestInterface $request, array $arguments) : ResponseInterface
{
$sess = session_encode();
session_decode(file_get_contents($this->sessionPath() . $arguments['hash']));
$data = array_combine(array_keys($_SESSION), array_values($_SESSION));
session_decode($sess);
return $this->renderJson($data);
}
protected function sessionPath() : string
{
return rtrim(ini_get("session.save_path"), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
}
public function createTable() : void
{
foreach($migrations->entities as $table) {

View File

@ -0,0 +1,37 @@
<?php
namespace Lean\Console\Controller;
use League\Route\Router;
use Picea\FileFetcher;
use Picea\Picea;
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
use Notes\Route\Annotation\Object\Route as RouteParam,
Notes\Route\Annotation\Method\Route,
Notes\Security\Annotation\Security,
Notes\Tell\Annotation\Language;
use \Lean\Console\Lib;
use Picea\Extension\UrlExtension;
/**
* @Language("lean.templating")
*/
class Templating extends Console {
use Lib\ConsoleControllerTrait;
/**
* @Route("/templating/picea", "name" => "lean.console:templating.picea")
*/
public function picea(ServerRequestInterface $request, array $arguments) : ResponseInterface
{
$picea = $this->container->has(Picea::class) ? $this->container->get(Picea::class) : false;
$list = $picea->fileFetcher->getFileList();
return $this->renderView("lean-console/page/templating/picea", get_defined_vars());
}
}

View File

@ -0,0 +1,67 @@
<?php
namespace Lean\Console\Form\Caching;
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
use \Lean\Console\Lib;
use Picea\{Caching\Opcache, Compiler\Context };
use Psr\Http\Message\ServerRequestInterface;
use Ulmus\Common\EntityResolver;
use \Ulmus\Entity\InformationSchema\Table;
use RecursiveIteratorIterator, RecursiveDirectoryIterator;
class Picea implements FormInterface
{
public \Picea\Picea $picea;
public array $folders;
public function __construct(\Picea\Picea $picea, array &$folders)
{
$this->folders = &$folders;
$this->picea = $picea;
}
public function initialize(FormContextInterface $context) : void
{
if ($this->picea->cache instanceof Opcache) {
$path = $this->picea->cache->cachePath() . "/";
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD);
foreach ($iterator as $file) {
if ($file->isFile() && in_array($file->getExtension(), [ 'php' ])) {
$this->folders[$path][] = $file;
}
}
}
}
public function validate(FormContextInterface $context) : bool
{
return $context->valid();
}
public function execute(FormContextInterface $context) : void
{
$deleted = $failed = 0;
foreach($this->folders as $path => $files) {
foreach($files as $file)
{
unlink($file->getPathname()) ? $deleted++ : $failed++;
}
}
if ($deleted) {
# $context->pushMessage();
}
if ($failed) {
# $context->pushMessage();
}
}
}

View File

@ -34,7 +34,6 @@ class Database implements FormInterface
continue;
}
#<<<<<<< HEAD
$tableEntity = $adapter->schemaTable($databaseName, $tableName);
if ( $tableEntity ) {
@ -60,6 +59,8 @@ class Database implements FormInterface
#>>>>>>> 7194a33bec884d745e838c8ac2693b353e95a3ce
}
$alter =false;
if ( $alter ) {
$context->status[$entity] = [
'msg' => "alter",

View File

@ -11,8 +11,8 @@ use Picea;
/**
* @Language("lean.route")
* @RouteParam("methods" => [ 'GET', 'POST', 'DELETE' ], "base" => "/~")
* @Security('locked' => true)
* @Taxus("admin")
* @Security('locked' => false)
* @Taxus("dev")
*/
trait ConsoleControllerTrait
{

5
src/Lib/FormContext.php Normal file
View File

@ -0,0 +1,5 @@
<?php
namespace Lean\Console\Lib;
class FormContext extends \Picea\Ui\Method\FormContext { }

View File

@ -0,0 +1,9 @@
<?php
class Triggers
{
public function onUpdateCurrentTimestamp(string $table) : string
{
}
}

View File

@ -12,7 +12,7 @@
[class^="btn-"]:hover, [class~=" btn-"]:hover {border-color: rgba(0, 0, 0, 0.5);text-decoration: underline;}
.btn-red {background: rgba(255,0,0,0.5);color: rgba(255, 255, 255, 0.9);}
code {white-space:pre;font-family:monospace;color: #cacaca;background: #434446;display: block;padding: 1rem;line-height: 1.5em;border: 1px solid #2e2e30;}
code {white-space:pre;font-family:monospace;color: #e6e6e6;background: #343537;display: block;padding: 1rem;line-height: 1.5em;border: 1px solid #2e2e30;}
h1 {font-size:2rem;color:#525960}
body {font-family:Helvetica Neue, Helvetica, Arial, sans-serif;}
summary {cursor:pointer;}
@ -20,7 +20,7 @@ summary {cursor:pointer;}
#body-main {background:#ccc;min-height:calc(100vh - 90px);display:flex}
/* Header */
#body-header {background: #6b7fa8; color:#fff; min-height:60px;line-height:60px;padding:0 1rem}
#body-header {background: #5e5e5e; color:#fff; min-height:60px;line-height:60px;padding:0 1rem}
#body-header .page-title {font-size:1.5rem}
#body-header .page-title:before {content:"🔳"; margin-right:10px}
@ -28,8 +28,8 @@ summary {cursor:pointer;}
#body-footer {background: #475262;color: #fff;height: 30px;line-height: 30px;font-size: 0.8rem;padding: 0 0.5rem;text-align: right;border-top:2px solid #434446;}
/* Sidebar */
#main-nav {background:#6b7fa8;border-top:2px solid #44526f;min-width:210px;color:#fff;font-family:consolas, courier new, monospace;font-size:0.9rem}
#main-nav label {background:rgba(0,0,0,0.2);text-transform:uppercase ; display:block;padding:0.8rem 1rem;font-size:1.15em;}
#main-nav {background:#1e1e1e;border-top:2px solid #46494f;min-width:210px;color:#fff;font-family:consolas, courier new, monospace;font-size:0.9rem}
#main-nav label {color: #a4a4a4;background:rgba(0,0,0,0.2);text-transform:uppercase ; display:block;padding:0.8rem 1rem;font-size:1.15em;}
#main-nav label:before {content:"⊙"; margin-right:10px}
#main-nav a {color: #efecec;text-decoration:none;display:block;padding:0rem 1rem;background:rgba(255,255,255,0.05);transition:all 0.3s ease;line-height:3em;font-size:0.9em}
#main-nav a:before {content:""; margin-right:10px;line-height:3em}

View File

@ -1,28 +1,28 @@
<nav id="main-nav">
<label>{% lang "lean.nav.lean.label" %}</label>
<ul>
<li><a href="{{ url('~') }}">{% lang "lean.nav.lean.dashboard" %}</a></li>
<li><a href="{% route 'lean.console:home' %}">{% lang "lean.nav.lean.dashboard" %}</a></li>
</ul>
<label>{% lang "lean.nav.request.label" %}</label>
<ul>
<li><a href="{{ url('~/request/routes') }}">{% lang "lean.nav.request.routes" %}</a></li>
<li><a href="{% route 'lean.console:request.route' %}">{% lang "lean.nav.request.routes" %}</a></li>
</ul>
<label>{% lang "lean.nav.storage.label" %}</label>
<ul>
{#<li><a href="{{ url('~/storage') }}">{% lang "lean.nav.storage.summary" %}</a></li>#}
<li><a href="{{ url('~/storage/database') }}">{% lang "lean.nav.storage.database" %}</a></li>
<li><a href="{{ url('~/storage/session') }}">{% lang "lean.nav.storage.session" %}</a></li>
<li><a href="{% route 'lean.console:storage.database' %}">{% lang "lean.nav.storage.database" %}</a></li>
<li><a href="{% route 'lean.console:storage.session' %}">{% lang "lean.nav.storage.session" %}</a></li>
</ul>
<label>{% lang "lean.nav.templating.label" %}</label>
<ul>
<li><a href="{{ url('~/templating/picea') }}">{% lang "lean.nav.templating.picea" %}</a></li>
<li><a href="{% route 'lean.console:templating.picea' %}">{% lang "lean.nav.templating.picea" %}</a></li>
</ul>
<label>{% lang "lean.nav.caching.label" %}</label>
<ul>
<li><a href="{{ url('~/storage') }}">{% lang "lean.nav.templating.picea" %}</a></li>
<li><a href="{% route 'lean.console:caching' %}">{% lang "lean.nav.templating.picea" %}</a></li>
</ul>
</nav>

View File

@ -0,0 +1,41 @@
{% extends "lean-console/base/layout" %}
{% language.set "lean.caching" %}
{% title _("title") %}
{% section "header" %}
<div class="page-title">{% _ "page-title" %}</div>
{% endsection %}
{% section "content" %}
{% foreach $list as $path => $folder %}
<section>
<header>
<h1>{{ $path }}</h1>
{% ui.form.post "caching.picea" %}
<button class="btn-red" type="submit">{% _ 'clear' %}</button>
{% ui.endform %}
</header>
<article class="picea">
{% foreach $folder as $file %}
<div class="grid">
<strong class="col route-name">{{ substr($file, strlen($path)) }}</strong>
<div>
</div>
</div>
{% endforeach %}
</article>
</section>
{% endforeach %}
<style>
section > header {display:flex;justify-content: space-between}
.picea h5 {font-size:1.5em; line-height:2em; font-weight:bold;text-decoration:underline}
.picea strong.grid {background: #353535;color: #fff;}
.picea .grid {padding:0.66rem 0.3rem;align-items:center}
.picea .grid strong {color:#444}
.picea .grid:nth-child(even) {background: #e3e3e3 }
</style>
{% endsection %}

View File

@ -40,7 +40,7 @@
</section>
<style>
.routes strong.grid {background:#172842;color:#eeffee}
.routes strong.grid {background: #353535;color: #fff;}
.routes .grid {padding:0.66rem 0.3rem}
.routes .grid strong {color:#444}
.routes .grid:nth-child(even) {background: #e3e3e3 }

View File

@ -29,10 +29,10 @@
<div class="grid db-grid">
<div class="col db-connection">{{ $connection->name }}</div>
<div class="col db-adapter">{{ $conf['adapter'] }}</div>
<div class="col db-host">{{ $conf['host'] }}:{{ $conf['port'] }}</div>
<div class="col db-name">{{ $conf['database'] }}</div>
<div class="col db-username">{{ $conf['username'] }}</div>
<div class="col db-adapter">{{ $conf['adapter'] ?? null }}</div>
<div class="col db-host">{{ $conf['host'] ?? null }}:{{ $conf['port'] ?? null }}</div>
<div class="col db-name">{{ $conf['database'] ?? null }}</div>
<div class="col db-username">{{ $conf['username'] ?? null }}</div>
</div>
<div class="tables">
@ -92,17 +92,17 @@
</section>
<style>
.databases strong.grid {background:#172842;color:#fff}
.databases strong.grid {background:#181818;color:#fff}
.databases .db-grid {padding:0.66rem 0.3rem}
.databases .db-grid strong {color:#444}
.databases .db-grid:nth-child(even) {background: #e3e3e3 }
.databases .db-grid:nth-child(even) {background: #e3e3e3;line-height: 1.5em;font-size: 1.3em;}
.databases .tables .table-item {padding:0.33rem 0;background:rgba(255,255,255,0.1)}
.databases .tables .table-item {padding:0.33rem 0;background:rgba(255,255,255,0.1);line-height: 1.8em;}
.databases .tables .table-item:nth-child(even) {background:rgba(255,255,255,0.2)}
.databases summary {background: #172841;color:#fff;margin: 0 -8px 0 -8px;padding:7px 10px}
.tables {background: #172841;margin: 0 -8px 0 -8px;color: #fff;padding: 4px 12px;}
.tables {background: #2d3137;margin: 0 -8px 0 -8px;color: #fff;padding: 2px 10px;}
.tables label {padding:10px 5px;display:block}
</style>
{% endsection %}

View File

@ -0,0 +1,42 @@
{% extends "lean-console/base/layout" %}
{% language.set "lean.storage" %}
{% title _("title") %}
{% section "header" %}
<div class="page-title">{% _ "page-title" %}</div>
{% endsection %}
{% section "content" %}
<section>
<header>
<h1>{% _ 'session.header' %}</h1>
</header>
<article class="sessions">
<strong class="grid">
<div class="col route-name">{% _ 'session.count', [ 'count' => count($sessions) ] %}</div>
</strong>
{% foreach $sessions as $session %}
<div class="grid">
<strong class="col route-name">{{ $session }}</strong>
<div class="col">{{ date('Y-m-d H:i:s', filemtime(realpath($path . DIRECTORY_SEPARATOR . $session))) }}</div>
<div class="col text-right">
<a target="_blank" class="btn-red" href="{% route 'lean.console:storage.session_content', [ 'hash' => $session ] %}">
Voir
</a>
</div>
</div>
{% endforeach %}
</article>
</section>
<style>
.sessions strong.grid {background: #353535;color: #fff;}
.sessions .grid {padding:0.66rem 0.3rem;align-items:center;justify-content:space-between;}
.sessions .grid strong {color:#444}
.sessions .grid:nth-child(even) {background: #e3e3e3 }
</style>
{% endsection %}

View File

@ -0,0 +1,42 @@
{% extends "lean-console/base/layout" %}
{% language.set "lean.templating" %}
{% title _("title") %}
{% section "header" %}
<div class="page-title">{% _ "page-title" %}</div>
{% endsection %}
{% section "content" %}
{% foreach $list as $path => $folder %}
<section>
<header>
<h1>{{ $path }}</h1>
</header>
<article class="picea">
{% foreach $folder as $file %}
<div class="grid">
<strong class="col route-name">{{ substr($file, strlen($path)) }}</strong>
<div>
{#<a target="_blank" class="btn-red" href="">
Voir
</a>#}
</div>
</div>
{% endforeach %}
</article>
</section>
{% endforeach %}
<style>
.picea h5 {font-size:1.5em; line-height:2em; font-weight:bold;text-decoration:underline}
.picea strong.grid {background: #353535;color: #fff;}
.picea .grid {padding:0.66rem 0.3rem;align-items:center}
.picea .grid strong {color:#444}
.picea .grid:nth-child(even) {background: #e3e3e3 }
section + section {margin-top:1.2rem}
</style>
{% endsection %}