Refactored the dashboard code, which was allowing each node type to

define its own dashboardURL.

There was a typo, while calling the dashboard function of a Node type.
This commit is contained in:
Ashesh Vashi 2018-07-25 12:10:46 +05:30
parent f7e43d5e50
commit e12e00703f
4 changed files with 67 additions and 31 deletions

View File

@ -1,11 +1,12 @@
define('pgadmin.dashboard', [
'sources/url_for', 'sources/gettext', 'require', 'jquery', 'underscore',
'sources/pgadmin', 'backbone', 'backgrid', 'flotr2',
'pgadmin.alertifyjs', 'pgadmin.backform', 'backgrid.filter',
'pgadmin.alertifyjs', 'pgadmin.backform',
'sources/nodes/dashboard', 'backgrid.filter',
'pgadmin.browser', 'bootstrap', 'wcdocker',
], function(
url_for, gettext, r, $, _, pgAdmin, Backbone, Backgrid, Flotr,
Alertify, Backform
Alertify, Backform, NodesDashboard
) {
pgAdmin.Browser = pgAdmin.Browser || {};
@ -250,38 +251,29 @@ define('pgadmin.dashboard', [
let self = this;
/* Clear all the interval functions of previous dashboards */
self.clearIntervalId();
if (itemData && itemData._type && dashboardVisible) {
var treeHierarchy = node.getTreeNodeHierarchy(item),
url = url_for('dashboard.index'),
b = pgAdmin.Browser,
m = b && b.Nodes[itemData._type];
url = NodesDashboard.url(itemData, item, treeHierarchy);
self.sid = self.did = -1;
self.version = itemData.version;
cancel_query_url = url_for('dashboard.index') + 'cancel_query/';
terminate_session_url = url_for('dashboard.index') + 'terminate_session/';
if (url === null) {
url = url_for('dashboard.index');
// Check if user is super user
var server = treeHierarchy['server'];
maintenance_database = (server && server.db) || null;
cancel_query_url = url + 'cancel_query/';
terminate_session_url = url + 'terminate_session/';
if (server && server.user && server.user.is_superuser) {
is_super_user = true;
} else {
is_super_user = false;
// Set current user
current_user = (server && server.user) ? server.user.name : null;
}
// Check if user is super user
var server = treeHierarchy['server'];
maintenance_database = (server && server.db) || null;
if (m && m.dashboard) {
if (_.isFunction(m.dashboard)) {
url = m.dashboard.apply(
item, itemData, node, treeHierarchy
);
if (server && server.user && server.user.is_superuser) {
is_super_user = true;
} else {
url = m.dashboard;
is_super_user = false;
// Set current user
current_user = (server && server.user) ? server.user.name : null;
}
} else {
if ('database' in treeHierarchy) {
self.sid = treeHierarchy.server._id;
self.did = treeHierarchy.database._id;
@ -310,8 +302,10 @@ define('pgadmin.dashboard', [
if (div) {
if (itemData.connected || _.isUndefined(itemData.connected)) {
// Avoid unnecessary reloads
if (url != $(dashboardPanel).data('dashboard_url') ||
(url == $(dashboardPanel).data('dashboard_url') && $(dashboardPanel).data('server_status') == false)) {
if (url !== $(dashboardPanel).data('dashboard_url') || (
url === $(dashboardPanel).data('dashboard_url') &&
$(dashboardPanel).data('server_status') == false)) {
// Clear out everything so any existing timers die off
$(div).empty();
$.ajax({

View File

@ -0,0 +1,30 @@
import {isString, isFunction} from 'sources/utils';
import pgBrowser from 'pgadmin.browser';
export function url(itemData, item, treeHierarchy) {
let treeNode = pgBrowser.treeMenu.findNodeByDomElement(item);
let url = null;
let getDashboardURL = (node) => {
let nodeData = node.getData();
let browserNode = pgBrowser.Nodes[nodeData._type];
let dashboardURL = browserNode && browserNode.dashboard;
if (isFunction(dashboardURL)) {
dashboardURL = dashboardURL.apply(
browserNode, [node, nodeData, treeHierarchy]
);
}
url = isString(dashboardURL) ? dashboardURL : null;
return (url !== null);
};
if (treeNode) {
if (getDashboardURL(treeNode) === false)
treeNode.anyFamilyMember(getDashboardURL);
}
return url;
}

View File

@ -7,6 +7,8 @@
//
//////////////////////////////////////////////////////////////////////////
import {isValidData} from 'sources/utils';
export class TreeNode {
constructor(id, data, domNode, parent) {
this.id = id;
@ -217,6 +219,6 @@ function findInTree(rootNode, path) {
})(rootNode);
}
export function isValidTreeNodeData(treeNodeData) {
return !_.isUndefined(treeNodeData) && !_.isNull(treeNodeData);
}
let isValidTreeNodeData = isValidData;
export {isValidTreeNodeData};

View File

@ -7,6 +7,8 @@
//
//////////////////////////////////////////////////////////////////////////
import _ from 'underscore';
export function parseShortcutValue(obj) {
var shortcut = '';
if (obj.alt) { shortcut += 'alt+'; }
@ -36,3 +38,11 @@ export function findAndSetFocus(container) {
}
}, 200);
}
let isValidData = (data) => (!_.isUndefined(data) && !_.isNull(data));
let isFunction = (fn) => (_.isFunction(fn));
let isString = (str) => (_.isString(str));
export {
isValidData, isFunction, isString,
};