Skip to content

Commit

Permalink
New features and bug fixes
Browse files Browse the repository at this point in the history
New features and bug fixes:
- Enable search
- Paging instead of scrollY, rows per page setting in module config
- Max width for left dag/user name column to better handle long dag/user names
- Increase table width
  • Loading branch information
lsgs committed Apr 5, 2020
1 parent d31cc82 commit 4da4753
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
29 changes: 13 additions & 16 deletions DAGSwitcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ protected function getPageRoute() {
/**
* Read the current configuration of users and enabled DAGs from the
* user-dag-mapping project setting (or fall back to most recent DAG
* Switcher record in redcap_log_event where stored until v1.2.1)
* Switcher record in redcap_log_event where stored until v1.2.1 -
* removed in v1.3.0)
* @return array
* keys: Usernames
* values: Array of DAGids user may switch to
Expand All @@ -127,19 +128,6 @@ public function getUserDAGs() {

if (!is_array($userDags)) {
$userDags = array();

$sql = "select data_values ".
"from redcap_log_event ".
"where project_id = ".db_escape($this->project_id)." ".
"and description = '".db_escape($this->getModuleName())."' ".
"order by log_event_id desc limit 1 ";
$r = db_query($sql);
if ($r->num_rows > 0) {
while ($row = $r->fetch_assoc()) {
$userDags = json_decode($row['data_values'], true);
}
$updateConfig = true;
}
}

// return only valid group_id values (remove any DAGs that have been deleted)
Expand Down Expand Up @@ -207,23 +195,32 @@ protected function includeDAGPageJs() {
$getTablePath = $this->getUrl('get_user_dags_table_ajax.php');
$getTableRowsPath = $this->getUrl('get_user_dags_table_rows_ajax.php');
$setUserDagPath = $this->getUrl('set_user_dag_ajax.php');

$pageSize = $this->getProjectSetting('page-at-n-rows');
$pageSize = (!is_null($pageSize) && intval($pageSize)>0)
? intval($pageSize)
: $pageSize = -1; // All

?>
<style type="text/css">
#dag-switcher-config-container { width:698px; display:none; margin-top:20px; }
#dag-switcher-config-container { width:100%; display:none; margin-top:20px; }
#dag-switcher-spin { width:100%; text-align:center; }
#dag-switcher-table-container { width:100%; display:none; }
#dag-switcher-table tr.odd { background-color: #f1f1f1 !important; }
#dag-switcher-table tr.even { background-color: #fafafa !important; }
#dag-switcher-table td { text-align: center; }
#dag-switcher-table td.highlight { background-color: whitesmoke !important; }
.DTFC_LeftBodyLiner { overflow-x: hidden; }
.dag-switcher-table-left-col { max-width: 300px; overflow: hidden; text-align: left; }
</style>
<script type="text/javascript" src="<?php echo $jsPath;?>"></script>
<script type="text/javascript">
$(document).ready(function() {
var getTableAjaxPath = '<?php echo $getTablePath;?>';
var getTableRowsAjaxPath = '<?php echo $getTableRowsPath;?>';;
var setUserDagAjaxPath = '<?php echo $setUserDagPath;?>';;
MCRI_DAG_Switcher_Config.initPage(app_path_images, getTableAjaxPath, getTableRowsAjaxPath, setUserDagAjaxPath);
var pageSize = <?php echo $pageSize;?>;;
MCRI_DAG_Switcher_Config.initPage(app_path_images, getTableAjaxPath, getTableRowsAjaxPath, setUserDagAjaxPath, pageSize);
});
</script>
<?php
Expand Down
11 changes: 7 additions & 4 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

"permissions": [
"redcap_every_page_top",
"redcap_module_project_enable",
"read redcap_log_event",
"read redcap_user_rights",
"write redcap_user_rights"
"redcap_module_project_enable"
],

"description": "Enable project users to switch between any number of Data Access Groups (and/or \"No Assignment\").",
Expand All @@ -36,6 +33,12 @@
],

"project-settings": [
{
"key": "page-at-n-rows",
"name": "Number of rows per table page:<br>Leave blank to show all DAGs/users (default).<br>(Can aid performance when project has hundreds of DAGs and users) ",
"required": false,
"type": "text"
},
{
"key": "user-dag-mapping",
"name": "User-DAG Mapping (updated by user/DAG selections on project DAGs page)",
Expand Down
27 changes: 18 additions & 9 deletions dag_user_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var MCRI_DAG_Switcher_Config = (function(window, document, $, undefined) {
var setUserDagAjaxPath;
var table;
var rowoption;
var pageSize;

function getTable() {
$('#dag-switcher-table-container').hide().html('');
Expand All @@ -19,23 +20,34 @@ var MCRI_DAG_Switcher_Config = (function(window, document, $, undefined) {
$.get(getTableAjaxPath+'&rowoption='+rowoption).then(function(data) {
$('#dag-switcher-spin').hide();
$('#dag-switcher-table-container').html(data).show();
initDataTable(rowoption);
initDataTable(rowoption, pageSize);
});
}

function initDataTable(rowoption) {
function initDataTable(rowoption, pageSize) {
var pageOpt = [], pageOptLbl = [];
if (pageSize>0) {
pageOpt.push(pageSize);
pageOptLbl.push(pageSize);
}
pageOpt.push(-1);
pageOptLbl.push("All");
table = $('#dag-switcher-table').DataTable( {
paging: false,
deferRender: true,
stateSave: true,
searching: true,
pagingType: "full_numbers",
lengthMenu: [ pageOpt, pageOptLbl ],
scrollX: true,
scrollY: "350px",
/*scrollY: "500px",*/
scrollCollapse: true,
fixedHeader: { header: true },
fixedColumns: { leftColumns: 1 }, /*this does weird things to the row colouring and you get overlapping cell wording when sorting on other columns */
ajax: getTableRowsAjaxPath+'&rowoption='+rowoption,
columnDefs: [
{
"targets": 0,
"className": "dag-switcher-table-left-col",
"render": function ( celldata, type, row ) {
var celltext;
if (typeof celldata.is_super !== 'undefined' && celldata.is_super) {
Expand Down Expand Up @@ -98,10 +110,6 @@ var MCRI_DAG_Switcher_Config = (function(window, document, $, undefined) {
cb.show();
});
});

var searchBox = $('#dag-switcher-table_filter');
var searchBoxParentPrevDiv = searchBox.parent().prev('div');
searchBox.detach().appendTo(searchBoxParentPrevDiv).css('float', 'left');
}

function refreshTableData() {
Expand All @@ -113,11 +121,12 @@ var MCRI_DAG_Switcher_Config = (function(window, document, $, undefined) {
}

return {
initPage: function(app_path_img, getTablePath, getTableRowsPath, setUserDagPath) {
initPage: function(app_path_img, getTablePath, getTableRowsPath, setUserDagPath, setPageSize) {
app_path_images = app_path_img;
getTableAjaxPath = getTablePath;
getTableRowsAjaxPath = getTableRowsPath;
setUserDagAjaxPath = setUserDagPath;
pageSize = setPageSize;

$('#dag-switcher-config-container').delegate('input[name=rowoption]','change', function () {
getTable();
Expand Down

0 comments on commit 4da4753

Please sign in to comment.