2020-09-28 01:26:50 +02:00
< ? php
2021-12-01 11:01:31 +01:00
use Cake\Utility\Hash ;
2021-12-14 15:09:40 +01:00
if ( ! empty ( $updateableTemplates [ 'new' ])) {
2021-12-20 14:28:04 +01:00
$alertHtml = sprintf (
'<strong>%s</strong> %s' ,
__ ( 'New meta-templates available!' ),
2022-03-08 17:22:39 +01:00
__n ( 'There is one new template on disk that can be loaded in the database' , 'There are {0} new templates on disk that can be loaded in the database:' , count ( $updateableTemplates [ 'new' ]), count ( $updateableTemplates [ 'new' ]))
2021-12-01 11:01:31 +01:00
);
2021-12-20 14:28:04 +01:00
$alertList = [];
$alertList = Hash :: extract ( $updateableTemplates [ 'new' ], '{s}.template' );
2021-12-01 11:01:31 +01:00
$alertList = array_map ( function ( $entry ) {
2021-12-20 14:28:04 +01:00
return sprintf ( '%s:%s %s' ,
h ( $entry [ 'namespace' ]),
h ( $entry [ 'name' ]),
$this -> Bootstrap -> button ([
'variant' => 'link' ,
'size' => 'sm' ,
'icon' => 'download' ,
'title' => __ ( 'Create this template' ),
2022-11-24 12:50:11 +01:00
'onclick' => " UI.submissionModalForIndex('/metaTemplates/createNewTemplate/ { $entry [ 'uuid' ] } ', '/meta-templates') " ,
2021-12-20 14:28:04 +01:00
])
);
2021-12-01 11:01:31 +01:00
}, $alertList );
$alertHtml .= $this -> Html -> nestedList ( $alertList );
}
2020-09-28 01:26:50 +02:00
echo $this -> element ( 'genericElements/IndexTable/index_table' , [
2021-12-20 14:28:04 +01:00
'notice' => ! empty ( $alertHtml ) ? [ 'html' => $alertHtml , 'variant' => 'warning' ,] : false ,
2020-09-28 01:26:50 +02:00
'data' => [
'data' => $data ,
'top_bar' => [
'children' => [
2020-12-07 16:06:01 +01:00
[
'type' => 'context_filters' ,
2020-12-08 15:15:58 +01:00
'context_filters' => $filteringContexts
2020-12-07 16:06:01 +01:00
],
2020-09-28 01:26:50 +02:00
[
'type' => 'search' ,
2021-11-10 15:31:09 +01:00
'button' => __ ( 'Search' ),
2020-09-28 01:26:50 +02:00
'placeholder' => __ ( 'Enter value to search' ),
'data' => '' ,
'searchKey' => 'value'
]
]
],
'fields' => [
[
'name' => '#' ,
'sort' => 'id' ,
'data_path' => 'id' ,
],
2020-11-20 11:09:24 +01:00
[
'name' => 'Enabled' ,
'sort' => 'enabled' ,
'data_path' => 'enabled' ,
2020-12-07 14:17:10 +01:00
'element' => 'toggle' ,
2020-12-10 15:18:02 +01:00
'url' => '/metaTemplates/toggle/{{0}}' ,
'url_params_vars' => [ 'id' ],
'toggle_data' => [
2020-12-15 16:36:53 +01:00
'editRequirement' => [
2020-12-10 15:18:02 +01:00
'function' => function ( $row , $options ) {
return true ;
2020-12-15 16:36:53 +01:00
},
2020-12-15 16:14:06 +01:00
],
'skip_full_reload' => true
2020-12-10 15:18:02 +01:00
]
],
[
'name' => 'Default' ,
'sort' => 'is_default' ,
'data_path' => 'is_default' ,
'element' => 'toggle' ,
'url' => '/metaTemplates/toggle/{{0}}/{{1}}' ,
'url_params_vars' => [[ 'datapath' => 'id' ], [ 'raw' => 'is_default' ]],
'toggle_data' => [
2020-12-15 16:36:53 +01:00
'editRequirement' => [
2020-12-10 15:18:02 +01:00
'function' => function ( $row , $options ) {
return true ;
}
],
'confirm' => [
'enable' => [
'titleHtml' => __ ( 'Make {{0}} the default template?' ),
'bodyHtml' => $this -> Html -> nestedList ([
__ ( 'Only one template per scope can be set as the default template' ),
2020-12-10 17:05:51 +01:00
'{{0}}' ,
2020-12-10 15:18:02 +01:00
]),
2021-01-18 08:51:16 +01:00
'type' => '{{0}}' ,
2021-01-13 14:17:55 +01:00
'confirmText' => __ ( 'Yes, set as default' ),
'arguments' => [
'titleHtml' => [ 'name' ],
'bodyHtml' => [
[
'function' => function ( $row , $data ) {
$conflictingTemplate = getConflictingTemplate ( $row , $data );
if ( ! empty ( $conflictingTemplate )) {
return sprintf (
2021-09-17 13:04:37 +02:00
" <span class= \" text-danger fw-bolder \" >%s</span> %s.<br />
< ul >< li >< span class = \ " fw-bolder \" >%s</span> %s <span class= \" fw-bolder \" >%s</span></li></ul> " ,
2021-01-13 14:17:55 +01:00
__ ( 'Conflict with:' ),
$this -> Html -> link (
h ( $conflictingTemplate -> name ),
'/metaTemplates/view/' . h ( $conflictingTemplate -> id ),
[ 'target' => '_blank' ]
),
__ ( 'By proceeding' ),
h ( $conflictingTemplate -> name ),
__ ( 'will not be the default anymore' )
);
}
return __ ( 'Current scope: {0}' , h ( $row -> scope ));
},
'data' => [
'defaultTemplatePerScope' => $defaultTemplatePerScope
]
]
2021-01-18 08:51:16 +01:00
],
'type' => [
'function' => function ( $row , $data ) {
$conflictingTemplate = getConflictingTemplate ( $row , $data );
if ( ! empty ( $conflictingTemplate )) {
return 'confirm-danger' ;
}
return 'confirm-warning' ;
},
'data' => [
'defaultTemplatePerScope' => $defaultTemplatePerScope
]
2021-01-13 14:17:55 +01:00
]
]
2020-12-10 15:18:02 +01:00
],
'disable' => [
'titleHtml' => __ ( 'Remove {{0}} as the default template?' ),
'type' => 'confirm-warning' ,
2021-01-13 14:17:55 +01:00
'confirmText' => __ ( 'Yes, do not set as default' ),
2021-01-18 08:51:16 +01:00
'arguments' => [
2021-01-13 14:17:55 +01:00
'titleHtml' => [ 'name' ],
]
2020-12-10 15:18:02 +01:00
]
]
2020-12-08 09:07:00 +01:00
]
2020-11-20 11:09:24 +01:00
],
2020-09-28 01:26:50 +02:00
[
'name' => __ ( 'Scope' ),
'sort' => 'scope' ,
'data_path' => 'scope' ,
],
[
'name' => __ ( 'Name' ),
'sort' => 'name' ,
'data_path' => 'name' ,
],
[
'name' => __ ( 'Namespace' ),
'sort' => 'namespace' ,
'data_path' => 'namespace' ,
],
2021-11-03 11:47:10 +01:00
[
'name' => __ ( 'Version' ),
'sort' => 'version' ,
'data_path' => 'version' ,
],
2020-09-28 01:26:50 +02:00
[
'name' => __ ( 'UUID' ),
'sort' => 'uuid' ,
'data_path' => 'uuid'
2021-12-01 11:01:31 +01:00
],
2020-09-28 01:26:50 +02:00
],
'title' => __ ( 'Meta Field Templates' ),
'description' => __ ( 'The various templates used to enrich certain objects by a set of standardised fields.' ),
2023-09-27 12:05:48 +02:00
'includeAllPagination' => true ,
2020-09-28 01:26:50 +02:00
'actions' => [
[
'url' => '/metaTemplates/view' ,
'url_params_data_paths' => [ 'id' ],
'icon' => 'eye'
],
2021-11-24 09:14:09 +01:00
[
2021-12-01 11:01:31 +01:00
'open_modal' => '/metaTemplates/update/[onclick_params_data_path]' ,
2021-12-14 15:09:40 +01:00
'modal_params_data_path' => 'id' ,
2021-12-01 11:01:31 +01:00
'title' => __ ( 'Update Meta-Template' ),
2021-11-24 09:14:09 +01:00
'icon' => 'download' ,
2021-12-01 11:01:31 +01:00
'complex_requirement' => [
'function' => function ( $row , $options ) {
2021-12-14 15:09:40 +01:00
return empty ( $row [ 'updateStatus' ][ 'up-to-date' ]) && empty ( $row [ 'updateStatus' ][ 'to-existing' ]);
2021-12-01 11:01:31 +01:00
}
]
2021-12-08 11:11:46 +01:00
],
[
'open_modal' => '/metaTemplates/getMetaFieldsToUpdate/[onclick_params_data_path]' ,
'modal_params_data_path' => 'id' ,
'title' => __ ( 'Get meta-fields that should be moved to the newest version of this meta-template' ),
'icon' => 'exclamation-triangle' ,
'variant' => 'warning' ,
'complex_requirement' => [
'function' => function ( $row , $options ) {
2021-12-14 15:09:40 +01:00
return ! empty ( $row [ 'updateStatus' ][ 'to-existing' ]) && empty ( $row [ 'updateStatus' ][ 'can-be-removed' ]);
2021-12-08 11:11:46 +01:00
}
]
],
2023-02-14 14:42:35 +01:00
[
'open_modal' => '/metaTemplates/migrateMetafieldsToNewestTemplate/[onclick_params_data_path]' ,
'modal_params_data_path' => 'id' ,
'title' => __ ( 'Update meta-fields to the newest version of this meta-template' ),
'icon' => 'arrow-circle-up' ,
'variant' => 'success' ,
'complex_requirement' => [
'function' => function ( $row , $options ) {
return ! empty ( $row [ 'updateStatus' ][ 'to-existing' ]) && empty ( $row [ 'updateStatus' ][ 'can-be-removed' ]);
}
]
],
2021-12-08 11:11:46 +01:00
[
'open_modal' => '/metaTemplates/delete/[onclick_params_data_path]' ,
'modal_params_data_path' => 'id' ,
2023-02-14 14:42:35 +01:00
'title' => __ ( 'This meta-template doesn\'t have any meta-fields and can be safely removed.' ),
2021-12-08 11:11:46 +01:00
'icon' => 'trash' ,
'variant' => 'success' ,
'complex_requirement' => [
'function' => function ( $row , $options ) {
2021-12-14 15:09:40 +01:00
return ! empty ( $row [ 'updateStatus' ][ 'to-existing' ]) && ! empty ( $row [ 'updateStatus' ][ 'can-be-removed' ]);
2021-12-08 11:11:46 +01:00
}
]
],
2020-09-28 01:26:50 +02:00
]
]
]);
2020-12-10 16:50:46 +01:00
function getConflictingTemplate ( $row , $data ) {
if ( ! empty ( $data [ 'data' ][ 'defaultTemplatePerScope' ][ $row -> scope ])) {
$conflictingTemplate = $data [ 'data' ][ 'defaultTemplatePerScope' ][ $row -> scope ];
if ( ! empty ( $conflictingTemplate )) {
return $conflictingTemplate ;
}
}
return [];
}