- WIP on database storage filling
This commit is contained in:
parent
2fd9331c15
commit
7117021750
@ -4,23 +4,25 @@
|
|||||||
.justify-content-around{justify-content: space-around;}.justify-content-end{justify-content: end}
|
.justify-content-around{justify-content: space-around;}.justify-content-end{justify-content: end}
|
||||||
.flex {display:flex}
|
.flex {display:flex}
|
||||||
|
|
||||||
:root {
|
:root {--color-red: #d47474}
|
||||||
--color-red: #d47474
|
|
||||||
}
|
|
||||||
|
|
||||||
.text-center{text-align:center;}.text-right{text-align:right}.text-left{text-align:left;}
|
.text-center{text-align:center;}.text-right{text-align:right}.text-left{text-align:left;}
|
||||||
|
.m-0 {margin:0!important}.mx-0 {margin-left:0!important;margin-right:0!important}.my-0 {margin-top:0!important;margin-bottom:0!important}
|
||||||
|
.p-0 {padding:0!important}.px-0 {padding-left:0!important;padding-right:0!important}.py-0 {padding-top:0!important;padding-bottom:0!important}
|
||||||
|
|
||||||
[class^="btn-"], [class~=" btn-"] { display: inline-block; font-weight: 400; text-align: center; white-space: nowrap; vertical-align: middle; user-select: none; border: 1px solid transparent; padding: .375rem .75rem; line-height: 1.5; border-radius: .25rem; cursor:pointer; transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out; background:rgba(0,0,0,0.3); color:rgba(255,255,255,0.8); text-decoration:none; }
|
[class^="btn-"], [class~=" btn-"] { display: inline-block; font-weight: 400; font-size:16px; text-align: center; white-space: nowrap; vertical-align: middle; user-select: none; border: 1px solid transparent; padding: .375rem .75rem; line-height: 1.5; border-radius: .25rem; cursor:pointer; transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out; background:rgba(0,0,0,0.3); color:rgba(255,255,255,0.8); text-decoration:none; }
|
||||||
[class^="btn-"]:hover, [class~=" btn-"]:hover {border-color: rgba(0, 0, 0, 0.5);text-decoration: underline;}
|
[class^="btn-"]:hover, [class~=" btn-"]:hover {border-color: rgba(0, 0, 0, 0.5);text-decoration: underline;}
|
||||||
.btn-red {background: rgba(155,0,0,0.5);color: rgba(255, 255, 255, 0.9);}
|
.btn-red {background: rgba(155,0,0,0.5);color: rgba(255, 255, 255, 0.9);}
|
||||||
.btn-green {background: rgba(0,155,0,0.5);color: rgba(255, 255, 255, 0.9);}
|
.btn-green {background: rgba(0,155,0,0.5);color: rgba(255, 255, 255, 0.9);}
|
||||||
.btn-blue {background: rgba(0,0,155,0.5);color: rgba(255, 255, 255, 0.9);}
|
.btn-blue {background: rgba(0,0,155,0.5);color: rgba(255, 255, 255, 0.9);}
|
||||||
|
.btn-yellow {background: rgba(249, 200, 11, 0.69);color: rgba(255, 255, 255, 0.9);}
|
||||||
|
.bg-yellow {background:#c09f1f!important}
|
||||||
|
|
||||||
body{background:#f3f3f9}
|
body{background:#f3f3f9}
|
||||||
code {white-space:pre-line;font-family:monospace;color: #e6e6e6;background: #343537;display: block;padding: 1rem;line-height: 1.5em;border: 1px solid #2e2e30;}
|
code {white-space:pre-line;font-family:monospace;color: #e6e6e6;background: #343537;display: block;padding: 1rem;line-height: 1.5em;border: 1px solid #2e2e30;}
|
||||||
body {font-family:Helvetica Neue, Helvetica, Arial, sans-serif;}
|
body {font-family:Helvetica Neue, Helvetica, Arial, sans-serif;}
|
||||||
summary {cursor:pointer;}
|
summary {cursor:pointer;}
|
||||||
|
|
||||||
|
|
||||||
#body-main {min-height:calc(100vh - 30px);display:flex}
|
#body-main {min-height:calc(100vh - 30px);display:flex}
|
||||||
|
|
||||||
/* Header */
|
/* Header */
|
||||||
|
|||||||
@ -19,10 +19,24 @@
|
|||||||
"create": "Create table",
|
"create": "Create table",
|
||||||
"createAll": "Create all tables",
|
"createAll": "Create all tables",
|
||||||
"query": "SQL Query",
|
"query": "SQL Query",
|
||||||
|
"add-column": "+ New row",
|
||||||
"alter": "Alter table",
|
"alter": "Alter table",
|
||||||
"alterAll": "Alter all tables",
|
"alterAll": "Alter all tables",
|
||||||
"uptodate": "This table is up-to-date"
|
"uptodate": "This table is up-to-date"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
|
"database_insert": {
|
||||||
|
"add": "Create",
|
||||||
|
"breadcrumb": "Insert",
|
||||||
|
"readonly": "This field is read-only",
|
||||||
|
|
||||||
|
"table": {
|
||||||
|
"column": "Column",
|
||||||
|
"type": "Data type",
|
||||||
|
"function": "Function",
|
||||||
|
"attributes": "Attributs",
|
||||||
|
"value": "Value"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -27,7 +27,7 @@ class Storage extends Console {
|
|||||||
$migrations = $this->container->has(Lib\DatabaseMigrations::class) ? $this->container->get(Lib\DatabaseMigrations::class) : false;
|
$migrations = $this->container->has(Lib\DatabaseMigrations::class) ? $this->container->get(Lib\DatabaseMigrations::class) : false;
|
||||||
$migrations->getEntities();
|
$migrations->getEntities();
|
||||||
|
|
||||||
$context = (new FormHandler($request, new Form\Storage\Database\Migrate($migrations)))->context;
|
$context = (new FormHandler($request, new Form\Storage\Database\Migrate($migrations), $this->pushContext(new Lib\FormContext($request, "database.migrate"))))->context;
|
||||||
|
|
||||||
return $this->renderView("lean-console/page/storage/database", get_defined_vars());
|
return $this->renderView("lean-console/page/storage/database", get_defined_vars());
|
||||||
}
|
}
|
||||||
@ -46,6 +46,16 @@ class Storage extends Console {
|
|||||||
return $this->renderView("lean-console/page/storage/database_import", get_defined_vars());
|
return $this->renderView("lean-console/page/storage/database_import", get_defined_vars());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route(route: "/storage/database/insert", name: "lean.console:storage.database_insert")]
|
||||||
|
public function insert(ServerRequestInterface $request, array $arguments) : ResponseInterface
|
||||||
|
{
|
||||||
|
$class = $request->getQueryParams()['source'] ?? $request->getParsedBody()['source'];
|
||||||
|
|
||||||
|
$context = (new FormHandler($request, new Form\Storage\Database\Insert(new $class())))->context;
|
||||||
|
|
||||||
|
return $this->renderView("lean-console/page/storage/database_insert", get_defined_vars());
|
||||||
|
}
|
||||||
|
|
||||||
#[Route(route: "/storage/session", name: "lean.console:storage.session")] # migrated from: "/storage/session", "name" => "lean.console:storage.session"
|
#[Route(route: "/storage/session", name: "lean.console:storage.session")] # migrated from: "/storage/session", "name" => "lean.console:storage.session"
|
||||||
public function session(ServerRequestInterface $request, array $arguments) : ResponseInterface
|
public function session(ServerRequestInterface $request, array $arguments) : ResponseInterface
|
||||||
{
|
{
|
||||||
|
|||||||
53
src/Form/Storage/Database/Insert.php
Normal file
53
src/Form/Storage/Database/Insert.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lean\Console\Form\Storage\Database;
|
||||||
|
|
||||||
|
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
|
||||||
|
|
||||||
|
use \Lean\Console\{ Lib, Entity };
|
||||||
|
|
||||||
|
use Picea\Compiler\Context;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Ulmus\{Attribute\Property\Field, Entity\EntityInterface, Entity\Field\Datetime, EntityCollection};
|
||||||
|
|
||||||
|
class Insert implements FormInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
protected EntityInterface $entity
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function initialize(FormContextInterface $context) : void
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validate(FormContextInterface $context) : bool
|
||||||
|
{
|
||||||
|
|
||||||
|
return $context->valid();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute(FormContextInterface $context) : void
|
||||||
|
{
|
||||||
|
foreach ($this->entity::resolveEntity()->fieldList() as $field) {
|
||||||
|
$type = $field->getTypes()[0];
|
||||||
|
$value = $context->{$field->name};
|
||||||
|
|
||||||
|
if (! $field->getAttribute(Field::class)->object->readonly) {
|
||||||
|
if ($type->isEnum() && $value) {
|
||||||
|
$this->entity->{$field->name} = $type->type::from($value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->entity->{$field->name} = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Temp patch while fixing default value in sqlite
|
||||||
|
if (property_exists($this->entity, 'createdAt')) {
|
||||||
|
$this->entity->createdAt = new Datetime();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->entity::repository()->save($this->entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -40,7 +40,7 @@
|
|||||||
<div class="col text-right">{% _ 'database.table.actions' %}</div>
|
<div class="col text-right">{% _ 'database.table.actions' %}</div>
|
||||||
</strong>
|
</strong>
|
||||||
|
|
||||||
{% ui:form.post "database" %}
|
{% ui:form.post "database.migrate", current_url() %}
|
||||||
{% foreach array_filter($migrations->entities, fn($e) => $e->databaseAdapter() === $connection) as $entity => $item %}
|
{% foreach array_filter($migrations->entities, fn($e) => $e->databaseAdapter() === $connection) as $entity => $item %}
|
||||||
<div class="grid table-item align-items-center">
|
<div class="grid table-item align-items-center">
|
||||||
<div class="col"><span>📄</span> <span>{{ $item->tableName() }}</span></div>
|
<div class="col"><span>📄</span> <span>{{ $item->tableName() }}</span></div>
|
||||||
@ -71,6 +71,10 @@
|
|||||||
</div>
|
</div>
|
||||||
{% break %}
|
{% break %}
|
||||||
{% endswitch %}
|
{% endswitch %}
|
||||||
|
|
||||||
|
<div class="text-right">
|
||||||
|
<a href="{% route 'lean.console:storage.database_insert', [ 'source' => $entity ] %}" class="btn-gray">{% _ 'database.table.add-column' %}</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endforeach %}
|
{% endforeach %}
|
||||||
|
|||||||
117
view/lean-console/page/storage/database_insert.phtml
Normal file
117
view/lean-console/page/storage/database_insert.phtml
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
{% use Ulmus\Attribute\Property\Field %}
|
||||||
|
{% use Lean\Console\Lib\Database\ModifierTypeEnum %}
|
||||||
|
|
||||||
|
{% extends "lean-console/base/layout" %}
|
||||||
|
|
||||||
|
{% language.set "lean.storage" %}
|
||||||
|
|
||||||
|
{% title _("title") %}
|
||||||
|
|
||||||
|
{% section "breadcrumb-items" %}
|
||||||
|
<li class="breadcrumb-item"><a href="{% route 'lean.console:storage.database' %}">{% _ 'database.breadcrumb' %}</a></li>
|
||||||
|
<li class="breadcrumb-item">{% _ 'database_insert.breadcrumb' %}</li>
|
||||||
|
{% endsection %}
|
||||||
|
|
||||||
|
{% section "content" %}
|
||||||
|
<section class="insert">
|
||||||
|
<header class="bg-yellow">
|
||||||
|
<h2>{{ $class }}</h2>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<div class="database_insert">
|
||||||
|
<div class="tables">
|
||||||
|
<strong class="grid table-item">
|
||||||
|
<div class="col">{% _ 'database_insert.table.column' %}</div>
|
||||||
|
<div class="col">{% _ 'database_insert.table.type' %}</div>
|
||||||
|
<div class="col text-center">{% _ 'database_insert.table.attributes' %}</div>
|
||||||
|
<div class="col col-grow-4 text-center">{% _ 'database_insert.table.value' %}</div>
|
||||||
|
</strong>
|
||||||
|
|
||||||
|
{% ui:form.post "database.insert", current_url(get()) %}
|
||||||
|
{% foreach $class::resolveEntity()->fieldList() as $field %}
|
||||||
|
<div class="grid table-item align-items-center column-item">
|
||||||
|
<div class="col">
|
||||||
|
<span>{{ $field->name }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col ">
|
||||||
|
{% foreach $field->getTypes() as $type %}
|
||||||
|
<span title="{{ $type->type }}">{{ $type->isObject() ? substr($type->type, strrpos($type->type, '\\') + 1) : $type->type }}</span>
|
||||||
|
{% endforeach %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col attributes text-center">
|
||||||
|
{% foreach $field->attributes as $attribute %}
|
||||||
|
<span class="attribute" title="{% json.pretty.html $attribute->object %}">{{ $attribute->tag }}</span>
|
||||||
|
{% endforeach %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col col-grow-4">
|
||||||
|
{% foreach $field->getTypes() as $type %}
|
||||||
|
{% php $attr = $field->getAttribute(Field::class)->object->readonly ? [ 'disabled' => 'disabled', 'placeholder' => _('database_insert.readonly') ] : [] %}
|
||||||
|
|
||||||
|
{% if enum_exists($type->type) %}
|
||||||
|
{% php $enum = array_map(fn($e) => $e->value, $type->type::cases()) %}
|
||||||
|
|
||||||
|
{% if $type->nullable %}
|
||||||
|
{% php $enum = [ null => null ] + $enum %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% ui:select $field->name, array_combine($enum, $enum), $context->{$field->name}, $attr %}
|
||||||
|
{% else %}
|
||||||
|
{% ui:text $field->name, $context->{$field->name}, $attr %}
|
||||||
|
{% endif %}
|
||||||
|
{% endforeach %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{# <div class="col">{% _ "database.table.fields", [ 'count' => count( $item->fieldList() ) ] %}</div>
|
||||||
|
<div class="col">
|
||||||
|
{% if $context->definition[$entity]['table']->modifier->query ?? false %}
|
||||||
|
<code>{{= implode('<br><br>',(array) $context->definition[$entity]['table']->modifier->query) }}</code>
|
||||||
|
{% else %}
|
||||||
|
<div style="color:#abecab">✓ {% _ 'database.table.uptodate' %}</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col">
|
||||||
|
</div> #}
|
||||||
|
</div>
|
||||||
|
{% endforeach %}
|
||||||
|
|
||||||
|
<div class="grid table-item">
|
||||||
|
<div class="col"></div>
|
||||||
|
<div class="col"></div>
|
||||||
|
<div class="col text-center"></div>
|
||||||
|
<div class="col col-grow-4 text-right py-2">
|
||||||
|
<button type="submit" class="btn-yellow">{% _ 'database_insert.add' %}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% ui:endform %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#main-content .insert article {background: #6a6a6a;padding:10px;}
|
||||||
|
|
||||||
|
select, input:not([type="file"]):not([type="button"]) {display: block;width: 100%;height: calc(2rem + 2px);padding: .375rem .75rem;font-size: 1rem;line-height: 1.5;color: #495057;background-color: #fff;background-clip: padding-box;border: 1px solid #ced4da; border-radius: 0; transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;}
|
||||||
|
select:disabled, input[disabled] {filter: contrast(60%);}
|
||||||
|
.database_insert strong.grid {background: #888a91;color:#fff}
|
||||||
|
|
||||||
|
.database_insert .db-grid {padding:0.66rem 0.3rem}
|
||||||
|
.database_insert .db-grid strong {color:#444}
|
||||||
|
.database_insert .db-grid:nth-child(even) {background: #e3e3e3;line-height: 1.5em;font-size: 1.3em;}
|
||||||
|
|
||||||
|
.database_insert .tables {color:#fff}
|
||||||
|
.database_insert .tables .table-item {padding:0.33rem 0;background:rgba(255,255,255,0.1);line-height: 1.8em;}
|
||||||
|
.database_insert .tables .table-item:nth-child(even) {background:rgba(255,255,255,0.2)}
|
||||||
|
.database_insert .attribute {display: inline-block;padding: .25em .4em 0 .4em;font-size: 70%;font-weight: 700;line-height: 1.2rem;text-align: center;white-space: nowrap;vertical-align: baseline;border-radius: .25rem;color:#ffe300; border:1px solid #ffe300}
|
||||||
|
.database_insert summary {background: #172841;color:#fff;margin: 0 -8px 0 -8px;padding:7px 10px}
|
||||||
|
|
||||||
|
.tables {background: #2d3137; #fff;padding: 2px 10px;}
|
||||||
|
.tables label {padding:10px 5px;display:block}
|
||||||
|
section + section { margin-top:15px; }
|
||||||
|
</style>
|
||||||
|
{% endsection %}
|
||||||
Loading…
x
Reference in New Issue
Block a user