Skip to content

Fix tab rendering for EnrollmentFlow plugins #235

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -61,13 +61,28 @@ public function beforeRender(\Cake\Event\EventInterface $event) {

$ret = parent::beforeRender($event);

$attributes = $this->viewBuilder()->getVar('attributes');

// Override the auto-generated title
switch($this->request->getParam('action')) {
case 'add':
$this->set('vv_title', __d('operation', 'add.a', [__d('core_enroller', 'controller.EnrollmentAttributes', [1])]));
$this->set(
'vv_title',
__d('operation', 'add.a-1', [
__d('core_enroller', 'controller.EnrollmentAttributes', [1]),
$attributes[$this->request->getQuery('attribute_type')]
])
);
break;
case 'edit':
$this->set('vv_title', __d('operation', 'edit.a', [__d('core_enroller', 'controller.EnrollmentAttributes', [1])]));
$vv_obj = $this->viewBuilder()->getVar('vv_obj');
$this->set(
'vv_title',
__d('operation', 'edit.a-1', [
__d('core_enroller', 'controller.EnrollmentAttributes', [1]),
$attributes[ $vv_obj['attribute'] ]
])
);
break;
case 'index':
$this->set('vv_title', __d('core_enroller', 'controller.EnrollmentAttributes', [99]));
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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']
]
);

Expand Down
Expand Up @@ -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.
Expand Down Expand Up @@ -158,37 +158,27 @@ public function initialize(array $config): void {
]
]);

$this->setLayout([ 'index' => 'iframe',
'add' => 'iframe',
'edit' => 'iframe',
'view' => 'iframe',
]);

// All the tabs share the same configuration in the ModelTable file
$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']
]
);

Expand Down
Expand Up @@ -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)]
]
Expand Down Expand Up @@ -94,8 +94,13 @@ $action_args['vv_actions_icon'] = 'add_circle';
$action_args['vv_actions_class'] = 'mvea-add-menu';
$actionOrderDefault = $this->Menu->getMenuOrder('Default');
foreach ($attributes as $attr => $hr_name) {
$title = __d('operation', 'add.a-1', [
__d('core_enroller', 'controller.EnrollmentAttributes', [1]),
$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)];
Expand All @@ -111,7 +116,7 @@ foreach ($attributes as $attr => $hr_name) {
'icon' => $actionIcon,
'iconClass' => '',
'url' => $actionUrl,
'class' => $actionClass,
'class' => $actionClass ?? '',
'label' => $actionLabel,
'dataAttrs' => []
];
Expand Down
6 changes: 6 additions & 0 deletions app/resources/locales/en_US/operation.po
Expand Up @@ -36,6 +36,9 @@ msgstr "Add"
msgid "add.a"
msgstr "Add a New {0}"

msgid "add.a-1"
msgstr "Add a New {0} `{1}`"

msgid "add.attribute"
msgstr "Add attribute"

Expand Down Expand Up @@ -135,6 +138,9 @@ msgstr "Edit"
msgid "edit.a"
msgstr "Edit {0}"

msgid "edit.a-1"
msgstr "Edit {0} `{1}`"

msgid "edit.PersonRoles.a"
msgstr "Edit Role {0}"

Expand Down
28 changes: 27 additions & 1 deletion app/src/Lib/Traits/LayoutTrait.php
Expand Up @@ -31,18 +31,44 @@

trait LayoutTrait
{
/**
* Layout configuration
*
* @var array
* @since COmanage Registry v5.0.0
*/
private array $layout = [];

/**
* Provide the default layout
*
* @since COmanage Registry v5.0.0
* @return string Type of redirect
*/
public function getLayout(string $action = ''): string {
public function getLayout(string $action = ''): string
{
if(!empty($this->layout)) {
return $this->layout[$action];
}

return match($action) {
'add',
'view',
'edit' => 'iframe',
default => 'default'
};
}

/**
* Set the layout variable
*
* @param array $layout
*
* @return void
* @since COmanage Registry v5.0.0
*/
public function setLayout(array $layout): void
{
$this->layout = $layout;
}
}
13 changes: 11 additions & 2 deletions app/src/Lib/Traits/TabTrait.php
Expand Up @@ -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;
}

Expand Down
38 changes: 22 additions & 16 deletions app/src/Model/Table/EnrollmentFlowStepsTable.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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']
]
]
);
Expand Down
12 changes: 0 additions & 12 deletions app/src/Model/Table/NamesTable.php
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions app/templates/EnrollmentFlowSteps/columns.inc
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion app/templates/Standard/subnavigation.inc
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions app/templates/element/subnavigation/tabList.php
Expand Up @@ -36,6 +36,14 @@
?>

<?php foreach($vv_subnavigation_tabs as $tab): ?>
<?php
if (isset($vv_sub_nav_attributes['skipTab'])
&& \in_array($tab, $vv_sub_nav_attributes['skipTab'], true)
) {
continue;
}
?>
<!-- if a tab has no fields do not render skip -->
<li class="nav-item">
<?php
$curId = $this->Tab->getCurrentId($tab, $isNested);
Expand Down