From 1a4f08448871f29d95961a3ecbd2bd904df55d4b Mon Sep 17 00:00:00 2001 From: Arlen Johnson Date: Fri, 23 Sep 2022 12:01:39 -0400 Subject: [PATCH] Refactor topLinks and add fields-nav.inc for edit view. (CFM-143) --- app/templates/Cos/columns.inc | 14 ++- app/templates/Groups/actions.inc | 73 ------------- app/templates/Groups/columns.inc | 39 ++++++- .../actions.inc => Groups/fields-nav.inc} | 19 ++-- app/templates/Names/columns.inc | 14 ++- app/templates/People/actions.inc | 103 ------------------ app/templates/People/columns.inc | 75 ++++++++++++- app/templates/Standard/add-edit-view.php | 34 +++++- app/templates/Standard/index.php | 13 +-- app/templates/Types/actions.inc | 43 -------- app/templates/Types/columns.inc | 18 ++- 11 files changed, 202 insertions(+), 243 deletions(-) delete mode 100644 app/templates/Groups/actions.inc rename app/templates/{Names/actions.inc => Groups/fields-nav.inc} (74%) delete mode 100644 app/templates/People/actions.inc delete mode 100644 app/templates/Types/actions.inc diff --git a/app/templates/Cos/columns.inc b/app/templates/Cos/columns.inc index d51b1a503..a6a35d2e6 100644 --- a/app/templates/Cos/columns.inc +++ b/app/templates/Cos/columns.inc @@ -38,7 +38,19 @@ $indexColumns = [ ] ]; +// $topLinks appear as an upper right menu +$topLinks = []; + +// $rowActions appear as row-level menu items in the index view gear icon +$rowActions = [ + [ + 'action' => 'duplicate', + 'class' => '', + 'icon' => 'content_copy' + ] +]; + +// TODO: develop bulk actions. For now, use a placeholder. $bulkActions = [ - // TODO: develop bulk actions. For now, use a placeholder. 'delete' => true ]; diff --git a/app/templates/Groups/actions.inc b/app/templates/Groups/actions.inc deleted file mode 100644 index 9f200ddbc..000000000 --- a/app/templates/Groups/actions.inc +++ /dev/null @@ -1,73 +0,0 @@ - 'group_members', - 'action' => 'index', - 'icon' => 'people', - 'type' => 'tab' - ], - [ - 'controller' => 'group_owners', - 'action' => 'index', - 'icon' => 'settings', - 'type' => 'tab' - ], - [ - 'controller' => 'group_nestings', - 'action' => 'index', - 'icon' => 'group_add', - 'type' => 'tab' - ], - [ - 'controller' => 'history_records', - 'action' => 'index', - 'icon' => 'history', - 'type' => 'tab' - ], - [ - 'controller' => 'identifiers', - 'action' => 'index', - 'icon' => 'label', - 'if' => 'notAutomatic', - 'type' => 'tab' - ], - [ - 'action' => 'reconcile', - 'icon' => 'sync', - 'type' => 'top-link' - ] -]; \ No newline at end of file diff --git a/app/templates/Groups/columns.inc b/app/templates/Groups/columns.inc index cb489e127..9ff193020 100644 --- a/app/templates/Groups/columns.inc +++ b/app/templates/Groups/columns.inc @@ -39,7 +39,44 @@ $indexColumns = [ ] ]; +// $topLinks appear as an upper right menu +$topLinks = []; + +// $rowActions appear as row-level menu items in the index view gear icon +$rowActions = [ + [ + 'controller' => 'group_members', + 'action' => 'index', + 'icon' => 'people' + ], + [ + 'controller' => 'group_owners', + 'action' => 'index', + 'icon' => 'settings' + ], + [ + 'controller' => 'group_nestings', + 'action' => 'index', + 'icon' => 'group_add' + ], + [ + 'controller' => 'history_records', + 'action' => 'index', + 'icon' => 'history' + ], + [ + 'controller' => 'identifiers', + 'action' => 'index', + 'icon' => 'label', + 'if' => 'notAutomatic' + ], + [ + 'action' => 'reconcile', + 'icon' => 'sync' + ] +]; + +// TODO: develop bulk actions. For now, use a placeholder. $bulkActions = [ - // TODO: develop bulk actions. For now, use a placeholder. 'delete' => true ]; \ No newline at end of file diff --git a/app/templates/Names/actions.inc b/app/templates/Groups/fields-nav.inc similarity index 74% rename from app/templates/Names/actions.inc rename to app/templates/Groups/fields-nav.inc index 5966a2c86..38d21495f 100644 --- a/app/templates/Names/actions.inc +++ b/app/templates/Groups/fields-nav.inc @@ -1,6 +1,6 @@ 'primary', - 'icon' => 'publish', - 'if' => 'notPrimary' + 'icon' => 'sync', + 'order' => 'Default', + 'label' => __d('operation', 'reconcile'), + 'link' => [ + 'action' => 'reconcile' + ], + 'class' => '' ] ]; \ No newline at end of file diff --git a/app/templates/Names/columns.inc b/app/templates/Names/columns.inc index 58ae42d4d..0e648e3d4 100644 --- a/app/templates/Names/columns.inc +++ b/app/templates/Names/columns.inc @@ -39,7 +39,19 @@ $indexColumns = [ ] ]; +// $topLinks appear as an upper right menu +$topLinks = []; + +// $rowActions appear as row-level menu items in the index view gear icon +$rowActions = [ + [ + 'action' => 'primary', + 'icon' => 'publish', + 'if' => 'notPrimary' + ] +]; + +// TODO: develop bulk actions. For now, use a placeholder. $bulkActions = [ - // TODO: develop bulk actions. For now, use a placeholder. 'delete' => true ]; \ No newline at end of file diff --git a/app/templates/People/actions.inc b/app/templates/People/actions.inc deleted file mode 100644 index 5d0cfa8d1..000000000 --- a/app/templates/People/actions.inc +++ /dev/null @@ -1,103 +0,0 @@ - 'names', - 'action' => 'index', - 'icon' => 'account_box', - 'iconClass' => 'material-icons-outlined', - 'type' => 'tab' - ], - [ - 'controller' => 'email_addresses', - 'action' => 'index', - 'icon' => 'email', - 'iconClass' => 'material-icons-outlined', - 'type' => 'tab' - ], - [ - 'controller' => 'identifiers', - 'action' => 'index', - 'icon' => 'fingerprint', - 'type' => 'tab', - 'class' => 'bottom-border' - ], - [ - 'controller' => 'person_roles', - 'action' => 'index', - 'icon' => 'emoji_people', - 'type' => 'tab' - ], - [ - 'controller' => 'external_identities', - 'action' => 'index', - 'icon' => 'system_update_alt', - 'type' => 'tab', - 'class' => 'bottom-border' - ], - [ - 'controller' => 'ad_hoc_attributes', - 'action' => 'index', - 'icon' => 'check_box', - 'iconClass' => 'material-icons-outlined', - 'type' => 'tab' - ], - [ - 'controller' => 'addresses', - 'action' => 'index', - 'icon' => 'contact_mail', - 'iconClass' => 'material-icons-outlined', - 'type' => 'tab' - ], - [ - 'controller' => 'history_records', - 'action' => 'index', - 'icon' => 'history', - 'type' => 'tab' - ], - [ - 'controller' => 'telephone_numbers', - 'action' => 'index', - 'icon' => 'phone', - 'type' => 'tab' - ], - [ - 'controller' => 'urls', - 'action' => 'index', - 'icon' => 'link', - 'type' => 'tab' - ] -]; diff --git a/app/templates/People/columns.inc b/app/templates/People/columns.inc index 641aaa171..d29f8d6a8 100644 --- a/app/templates/People/columns.inc +++ b/app/templates/People/columns.inc @@ -40,7 +40,80 @@ $indexColumns = [ ] ]; +// $topLinks appear as an upper right menu +$topLinks = []; + +// $rowActions appear as row-level menu items in the index view gear icon +$rowActions = [ + [ + 'controller' => 'names', + 'action' => 'index', + 'icon' => 'account_box', + 'iconClass' => 'material-icons-outlined', + 'type' => 'tab' + ], + [ + 'controller' => 'email_addresses', + 'action' => 'index', + 'icon' => 'email', + 'iconClass' => 'material-icons-outlined', + 'type' => 'tab' + ], + [ + 'controller' => 'identifiers', + 'action' => 'index', + 'icon' => 'fingerprint', + 'type' => 'tab', + 'class' => 'bottom-border' + ], + [ + 'controller' => 'person_roles', + 'action' => 'index', + 'icon' => 'emoji_people', + 'type' => 'tab' + ], + [ + 'controller' => 'external_identities', + 'action' => 'index', + 'icon' => 'system_update_alt', + 'type' => 'tab', + 'class' => 'bottom-border' + ], + [ + 'controller' => 'ad_hoc_attributes', + 'action' => 'index', + 'icon' => 'check_box', + 'iconClass' => 'material-icons-outlined', + 'type' => 'tab' + ], + [ + 'controller' => 'addresses', + 'action' => 'index', + 'icon' => 'contact_mail', + 'iconClass' => 'material-icons-outlined', + 'type' => 'tab' + ], + [ + 'controller' => 'history_records', + 'action' => 'index', + 'icon' => 'history', + 'type' => 'tab' + ], + [ + 'controller' => 'telephone_numbers', + 'action' => 'index', + 'icon' => 'phone', + 'type' => 'tab' + ], + [ + 'controller' => 'urls', + 'action' => 'index', + 'icon' => 'link', + 'type' => 'tab' + ] +]; + +// TODO: develop bulk actions. For now, use a placeholder. $bulkActions = [ - // TODO: develop bulk actions. For now, use a placeholder. 'expunge' => true ]; \ No newline at end of file diff --git a/app/templates/Standard/add-edit-view.php b/app/templates/Standard/add-edit-view.php index d6a58418b..abb41d9a4 100644 --- a/app/templates/Standard/add-edit-view.php +++ b/app/templates/Standard/add-edit-view.php @@ -36,6 +36,22 @@ // If you're looking to set a custom $vv_title, you might be able to use // generateDisplayField() on the Table instead + +// Include subnavigation structures on edit pages +// XXX: if CFM-218 (Make fields.inc configuration only) is accepted, move the contents of fields-nav.inc into fields.inc. +if($vv_action == 'edit') { + if(file_exists(ROOT . DS . "templates" . DS . $modelsName . DS . "fields-nav.inc")) { + include(ROOT . DS . "templates" . DS . $modelsName . DS . "fields-nav.inc"); + } +} + +// $linkFilter is used for models that belong to a specific parent model (eg: co_id) +$linkFilter = []; + +if(!empty($vv_primary_link) && !empty($this->request->getQuery($vv_primary_link))) { + $linkFilter = [$vv_primary_link => $this->request->getQuery($vv_primary_link)]; +} + ?>
@@ -46,7 +62,23 @@ $action_args = array(); $action_args['vv_attr_id'] = $vv_obj->id; - // TODO: More actions in the config? Add them to $action_args['vv_actions'][] here. + foreach(($topLinks ?? []) as $t) { + if($vv_permissions[ $t['link']['action'] ]) { + // We need to inject $linkFilter, but not overwrite any existing query params + if(!empty($t['link']['?'])) { + $t['link']['?'] = array_merge($t['link']['?'], $linkFilter); + } else { + $t['link']['?'] = $linkFilter; + } + + $action_args['vv_actions'][] = [ + 'order' => $this->Menu->getMenuOrder($t['order']), + 'icon' => $this->Menu->getMenuIcon($t['icon']), + 'url' => $this->Url->build($t['link']), + 'label' => $t['label'], + ]; + } + } // Delete if($vv_action != 'add' && !empty($vv_obj->id) && $vv_permissions['delete']) { diff --git a/app/templates/Standard/index.php b/app/templates/Standard/index.php index 656932ec9..dc25d4c4e 100644 --- a/app/templates/Standard/index.php +++ b/app/templates/Standard/index.php @@ -51,9 +51,6 @@ // Read the index configuration ($indexColumns) and the associated actions for this model include(ROOT . DS . "templates" . DS . $modelsName . DS . "columns.inc"); -if(file_exists(ROOT . DS . "templates" . DS . $modelsName . DS . "actions.inc")) { - include(ROOT . DS . "templates" . DS . $modelsName . DS . "actions.inc"); -} // $linkFilter is used for models that belong to a specific parent model (eg: co_id) $linkFilter = []; @@ -116,7 +113,7 @@ function _column_key($modelsName, $c, $tz=null) { 'label' => __d('operation', 'add.a', __d('controller', $modelsName, [1])), ]; - foreach(($indexTopLinks ?? []) as $t) { + foreach(($topLinks ?? []) as $t) { if($vv_permissions[ $t['link']['action'] ]) { // We need to inject $linkFilter, but not overwrite any existing query params if(!empty($t['link']['?'])) { @@ -176,14 +173,14 @@ function _column_key($modelsName, $c, $tz=null) {
- + - + Menu->getMenuOrder('Default'); - foreach($actions as $a) { + foreach($rowActions as $a) { $ok = false; if(!empty($a['controller'])) { $tableName = Inflector::camelize($a['controller']); diff --git a/app/templates/Types/actions.inc b/app/templates/Types/actions.inc deleted file mode 100644 index cc9ceba6e..000000000 --- a/app/templates/Types/actions.inc +++ /dev/null @@ -1,43 +0,0 @@ - 'settings_backup_restore', - 'order' => 'Default', - 'label' => __d('operation', 'Types.restore'), - 'link' => [ - 'action' => 'restore' - ], - 'class' => '' - ] -]; - -// Actions appear as row-level menu items in the index view gear icon and as a tab menu or top-link menu on -// edit and view pages based on user permissions. -$actions = []; \ No newline at end of file diff --git a/app/templates/Types/columns.inc b/app/templates/Types/columns.inc index 54b8b77ac..a34b1d53e 100644 --- a/app/templates/Types/columns.inc +++ b/app/templates/Types/columns.inc @@ -41,7 +41,23 @@ $indexColumns = [ ] ]; +// $topLinks appear as an upper right menu +$topLinks = [ + [ + 'icon' => 'settings_backup_restore', + 'order' => 'Default', + 'label' => __d('operation', 'Types.restore'), + 'link' => [ + 'action' => 'restore' + ], + 'class' => '' + ] +]; + +// $rowActions appear as row-level menu items in the index view gear icon +$rowActions = []; + +// TODO: develop $bulkActions. For now, use a placeholder. $bulkActions = [ - // TODO: develop bulk actions. For now, use a placeholder. 'delete' => true ]; \ No newline at end of file