Skip to content

CFM-143_DRY_Refactor_topLinks_and_indexActions_make_use_of_an_element_or_MenuHelper #20

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/src/Lib/Traits/SearchFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

namespace App\Lib\Traits;

use Cake\Utility\Inflector;

trait SearchFilterTrait {
// Array (and configuration) of permitted search filters
private $searchFilters = array();
Expand All @@ -54,9 +56,9 @@ public function getLabel(string $attribute): string {
if($l != $attribute) {
return $l;
}
// If we make it here, just return $attribute
return $attribute;

// If we make it here, just return a pretty version of the $attribute name
return Inflector::humanize($attribute);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/src/View/Helper/MenuHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public function getMenuIcon($action) {
'Delete' => 'delete'
);

return $icon[$action];
// For the actions with Default order we can pass directly the name of the icon
return $icon[$action] ?? $action;
}

}
76 changes: 45 additions & 31 deletions app/templates/Standard/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,38 +91,52 @@ function _column_key($modelsName, $c, $tz=null) {
<h1><?= $vv_title; ?></h1>
</div>

<?php if($vv_permissions['add']): ?>
<ul id="topLinks">
<li>
<?= $this->Html->link('<em class="material-icons" aria-hidden="true">add_circle</em> ' .
__d('operation', 'add.a', __d('controller', $modelsName, [1])),
['action' => 'add', '?' => $linkFilter],
['escape' => false]); ?>
</li>
<?php
if(!empty($topLinks)) {
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;
}
print '<li>' .
$this->Html->link(
'<em class="material-icons" aria-hidden="true">' . $t['icon']. '</em> ' . $t['label'],
$t['link'],
['escape' => false, 'class' => $t['class']]
) . '
</li>';
}
}
<?php
// Action list for top menu dropdown / button listing
// Index view top link action item can be atomized using the user's identifier
// since there will not always be an object id available. Like the case of add action
if($vv_permissions['add']) {
$action_args = array();
$action_args['vv_attr_id'] = $vv_user['username'];

$action_args['vv_actions'][] = [
'order' => $this->Menu->getMenuOrder('Add'),
'icon' => $this->Menu->getMenuIcon('Add'),
'url' => $this->Url->build(
[
'controller' => $modelsName,
'action' => 'add',
'?' => $linkFilter
]
),
'label' => __d('operation', 'add.a', __d('controller', $modelsName, [1])),
];

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;
}
?>
</ul>
<?php endif; ?>

$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'],
];
}
}
}

if(!empty($action_args['vv_actions'])) {
print '<div class="field-actions top-links">';
print $this->element('menuAction', $action_args);
print '</div>';
}
?>
</div>
<?php if(!empty($indexBanners)): ?>
<?php foreach($indexBanners as $b): ?>
Expand Down
1 change: 1 addition & 0 deletions app/webroot/css/co-base.css
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ instead, reveal in user menu */
display: flex;
justify-content: space-between;
margin: 1em 0 0.5em;
align-items: baseline;
}
.pageTitle {
padding-bottom: 0.25em;
Expand Down