Skip to content

Commit

Permalink
Add recent charts and reports portlet
Browse files Browse the repository at this point in the history
  • Loading branch information
mkzia committed Jun 20, 2019
1 parent 464a778 commit 5a5c4f1
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 7 deletions.
44 changes: 44 additions & 0 deletions classes/Rest/Controllers/SummaryControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public function setupRoutes(Application $app, ControllerCollection $controller)

$controller->post("$root/layout", "$class::setLayout");
$controller->delete("$root/layout", "$class::resetLayout");

$controller->get("$root/recentchartsreports", "$class::getRecentChartsReports");
}

/*
Expand Down Expand Up @@ -191,4 +193,46 @@ public function resetLayout(Request $request, Application $app)
'total' => 1
));
}

/**
* Get recent charts and reports.
**/
public function getRecentChartsReports(Request $request, Application $app)
{
$user = $this->authorize($request);
if (isset($user)) {
// fetch charts
$queries = new \UserStorage($user, 'queries_store');
$data = $queries->get();
foreach ($data as &$query) {
$query['name'] = htmlspecialchars($query['name'], ENT_COMPAT, 'UTF-8', false);
$query['type'] = 'Chart';
}
// fetch reports
$rm = new \XDReportManager($user);
$reports = $rm->fetchReportTable();
foreach ($reports as &$report) {
$tmp = array();
$tmp['type'] = 'Report';
$tmp['name'] = $report['report_name'];
$tmp['chart_count'] = $report['chart_count'];
$tmp['charts_per_page'] = $report['charts_per_page'];
$tmp['creation_method'] = $report['creation_method'];
$tmp['report_delivery'] = $report['report_delivery'];
$tmp['report_format'] = $report['report_format'];
$tmp['report_id'] = $report['report_id'];
$tmp['report_name'] = $report['report_name'];
$tmp['report_schedule'] = $report['report_schedule'];
$tmp['report_title'] = $report['report_title'];
$tmp['ts'] = $report['last_modified'];
$tmp['config'] = $report['report_id'];
$data[] = $tmp;
}
return $app->json(array(
'success' => true,
'total' => count($data),
'data' => $data
));
}
}
}
9 changes: 6 additions & 3 deletions classes/XDReportManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ public function fetchReportTable()
r.format,
r.schedule,
r.delivery,
COUNT(rc.chart_id) AS chart_count
COUNT(rc.chart_id) AS chart_count,
UNIX_TIMESTAMP(r.last_modified) as last_modified
FROM Reports r
LEFT JOIN ReportCharts rc ON rc.report_id = r.report_id
WHERE r.user_id = :user_id
Expand All @@ -487,7 +488,8 @@ public function fetchReportTable()
r.charts_per_page,
r.format,
r.schedule,
r.delivery
r.delivery,
r.last_modified
";

$Entries = array();
Expand All @@ -507,7 +509,8 @@ public function fetchReportTable()
'report_format' => $entry['format'],
'report_schedule' => $entry['schedule'],
'report_delivery' => $entry['delivery'],
'chart_count' => $entry['chart_count']
'chart_count' => $entry['chart_count'],
'last_modified' => $entry['last_modified']
);
}

