new: [metaTemplateNameDirectory] Added index to see the known template and their associated saved meta-templates

refacto/CRUDComponent
Sami Mokaddem 2023-02-27 12:16:36 +01:00
parent ce8a7ba1be
commit 6fc568e80e
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
4 changed files with 108 additions and 2 deletions

View File

@ -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'],

View File

@ -0,0 +1,35 @@
<?php
namespace App\Controller;
use App\Controller\AppController;
use Cake\Utility\Hash;
use Cake\Utility\Text;
use Cake\Utility\Inflector;
use Cake\ORM\TableRegistry;
use \Cake\Database\Expression\QueryExpression;
use Cake\Http\Exception\NotFoundException;
use Cake\Http\Exception\MethodNotAllowedException;
use Cake\Routing\Router;
class MetaTemplateNameDirectoryController extends AppController
{
public $quickFilterFields = [['name' => 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;
}
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,60 @@
<?php
use Cake\Utility\Hash;
echo $this->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' => []
]
]);