diff --git a/src/Controller/Component/ACLComponent.php b/src/Controller/Component/ACLComponent.php index 4d37067..f7468e9 100644 --- a/src/Controller/Component/ACLComponent.php +++ b/src/Controller/Component/ACLComponent.php @@ -146,6 +146,9 @@ class ACLComponent extends Component 'toggle' => ['perm_admin'], 'view' => ['perm_admin'], ], + 'MetaTemplateNameDirectory' => [ + 'index' => ['perm_admin'], + ], 'Organisations' => [ 'add' => ['perm_admin'], 'delete' => ['perm_admin'], diff --git a/src/Controller/MetaTemplateNameDirectoryController.php b/src/Controller/MetaTemplateNameDirectoryController.php new file mode 100644 index 0000000..98c6884 --- /dev/null +++ b/src/Controller/MetaTemplateNameDirectoryController.php @@ -0,0 +1,35 @@ + true], 'uuid', 'version']; + public $filterFields = ['name', 'uuid', 'version']; + public $containFields = ['MetaTemplates']; + + + public function index() + { + $this->CRUD->index([ + 'filters' => $this->filterFields, + 'quickFilters' => $this->quickFilterFields, + 'contain' => $this->containFields, + ]); + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; + } + } +} diff --git a/src/Model/Table/MetaTemplateNameDirectoryTable.php b/src/Model/Table/MetaTemplateNameDirectoryTable.php index 32e0869..df39103 100644 --- a/src/Model/Table/MetaTemplateNameDirectoryTable.php +++ b/src/Model/Table/MetaTemplateNameDirectoryTable.php @@ -7,6 +7,7 @@ use App\Model\Entity\MetaTemplateNameDirectory; use App\Model\Table\AppTable; use Cake\ORM\RulesChecker; use Cake\Validation\Validator; +use Cake\Log\Log; class MetaTemplateNameDirectoryTable extends AppTable { @@ -20,6 +21,9 @@ class MetaTemplateNameDirectoryTable extends AppTable 'foreignKey' => 'meta_template_directory_id', ] ); + $this->hasOne('MetaTemplates', [ + 'foreignKey' => 'meta_template_directory_id', + ]); $this->setDisplayField('name'); } @@ -59,7 +63,11 @@ class MetaTemplateNameDirectoryTable extends AppTable if (!empty($existingTemplate)) { return $existingTemplate; } - $this->save($metaTemplateDirectory); - return $metaTemplateDirectory; + $savedEntity = $this->save($metaTemplateDirectory); + if ($savedEntity) { + return $metaTemplateDirectory; + } + Log::error(__('Could not save meta_template_directory. Reasons: {0}', json_encode($metaTemplateDirectory->getErrors()))); + return false; } } diff --git a/templates/MetaTemplateNameDirectory/index.php b/templates/MetaTemplateNameDirectory/index.php new file mode 100644 index 0000000..0b57d8c --- /dev/null +++ b/templates/MetaTemplateNameDirectory/index.php @@ -0,0 +1,60 @@ +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' => __('Name'), + 'sort' => 'name', + 'data_path' => 'name', + ], + [ + 'name' => __('Namespace'), + 'sort' => 'namespace', + 'data_path' => 'namespace', + ], + [ + 'name' => __('UUID'), + 'sort' => 'uuid', + 'data_path' => 'uuid' + ], + [ + 'name' => __('Version'), + 'sort' => 'version', + 'data_path' => 'version', + ], + [ + 'name' => __('Associated Meta-Template'), + 'sort' => 'meta_template.id', + 'data_path' => 'meta_template.id', + 'element' => 'function', + 'function' => function($row, $viewContext) { + return $viewContext->Bootstrap::node('a', [ + 'href' => h($baseurl . '/metaTemplates/view/' . $row->meta_template->id ?? ''), + ], !empty($row->meta_template->name) ? (sprintf('%s (v%s)', h($row->meta_template->name), h($row->meta_template->version))) :''); + } + ], + ], + 'title' => __('Meta Template Name Directory'), + 'description' => __('The directory of all meta templates known by the system.'), + 'actions' => [] + ] +]);