Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Yoda) Vueify frontend actions #17

Open
wants to merge 74 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
784355c
Js routes, layout, menu
schtr4jh Nov 22, 2020
084576c
Cleanup form, tables, vueify
schtr4jh Nov 24, 2020
e6651b6
Update styles
schtr4jh Nov 24, 2020
59cb1a2
Update themify route
schtr4jh Nov 24, 2020
117a013
New route
schtr4jh Nov 24, 2020
6181128
Jquery
schtr4jh Nov 24, 2020
9fd203b
Auth in, inline block
schtr4jh Nov 26, 2020
30bc457
Remove twig vue views
schtr4jh Nov 27, 2020
a152f8d
Merge remote-tracking branch 'origin/master' into master-yoda
schtr4jh Nov 27, 2020
0c93356
Change routing
schtr4jh Nov 29, 2020
713f775
Mappings, form
schtr4jh Nov 29, 2020
1b69496
Meta update
schtr4jh Dec 1, 2020
b914e9e
Merge branch 'master' into master-yoda
schtr4jh Dec 10, 2020
1558b0d
Hub uuid
schtr4jh Dec 10, 2020
319ac3b
Merge branch 'master' into master-yoda
schtr4jh Jan 23, 2021
7300bc3
Allow layout
schtr4jh Jan 24, 2021
0560109
Merge branch 'master' into master-yoda
schtr4jh Feb 6, 2021
152dd08
Fix missmerge
schtr4jh Feb 6, 2021
356031e
Merge branch 'master' into master-yoda
schtr4jh Feb 27, 2021
9c4f585
Trim
schtr4jh Feb 28, 2021
360d4eb
Merge branch 'master' into master-yoda
schtr4jh Mar 16, 2021
c13b437
Static fields
schtr4jh Mar 16, 2021
5f641ee
Merge branch 'master-yoda' of https://github.com/pckg/generic into ma…
schtr4jh Mar 16, 2021
07e182c
Merge branch 'master' into master-yoda
schtr4jh Apr 3, 2021
5c078bd
Better vue routes
schtr4jh Apr 6, 2021
d4c96f8
Pre-release fixes
schtr4jh Apr 11, 2021
c4b6696
Request mock
schtr4jh Apr 26, 2021
2fbc646
Admin group
schtr4jh May 2, 2021
3ad2f16
Merge branch 'master' into master-yoda
schtr4jh May 8, 2021
bd368ba
Enriched, httpql
schtr4jh May 8, 2021
b9e2ff6
Update httpql
schtr4jh May 8, 2021
644d148
Styling, actions, tabs
schtr4jh Jun 6, 2021
5b7287b
Merge remote-tracking branch 'origin/master' into master-yoda
schtr4jh Jun 6, 2021
ed76752
Form and style updates
schtr4jh Jun 9, 2021
18b6b54
Change color
schtr4jh Jun 10, 2021
d769f26
Cleanup
schtr4jh Jun 21, 2021
697271c
Fix picture
schtr4jh Aug 13, 2021
b8a3d5d
Fix form modeling, table checkboxes
schtr4jh Aug 14, 2021
2463560
Datetime alignment
schtr4jh Aug 14, 2021
1628fe7
Eager load
schtr4jh Aug 16, 2021
e7bc6fe
Warning, no grid form, async delete
schtr4jh Sep 1, 2021
36db8c2
Editor
schtr4jh Sep 15, 2021
e319844
Bootstrapless modal
schtr4jh Sep 16, 2021
fc0ad21
Reverse relation
schtr4jh Sep 16, 2021
36256ea
Remember view/edit mode
schtr4jh Sep 16, 2021
520c011
Merge remote-tracking branch 'origin/master' into master-yoda
schtr4jh Sep 19, 2021
264ac8f
Merge branch 'master' into master-yoda
schtr4jh Oct 1, 2021
45d7bf2
Bootstrap plugin
schtr4jh Nov 11, 2021
9cac74f
Bugfixes and updates
schtr4jh Nov 11, 2021
5b0c498
Migrate to translator and adapter
schtr4jh Nov 11, 2021
df835af
Extract to pagebuilder
schtr4jh Nov 12, 2021
cb7f72a
Extract resolvers and migrations
schtr4jh Nov 12, 2021
6f3e5f8
phpcs
schtr4jh Nov 12, 2021
f059faa
Clean
schtr4jh Nov 13, 2021
e808e68
Move from generic
schtr4jh Nov 14, 2021
2493b11
Bugfix
schtr4jh Nov 20, 2021
a8c256e
api, settings
schtr4jh Jan 15, 2022
de7709b
Move url
schtr4jh Feb 8, 2022
4bd29f6
Bulk edit
schtr4jh Mar 2, 2022
37f8a56
Fix edit view
schtr4jh Mar 3, 2022
fc8bcea
Don't load ids
schtr4jh Mar 3, 2022
bf64d74
Pass route
schtr4jh Apr 3, 2022
d8daa93
Update style
schtr4jh Apr 9, 2022
8db6fa1
Proper rewrite?
schtr4jh May 10, 2022
eed205e
Merge branch 'master-yoda' of https://github.com/pckg/generic into ma…
schtr4jh May 10, 2022
1c85d2e
Filter relation
schtr4jh May 10, 2022
0d443d9
Relation
schtr4jh May 10, 2022
6c2f8d4
Okay implementation
schtr4jh May 11, 2022
4966f14
Tabelizes and functionizes
schtr4jh Aug 8, 2022
092fbf3
Parentmost
schtr4jh Aug 15, 2022
2658161
Optimize
schtr4jh Aug 24, 2022
af2866c
Multiple sources
schtr4jh Sep 19, 2022
e23a4dd
Merge changes
schtr4jh Sep 19, 2022
58f7b5b
Double click, reformat
schtr4jh Sep 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,208 changes: 1,303 additions & 905 deletions composer.lock

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions src/Pckg/Dynamic/Controller/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ public function getExportTableAction(Table $table, Strategy $strategy, Dynamic $
*/
$listableFields = $table->listableFields;
$listedFields = $table->getFields($listableFields, $dynamicService->getFilterService());
$relations = (new Relations())->withShowTable()
->withOnField()
->where('on_table_id', $table->id)
->where('dynamic_relation_type_id', 1)
->all();
$relations = $table->getBelongsToRelations();
foreach ($relations as $relation) {
$relation->loadOnEntity($entity, $dynamicService);
}
Expand Down
171 changes: 152 additions & 19 deletions src/Pckg/Dynamic/Controller/HttpQl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

namespace Pckg\Dynamic\Controller;

use Pckg\Concept\Reflect;
use Pckg\Database\Entity;
use Pckg\Database\Helper\Convention;
use Pckg\Database\Record;
use Pckg\Database\Relation\HasMany;
use Pckg\Dynamic\Entity\Fields;
use Pckg\Dynamic\Record\Field;
use Pckg\Dynamic\Record\Relation;
use Pckg\Dynamic\Record\Tab;
use Pckg\Dynamic\Record\Table;
use Pckg\Dynamic\Resolver\TableQl;
use Pckg\Dynamic\Service\Dynamic;
use Pckg\Generic\Controller\Generic;
use Pckg\Maestro\Service\Tabelize;

class HttpQl
Expand All @@ -33,6 +36,82 @@ protected function fetchTable(Dynamic $dynamicService)
return (new TableQl($dynamicService))->resolve($path);
}