Expand Down
3 changes: 2 additions & 1 deletion configuration/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"xdmod": {
"portal": {
"js": [
"gui/js/modules/summary/ChartPortlet.js"
"gui/js/modules/summary/ChartPortlet.js",
"gui/js/modules/summary/RecentChartsReportsPortlet.js"
]
}
}
Expand Down
18 changes: 18 additions & 0 deletions configuration/etl/etl.d/xdmod-migration-8_1_2-8_5_0.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@
"schema": "modw_aggregates"
}
}
},
{
"name": "update-moddb-tables",
"description": "Update moddb tables",
"namespace": "ETL\\Maintenance",
"class": "ManageTables",
"options_class": "MaintenanceOptions",
"definition_file_list": [
"xdb/reports.json"
],
"endpoints": {
"destination": {
"type": "mysql",
"name": "Database",
"config": "database",
"schema": "moddb"
}
}
}
]
}
7 changes: 7 additions & 0 deletions configuration/etl/etl_tables.d/xdb/reports.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@
"name": "active_role",
"type": "varchar(30)",
"nullable": true
},
{
"name": "last_modified",
"type": "timestamp",
"nullable": false,
"default": "CURRENT_TIMESTAMP",
"extra": "ON UPDATE CURRENT_TIMESTAMP"
}
],
"indexes": [],
Expand Down
6 changes: 6 additions & 0 deletions html/gui/js/modules/ReportGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ XDMoD.Module.ReportGenerator = Ext.extend(XDMoD.PortalModule, {
listeners: {
beforerender: function(panel) {
panel.initialize(panel);
},
load_report: function (reportId) {
var tabPanel = Ext.getCmp('main_tab_panel');
tabPanel.setActiveTab('report_generator');
var reportGrid = this.find('itemId', 'reportQueueGrid');
reportGrid[0].fireEvent('load_report', reportId);
}
},

Expand Down
136 changes: 136 additions & 0 deletions html/gui/js/modules/summary/RecentChartsReportsPortlet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
Ext.namespace('XDMoD.Modules.SummaryPortlets');

XDMoD.Modules.SummaryPortlets.RecentChartsReportsPortlet = Ext.extend(Ext.ux.Portlet, {

layout: 'fit',
autoScroll: true,
title: 'Recent Charts and Reports',
width: 1000,

initComponent: function () {
var aspectRatio = 11 / 17;

this.chartReportStore = new Ext.data.JsonStore({
// store configs
autoDestroy: true,
url: XDMoD.REST.url + '/summary/recentchartsreports',
// reader configs
root: 'data',
idProperty: 'name',
autoLoad: true,
fields: [
'name',
'report_id',
'url',
'config',
'type',
{ name: 'recordid', type: 'int' },
{
name: 'ts',
convert: function (v, rec) {
return Ext.util.Format.date(new Date(rec.ts * 1000).toString(), 'Y-m-d h:i:s');
}
}
],
sortInfo: {
field: 'ts',
direction: 'DESC'
}

});

var searchField = new Ext.form.TwinTriggerField({
xtype: 'twintriggerfield',
validationEvent: false,
validateOnBlur: false,
trigger1Class: 'x-form-clear-trigger',
trigger2Class: 'x-form-search-trigger',
hideTrigger1: true,
enableKeyEvents: true,
emptyText: 'Search',
store: this.chartReportStore,
onTrigger1Click: function () {
this.store.clearFilter();
this.el.dom.value = '';
this.triggers[0].hide();
},
onTrigger2Click: function () {
var v = this.getRawValue();
if (v.length < 1) {
this.onTrigger1Click();
return;
}
this.store.filter('name', v, true, false);
this.triggers[0].show();
},
listeners: {
scope: this,
specialkey: function (field, e) {
// e.HOME, e.END, e.PAGE_UP, e.PAGE_DOWN,
// e.TAB, e.ESC, arrow keys: e.LEFT, e.RIGHT, e.UP, e.DOWN
if (e.getKey() === e.ENTER) {
searchField.onTrigger2Click();
}
}
}
});

this.chartReportGrid = new Ext.grid.GridPanel({
store: this.chartReportStore,
border: false,
monitorResize: true,
autoScroll: true,
viewConfig: {
forceFit: true
},
colModel: new Ext.grid.ColumnModel({
columns: [
{ header: 'Name', dataIndex: 'name', width: 250 },
{ header: 'Type', dataIndex: 'type' },
{ header: 'Last Modified', dataIndex: 'ts' }
],
defaults: {
sortable: true,
menuDisabled: true
}
}),
tbar: {
items: [
searchField,
{
iconCls: 'refresh',
text: 'Refresh',
scope: this,
handler: function () {
this.chartReportStore.reload();
}
}
]
},
selModel: new Ext.grid.RowSelectionModel({
singleSelect: true,
listeners: {
rowselect: function (selModel, index, r) {
selModel.clearSelections();
if (r.data.type === 'Chart') {
var config = Ext.util.JSON.decode(r.data.config);
XDMoD.Module.MetricExplorer.setConfig(config, r.data.name, false);
} else if (r.data.type === 'Report') {
CCR.xdmod.ui.reportGenerator.fireEvent('load_report', r.data.report_id);
}
}
}
})
});

this.height = this.width * aspectRatio;
this.items = [this.chartReportGrid];
XDMoD.Modules.SummaryPortlets.RecentChartsReportsPortlet.superclass.initComponent.apply(this, arguments);
}
});

/**
* The Ext.reg call is used to register an xtype for this class so it
* can be dynamically instantiated
*/
Ext.reg('RecentChartsReportsPortlet', XDMoD.Modules.SummaryPortlets.RecentChartsReportsPortlet);
27 changes: 24 additions & 3 deletions html/gui/js/report_builder/ReportsOverview.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,13 @@ XDMoD.ReportsOverview = Ext.extend(Ext.Panel, {

// ----------------------------------------------------

var editReport;

var queueGrid = new Ext.grid.GridPanel({

store: this.reportStore,
//id: 'reportPool_queueGrid' + Ext.id(),
itemId: 'reportQueueGrid',

viewConfig: {
emptyText: reportsEmptyText,
Expand All @@ -253,7 +256,26 @@ XDMoD.ReportsOverview = Ext.extend(Ext.Panel, {
{header: 'Schedule', width: 70, dataIndex: 'report_schedule', sortable: true},
{header: 'Delivery Format', width: 70, dataIndex: 'report_format', sortable: true, renderer: reportFormatColumnRenderer},
{header: '# Charts', width: 70, dataIndex: 'chart_count', sortable: true, renderer: numChartsColumnRenderer}
]
],
listeners: {
load_report: function (reportId) {
this.store.load({
callback: function (records, operation, success) {
var index = queueGrid.store.find('report_id', reportId);
queueGrid.getSelectionModel().selectRow(index);
if ((self.parent.reportCreator.report_id !== reportId) && (self.parent.reportCreator.isDirty() === true)) {
Ext.Msg.show({
title: 'Cannot open another report!',
msg: 'You cannot open another report because this report has unsaved changes.',
buttons: Ext.Msg.OK
});
} else {
editReport();
}
}
});
}
}

});//queueGrid

Expand Down Expand Up @@ -373,8 +395,7 @@ XDMoD.ReportsOverview = Ext.extend(Ext.Panel, {

// ----------------------------------------------------

var editReport = function(){

editReport = function () {
var record = queueGrid.getSelectionModel().getSelected();

XDMoD.TrackEvent('Report Generator (My Reports)', 'Attempting to edit report', record.data.report_name);
Expand Down

0 comments on commit 5a5c4f1

Please sign in to comment.