In my opinion this is a game changer for dashboards functionality in phpr. I hope this can be implemented natively in subsequent releases. Meaning giving us the option to pass custom parameters to the fetched child elements in dashboards.
PHPR Dashboard gives you "drill down" capabilities by using the "filter by master" option, or by simply adding a child table via selecting the "Details" radio option button when adding a new dashboard element.
However, you are limited to only filtering based on a single defined relationship structure between a given master/child relationship.
Here is how you pass additional POST parameters along to the related dash elements (those that have been connected to using "filter by master" or inserted as details:
Step 1:
In the master dash element JS OnLoad event add the following:
document.master_refresher = pageObj;//Nice hack to be able to call sendMoveAction(); to refresh the child detail records. For this we specifically want them to refresh when we copy a diagram by clicking the custom copy button we placed in edit popup of diagram
document.master_refresher_filter_by_selected_snapshotComponentID = false; //When true then we start to enforce child dash elements filtering via their BeforeSQL list events
document.master_refresher_additional_param = '0';// This is a global var that we redeclare a value in the grid element where we want to trigger the other related dash elements to refresh.
//Let's Hijack this function getDefaultPageParams which is native to RunnerAll.js in order to pass additional parameters (as post values) to each of the child dashelements that is connected to our master
document.master_refresher.dashboard.constructor.prototype.getDefaultPageParams = function( dbelem ) {
var params = {
dashboard: this,
parentId: this.id,
pageType: this.getElementPageType( dbelem.type ),
pageMode: this.getElementPageMode( dbelem.type ),
tName: dbelem.table,
openMode: Runner.pages.constants.OPENMODE_DASHCONTAINER, //
openContainer: $('#dashelement_' + dbelem.elementName + this.id)[0],
dashElement: dbelem.elementName,
dashElementSettings: jQuery.extend(true, {}, dbelem ),
baseParams: {
parId: this.id,
table: this.tName,
dashelement: dbelem.elementName,
mode: this.getElementPageRequestMode( dbelem.type ),
//The 2 lines below are the only lines I added to default code I found in RunnerAll.js
filterOnSnapshotComponentID: document.master_refresher_filter_by_selected_snapshotComponentID, //This will tell our page whether to apply additional filter parameter below
snapshotComponentID: document.master_refresher_additional_param //our additional filter parameter
}
};
if ( dbelem.type == Runner.pages.constants.DASHBOARD_LIST || dbelem.type == Runner.pages.constants.DASHBOARD_DETAILS ) {
params.multiRecordPage = true;
}
if ( dbelem.type == Runner.pages.constants.DASHBOARD_MAP ) {
params.requestUrl = Runner.pages.getUrl( dbelem.table, Runner.pages.constants.PAGE_LIST );
params.pageMode = dbelem.updateMoved ? Runner.pages.constants.MAP_DASHBOARD : Runner.pages.constants.GRIDBASED_MAP_DASHBOARD;
}
return params;
};
Step 2:
In the master dash element that you want to click on a row to have it start filtering other dash elements, add the following to JS OnLoad event
//Let's determine record id (db primary key) of row that was clicked and pass parameters!
//Bind on click event to that grid's rows
$('#dashelement_DASH_Epic_Details_Snapshot_Components_list1 > table > tbody > tr:nth-child(2) > td > div > div > div.rnr-middle > div.rnr-center > div > table').on( 'click', '[data-record-id]', function() {
for(i = 0; i < pageObj.controlsMap.gridRows.length; i++){
if(pageObj.controlsMap.gridRows[i].id == pageObj.selectedId){
console.log( i + ' here is the primary key of item that was clicked: ' + pageObj.controlsMap.gridRows[i].keys[0]);//Gives us the primary db key(s) of clicked row
//This global var gets used by our hijacked getDefaultPageParams function we defined in the DASH_Epic_Details_Epic javascript page
//We hijacked the function there because its the main master element in the dashboard, hence calling send move action here tricks that page into thinking it needs to broadcast send action
document.master_refresher_additional_param = pageObj.controlsMap.gridRows[i].keys[0];
document.master_refresher_filter_by_selected_snapshotComponentID = sessionStorage.getItem("toggle_task_status");
}
};//end for loop
document.master_refresher.sendMoveAction();
});//end on
Step 3:
Now in the child dashboard elements you want to filter add this to Before SQL Event:
//This is custom post value we added via our hijack of getDefaultPageParams function. The extra two baseParams we added there, are now visible here and hence we can filter the results :-)
//Note the posted filterOnSnapshotComponentID is used simply to let our script know whether we should use our multiple filter option.
if( postvalue('filterOnSnapshotComponentID') == 'on' AND postvalue('snapshotComponentID')){
$strWhereClause = whereAdd($strWhereClause, " LinkSnapshotComponentID = '".postvalue('snapshotComponentID')."'");
}
Step 4:
Closing notes.. I added the filterOnSnapshotComponentID baseParam as a way of turning this extra filtering option on or off entirely on the dashboard. I simply added a jquery toggle button to set the value of the "document.master_refresher_filter_by_selected_snapshotComponentID" variable in the dashboard. When its toggled on then the dashboard knows to make use of the extra filters, otherwise it simply defaults to native phpr dashboard master/child relationship filtering.
Step 5:
Done!