From abd5dab6053e8958ec31eb15b37cafbc2096f2ab Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Fri, 31 Mar 2023 13:55:48 +0200 Subject: [PATCH 1/5] chg: [command:importer] Make sure to use the latest known version of the template --- src/Command/ImporterCommand.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Command/ImporterCommand.php b/src/Command/ImporterCommand.php index 3aba536..dee4e24 100644 --- a/src/Command/ImporterCommand.php +++ b/src/Command/ImporterCommand.php @@ -158,6 +158,7 @@ class ImporterCommand extends Command if (!$this->noMetaTemplate) { $metaTemplate = $this->MetaTemplates->find() ->where(['uuid' => $config['metaTemplateUUID']]) + ->order(['version' => 'DESC']) ->first(); if (!is_null($metaTemplate)) { $metaTemplateFieldsMapping = $this->MetaTemplates->MetaTemplateFields->find('list', [ @@ -192,6 +193,7 @@ class ImporterCommand extends Command $metaEntity->field = $fieldName; $metaEntity->scope = $table->getBehavior('MetaFields')->getScope(); $metaEntity->meta_template_id = $metaTemplate->id; + $metaEntity->meta_template_directory_id = $metaTemplate->meta_template_directory_id; if (isset($metaTemplateFieldsMapping[$fieldName])) { // a meta field template must exists $metaEntity->meta_template_field_id = $metaTemplateFieldsMapping[$fieldName]; } else { From 7a8eb6ba50592a437a066cd7f61c93e399f13152 Mon Sep 17 00:00:00 2001 From: iglocska Date: Thu, 25 May 2023 16:11:21 +0200 Subject: [PATCH 2/5] chg: [CRUD] allow for sorting on related model fields - some hacks to resolve issues with sorting on related fields --- src/Controller/Component/CRUDComponent.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index d56609c..adc569b 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -50,7 +50,6 @@ class CRUDComponent extends Component if ($this->taggingSupported()) { $options['filters'][] = 'filteringTags'; } - $optionFilters = []; $optionFilters += empty($options['filters']) ? [] : $options['filters']; foreach ($optionFilters as $i => $filter) { @@ -85,9 +84,22 @@ class CRUDComponent extends Component $this->Controller->paginate['order'] = $options['order']; } } + if (!empty($this->request->getQuery('sort'))) { + $sort = $this->request->getQuery('sort'); + $direction = $this->request->getQuery('direction'); + if ($this->_validOrderFields($sort) && ($direction === 'asc' || $direction === 'desc')) { + $sort = explode('.', $sort); + if (count($sort) > 1) { + $sort[0] = Inflector::camelize(Inflector::pluralize($sort[0])); + } + $sort = implode('.', $sort); + $query->order($sort . ' ' . $direction); + } + } if ($this->metaFieldsSupported() && !$this->Controller->ParamHandler->isRest()) { $query = $this->includeRequestedMetaFields($query); } + if (!$this->Controller->ParamHandler->isRest()) { $this->setRequestedEntryAmount(); } @@ -1673,7 +1685,7 @@ class CRUDComponent extends Component return false; } } else { - $association = $this->Table->associations()->get($model); + $association = $this->Table->associations()->get(Inflector::camelize(Inflector::pluralize($model))); $associatedTable = $association->getTarget(); if (empty($associatedTable->getSchema()->typeMap()[$subField])) { return false; From 41749ae5a83d1c916bf627e0f53f882eeec58253 Mon Sep 17 00:00:00 2001 From: iglocska Date: Thu, 25 May 2023 16:22:49 +0200 Subject: [PATCH 3/5] fix: [users] added the country information to the index / view --- src/Controller/UsersController.php | 2 +- src/Model/Table/UsersTable.php | 3 ++- templates/Organisations/add.php | 2 +- templates/Users/index.php | 6 +++++- templates/Users/view.php | 4 ++++ templates/element/genericElements/Form/fieldScaffold.php | 4 ++++ 6 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Controller/UsersController.php b/src/Controller/UsersController.php index dad2bc7..95db80a 100644 --- a/src/Controller/UsersController.php +++ b/src/Controller/UsersController.php @@ -11,7 +11,7 @@ use Cake\Http\Exception\NotFoundException; class UsersController extends AppController { - public $filterFields = ['Individuals.uuid', 'username', 'Individuals.email', 'Individuals.first_name', 'Individuals.last_name', 'Organisations.name']; + public $filterFields = ['Individuals.uuid', 'username', 'Individuals.email', 'Individuals.first_name', 'Individuals.last_name', 'Organisations.name', 'Organisation.nationality']; public $quickFilterFields = ['Individuals.uuid', ['username' => true], ['Individuals.first_name' => true], ['Individuals.last_name' => true], 'Individuals.email']; public $containFields = ['Individuals', 'Roles', 'UserSettings', 'Organisations']; diff --git a/src/Model/Table/UsersTable.php b/src/Model/Table/UsersTable.php index 86160d5..cc2c0ba 100644 --- a/src/Model/Table/UsersTable.php +++ b/src/Model/Table/UsersTable.php @@ -47,7 +47,8 @@ class UsersTable extends AppTable 'Organisations', [ 'dependent' => false, - 'cascadeCallbacks' => false + 'cascadeCallbacks' => false, + 'strategy' => 'join' ] ); $this->hasMany( diff --git a/templates/Organisations/add.php b/templates/Organisations/add.php index e430cc6..75eeee6 100644 --- a/templates/Organisations/add.php +++ b/templates/Organisations/add.php @@ -2,7 +2,7 @@ echo $this->element('genericElements/Form/genericForm', array( 'data' => array( 'description' => __('Organisations can be equivalent to legal entities or specific individual teams within such entities. Their purpose is to relate individuals to their affiliations and for release control of information using the Trust Circles.'), - 'model' => 'Organisations', + 'model' => 'Organisation', 'fields' => array( array( 'field' => 'name' diff --git a/templates/Users/index.php b/templates/Users/index.php index 1dff40d..d06578c 100644 --- a/templates/Users/index.php +++ b/templates/Users/index.php @@ -1,7 +1,6 @@ element('genericElements/IndexTable/index_table', [ 'data' => [ 'data' => $data, @@ -88,6 +87,11 @@ echo $this->element('genericElements/IndexTable/index_table', [ 'url' => '/roles/view/{{0}}', 'url_vars' => ['role.id'] ], + [ + 'name' => __('Country'), + 'sort' => 'organisation.nationality', + 'data_path' => 'organisation.nationality' + ], [ 'name' => __('# User Settings'), 'element' => 'count_summary', diff --git a/templates/Users/view.php b/templates/Users/view.php index 4e2bda7..5ffafda 100644 --- a/templates/Users/view.php +++ b/templates/Users/view.php @@ -44,6 +44,10 @@ $fields = [ 'key' => __('Last name'), 'path' => 'individual.last_name' ], + [ + 'key' => __('Country'), + 'path' => 'organisation.nationality' + ], [ 'key' => __('Alignments'), 'type' => 'alignment', diff --git a/templates/element/genericElements/Form/fieldScaffold.php b/templates/element/genericElements/Form/fieldScaffold.php index f95bdde..6a6d789 100644 --- a/templates/element/genericElements/Form/fieldScaffold.php +++ b/templates/element/genericElements/Form/fieldScaffold.php @@ -1,5 +1,9 @@ request->getParam('controller')))) : + h($data['model']); $fieldTemplate = 'genericField'; if (!empty($fieldData['type'])) { if (file_exists(ROOT . '/templates/element/genericElements/Form/Fields/' . $fieldData['type'] . 'Field.php')) { From 011f7f452cdd3f4f0be009c143e469fc046d4dfe Mon Sep 17 00:00:00 2001 From: iglocska Date: Fri, 26 May 2023 16:01:01 +0200 Subject: [PATCH 4/5] new: [enumerations] schema update added --- .../20230526000000_Enumerations.php | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 config/Migrations/20230526000000_Enumerations.php diff --git a/config/Migrations/20230526000000_Enumerations.php b/config/Migrations/20230526000000_Enumerations.php new file mode 100644 index 0000000..cac527b --- /dev/null +++ b/config/Migrations/20230526000000_Enumerations.php @@ -0,0 +1,116 @@ +hasTable('enumeration_collections'); + if (!$exists) { + $enumerationCollectionsTable = $this->table('enumeration_collections', [ + 'signed' => false, + 'collation' => 'utf8mb4_unicode_ci' + ]); + $enumerationCollectionsTable + ->addColumn('id', 'integer', [ + 'autoIncrement' => true, + 'limit' => 10, + 'signed' => false, + ]) + ->addPrimaryKey('id') + ->addColumn('uuid', 'string', [ + 'null' => false, + 'limit' => 40, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + ]) + ->addColumn('name', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + ]) + ->addColumn('description', 'text', [ + 'default' => null, + 'null' => true + ]) + ->addColumn('target_model', 'string', [ + 'null' => false, + 'limit' => 255, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + ]) + ->addColumn('target_field', 'string', [ + 'null' => false, + 'limit' => 255, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + ]) + ->addColumn('enabled', 'boolean', [ + 'default' => 0, + ]) + ->addColumn('deleted', 'boolean', [ + 'default' => 0, + ]) + ->addColumn('created', 'datetime', [ + 'null' => false + ]) + ->addColumn('modified', 'datetime', [ + 'null' => false + ]) + ->addIndex('name') + ->addIndex('target_model') + ->addIndex('target_field') + ->addIndex('uuid', ['unique' => true]); + + $enumerationCollectionsTable->create(); + } + + + + $exists = $this->hasTable('enumerations'); + if (!$exists) { + $enumerationsTable = $this->table('enumerations', [ + 'signed' => false, + 'collation' => 'utf8mb4_unicode_ci' + ]); + $enumerationsTable + ->addColumn('id', 'integer', [ + 'autoIncrement' => true, + 'limit' => 10, + 'signed' => false, + ]) + ->addPrimaryKey('id') + ->addColumn('value', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + ]) + ->addColumn('enumeration_collection_id', 'integer', [ + 'limit' => 10, + 'signed' => false, + 'null' => false + ]) + ->addIndex('value') + ->addIndex('enumeration_collection_id'); + $enumerationsTable->create(); + } + } +} From 52e8a5c6a698132682d061adca50b01fa32d83f4 Mon Sep 17 00:00:00 2001 From: iglocska Date: Fri, 26 May 2023 16:13:52 +0200 Subject: [PATCH 5/5] new: [enumerations] added enumerations system - for string entry fields, simply add lists of values to convert the text entry for values - helps with maintaining accurate lists - currently the fields that are valid targets are organisations.nationality, organisations.sector, organisations.type --- src/Controller/Component/ACLComponent.php | 11 ++ src/Controller/Component/CRUDComponent.php | 8 ++ .../Component/Navigation/sidemenu.php | 5 + .../EnumerationCollectionsController.php | 98 +++++++++++++++ src/Controller/EnumerationsController.php | 40 ++++++ src/Model/Entity/Enumeration.php | 11 ++ src/Model/Entity/EnumerationCollection.php | 11 ++ .../Table/EnumerationCollectionsTable.php | 118 ++++++++++++++++++ src/Model/Table/EnumerationsTable.php | 29 +++++ templates/EnumerationCollections/add.php | 40 ++++++ templates/EnumerationCollections/index.php | 96 ++++++++++++++ templates/EnumerationCollections/view.php | 46 +++++++ templates/Enumerations/index.php | 43 +++++++ .../genericElements/Form/genericForm.php | 8 ++ 14 files changed, 564 insertions(+) create mode 100644 src/Controller/EnumerationCollectionsController.php create mode 100644 src/Controller/EnumerationsController.php create mode 100644 src/Model/Entity/Enumeration.php create mode 100644 src/Model/Entity/EnumerationCollection.php create mode 100644 src/Model/Table/EnumerationCollectionsTable.php create mode 100644 src/Model/Table/EnumerationsTable.php create mode 100644 templates/EnumerationCollections/add.php create mode 100644 templates/EnumerationCollections/index.php create mode 100644 templates/EnumerationCollections/view.php create mode 100644 templates/Enumerations/index.php diff --git a/src/Controller/Component/ACLComponent.php b/src/Controller/Component/ACLComponent.php index cbd1cb8..7e8cd2f 100644 --- a/src/Controller/Component/ACLComponent.php +++ b/src/Controller/Component/ACLComponent.php @@ -75,6 +75,17 @@ class ACLComponent extends Component 'delete' => ['*'], 'index' => ['*'] ], + 'Enumerations' => [ + 'delete' => ['perm_admin'], + 'index' => ['*'] + ], + 'EnumerationCollections' => [ + 'view' => ['*'], + 'add' => ['perm_admin'], + 'edit' => ['perm_admin'], + 'delete' => ['perm_admin'], + 'index' => ['*'] + ], 'Inbox' => [ 'createEntry' => ['OR' => ['perm_admin', 'perm_sync']], 'delete' => ['perm_admin'], diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index adc569b..9891b20 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -399,6 +399,14 @@ class CRUDComponent extends Component if (!empty($params['fields'])) { $this->Controller->set('fields', $params['fields']); } + $EnumerationCollections = TableRegistry::getTableLocator()->get('EnumerationCollections'); + $modelAlias = $this->Table->getAlias(); + if (in_array($this->Table->getAlias(), $EnumerationCollections->getValidModelList())) { + $enumerations = $EnumerationCollections->getFieldValues($modelAlias); + if (!empty($enumerations)) { + $this->Controller->set('enumerations', $enumerations); + } + } $this->Controller->entity = $data; $this->Controller->set('entity', $data); } diff --git a/src/Controller/Component/Navigation/sidemenu.php b/src/Controller/Component/Navigation/sidemenu.php index 84fcf6c..ec00e27 100644 --- a/src/Controller/Component/Navigation/sidemenu.php +++ b/src/Controller/Component/Navigation/sidemenu.php @@ -128,6 +128,11 @@ class Sidemenu { 'url' => '/permissionLimitations/index', 'icon' => 'jedi', ], + 'Enumerations' => [ + 'label' => __('Collections'), + 'url' => '/enumerationCollections/index', + 'icon' => 'list', + ], ] ], 'API' => [ diff --git a/src/Controller/EnumerationCollectionsController.php b/src/Controller/EnumerationCollectionsController.php new file mode 100644 index 0000000..bbf994f --- /dev/null +++ b/src/Controller/EnumerationCollectionsController.php @@ -0,0 +1,98 @@ +CRUD->index([ + 'filters' => $this->filterFields, + 'quickFilters' => $this->quickFilterFields, + 'contain' => ['Enumerations'], + 'afterFind' => function($data) { + $data->value_count = isset($data->enumerations) ? count($data->enumerations) : 0; + $data->values = Hash::extract($data, 'enumerations.{n}.value'); + unset($data->enumerations); + return $data; + } + ]); + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; + } + $this->set('metaGroup', 'Enumerations'); + } + + public function add() + { + $this->CRUD->add([ + 'afterSave' => function($data) { + $this->EnumerationCollections->captureValues($data); + } + ]); + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; + } + $this->set(compact('enumerations')); + $this->set('metaGroup', 'Enumerations'); + } + + public function view($id) + { + $this->CRUD->view($id); + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; + } + $this->set('metaGroup', 'Enumerations'); + } + + public function edit($id) + { + $this->CRUD->edit($id, [ + 'afterSave' => function($data) { + $this->EnumerationCollections->purgeValues($data); + $this->EnumerationCollections->captureValues($data); + }, + 'contain' => ['Enumerations'], + 'afterFind' => function($data) { + $values = []; + foreach ($data['enumerations'] as $enumeration) { + $values[] = $enumeration['value']; + } + $data->values = implode(PHP_EOL, $values); + return $data; + } + ]); + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; + } + $this->set('metaGroup', 'Enumerations'); + $this->render('add'); + } + + public function delete($id) + { + $this->CRUD->delete($id); + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; + } + $this->set('metaGroup', 'Enumerations'); + } +} diff --git a/src/Controller/EnumerationsController.php b/src/Controller/EnumerationsController.php new file mode 100644 index 0000000..c4aa956 --- /dev/null +++ b/src/Controller/EnumerationsController.php @@ -0,0 +1,40 @@ +CRUD->index([ + 'filters' => $this->filterFields, + 'quickFilters' => $this->quickFilterFields + ]); + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; + } + $this->set('metaGroup', 'Enumerations'); + } + public function delete($id) + { + $this->CRUD->delete($id); + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; + } + $this->set('metaGroup', 'Enumerations'); + } +} diff --git a/src/Model/Entity/Enumeration.php b/src/Model/Entity/Enumeration.php new file mode 100644 index 0000000..b6659a3 --- /dev/null +++ b/src/Model/Entity/Enumeration.php @@ -0,0 +1,11 @@ + [ + 'country', + 'sector', + 'type' + ] + ]; + public function initialize(array $config): void + { + parent::initialize($config); + $this->addBehavior('UUID'); + $this->addBehavior('AuditLog'); + $this->addBehavior('Timestamp'); + $this->hasMany( + 'Enumerations', + [ + 'dependent' => true + ] + ); + $this->setDisplayField('name'); + } + + public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options) + { + if (empty($data['uuid'])) { + $data['uuid'] = Text::uuid(); + } + return true; + } + + public function validationDefault(Validator $validator): Validator + { + $validator + ->notEmptyString('name') + ->requirePresence(['name'], 'create') + ->notEmptyString('uuid') + ->requirePresence(['uuid'], 'create') + ->notEmptyString('target_model') + ->requirePresence(['target_model'], 'create') + ->notEmptyString('target_field') + ->requirePresence(['target_field'], 'create'); + return $validator; + } + + public function getValidFieldList(?string $model = null): array + { + if (!empty($model)) { + if (empty($this->fieldMapping[$model])) { + return []; + } else { + return $this->fieldMapping[$model]; + } + } else { + return $this->fieldMapping; + } + } + + public function getValidModelList(?string $model = null): array + { + + return array_keys($this->fieldMapping); + } + + public function getFieldValues($model): array + { + $collections = $this->find('all')->where(['target_model' => $model, 'enabled' => 1, 'deleted' => 0])->contain(['Enumerations'])->disableHydration()->all()->toArray(); + $options = []; + foreach ($collections as $collection) { + if (empty($collection['target_field'])) { + $options[$collection['target_field']] = []; + } + foreach ($collection['enumerations'] as $enumeration) { + $options[$collection['target_field']][$enumeration['value']] = $enumeration['value']; + } + } + return $options; + } + + public function purgeValues(\App\Model\Entity\EnumerationCollection $entity): void + { + $this->Enumerations->deleteAll([ + 'enumeration_collection_id' => $entity->id + ]); + } + + public function captureValues(\App\Model\Entity\EnumerationCollection $entity): void + { + if (!empty($entity->values)) { + $values = $entity->values; + $collection_id = $entity->id; + if (!is_array($values)) { + $values = explode("\n", $values); + } + foreach ($values as $value) { + $enumeration = $this->Enumerations->newEntity([ + 'value' => trim($value), + 'enumeration_collection_id' => $entity->id + ]); + $this->Enumerations->save($enumeration); + } + } + } +} diff --git a/src/Model/Table/EnumerationsTable.php b/src/Model/Table/EnumerationsTable.php new file mode 100644 index 0000000..a6a65bd --- /dev/null +++ b/src/Model/Table/EnumerationsTable.php @@ -0,0 +1,29 @@ +belongsTo( + 'EnumerationCollection' + ); + $this->setDisplayField('value'); + } + + public function validationDefault(Validator $validator): Validator + { + $validator + ->notEmptyString('value') + ->requirePresence(['value'], 'create') + ->notEmptyString('enumeration_collection_id') + ->requirePresence(['enumeration_collection_id'], 'create'); + return $validator; + } +} diff --git a/templates/EnumerationCollections/add.php b/templates/EnumerationCollections/add.php new file mode 100644 index 0000000..fc1be6f --- /dev/null +++ b/templates/EnumerationCollections/add.php @@ -0,0 +1,40 @@ +element('genericElements/Form/genericForm', [ + 'data' => [ + 'description' => __('Roles define global rules for a set of users, including first and foremost access controls to certain functionalities.'), + 'model' => 'EnumerationCollections', + 'fields' => [ + [ + 'field' => 'name', + 'label' => __('Name') + ], + [ + 'field' => 'enabled', + 'label' => __('Enabled'), + 'type' => 'checkbox', + ], + [ + 'field' => 'target_model', + 'label' => __('Model'), + ], + [ + 'field' => 'target_field', + 'label' => __('Field'), + ], + [ + 'field' => 'description', + 'label' => __('Description'), + ], + [ + 'field' => 'values', + 'label' => __('Values'), + 'type' => 'textarea' + ], + ], + 'submit' => [ + 'action' => $this->request->getParam('action') + ] + ] + ]); +?> + diff --git a/templates/EnumerationCollections/index.php b/templates/EnumerationCollections/index.php new file mode 100644 index 0000000..a4cefd1 --- /dev/null +++ b/templates/EnumerationCollections/index.php @@ -0,0 +1,96 @@ +role->perm_admin)) { + $topbarChildren[] = [ + 'type' => 'simple', + 'children' => [ + 'data' => [ + 'type' => 'simple', + 'text' => __('Add Enumeration Collection'), + 'class' => 'btn btn-primary', + 'popover_url' => '/enumerationCollections/add' + ] + ] + ]; +} +$topbarChildren[] = [ + 'type' => 'search', + 'button' => __('Search'), + 'placeholder' => __('Enter value to search'), + 'data' => '', + 'searchKey' => 'value' +]; + +echo $this->element('genericElements/IndexTable/index_table', [ + 'data' => [ + 'data' => $data, + 'top_bar' => [ + 'children' => $topbarChildren, + ], + 'fields' => [ + [ + 'name' => '#', + 'sort' => 'id', + 'data_path' => 'id', + ], + [ + 'name' => __('Name'), + 'sort' => 'name', + 'data_path' => 'name', + ], + [ + 'name' => __('Enabled'), + 'sort' => 'enabled', + 'data_path' => 'enabled', + ], + [ + 'name' => __('UUID'), + 'sort' => 'uuid', + 'data_path' => 'uuid', + ], + [ + 'name' => __('Model'), + 'sort' => 'target_model', + 'data_path' => 'target_model', + ], + [ + 'name' => __('Field'), + 'sort' => 'target_field', + 'data_path' => 'target_field', + ], + [ + 'name' => __('Values'), + 'sort' => 'value_count', + 'data_path' => 'value_count', + ], + [ + 'name' => __('Description'), + 'data_path' => 'description', + ], + ], + 'title' => __('Enumeration Collections Index'), + 'description' => __('A list collections that can be used to convert string input fields into selections wherever it makes sense.'), + 'pull' => 'right', + 'actions' => [ + [ + 'url' => '/enumerationCollections/view', + 'url_params_data_paths' => ['id'], + 'icon' => 'eye' + ], + [ + 'open_modal' => '/enumerationCollections/edit/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', + 'icon' => 'edit', + 'requirement' => !empty($loggedUser['role']['perm_admin']) + ], + [ + 'open_modal' => '/enumerationCollections/delete/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', + 'icon' => 'trash', + 'requirement' => !empty($loggedUser['role']['perm_admin']) + ], + ] + ] +]); +echo ''; +?> diff --git a/templates/EnumerationCollections/view.php b/templates/EnumerationCollections/view.php new file mode 100644 index 0000000..7b46610 --- /dev/null +++ b/templates/EnumerationCollections/view.php @@ -0,0 +1,46 @@ +element( + '/genericElements/SingleViews/single_view', + [ + 'data' => $entity, + 'fields' => [ + [ + 'key' => __('ID'), + 'path' => 'id' + ], + [ + 'key' => __('Name'), + 'path' => 'name' + ], + [ + 'key' => __('Enabled'), + 'path' => 'enabled', + 'type' => 'boolean' + ], + [ + 'key' => __('UUID'), + 'path' => 'uuid' + ], + [ + 'key' => __('Model'), + 'path' => 'target_model' + ], + [ + 'key' => __('Field'), + 'path' => 'target_field' + ], + [ + 'key' => __('Description'), + 'path' => 'description' + ], + + ], + 'children' => [ + [ + 'url' => '/Enumerations/index?EnumerationCollection.id={{0}}', + 'url_params' => ['id'], + 'title' => __('Values') + ] + ] + ] +); diff --git a/templates/Enumerations/index.php b/templates/Enumerations/index.php new file mode 100644 index 0000000..e1b8e1b --- /dev/null +++ b/templates/Enumerations/index.php @@ -0,0 +1,43 @@ +element('genericElements/IndexTable/index_table', [ + 'data' => [ + 'data' => $data, + 'top_bar' => [ + 'children' => [ + [ + 'type' => 'search', + 'button' => __('Search'), + 'placeholder' => __('Enter value to search'), + 'data' => '', + 'searchKey' => 'value' + ] + ] + ], + 'fields' => [ + [ + 'name' => '#', + 'sort' => 'id', + 'data_path' => 'id', + ], + [ + 'name' => __('Value'), + 'sort' => 'value', + 'data_path' => 'value', + ] + ], + 'title' => __('Enumerations Index'), + 'description' => null, + 'pull' => 'right', + 'actions' => [ + [ + 'open_modal' => '/enumerations/delete/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', + 'icon' => 'trash', + 'requirement' => !empty($loggedUser['role']['perm_admin']) + ], + ] + ] +]); +echo ''; +?> diff --git a/templates/element/genericElements/Form/genericForm.php b/templates/element/genericElements/Form/genericForm.php index c0164a7..8a564de 100644 --- a/templates/element/genericElements/Form/genericForm.php +++ b/templates/element/genericElements/Form/genericForm.php @@ -26,6 +26,14 @@ } $formRandomValue = Cake\Utility\Security::randomString(8); $initSelect2 = false; + + if (!empty($enumerations)) { + foreach ($data['fields'] as $k => $field) { + if (isset($enumerations[$field['field']])) { + $data['fields'][$k]['options'] = $enumerations[$field['field']]; + } + } + } $formCreate = $this->Form->create($entity, ['id' => 'form-' . $formRandomValue]); $default_template = [ 'inputContainer' => '
{{content}}
',