Skip to content

Commit

Permalink
Build Person "Action" menu from $topLinks and move "Add" menu onto Pe…
Browse files Browse the repository at this point in the history
…rson tab (CFM-260) (#87)

* Move person canvas Add menu to the Person tab (CFM-260)

* Remove "Person Role" from Add menu now that it is contextually connected only to the Person tab (CFM-260)

* Ensure that the Person canvas menu link are built from $topLinks in config (CFM-260)
  • Loading branch information
arlen authored Apr 5, 2023
1 parent 997a207 commit 16aec3e
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 154 deletions.
60 changes: 58 additions & 2 deletions app/templates/People/fields-nav.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*/

// XXX: if CFM-218 (Make fields.inc configuration only) is accepted, move the contents of this file into fields.inc

// Output for $topLinks from this specific configuration is presented in the Person canvas "Actions" menu.
$topLinks = [
[
'icon' => 'history',
Expand All @@ -37,8 +39,62 @@ $topLinks = [
'?' => [
'person_id' => $vv_obj->id
]
],
'class' => ''
]
]
];

// $addMenuLinks is also given slightly different treatment from the typical $topLinks found in most views:
// it is a page-global menu used for adding MVEAs to the person canvas and is given special treatment in
// element/personCanvas.php.
$addMenuLinks = [
[
'controller' => 'names',
'action' => 'add',
'icon' => 'account_box',
'iconClass' => 'material-icons-outlined'
],
[
'controller' => 'email_addresses',
'action' => 'add',
'icon' => 'email',
'iconClass' => 'material-icons-outlined'
],
[
'controller' => 'identifiers',
'action' => 'add',
'icon' => 'fingerprint'
],
[
'controller' => 'ad_hoc_attributes',
'action' => 'add',
'icon' => 'check_box',
'iconClass' => 'material-icons-outlined'
],
[
'controller' => 'addresses',
'action' => 'add',
'icon' => 'contact_mail',
'iconClass' => 'material-icons-outlined'
],
[
'controller' => 'history_records',
'action' => 'add',
'icon' => 'history'
],
[
'controller' => 'pronouns',
'action' => 'add',
'icon' => 'transgender'
],
[
'controller' => 'telephone_numbers',
'action' => 'add',
'icon' => 'phone'
],
[
'controller' => 'urls',
'action' => 'add',
'icon' => 'link'
]
];

Expand Down
53 changes: 7 additions & 46 deletions app/templates/Standard/add-edit-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
if(!empty($subnav)) {
// Include the $flashArgs for the subnavigation element
$subnav['flashArgs'] = $flashArgs;
if(!empty($topLinks) && ($modelsName == 'People' && $vv_action == 'edit')) {
// We are in Person canvas mode: pass along the top links for building the Actions menu.
$subnav['topLinks'] = $topLinks;
}
// Generate the subnavigation title and tabs
print $this->element('subnavigation', $subnav);
}
Expand All @@ -79,53 +83,10 @@
<?php /** Special case the Person "canvas" **/ ?>
<?php if($modelsName == 'People' && $vv_action == 'edit'): ?>
<?php
// Person Attributes to display.
$attributes = [
'names',
'email_addresses',
'identifiers',
'ad_hoc_attributes',
'addresses',
'telephone_numbers',
'urls',
'pronouns'
];

// Count the number of widgets that will be displayed
$widgetCount = 0;
foreach($attributes as $attr) {
if(!empty($vv_obj[$attr])) {
$widgetCount++;
}
}

