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.pull/14/head
parent
f7e43d5e50
commit
e12e00703f
|
@ -1,11 +1,12 @@
|
||||||
define('pgadmin.dashboard', [
|
define('pgadmin.dashboard', [
|
||||||
'sources/url_for', 'sources/gettext', 'require', 'jquery', 'underscore',
|
'sources/url_for', 'sources/gettext', 'require', 'jquery', 'underscore',
|
||||||
'sources/pgadmin', 'backbone', 'backgrid', 'flotr2',
|
'sources/pgadmin', 'backbone', 'backgrid', 'flotr2',
|
||||||
'pgadmin.alertifyjs', 'pgadmin.backform', 'backgrid.filter',
|
'pgadmin.alertifyjs', 'pgadmin.backform',
|
||||||
|
'sources/nodes/dashboard', 'backgrid.filter',
|
||||||
'pgadmin.browser', 'bootstrap', 'wcdocker',
|
'pgadmin.browser', 'bootstrap', 'wcdocker',
|
||||||
], function(
|
], function(
|
||||||
url_for, gettext, r, $, _, pgAdmin, Backbone, Backgrid, Flotr,
|
url_for, gettext, r, $, _, pgAdmin, Backbone, Backgrid, Flotr,
|
||||||
Alertify, Backform
|
Alertify, Backform, NodesDashboard
|
||||||
) {
|
) {
|
||||||
|
|
||||||
pgAdmin.Browser = pgAdmin.Browser || {};
|
pgAdmin.Browser = pgAdmin.Browser || {};
|
||||||
|
@ -250,38 +251,29 @@ define('pgadmin.dashboard', [
|
||||||
let self = this;
|
let self = this;
|
||||||
/* Clear all the interval functions of previous dashboards */
|
/* Clear all the interval functions of previous dashboards */
|
||||||
self.clearIntervalId();
|
self.clearIntervalId();
|
||||||
|
|
||||||
if (itemData && itemData._type && dashboardVisible) {
|
if (itemData && itemData._type && dashboardVisible) {
|
||||||
var treeHierarchy = node.getTreeNodeHierarchy(item),
|
var treeHierarchy = node.getTreeNodeHierarchy(item),
|
||||||
url = url_for('dashboard.index'),
|
url = NodesDashboard.url(itemData, item, treeHierarchy);
|
||||||
b = pgAdmin.Browser,
|
|
||||||
m = b && b.Nodes[itemData._type];
|
|
||||||
|
|
||||||
self.sid = self.did = -1;
|
if (url === null) {
|
||||||
self.version = itemData.version;
|
url = url_for('dashboard.index');
|
||||||
cancel_query_url = url_for('dashboard.index') + 'cancel_query/';
|
|
||||||
terminate_session_url = url_for('dashboard.index') + 'terminate_session/';
|
|
||||||
|
|
||||||
// Check if user is super user
|
cancel_query_url = url + 'cancel_query/';
|
||||||
var server = treeHierarchy['server'];
|
terminate_session_url = url + 'terminate_session/';
|
||||||
maintenance_database = (server && server.db) || null;
|
|
||||||
|
|
||||||
if (server && server.user && server.user.is_superuser) {
|
// Check if user is super user
|
||||||
is_super_user = true;
|
var server = treeHierarchy['server'];
|
||||||
} else {
|
maintenance_database = (server && server.db) || null;
|
||||||
is_super_user = false;
|
|
||||||
// Set current user
|
|
||||||
current_user = (server && server.user) ? server.user.name : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m && m.dashboard) {
|
if (server && server.user && server.user.is_superuser) {
|
||||||
if (_.isFunction(m.dashboard)) {
|
is_super_user = true;
|
||||||
url = m.dashboard.apply(
|
|
||||||
item, itemData, node, treeHierarchy
|
|
||||||
);
|
|
||||||
} else {
|
} 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) {
|
if ('database' in treeHierarchy) {
|
||||||
self.sid = treeHierarchy.server._id;
|
self.sid = treeHierarchy.server._id;
|
||||||
self.did = treeHierarchy.database._id;
|
self.did = treeHierarchy.database._id;
|
||||||
|
@ -310,8 +302,10 @@ define('pgadmin.dashboard', [
|
||||||
if (div) {
|
if (div) {
|
||||||
if (itemData.connected || _.isUndefined(itemData.connected)) {
|
if (itemData.connected || _.isUndefined(itemData.connected)) {
|
||||||
// Avoid unnecessary reloads
|
// Avoid unnecessary reloads
|
||||||
if (url != $(dashboardPanel).data('dashboard_url') ||
|
if (url !== $(dashboardPanel).data('dashboard_url') || (
|
||||||
(url == $(dashboardPanel).data('dashboard_url') && $(dashboardPanel).data('server_status') == false)) {
|
url === $(dashboardPanel).data('dashboard_url') &&
|
||||||
|
$(dashboardPanel).data('server_status') == false)) {
|
||||||
|
// Clear out everything so any existing timers die off
|
||||||
$(div).empty();
|
$(div).empty();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -7,6 +7,8 @@
|
||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
import {isValidData} from 'sources/utils';
|
||||||
|
|
||||||
export class TreeNode {
|
export class TreeNode {
|
||||||
constructor(id, data, domNode, parent) {
|
constructor(id, data, domNode, parent) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -217,6 +219,6 @@ function findInTree(rootNode, path) {
|
||||||
})(rootNode);
|
})(rootNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isValidTreeNodeData(treeNodeData) {
|
let isValidTreeNodeData = isValidData;
|
||||||
return !_.isUndefined(treeNodeData) && !_.isNull(treeNodeData);
|
|
||||||
}
|
export {isValidTreeNodeData};
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
import _ from 'underscore';
|
||||||
|
|
||||||
export function parseShortcutValue(obj) {
|
export function parseShortcutValue(obj) {
|
||||||
var shortcut = '';
|
var shortcut = '';
|
||||||
if (obj.alt) { shortcut += 'alt+'; }
|
if (obj.alt) { shortcut += 'alt+'; }
|
||||||
|
@ -36,3 +38,11 @@ export function findAndSetFocus(container) {
|
||||||
}
|
}
|
||||||
}, 200);
|
}, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let isValidData = (data) => (!_.isUndefined(data) && !_.isNull(data));
|
||||||
|
let isFunction = (fn) => (_.isFunction(fn));
|
||||||
|
let isString = (str) => (_.isString(str));
|
||||||
|
|
||||||
|
export {
|
||||||
|
isValidData, isFunction, isString,
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue