From 13fe1296af013f79b3cbb6204ecbb2d924d7cb23 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Mon, 14 Oct 2024 15:54:06 +0300 Subject: [PATCH 1/3] Fix tab rendering for EnrollmentFlow plugins --- .../Model/Table/AttributeCollectorsTable.php | 27 +++---------- .../Model/Table/EnrollmentAttributesTable.php | 30 ++++----------- .../EnrollmentAttributes/columns.inc | 7 ++-- app/src/Lib/Traits/LayoutTrait.php | 4 ++ app/src/Lib/Traits/TabTrait.php | 13 ++++++- .../Model/Table/EnrollmentFlowStepsTable.php | 38 +++++++++++-------- app/src/Model/Table/NamesTable.php | 12 ------ app/templates/EnrollmentFlowSteps/columns.inc | 4 ++ app/templates/Standard/subnavigation.inc | 2 +- .../element/subnavigation/tabList.php | 8 ++++ 10 files changed, 67 insertions(+), 78 deletions(-) diff --git a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php index 2c1699dd..e7f74a3e 100644 --- a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php +++ b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php @@ -40,6 +40,7 @@ class AttributeCollectorsTable extends Table { use \App\Lib\Traits\AutoViewVarsTrait; use \App\Lib\Traits\CoLinkTrait; + use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PrimaryLinkTrait; use \App\Lib\Traits\TabTrait; @@ -79,33 +80,17 @@ public function initialize(array $config): void { $this->setTabsConfig( [ // Ordered list of Tabs - 'tabs' => ['EnrollmentFlows', 'EnrollmentFlowSteps', 'Petitions'], + 'tabs' => ['EnrollmentFlowSteps', 'CoreEnroller.AttributeCollectors', 'CoreEnroller.EnrollmentAttributes'], // What actions will inlcude the subnavigation header 'action' => [ // If a model renders in a subnavigation mode in edit/view mode, it cannot // render in index mode for the same use case/context // XXX edit should go first. - 'EnrollmentFlows' => ['edit', 'view'], - 'EnrollmentFlowSteps' => ['index'], - 'Petitions' => ['index'], + 'EnrollmentFlowSteps' => ['edit', 'view'], + 'CoreEnroller.AttributeCollectors' => ['edit'], + 'CoreEnroller.EnrollmentAttributes' => ['index'], ], - // What model will have a counter-badge after the tab title - 'counter' => ['EnrollmentFlowSteps', 'Petitions'], - 'nested' => [ - // Ordered list of Tabs - 'tabs' => ['EnrollmentFlowSteps', 'CoreEnroller.AttributeCollectors', 'CoreEnroller.EnrollmentAttributes'], - // What actions will include the subnavigation header - 'action' => [ - // If a model renders in a subnavigation mode in edit/view mode, it cannot - // render in index mode for the same use case/context - // XXX edit should go first. - 'EnrollmentFlowSteps' => ['edit', 'view'], - 'CoreEnroller.AttributeCollectors' => ['edit'], - 'CoreEnroller.EnrollmentAttributes' => ['index'] - ], - // What model will have a counter-badge after the tab title - 'counter' => ['CoreEnroller.EnrollmentAttributes'], - ] + 'skipTab' => ['CoreEnroller.AttributeCollectors'] ] ); diff --git a/app/plugins/CoreEnroller/src/Model/Table/EnrollmentAttributesTable.php b/app/plugins/CoreEnroller/src/Model/Table/EnrollmentAttributesTable.php index 82dbfd24..65f7bdbc 100644 --- a/app/plugins/CoreEnroller/src/Model/Table/EnrollmentAttributesTable.php +++ b/app/plugins/CoreEnroller/src/Model/Table/EnrollmentAttributesTable.php @@ -41,12 +41,12 @@ class EnrollmentAttributesTable extends Table { use \App\Lib\Traits\AutoViewVarsTrait; use \App\Lib\Traits\CoLinkTrait; + use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PrimaryLinkTrait; + use \App\Lib\Traits\TabTrait; use \App\Lib\Traits\TableMetaTrait; use \App\Lib\Traits\ValidationTrait; - use \App\Lib\Traits\TabTrait; - use \App\Lib\Traits\LayoutTrait; /** * Perform Cake Model initialization. @@ -162,33 +162,17 @@ public function initialize(array $config): void { $this->setTabsConfig( [ // Ordered list of Tabs - 'tabs' => ['EnrollmentFlows', 'EnrollmentFlowSteps', 'Petitions'], + 'tabs' => ['EnrollmentFlowSteps', 'CoreEnroller.AttributeCollectors', 'CoreEnroller.EnrollmentAttributes'], // What actions will inlcude the subnavigation header 'action' => [ // If a model renders in a subnavigation mode in edit/view mode, it cannot // render in index mode for the same use case/context // XXX edit should go first. - 'EnrollmentFlows' => ['edit', 'view'], - 'EnrollmentFlowSteps' => ['index'], - 'Petitions' => ['index'], + 'EnrollmentFlowSteps' => ['edit', 'view'], + 'CoreEnroller.AttributeCollectors' => ['edit'], + 'CoreEnroller.EnrollmentAttributes' => ['index'], ], - // What model will have a counter-badge after the tab title - 'counter' => ['EnrollmentFlowSteps', 'Petitions'], - 'nested' => [ - // Ordered list of Tabs - 'tabs' => ['EnrollmentFlowSteps', 'CoreEnroller.AttributeCollectors', 'CoreEnroller.EnrollmentAttributes'], - // What actions will include the subnavigation header - 'action' => [ - // If a model renders in a subnavigation mode in edit/view mode, it cannot - // render in index mode for the same use case/context - // XXX edit should go first. - 'EnrollmentFlowSteps' => ['edit', 'view'], - 'CoreEnroller.AttributeCollectors' => ['edit'], - 'CoreEnroller.EnrollmentAttributes' => ['index'] - ], - // What model will have a counter-badge after the tab title - 'counter' => ['CoreEnroller.EnrollmentAttributes'], - ] + 'skipTab' => ['CoreEnroller.AttributeCollectors'] ] ); diff --git a/app/plugins/CoreEnroller/templates/EnrollmentAttributes/columns.inc b/app/plugins/CoreEnroller/templates/EnrollmentAttributes/columns.inc index 9fdc0d76..9fc3b184 100644 --- a/app/plugins/CoreEnroller/templates/EnrollmentAttributes/columns.inc +++ b/app/plugins/CoreEnroller/templates/EnrollmentAttributes/columns.inc @@ -33,7 +33,7 @@ $indexColumns = [ 'label' => [ 'type' => 'link', 'sortable' => true, - 'class' => 'cm-modal-link nospin', // launch this in a modal +// 'class' => 'cm-modal-link nospin', // launch this in a modal 'dataAttrs' => [ ['data-cm-modal-title', __d('operation', 'EnrollmentAttributes', 1)] ] @@ -95,7 +95,8 @@ $action_args['vv_actions_class'] = 'mvea-add-menu'; $actionOrderDefault = $this->Menu->getMenuOrder('Default'); foreach ($attributes as $attr => $hr_name) { $actionLabel = $hr_name; - $actionClass = 'cm-modal-link nospin'; + // XXX This is already inside a modal. We just need the layout to be correct +// $actionClass = 'cm-modal-link nospin'; $actionOrder = $actionOrderDefault++; $actionIcon = $attributeToIcons[$attr] ?? $this->Menu->getMenuIcon('Default'); $dataAttrs = ['data-cm-modal-title', __d('file-connector', 'EnrollmentAttributes', 1)]; @@ -111,7 +112,7 @@ foreach ($attributes as $attr => $hr_name) { 'icon' => $actionIcon, 'iconClass' => '', 'url' => $actionUrl, - 'class' => $actionClass, + 'class' => $actionClass ?? '', 'label' => $actionLabel, 'dataAttrs' => [] ]; diff --git a/app/src/Lib/Traits/LayoutTrait.php b/app/src/Lib/Traits/LayoutTrait.php index a24143c7..f2973df8 100644 --- a/app/src/Lib/Traits/LayoutTrait.php +++ b/app/src/Lib/Traits/LayoutTrait.php @@ -38,6 +38,10 @@ trait LayoutTrait * @return string Type of redirect */ public function getLayout(string $action = ''): string { + if ($action === 'index' && $this->getTable() === 'enrollment_attributes') { + return 'iframe'; + } + return match($action) { 'add', 'view', diff --git a/app/src/Lib/Traits/TabTrait.php b/app/src/Lib/Traits/TabTrait.php index 331224cd..66f029f2 100644 --- a/app/src/Lib/Traits/TabTrait.php +++ b/app/src/Lib/Traits/TabTrait.php @@ -40,11 +40,20 @@ trait TabTrait private array $tabsConfig = []; /** - * @return array + * Get the configuration for tabs based on the specified action. + * + * @param string $action The action for which the tab configuration is requested. + * + * @return array The tab configuration for the specified action, or the entire tab configuration + * if the action is not specified or invalid. * @since COmanage Registry v5.0.0 */ - public function getTabsConfig(): array + public function getTabsConfig(string $action): array { + if(!empty($action) && !empty($this->tabsConfig[$action])) { + return $this->tabsConfig[$action]; + } + return $this->tabsConfig; } diff --git a/app/src/Model/Table/EnrollmentFlowStepsTable.php b/app/src/Model/Table/EnrollmentFlowStepsTable.php index fd3bd94f..f48c612b 100644 --- a/app/src/Model/Table/EnrollmentFlowStepsTable.php +++ b/app/src/Model/Table/EnrollmentFlowStepsTable.php @@ -45,6 +45,7 @@ class EnrollmentFlowStepsTable extends Table { use \App\Lib\Traits\PluggableModelTrait; use \App\Lib\Traits\PrimaryLinkTrait; use \App\Lib\Traits\TabTrait; + use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\TableMetaTrait; use \App\Lib\Traits\ValidationTrait; @@ -114,23 +115,25 @@ public function initialize(array $config): void { $this->setTabsConfig( [ - // Ordered list of Tabs - 'tabs' => ['EnrollmentFlows', 'EnrollmentFlowSteps', 'Petitions'], - // What actions will inlcude the subnavigation header - 'action' => [ - // If a model renders in a subnavigation mode in edit/view mode, it cannot - // render in index mode for the same use case/context - // XXX edit should go first. - 'EnrollmentFlows' => ['edit', 'view'], - 'EnrollmentFlowSteps' => ['index'], - 'Petitions' => ['index'], + 'index' => [ + // Ordered list of Tabs + 'tabs' => ['EnrollmentFlows', 'EnrollmentFlowSteps', 'Petitions'], + // What actions will inlcude the subnavigation header + 'action' => [ + // If a model renders in a subnavigation mode in edit/view mode, it cannot + // render in index mode for the same use case/context + // XXX edit should go first. + 'EnrollmentFlows' => ['edit', 'view'], + 'EnrollmentFlowSteps' => ['index'], + 'Petitions' => ['index'], + ], + // What model will have a counter-badge after the tab title + 'counter' => ['EnrollmentFlowSteps', 'Petitions'] ], - // What model will have a counter-badge after the tab title - 'counter' => ['EnrollmentFlowSteps', 'Petitions'], - 'nested' => [ + 'edit' => [ // Ordered list of Tabs 'tabs' => ['EnrollmentFlowSteps', 'EnrollmentFlowSteps.Plugin', 'EnrollmentFlowSteps.Hierarchy'], - // What actions will include the subnavigation header + // What actions will inlcude the subnavigation header 'action' => [ // If a model renders in a subnavigation mode in edit/view mode, it cannot // render in index mode for the same use case/context @@ -141,8 +144,11 @@ public function initialize(array $config): void { // EnrollmentFlowSteps -> plugin -> @plugin 'EnrollmentFlowSteps.Hierarchy' => ['index'] ], - // What model will have a counter-badge after the tab title - 'counter' => ['EnrollmentFlowSteps.Hierarchy'], + // For whatever reason, we want to skip a tab from rendering. Here we do not render + // because the configuration has no fields. + // We do not do this dynamically since it is a very rare use case and the table + // has metadata fields. This means that we should filter them out. + 'skipTab' => ['EnrollmentFlowSteps.Plugin'] ] ] ); diff --git a/app/src/Model/Table/NamesTable.php b/app/src/Model/Table/NamesTable.php index 8b960aab..df19131c 100644 --- a/app/src/Model/Table/NamesTable.php +++ b/app/src/Model/Table/NamesTable.php @@ -65,18 +65,6 @@ class NamesTable extends Table { 'preferred' ] ]; - - /** - * Provide the default layout - * - * @since COmanage Registry v5.0.0 - * @return string Type of redirect - */ - public function getLayout(string $action = ''): string { - return match($action) { - default => 'iframe' - }; - } /** * Perform Cake Model initialization. diff --git a/app/templates/EnrollmentFlowSteps/columns.inc b/app/templates/EnrollmentFlowSteps/columns.inc index 6786d79d..133c20ea 100644 --- a/app/templates/EnrollmentFlowSteps/columns.inc +++ b/app/templates/EnrollmentFlowSteps/columns.inc @@ -33,6 +33,10 @@ $indexColumns = [ 'description' => [ 'type' => 'link', 'sortable' => true, + 'class' => 'cm-modal-link nospin', // launch this in a modal + 'dataAttrs' => [ + ['data-cm-modal-title', __d('controller', 'EnrollmentFlowSteps', 1)] + ] ], 'actor_type' => [ 'type' => 'enum', diff --git a/app/templates/Standard/subnavigation.inc b/app/templates/Standard/subnavigation.inc index 13d3460e..9192aff9 100644 --- a/app/templates/Standard/subnavigation.inc +++ b/app/templates/Standard/subnavigation.inc @@ -32,7 +32,7 @@ declare(strict_types = 1); $fullModelsName = !empty($this->getPlugin()) ? $this->getPlugin() . '.' . $modelsName : $modelsName; $modelsTable = $this->Tab->getModelTableReference($fullModelsName); if(method_exists($modelsTable, 'getTabsConfig')) { - $tabsConfiguration = $modelsTable->getTabsConfig(); + $tabsConfiguration = $modelsTable->getTabsConfig($vv_action); $subnav = [ 'flashArgs' => $flashArgs ?? [], ...$tabsConfiguration diff --git a/app/templates/element/subnavigation/tabList.php b/app/templates/element/subnavigation/tabList.php index f5baabb3..03342c97 100644 --- a/app/templates/element/subnavigation/tabList.php +++ b/app/templates/element/subnavigation/tabList.php @@ -36,6 +36,14 @@ ?> + +