- Bugfixes and work done on the console

This commit is contained in:
Dave Mc Nicoll 2021-08-27 18:06:55 +00:00
parent 23af120020
commit 7194a33bec
6 changed files with 71 additions and 15 deletions

28
src/Controller/Dev.php Normal file
View File

@ -0,0 +1,28 @@
<?php
namespace Lean\Console\Controller;
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;
/**
* @Language("lean.dev")
*/
class Dev {
use Lib\ConsoleControllerTrait;
/**
* @Route("/phpinfo", "name" => "lean.dev:phpinfo")
*/
public function home(ServerRequestInterface $request, array $arguments) : ResponseInterface
{
phpinfo();
die();
}
}

View File

@ -8,6 +8,7 @@ use \Lean\Console\Lib;
use Picea\Compiler\Context;
use Psr\Http\Message\ServerRequestInterface;
use Ulmus\Common\EntityResolver;
use \Ulmus\Entity\InformationSchema\Table;
class Database implements FormInterface
@ -31,22 +32,35 @@ class Database implements FormInterface
continue;
}
$table = Table::repository()->where(Table::field('name'), $table->tableName())
$table = Table::repository()
->where(Table::field('name'), $table->tableName())
->where(Table::field('schema'), $table->databaseName())
->loadOne();
if ( $table ) {
#$fields = $entiy::resolveEntity()->fieldList();
$fields = $entity::resolveEntity()->fieldList(EntityResolver::KEY_COLUMN_NAME, true);
foreach($table->columns as $col) {
//dump( $entity::field($col->name) );
$alter = [];
foreach($fields as $field => $definition) {
if ( $table->columns->filtersCollection(fn($e) => $e->name === $field)->count() === 0 ) {
$alter[$field] = $definition;
}
}
# if columns are different
$context->status[$entity] = [
'msg' => "up-to-date",
'query' => "",
];
if ( $alter ) {
$context->status[$entity] = [
'msg' => "alter",
"query" => $entity::repository()->alterSqlQuery($alter)->getSqlQuery(true),
];
}
else {
# if columns are different
$context->status[$entity] = [
'msg' => "up-to-date",
'query' => "",
];
}
}
else {
$context->status[$entity] = [
@ -76,6 +90,9 @@ class Database implements FormInterface
$entity::repository()->createTable();
}
}
elseif ( $context->alter ?? false ) {
}
$this->initialize($context);
}

View File

@ -11,7 +11,8 @@ use Picea;
/**
* @Language("lean.route")
* @RouteParam("methods" => [ 'GET', 'POST', 'DELETE' ], "base" => "/~")
* @Security('locked' => false)
* @Security('locked' => true)
* @Taxus("admin")
*/
trait ConsoleControllerTrait
{
@ -23,6 +24,5 @@ trait ConsoleControllerTrait
$this->picea = $picea;
$this->session = $session;
$this->container = $container;
// $this->mailer = $mailer;
}
}

View File

@ -30,6 +30,8 @@ class DatabaseMigrations
$this->entities[$entity] = $entity::resolveEntity();
}
}
ksort($this->entities);
}
protected static function files(string $path, string $fileExtension = "") : \Generator

View File

@ -20,15 +20,15 @@ summary {cursor:pointer;}
#body-main {background:#ccc;min-height:calc(100vh - 90px);display:flex}
/* Header */
#body-header {background: #385075; color:#fff; min-height:60px;line-height:60px;padding:0 1rem}
#body-header {background: #6b7fa8; 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}
/* Footer */
#body-footer {background: #2e2e30;color: #fff;height: 30px;line-height: 30px;font-size: 0.8rem;padding: 0 0.5rem;text-align: right;border-top:2px solid #434446;}
#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:#393a3c;border-top:2px solid #172842;min-width:210px;color:#fff;font-family:consolas, courier new, monospace;font-size:0.9rem}
#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 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}
@ -37,7 +37,7 @@ summary {cursor:pointer;}
#main-nav li + li {border-top:1px solid #555}
/* Main content */
#main-content {padding:4vh 2vw;border-top:2px solid #172842;width:100%;}
#main-content {padding:4vh 2vw;border-top:2px solid #7d7d7d;width:100%;}
#main-content section {border-radius:4px;box-shadow: 1px 1px 3px rgba(0,0,0,0.5)}
#main-content section article {background:#fff;padding:2vh 1vw;}
#main-content section header {background:#e8e8e8;padding:2vh 1vw;}

View File

@ -55,6 +55,7 @@
<div>🗸 This table is up-to-date</div>
{% endif %}
</div>
<div class="col">
{% switch $context->status[$entity]['msg'] %}
{% case 'unexisting' %}
@ -64,6 +65,14 @@
<button name="create" value="{{$entity}}" class="btn-blue">🗸 {% _ 'database.table.create' %}</button>
</div>
{% break %}
{% case 'altering' %}
{% php $alter[] = $entity %}
<div class="text-right">
<button name="create" value="{{$entity}}" class="btn-blue">🗸 {% _ 'database.table.alter' %}</button>
</div>
{% break %}
{% endswitch %}
</div>
</div>