Skip to content

Commit

Permalink
Improve Relink UI and add People Picker (CFM-125)
Browse files Browse the repository at this point in the history
  • Loading branch information
arlen committed May 23, 2025
1 parent 2299e55 commit a87f181
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/resources/locales/en_US/field.po
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@ msgstr "Redirect on Duplicate"
msgid "EnrollmentFlows.redirect_on_finalize"
msgstr "Redirect on Finalize"

msgid "ExternalIdentitySources.target_person_id"
msgstr "Target Person"

msgid "ExternalIdentitySources.hash_source_record"
msgstr "Hash Source Records"

Expand Down
4 changes: 3 additions & 1 deletion app/src/Controller/ExternalIdentitiesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

use Cake\Event\EventInterface;
use Cake\Http\Response;
use \App\Lib\Util\StringUtilities;
use Cake\ORM\TableRegistry;

// Use extend MVEAController for breadcrumb rendering. ExternalIdentities is
Expand Down Expand Up @@ -87,6 +88,7 @@ public function beforeRender(EventInterface $event) {
// Pull the Person name for breadcrumb rendering

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

if(!empty($link->value)) {
$this->set('vv_bc_parent_obj', $this->ExternalIdentities->People->get($link->value));
Expand All @@ -112,7 +114,7 @@ public function relink(string $id) {
try {
$Pipelines = TableRegistry::getTableLocator()->get('Pipelines');

$Pipelines->relink((int)$id, (int)$reqData['target_person_id']);
$Pipelines->relink((int)$id, StringUtilities::extractPeoplePickerPersonId($reqData['target_person_id']));

$this->Flash->success(__d('result', 'ExternalIdentities.relinked', [$id, $reqData['target_person_id']]));

Expand Down
16 changes: 16 additions & 0 deletions app/src/Lib/Util/StringUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,22 @@ public static function entityAndActionToTitle($entity,
return [$title, $supertitle, $subtitle];
}

/**
* Extract and return the Person ID from a People Picker string
*
* @since COmanage Registry v5.2.0
* @param string $s Person string from the People Picker widget, e.g. "Jane+Doe+(ID:+2125)"
* @return int extracted Person ID (converted to int from the extracted string)
*/

public static function extractPeoplePickerPersonId(string $s): int {
// Regular expression for handling People Picker input
$re = '/^.*\(ID: (\d+)\)$/m';
// Extract the People Picker Person ID
preg_match_all($re, $s, $matchesTarget, PREG_SET_ORDER, 0);
return (int)$matchesTarget[0][1];
}

/**
* Determine the class name from a foreign key (eg: report_id -> Reports).
*
Expand Down
10 changes: 10 additions & 0 deletions app/src/Model/Table/ExternalIdentitiesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ public function initialize(array $config): void {
'type' => 'enum',
// XXX maybe this (and EIRoles) should be SuspendableStatusEnum?
'class' => 'StatusEnum'
],
// Required for peoplePicker (for re-linking)
'cosettings' => [
'type' => 'auxiliary',
'model' => 'CoSettings'
],
// Required for peoplePicker (for re-linking)
'types' => [
'type' => 'auxiliary',
'model' => 'Types'
]
]);

Expand Down
32 changes: 28 additions & 4 deletions app/templates/ExternalIdentities/relink.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,33 @@
]);

print $this->Form->hidden('external_identity_id', ['default' => $vv_external_identity->id]);
// This label isn't localized, but it should go away when the UX is fixed
print $this->Form->control('target_person_id', ['type' => 'integer', 'label' => 'Target Person ID']);

print $this->Form->submit();
?>
<ul id="edit_ei-relink" class="fields form-list">
<?php
$this->Form->unlockField('target_person_id');
$vv_autocomplete_arguments = [
'fieldName' => 'target_person_id',
'fieldLabel' => __d('field', 'ExternalIdentitySources.target_person_id'),
'autocomplete' => [
'configuration' => [
'action' => 'GET',
'for' => 'co'
]
]
];
print $this->element('form/listItem', ['arguments' => $vv_autocomplete_arguments]);

?>
<li class="fields-submit">
<div class="field">
<div class="field-name">
</div>
<div class="field-info">
<?= $this->Form->submit() ?>
</div>
</div>
</li>
</ul>

<?php
print $this->Form->end();
2 changes: 1 addition & 1 deletion app/templates/element/form/listItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
declare(strict_types = 1);

// Make the element configuration available downstream
// XXX Unfortunately CAKEPHP doe not create a viewvar space for the element
// XXX Unfortunately CAKEPHP does not create a viewvar space for the element
// parameters. As a result we do not know which one is which unless we:
// - add a prefix and create a namespace
// - wrap them in an array.
Expand Down

0 comments on commit a87f181

Please sign in to comment.