chg: [genericElement:index] Allow support of closure for variables and type
parent
3d647680a0
commit
fa49821731
|
@ -55,6 +55,7 @@ class MetaTemplatesController extends AppController
|
|||
if ($this->ParamHandler->isRest()) {
|
||||
return $this->restResponsePayload;
|
||||
}
|
||||
$this->set('defaultTemplatePerScope', $this->MetaTemplates->getDefaultTemplatePerScope());
|
||||
$this->set('alignmentScope', 'individuals');
|
||||
$this->set('metaGroup', 'Administration');
|
||||
}
|
||||
|
@ -79,4 +80,10 @@ class MetaTemplatesController extends AppController
|
|||
return $this->ajaxResponsePayload;
|
||||
}
|
||||
}
|
||||
|
||||
public function getDefaultTemplatePerScope($scope = '')
|
||||
{
|
||||
$defaultTemplate = $this->MetaTemplates->getDefaultTemplatePerScope($scope);
|
||||
return $this->RestResponse->viewData($defaultTemplate, 'json');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,20 @@ class MetaTemplatesTable extends AppTable
|
|||
return $template;
|
||||
}
|
||||
|
||||
public function getDefaultTemplatePerScope(String $scope = '')
|
||||
{
|
||||
$query = $this->find('list', [
|
||||
'keyField' => 'scope',
|
||||
'valueField' => function ($template) {
|
||||
return $template;
|
||||
}
|
||||
])->where(['is_default' => true]);
|
||||
if (!empty($scope)) {
|
||||
$query->where(['scope' => $scope]);
|
||||
}
|
||||
return $query->all()->toArray();
|
||||
}
|
||||
|
||||
public function loadMetaFile(String $filePath)
|
||||
{
|
||||
if (file_exists($filePath)) {
|
||||
|
|
|
@ -18,20 +18,26 @@ class StringFromPathHelper extends Helper
|
|||
if (!empty($dataPaths)) {
|
||||
$extractedVars = [];
|
||||
foreach ($dataPaths as $i => $dataPath) {
|
||||
$varValue = '';
|
||||
if (is_array($dataPath)) {
|
||||
$varValue = '';
|
||||
if (!empty($dataPath['datapath'])) {
|
||||
$varValue = Hash::get($data, $dataPath['datapath']);
|
||||
} else if (!empty($dataPath['raw'])) {
|
||||
$varValue = $dataPath['raw'];
|
||||
} else if (!empty($dataPath['function'])) {
|
||||
$varValue = $dataPath['function']($data, $dataPath);
|
||||
}
|
||||
$extractedVars[] = $varValue;
|
||||
// $extractedVars[] = $varValue;
|
||||
} else {
|
||||
$extractedVars[] = Hash::get($data, $dataPath);
|
||||
$varValue = Hash::get($data, $dataPath);
|
||||
}
|
||||
if (empty($dataPath['function'])) {
|
||||
$varValue = $options['sanitize'] ? h($varValue) : $varValue;
|
||||
}
|
||||
$extractedVars[] = $varValue;
|
||||
}
|
||||
foreach ($extractedVars as $i => $value) {
|
||||
$value = $options['sanitize'] ? h($value) : $value;
|
||||
$value = $options['highlight'] ? "<span class=\"font-weight-light\">${value}</span>" : $value;
|
||||
$str = str_replace(
|
||||
"{{{$i}}}",
|
||||
|
|
|
@ -57,19 +57,40 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
|||
'titleHtml_vars' => ['name'],
|
||||
'bodyHtml' => $this->Html->nestedList([
|
||||
__('Only one template per scope can be set as the default template'),
|
||||
__('Current scope: {{0}}'),
|
||||
'{{1}}',
|
||||
]),
|
||||
'bodyHtml_vars' => ['scope'],
|
||||
'type' => 'confirm-warning',
|
||||
'bodyHtml_vars' => [
|
||||
'scope',
|
||||
[
|
||||
'function' => function($row, $data) {
|
||||
$conflictingTemplate = getConflictingTemplate($row, $data);
|
||||
if (!empty($conflictingTemplate)) {
|
||||
return sprintf('<span class="text-danger font-weight-bolder">%s</span> %s', __('Conflict with:'), h($conflictingTemplate->name));
|
||||
}
|
||||
return __('Current scope: {0}', h($row->scope));
|
||||
},
|
||||
'data' => [
|
||||
'defaultTemplatePerScope' => $defaultTemplatePerScope
|
||||
]
|
||||
]
|
||||
],
|
||||
'type' => [
|
||||
'function' => function($row, $data) {
|
||||
$conflictingTemplate = getConflictingTemplate($row, $data);
|
||||
if (!empty($conflictingTemplate)) {
|
||||
return 'confirm-danger';
|
||||
}
|
||||
return 'confirm-warning';
|
||||
},
|
||||
'data' => [
|
||||
'defaultTemplatePerScope' => $defaultTemplatePerScope
|
||||
]
|
||||
],
|
||||
'confirmText' => __('Yes, set as default')
|
||||
],
|
||||
'disable' => [
|
||||
'titleHtml' => __('Remove {{0}} as the default template?'),
|
||||
'titleHtml_vars' => ['name'],
|
||||
'bodyHtml' => $this->Html->nestedList([
|
||||
__('Current scope: {{0}}'),
|
||||
]),
|
||||
'bodyHtml_vars' => ['scope'],
|
||||
'type' => 'confirm-warning',
|
||||
'confirmText' => __('Yes, do not set as default')
|
||||
]
|
||||
|
@ -109,4 +130,14 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
|||
]
|
||||
]
|
||||
]);
|
||||
|
||||
function getConflictingTemplate($row, $data) {
|
||||
if (!empty($data['data']['defaultTemplatePerScope'][$row->scope])) {
|
||||
$conflictingTemplate = $data['data']['defaultTemplatePerScope'][$row->scope];
|
||||
if (!empty($conflictingTemplate)) {
|
||||
return $conflictingTemplate;
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -47,6 +47,12 @@
|
|||
['highlight' => true]
|
||||
);
|
||||
}
|
||||
if (!empty($confirmOptions[$optionType]['type'])) {
|
||||
if (!empty($confirmOptions[$optionType]['type']['function'])) {
|
||||
$typeData = !empty($confirmOptions[$optionType]['type']['data']) ? $confirmOptions[$optionType]['type'] : [];
|
||||
$confirmOptions[$optionType]['type'] = $confirmOptions[$optionType]['type']['function']($row, $typeData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$url = $this->StringFromPath->buildStringFromDataPath($field['url'], $row, $field['url_params_vars']);
|
||||
|
|
|
@ -139,7 +139,7 @@ class ModalFactory {
|
|||
scrollable: false,
|
||||
title: '',
|
||||
titleHtml: false,
|
||||
body: '',
|
||||
body: false,
|
||||
bodyHtml: false,
|
||||
variant: '',
|
||||
modalClass: [],
|
||||
|
|
Loading…
Reference in New Issue