/**
* Get all records.
*
* @param Table $table
* @return mixed|null
* @throws \Throwable
*/
public function getTableAction(Table $table)
{
$tabelize = resolve(Tabelize::class);
$tabelize->setEnriched(false);

return Reflect::method($this, 'searchIndexAction', ['table' => $table, 'tabelize' => $tabelize]);
}

public function getRecordAction(Table $table, Record $record)
{
$tabelize = resolve(Tabelize::class);
$tabelize->setEnriched(false);

return [
'record' => Reflect::method(Records::class, 'getViewAction', ['table' => $table, 'record' => $record, 'tabelize' => $tabelize])['mappedRecord']
];
}

public function patchRecordAction(Table $table, Record $record)
{
$tabelize = resolve(Tabelize::class);
$tabelize->setEnriched(false);

return [
'record' => Reflect::method(Records::class, 'patchEditAction', ['table' => $table, 'record' => $record, 'tabelize' => $tabelize])['mappedRecord']
];
}

// full update
public function postRecordAction(Table $table, Record $record)
{
$tabelize = resolve(Tabelize::class);
$tabelize->setEnriched(false);

return [
'record' => Reflect::method(Records::class, 'postEditAction', ['table' => $table, 'record' => $record, 'tabelize' => $tabelize])['mappedRecord']
];
}

