Skip to content

Commit

Permalink
Allow deletion of group nestings; present nesting form in modal; add …
Browse files Browse the repository at this point in the history
…link to Person in Group Member form. (CFM-41) (COmanage#239)
  • Loading branch information
arlen authored Oct 18, 2024
1 parent 8bda023 commit 2f6d88d
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 63 deletions.
6 changes: 6 additions & 0 deletions app/resources/locales/en_US/field.po
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ msgstr "Direct"
msgid "GroupNestings.group_id"
msgstr "Nested Group"

msgid "GroupNestings.group_id.desc"
msgstr "The current group. It will be nested into the Target Group."

msgid "GroupNestings.negate"
msgstr "Negate Nesting"

Expand All @@ -429,6 +432,9 @@ msgstr "If true, members of the Nested Group will not be eligible to be a member
msgid "GroupNestings.target_group_id"
msgstr "Target Group"

msgid "GroupNestings.target_group_id.desc"
msgstr "Where the current group will be nested"

msgid "Groups.desc.admins"
msgstr "{0} Administrators"

Expand Down
3 changes: 3 additions & 0 deletions app/resources/locales/en_US/result.po
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ msgstr "Added {0} as an owner of group {1}"
msgid "GroupOwners.deleted"
msgstr "Removed {0} as an owner of group {1}"

msgid "GroupNesting.deleted"
msgstr "Removed nesting from group"

msgid "IdentifierAssignments.assigned.already"
msgstr "Identifiers Already Assigned ({0})"

Expand Down
45 changes: 31 additions & 14 deletions app/src/Controller/GroupNestingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,38 @@ class GroupNestingsController extends StandardController {
*/

public function beforeRender(\Cake\Event\EventInterface $event) {
// Pull the Group name for breadcrumb rendering

$link = $this->getPrimaryLink(true);

if(!empty($link->value)) {
$this->set('vv_bc_parent_obj', $this->GroupNestings->Groups->get($link->value));
$this->set('vv_bc_parent_displayfield', $this->GroupNestings->Groups->getDisplayField());
if($this->request->getParam('action') != 'deleted') {
// Pull the Group name for breadcrumb rendering
$link = $this->getPrimaryLink(true);

if(!empty($link->value)) {
$this->set('vv_bc_parent_obj', $this->GroupNestings->Groups->get($link->value));
$this->set('vv_bc_parent_displayfield', $this->GroupNestings->Groups->getDisplayField());
}

// We need to calculate the available set of groups for nesting. We do this
// here rather than via autoViewVars because we need to know the current
// group (to exclude it).

$this->set('targetGroups', $this->GroupNestings->availableGroups((int)$link->value));

return parent::beforeRender($event);
}
}

/**
* Handle the deleted action for a Group Nesting.
* This is used to set a flash message and override the target window.
*
* @since COmanage Registry v5.0.0
*/

public function deleted() {
// Add a flash message
$this->Flash->information(__d('result','GroupNesting.deleted'));
// Set the target window
$this->set('vv_target_window', 'top');

// We need to calculate the available set of groups for nesting. We do this
// here rather than via autoViewVars because we need to know the current
// group (to exclude it).

$this->set('targetGroups', $this->GroupNestings->availableGroups((int)$link->value));

return parent::beforeRender($event);
return parent::deleted();
}
}
18 changes: 17 additions & 1 deletion app/src/Model/Table/GroupNestingsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ class GroupNestingsTable extends Table {
use \App\Lib\Traits\TableMetaTrait;
use \App\Lib\Traits\ValidationTrait;

/**
* Provide the default layout
*
* @since COmanage Registry v5.0.0
* @return string Type of redirect
*/
public function getLayout(string $action = ''): string {
return match($action) {
'add','edit','view','deleted' => 'iframe',
default => 'default'
};
}

/**
* Perform Cake Model initialization.
*
Expand Down Expand Up @@ -76,6 +89,8 @@ public function initialize(array $config): void {

$this->setPrimaryLink('group_id');
$this->setRequiresCO(true);
$this->setRedirectGoal('self');
$this->setRedirectGoal(action: 'delete', goal: 'deleted');

$this->setEditContains(['Groups', 'GroupMembers', 'TargetGroups']);

Expand All @@ -92,7 +107,8 @@ public function initialize(array $config): void {
// Actions that operate over a table (ie: do not require an $id)
'table' => [
'add' => ['platformAdmin', 'coAdmin'],
'index' => ['platformAdmin', 'coAdmin']
'index' => ['platformAdmin', 'coAdmin'],
'deleted' => ['platformAdmin', 'coAdmin']
]
]);

Expand Down
17 changes: 16 additions & 1 deletion app/templates/GroupMembers/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if($vv_action == 'add') {
'person_id' => $vv_selected_person['id']
];

// Present the person information in the view
// Present the person name in the view
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => '',
Expand Down Expand Up @@ -64,6 +64,21 @@ if($vv_action == 'add') {
$hidden = [
'person_id' => $vv_obj->person_id
];

// Set the selected person for edit and view also
// so we can display the name and link to the person canvas.
$selectedPerson = [
'id' => $vv_obj->person_id,
'name' => $vv_obj->person->primary_name->full_name
];
$this->set('vv_selected_person', $selectedPerson);
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => '',
'fieldLabel' => __d('field','name'),
'groupmember' => $selectedPerson
]
]);
}

print $this->element('form/listItem', [
Expand Down
40 changes: 35 additions & 5 deletions app/templates/GroupNestings/columns.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,44 @@
*/

$indexColumns = [
'name' => [
'label' => __d('field', 'GroupNestings.target_group_id'),
'type' => 'relatedLink',
'model' => 'target_group',
'field' => 'name'
'id' => [
'type' => 'link',
'class' => 'cm-modal-link nospin', // launch this in a modal
'dataAttrs' => [
['data-cm-modal-title', __d('controller', 'GroupNestings', 1)]
]
],
'group' => [
'label' => __d('field', 'GroupNestings.target_group_id'),
'type' => 'relatedLink',
'model' => 'target_group',
'field' => 'name',
'class' => 'cm-modal-link nospin', // launch this in a modal
'dataAttrs' => [
['data-cm-modal-title', __d('controller', 'GroupNestings', 1)]
]
]
];

// $topLinks appear as an upper right menu
$topLinks = [
[
'icon' => $this->Menu->getMenuIcon('Add'),
'order' => $this->Menu->getMenuOrder('Add'),
'label' => __d('operation', 'add.a',[__d('controller', 'GroupNestings', 1)]),
'link' => [
'action' => 'add'
],
'class' => 'cm-modal-link nospin', // launch this in a modal
'dataAttrs' => [
['data-cm-modal-title', __d('controller', 'GroupNestings', 1)]
]
]
];

// Suppress the normal add link in lieu of the one above
$suppressAddLink = true;

/*
// When the $bulkActions variable exists in a columns.inc config, the "Bulk edit" switch will appear in the index.
$bulkActions = [
Expand Down
34 changes: 0 additions & 34 deletions app/templates/GroupNestings/fields-nav.inc

This file was deleted.

12 changes: 8 additions & 4 deletions app/templates/GroupNestings/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ if($vv_action == 'add') {
'url' => [
'controller' => 'groups',
'action' => 'edit',
$vv_obj->target_group_id]
$vv_obj->target_group_id
],
'target' => '_top'
];
// The target group can't be changed after adding
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => 'target_group_id',
'status' => $vv_obj->target_group->name,
'link' => $link,
'link' => $link
]
]);
}
Expand All @@ -53,14 +55,16 @@ if($vv_action == 'add' || $vv_action == 'edit') {
'url' => [
'controller' => 'groups',
'action' => 'edit',
$vv_bc_parent_obj->id]
$vv_bc_parent_obj->id,
],
'target' => '_top'
];
// The target group can't be changed after adding
print $this->element('form/listItem', [
'arguments' => [
'fieldName' => 'group_id',
'status' => $vv_bc_parent_obj->name,
'link' => $link,
'link' => $link
]
]);

Expand Down
14 changes: 11 additions & 3 deletions app/templates/element/form/infoDiv/groupMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,18 @@

<?php if(isset($vv_selected_person)): ?>
<div class="field-info">
<span class="group-member-to-add-name">
<?= $vv_selected_person['name'] ?>
<span class="group-member-name">
<?= $this->Html->link(
$vv_selected_person['name'],
['plugin' => null,
'controller' => 'people',
'action' => 'edit',
$vv_selected_person['id']
],
['target' => '_top']
);?>
</span>
<span class="group-member-to-add-id">
<span class="group-member-id">
(<?= __d('information', 'entity.id', [$vv_selected_person['id']]) ?>)
</span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/webroot/css/co-base.css
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ li[data-pc-section="emptymessage"] {
padding: 1em;
gap: 4px;
}
.group-member-to-add-name {
.group-member-name {
margin-right: 0.5em;
font-size: 1.4em;
}
Expand Down

0 comments on commit 2f6d88d

Please sign in to comment.