{{= implode('
',(array) $context->definition[$entity]['table']->modifier->query) }}
+ {% else %}
+ diff --git a/asset/lean-console/lean-console-bw.css b/asset/lean-console/lean-console-bw.css index 026697b..2164983 100644 --- a/asset/lean-console/lean-console-bw.css +++ b/asset/lean-console/lean-console-bw.css @@ -4,23 +4,25 @@ .justify-content-around{justify-content: space-around;}.justify-content-end{justify-content: end} .flex {display:flex} -:root { - --color-red: #d47474 -} - +:root {--color-red: #d47474} .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;} .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-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} 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;} summary {cursor:pointer;} + #body-main {min-height:calc(100vh - 30px);display:flex} /* Header */ diff --git a/meta/i18n/en/lean.storage.json b/meta/i18n/en/lean.storage.json index aa09a68..22fc75c 100644 --- a/meta/i18n/en/lean.storage.json +++ b/meta/i18n/en/lean.storage.json @@ -19,10 +19,24 @@ "create": "Create table", "createAll": "Create all tables", "query": "SQL Query", + "add-column": "+ New row", "alter": "Alter table", "alterAll": "Alter all tables", "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" + } + } } \ No newline at end of file diff --git a/src/Controller/Storage.php b/src/Controller/Storage.php index dfd7951..cccb4ea 100644 --- a/src/Controller/Storage.php +++ b/src/Controller/Storage.php @@ -27,7 +27,7 @@ class Storage extends Console { $migrations = $this->container->has(Lib\DatabaseMigrations::class) ? $this->container->get(Lib\DatabaseMigrations::class) : false; $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()); } @@ -46,6 +46,16 @@ class Storage extends Console { 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" public function session(ServerRequestInterface $request, array $arguments) : ResponseInterface { diff --git a/src/Form/Storage/Database/Insert.php b/src/Form/Storage/Database/Insert.php new file mode 100644 index 0000000..60cc2e4 --- /dev/null +++ b/src/Form/Storage/Database/Insert.php @@ -0,0 +1,53 @@ +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); + } +} diff --git a/view/lean-console/page/storage/database.phtml b/view/lean-console/page/storage/database.phtml index 738b95d..19d6f89 100644 --- a/view/lean-console/page/storage/database.phtml +++ b/view/lean-console/page/storage/database.phtml @@ -40,7 +40,7 @@
{{= implode('
',(array) $context->definition[$entity]['table']->modifier->query) }}
+ {% else %}
+