public function deleteRecordAction(Table $table, Record $record)
{
$tabelize = resolve(Tabelize::class);
$tabelize->setEnriched(false);

return Reflect::method(Records::class, 'deleteDeleteAction', ['table' => $table, 'record' => $record, 'tabelize' => $tabelize])['mappedRecord'];
}

/**
* Insert multiple records.
*/
public function postTableAction(Table $table)
{
return Reflect::method(Records::class, 'postAddAction', ['table' => $table]);
}

/**
* Patch multiple records.
*/
public function patchTableAction()
{
}

/**
* Delete multiple records.
*/
public function deleteTableAction()
{
}

/**
* This works the same as postAddAction from Record.
* Except, it accepts data in other format.
Expand All @@ -46,9 +125,8 @@ public function putIndexAction(Dynamic $dynamicService)

/**
* This works only for file uploads.
* It will be refactored to a separate method in next version.
*/
public function postIndexAction(Dynamic $dynamic)
public function postUploadAction(Dynamic $dynamic)
{
if (!files()->all()) {
throw new \Exception('Incomplete request');
Expand All @@ -64,6 +142,32 @@ public function postIndexAction(Dynamic $dynamic)
return resolve(Records::class)->postUploadAction($table, $record, $field);
}

/**
* Read Orm data from body or headers.
*/
public function fetchORM()
{
$ormFields = json_decode(post('X-Pckg-Orm-Fields', ''), true);
$ormFilters = json_decode(post('X-Pckg-Orm-Filters', ''), true);
$ormPaginator = json_decode(post('X-Pckg-Orm-Paginator', ''), true);
$ormSearch = json_decode(post('X-Pckg-Orm-Search', ''), true);
$ormMeta = json_decode(post('X-Pckg-Orm-Meta', ''), true);

foreach (['Fields' => [], 'Filters' => [], 'Paginator' => [], 'Search' => null, 'Meta' => []] as $key => $def) {
if (!${'orm' . $key}) {
${'orm' . $key} = json_decode(request()->getHeaderLine('X-Pckg-Orm-' . $key, ''), true);
}
if (!${'orm' . $key}) {
${'orm' . $key} = get(strtolower($key), []);
}
if (!${'orm' . $key}) {
${'orm' . $key} = $def;
}
}

return [$ormFields, $ormFilters, $ormPaginator, $ormSearch, $ormMeta];
}

/**
* Return list of all records, paginated.
*
Expand All @@ -82,14 +186,8 @@ public function searchIndexAction(
if (!$table) {
$table = $this->fetchTable($dynamicService);
}
/**
* Read Orm data.
*/
$ormFields = json_decode(post('X-Pckg-Orm-Fields'), true);
$ormFilters = json_decode(post('X-Pckg-Orm-Filters'), true);
$ormPaginator = json_decode(post('X-Pckg-Orm-Paginator'), true);
$ormSearch = json_decode(post('X-Pckg-Orm-Search'), true);
$ormMeta = json_decode(post('X-Pckg-Orm-Meta'), true);

[$ormFields, $ormFilters, $ormPaginator, $ormSearch, $ormMeta] = $this->fetchORM();

/**
* Set defaults.
Expand Down Expand Up @@ -381,7 +479,7 @@ public function getDownloadAction()
public function getDefinitionAction()
{
return [
'entities' => (new \Pckg\Dynamic\Entity\Tables())->where('repository', 'default')
'schemas' => (new \Pckg\Dynamic\Entity\Tables())->where('repository', 'default')
->joinPermissionTo('write')
->withFields(function (HasMany $fields) {
$fields->orderBy('order');
Expand All @@ -390,17 +488,52 @@ public function getDefinitionAction()
->orderBy('`order`')
->all()
->map(function (Table $table) {
$singleton = ucfirst(toCamel($table->table));
if (strrpos($singleton, 'ies') === strlen($singleton) - strlen('ies')) {
$singleton = substr($singleton, 0, -strlen('ies')) . 'y';
} else if (strrpos($singleton, 'es') === strlen($singleton) - strlen('es')) {
$singleton = substr($singleton, 0, -strlen('es'));
} else if (strrpos($singleton, 's') === strlen($singleton) - strlen('s')) {
$singleton = substr($singleton, 0, -strlen('s'));
}

// http://niem.github.io/json/tutorial/#define-a-niem-exchange-model
return [
'$schema' => router()->getRoutePrefix(true) . '/api/http-ql/definition#schemas.' . $table->table,
'type' => 'object',
'properties' => [
'@context' => [
'$ref' => '#/definitions/@context',
],
'j:' . $singleton => [
'$ref' => '#/definitions/@context'
],
],
'additionalProperties' => false,
'required' => [
'@context',
'j:' . $singleton => '#/definitions/j:' . $singleton,
],
'definitions' => [
'@context' => [
'type' => 'object',
],
'j:' . $singleton => [
'type' => 'object',
'properties' => $table->fields->map(function (Field $field) {
return [
'type' => 'nc:' . $field->fieldType->slug,
'title' => $field->title,
];
})->keyBy('field')->all(),
'additionalProperties' => false,
'required' => $table->fields->filter(fn(Field $field) => $field->required)
->map('field')
->values(),
],
],
'table' => $table->table,
'title' => $table->title,
'fields' => $table->fields->map(function (Field $field) {
return [
'field' => $field->field,
'title' => $field->title,
'type' => $field->fieldType->slug,
'required' => !!$field->required,
];
})->keyBy('field')->all()
];
})->keyBy('table')->all(),
];
Expand Down
24 changes: 11 additions & 13 deletions src/Pckg/Dynamic/Controller/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public function importContent(Table $table, Reader $csv, $strategy = null)
$headers = [];
$csv->setHeaderOffset(1);
$availableFields = $table->listableFields(function (HasMany $fields) {

$fields->realFields();
});
$arrAvailableFields = $availableFields->map('field')->all();
Expand Down Expand Up @@ -202,34 +201,33 @@ public function importContent(Table $table, Reader $csv, $strategy = null)
}

runInLocale(function () use ($uniqueFields, $table, $values, $uniqueValues, &$prevRecord, $strategy) {

$entity = $table->createEntity();
if (!$prevRecord && $uniqueFields && $uniqueValues) {
/**
* Check for existing records.
*/
$record = Record::getOrNew($uniqueValues, $entity);
/**
* Check for existing records.
*/
$record = $prevRecord = Record::getOrNew($uniqueValues, $entity);
if ($strategy === 'skip' && !$record->isNew()) {
// import translations separately?
return;
}
$prevRecord = $record;
} elseif (!$prevRecord) {
// no unique fields or no unique values, insert
/**
* Create new record.
*/
$record = $prevRecord = new Record([], $entity);
} else {
/**
* Update translation.
*/
/**
* Update translation.
*/
$record = $prevRecord;
}

$record->set($values);
/**
* Save record.
*/
/**
* Save record.
*/
$record->save($entity);
}, $locale);
}
Expand Down
Loading