$objId = null;
if(!empty($vv_obj)) {
$objId = $vv_obj->id;
}
// The person canvas has $addMenuLinks defined in templates/People/fields-nav.inc config.
print $this->element('personCanvas', ['vv_add_menu_links' => $addMenuLinks]);
?>
<div id="person-canvas" class="co-cards">
<!-- Person Attributes -->
<div id="person-canvas-attributes-js" class="row row-cols-1 g-4 <?= ($widgetCount > 1) ? 'row-cols-md-2' : ''?>">
<?php
foreach($attributes as $attr) {
if(!empty(($vv_obj[$attr]))) {
print $this->element(
'mveaJs',
[
'htmlId' => 'person-canvas-' . $attr . '-js',
'parentId' => $objId,
'mveaType' => $attr,
'entityType' => 'person'
]
);
}
}
// XXX Add the DOB as its own special card.
?>
</div>
</div>
<?php else: /** normal output **/ ?>
<?php else: /** Normal output **/ ?>
<div class="pageTitleContainer">
<div class="pageTitle">
<?php if(empty($subnav)): ?>
Expand Down
126 changes: 126 additions & 0 deletions app/templates/element/personCanvas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php
/**
* COmanage Registry Person Canvas Element
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry
* @since COmanage Registry v5.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

// Get the object ID
if (!empty($vv_obj)) {
// This will work for most top-level edit views
// XXX we might produce the $vv_primary_link for edit views so the approach below could be deprecated
$curId = $vv_obj->id;
if(!empty($vv_person_id)) {
$curId = $vv_person_id;
} elseif(!empty($vv_primary_link_id)) {
$curId = $vv_primary_link_id;
}
}

// Build the Add menu
$action_args = array();
$action_args['vv_attr_id'] = $curId;
$action_args['vv_actions_type'] = 'person-actions-add-menu';
$action_args['vv_actions_title'] = __d('operation','add');
$action_args['vv_actions_icon'] = 'add_circle';
$action_args['vv_actions_class'] = 'person-actions-add-menu';
$actionOrderDefault = $this->Menu->getMenuOrder('Default');
$personAddMenuActions = $vv_add_menu_links;
foreach(($personAddMenuActions ?? []) as $a) {
$actionOrder = !empty($a['order']) ? $a['order'] : $actionOrderDefault++;
$actionIcon = !empty($a['icon']) ? $a['icon'] : $this->Menu->getMenuIcon('Default');
$actionIconClass = !empty($a['iconClass']) ? $a['iconClass'] : '';
$actionClass = !empty($a['class']) ? $a['class'] : '';
$actionUrl = $this->Url->build(
[
'controller' => $a['controller'],
'action' => $a['action'],
'?' => [
'person_id' => $curId
]
]
);
$actionLabel = __d('controller', Cake\Utility\Inflector::camelize($a['controller']), [1]);
$action_args['vv_actions'][] = [
'order' => $actionOrder,
'icon' => $actionIcon,
'iconClass' => $actionIconClass,
'url' => $actionUrl,
'class' => $actionClass,
'label' => $actionLabel
];
}
?>
<div class="field-actions person-actions-add-menu-container">
<?= $this->element('menuAction', $action_args) ?>
</div>


<?php
// Construct the canvas using JavaScript components.
// Person Attributes to display.
$attributes = [
'names',
'email_addresses',
'identifiers',
'ad_hoc_attributes',
'addresses',
'telephone_numbers',
'urls',
'pronouns'
];

// Count the number of widgets that will be displayed
$widgetCount = 0;
foreach($attributes as $attr) {
if(!empty($vv_obj[$attr])) {
$widgetCount++;
}
}

$objId = null;
if(!empty($vv_obj)) {
$objId = $vv_obj->id;
}
?>
<div id="person-canvas" class="co-cards">
<!-- Person Attributes -->
<div id="person-canvas-attributes-js" class="row row-cols-1 g-4 <?= ($widgetCount > 1) ? 'row-cols-md-2' : ''?>">
<?php
foreach($attributes as $attr) {
if(!empty(($vv_obj[$attr]))) {
print $this->element(
'mveaJs',
[
'htmlId' => 'person-canvas-' . $attr . '-js',
'parentId' => $objId,
'mveaType' => $attr,
'entityType' => 'person'
]
);
}
}
// XXX Add the DOB as its own special card.
?>
</div>
</div>
Loading

0 comments on commit 16aec3e

Please sign in to comment.