Skip to content

Commit

Permalink
Fix sorting in user switch dropdown and user rights page
Browse files Browse the repository at this point in the history
Fix sorting of DAG names in user switch dropdown and user rights page popovers
  • Loading branch information
Luke Stevens committed Aug 12, 2019
1 parent 5be8fe0 commit 2e0eef0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
18 changes: 9 additions & 9 deletions DAGSwitcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ public function getUserDAGsTable($rowsAreDags=true) {
$col0Hdr = $this->lang['global_22']; // Data Access Groups
$colGroupHdr = $this->lang['control_center_132']; // Users
$colSet = REDCap::getUsers();
uasort($colSet, $this->value_compare_func); // sort in ascending order by value, case-insensitive, preserving keys
uasort($colSet, array($this,'value_compare_func')); // sort in ascending order by value, case-insensitive, preserving keys
$this->setUserSetting('rowoption', 'dags');
$superusers = $this->readSuperUserNames();
} else { // $rowsAreDags===false // columns are dags
// column-per-dag, row-per-user (load via ajax)
$col0Hdr = $this->lang['control_center_132']; // Users
$colGroupHdr = $this->lang['global_22']; // Data Access Groups
$colSet = REDCap::getGroupNames(false);
uasort($colSet, $this->value_compare_func); // sort in ascending order by value, case-insensitive, preserving keys
uasort($colSet, array($this,'value_compare_func')); // sort in ascending order by value, case-insensitive, preserving keys
$colSet = array(0=>$this->lang['data_access_groups_ajax_23']) + (array)$colSet; // [No Assignment]
$this->setUserSetting('rowoption', 'users');
}
Expand Down Expand Up @@ -306,10 +306,10 @@ public function getUserDAGsTableRowData($rowsAreDags=true) {
$usersEnabledDags = $this->getUserDAGs();

$users = REDCap::getUsers();
uasort($users, $this->value_compare_func); // sort in ascending order by value, case-insensitive, preserving keys
uasort($users, array($this,'value_compare_func')); // sort in ascending order by value, case-insensitive, preserving keys

$dags = REDCap::getGroupNames(false);
uasort($dags, $this->value_compare_func); // sort in ascending order by value, case-insensitive, preserving keys
uasort($dags, array($this,'value_compare_func')); // sort in ascending order by value, case-insensitive, preserving keys
$dags = array(0=>$this->lang['data_access_groups_ajax_23']) + (array)$dags; // [No Assignment]

$rows = array();
Expand Down Expand Up @@ -438,14 +438,14 @@ protected function renderUserDAGInfo() {
}
}

uasort($thisUserOtherDags, $this->value_compare_func); // sort dag names alphabetically in dialog, preserving keys
uasort($thisUserOtherDags, array($this,'value_compare_func')); // sort dag names alphabetically in dialog, preserving keys

$changeButton = RCView::button(array('id'=>'dag-switcher-change-button', 'class'=>'btn btn-sm btn-primary'), $dagSwitchDialogBtnText);
$changeButton = RCView::button(array('id'=>'dag-switcher-change-button', 'class'=>'btn btn-sm btn-primaryrc'), '<i class="fas fa-random mr-1"></i>'.$dagSwitchDialogBtnText);

$dagSelect = RCView::select(array('id'=>'dag-switcher-change-select', 'class'=>'form-control'), $thisUserOtherDags);

$apiMsg = '';
if ($this->user_rights['api_export'] || $this->user_rights['api_export']) {
if ($this->user_rights['api_export'] || $this->user_rights['api_import']) {
$apiMsg = RCView::div(
array('class'=>'blue', 'style'=>'margin:5px 0;'),
RCView::img(array('src'=>'computer.png')).
Expand All @@ -456,7 +456,7 @@ protected function renderUserDAGInfo() {
).
RCView::div(
array('id'=>'dag-switch-api-info', 'style'=>'display:none;margin-top:10px;'),
'<strong>POST</strong> "token" and "dag" (id or unique name) to your API endpoint.<br>You must including the query string shown in this example:<br><span style="font-family:monospace;font-size:80%;">curl -d "token=ABCDEF0123456789ABCDEF0123456789&dag=site_a" <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"'.APP_PATH_WEBROOT_FULL.'/api/?NOAUTH&type=module&prefix=dag_switcher&page=user_dag_switch_api"</span>'
'<strong>POST</strong> "token" and "dag" (id or unique name) to your API endpoint.<br>You must include the query string shown in this example:<br><span style="font-family:monospace;font-size:80%;">curl -d "token=ABCDEF0123456789ABCDEF0123456789&dag=site_a" <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"'.APP_PATH_WEBROOT_FULL.'/api/?NOAUTH&type=module&prefix=dag_switcher&page=user_dag_switch_api"</span>'
)
);
}
Expand Down Expand Up @@ -639,7 +639,7 @@ public function redcap_module_project_enable($version, $project_id) {
* @param string $b
* @return string
*/
private function value_compare_func(string $a, string $b) {
private static function value_compare_func(string $a, string $b) {
return strcmp(strtolower($a), strtolower($b));
}
}
11 changes: 8 additions & 3 deletions user_rights.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@ var MCRI_DAG_Switcher_User_Rights = (function(window, document, $, JSON, undefin
};

function appendDagInfo(appendAfter, user, dagIdList) {
var content = '<div style=\'font-size:75%;padding:5px;\'>User <span class=\'text-primary\'>'+user+'</span> may switch to DAGs:<ul style=\'padding-left:10px;\'>';
var dagNames = [];
dagIdList.forEach(function(dagId) {
content += '<li><span class=\'text-info\'>'+allDagNames[dagId]+'</span></li>';
dagNames.push(allDagNames[dagId]);
});
dagNames.sort()
var content = '<div style=\'font-size:75%;padding:5px;\'>User <span class=\'text-primary\'>'+user+'</span> may switch to DAGs:<ul style=\'padding-left:10px;\'>';
dagNames.forEach(function(el) {
content += '<li><span class=\'text-info\'>'+el+'</span></li>';
});
content += '</ul>';
appendAfter.after(' <a href="#" data-toggle="popover" data-content="'+content+'" style="font-size:75%;color:gray;">(+'+dagIdList.length+')</a>');
};

var activatePopovers = function() {
$('[data-toggle="popover"]').popover({
title: 'DAG Switcher',
title: '<i class="fas fa-cube mr-1"></i>DAG Switcher',
html: true,
trigger: 'hover',
container: 'body',
Expand Down

0 comments on commit 2e0eef0

Please sign in to comment.