Fixed the warnings/errors reported by eslint for all the static

javascripts.
This commit is contained in:
Ashesh Vashi
2018-01-12 12:59:51 +05:30
parent b78b97d89b
commit c32eb6bd37
102 changed files with 25830 additions and 24548 deletions

View File

@@ -1,9 +1,8 @@
define('misc.bgprocess', [
'sources/pgadmin', 'sources/gettext', 'sources/url_for', 'underscore',
'underscore.string', 'jquery', 'pgadmin.browser', 'alertify',
'pgadmin.browser.messages'
], function(
pgAdmin, gettext, url_for, _, S, $, pgBrowser, alertify, pgMessages
pgAdmin, gettext, url_for, _, S, $, pgBrowser, Alertify
) {
pgBrowser.BackgroundProcessObsorver = pgBrowser.BackgroundProcessObsorver || {};
@@ -12,6 +11,8 @@ define('misc.bgprocess', [
return pgBrowser.BackgroundProcessObsorver;
}
var wcDocker = window.wcDocker;
var BGProcess = function(info, notify) {
var self = this;
setTimeout(
@@ -45,7 +46,9 @@ define('misc.bgprocess', [
notifier: null,
container: null,
panel: null,
logs: $('<ol></ol>', {class: 'pg-bg-process-logs'})
logs: $('<ol></ol>', {
class: 'pg-bg-process-logs',
}),
});
if (this.notify) {
@@ -62,7 +65,7 @@ define('misc.bgprocess', [
if (!process.notifier)
process.show.apply(process);
}
)
);
}
var self = this;
@@ -75,29 +78,32 @@ define('misc.bgprocess', [
bgprocess_url: function(type) {
switch (type) {
case 'status':
if (this.details && this.out != -1 && this.err != -1) {
return url_for(
case 'status':
if (this.details && this.out != -1 && this.err != -1) {
return url_for(
'bgprocess.detailed_status', {
'pid': this.id,
'out': this.out,
'err': this.err
'err': this.err,
}
);
}
return url_for('bgprocess.status', {'pid': this.id});
case 'acknowledge':
return url_for('bgprocess.acknowledge', {'pid': this.id});
default:
return url_for('bgprocess.list');
}
return url_for('bgprocess.status', {
'pid': this.id,
});
case 'acknowledge':
return url_for('bgprocess.acknowledge', {
'pid': this.id,
});
default:
return url_for('bgprocess.list');
}
},
update: function(data) {
var self = this,
out = [],
err = [],
idx = 0;
out = [],
err = [];
if ('stime' in data)
self.stime = new Date(data.stime);
@@ -131,9 +137,7 @@ define('misc.bgprocess', [
}
self.completed = self.completed || (
'err' in data && 'out' in data && data.err.done && data.out.done
) || (
!self.details && !_.isNull(self.exit_code)
);
) || (!self.details && !_.isNull(self.exit_code));
var io = 0,
ie = 0,
@@ -145,7 +149,7 @@ define('misc.bgprocess', [
};
while (io < out.length && ie < err.length) {
if (pgAdmin.natural_sort(out[io][0], err[ie][0]) <= 0){
if (pgAdmin.natural_sort(out[io][0], err[ie][0]) <= 0) {
res.push('<li class="pg-bg-res-out">' + escapeHTML(out[io++][1]) + '</li>');
} else {
res.push('<li class="pg-bg-res-err">' + escapeHTML(err[ie++][1]) + '</li>');
@@ -179,7 +183,7 @@ define('misc.bgprocess', [
self.curr_status = gettext('Successfully completed.');
} else {
self.curr_status = S(
gettext("Failed (exit code: %s).")
gettext('Failed (exit code: %s).')
).sprintf(String(self.exit_code)).value();
}
}
@@ -198,7 +202,9 @@ define('misc.bgprocess', [
);
}
setTimeout(function() {self.show.apply(self)}, 10);
setTimeout(function() {
self.show.apply(self);
}, 10);
}
if (!self.completed) {
@@ -219,15 +225,19 @@ define('misc.bgprocess', [
url: self.bgprocess_url('status'),
cache: false,
async: true,
contentType: "application/json",
contentType: 'application/json',
success: function(res) {
setTimeout(function() { self.update(res); }, 10);
setTimeout(function() {
self.update(res);
}, 10);
},
error: function(res) {
// Try after some time only if job id present
if (res.status != 410)
setTimeout(function() { self.update(res); }, 10000);
}
setTimeout(function() {
self.update(res);
}, 10000);
},
});
},
@@ -237,35 +247,40 @@ define('misc.bgprocess', [
if (self.notify && !self.details) {
if (!self.notifier) {
var header = $('<div></div>', {
class: "h5 pg-bg-notify-header"
}).append($('<span></span>').text(self.desc)),
content = $('<div class="pg-bg-bgprocess row"></div>').append(
header
).append(
$('<div></div>', {class: 'pg-bg-notify-body h6' }).append(
$('<div></div>', {class: 'pg-bg-start col-xs-12' }).append(
$('<div></div>').text(self.stime.toString())
).append(
$('<div class="pg-bg-etime"></div>')
)
)
),
for_details = $('<div></div>', {
class: "col-xs-12 text-center pg-bg-click h6"
class: 'h5 pg-bg-notify-header',
}).append($('<span></span>').text(self.desc)),
content = $('<div class="pg-bg-bgprocess row"></div>').append(
header
).append(
$('<div></div>', {
class: 'pg-bg-notify-body h6',
}).append(
$('<span></span>').text(gettext('Click here for details.'))
).appendTo(content),
status = $('<div></div>', {
class: "pg-bg-status col-xs-12 h5 " + ((self.exit_code === 0) ?
'bg-success': (self.exit_code == 1) ?
'bg-failed' : '')
}).appendTo(content),
close_me = $(
'<div class="bg-close"><i class="fa fa-close"></i></div>'
).appendTo(header);
$('<div></div>', {
class: 'pg-bg-start col-xs-12',
}).append(
$('<div></div>').text(self.stime.toString())
).append(
$('<div class="pg-bg-etime"></div>')
)
)
),
for_details = $('<div></div>', {
class: 'col-xs-12 text-center pg-bg-click h6',
}).append(
$('<span></span>').text(gettext('Click here for details.'))
).appendTo(content),
close_me = $(
'<div class="bg-close"><i class="fa fa-close"></i></div>'
).appendTo(header);
$('<div></div>', {
class: 'pg-bg-status col-xs-12 h5 ' + ((self.exit_code === 0) ?
'bg-success' : (self.exit_code == 1) ?
'bg-failed' : ''),
}).appendTo(content);
self.container = content;
self.notifier = alertify.notify(
self.notifier = Alertify.notify(
content.get(0), 'bg-bgprocess', 0, null
);
@@ -281,7 +296,7 @@ define('misc.bgprocess', [
this.show_detailed_view.apply(this);
}.bind(self));
close_me.on('click', function(ev) {
close_me.on('click', function() {
this.notifier.dismiss();
this.notifier = null;
this.acknowledge_server.apply(this);
@@ -312,37 +327,37 @@ define('misc.bgprocess', [
if (self.exit_code === 0) {
$status_bar.addClass('bg-success');
} else if (self.exit_code == 1){
} else if (self.exit_code == 1) {
$status_bar.addClass('bg-failed');
}
} else {
self.show_detailed_view.apply(self)
self.show_detailed_view.apply(self);
}
},
show_detailed_view: function() {
var self = this,
panel = this.panel,
is_new = false;
panel = this.panel,
is_new = false;
if (!self.panel) {
is_new = true;
panel = this.panel =
pgBrowser.BackgroundProcessObsorver.create_panel();
pgBrowser.BackgroundProcessObsorver.create_panel();
panel.title('Process Watcher - ' + _.escape(self.desc));
panel.focus();
}
var container = panel.$container,
status_class = (
(self.exit_code === 0) ?
'bg-bgprocess-success': (self.exit_code == 1) ?
'bg-bgprocess-failed' : ''
),
$logs = container.find('.bg-process-watcher'),
$header = container.find('.bg-process-details'),
$footer = container.find('.bg-process-footer');
status_class = (
(self.exit_code === 0) ?
'bg-bgprocess-success' : (self.exit_code == 1) ?
'bg-bgprocess-failed' : ''
),
$logs = container.find('.bg-process-watcher'),
$header = container.find('.bg-process-details'),
$footer = container.find('.bg-process-footer');
if (is_new) {
// set logs
@@ -413,14 +428,15 @@ define('misc.bgprocess', [
url: self.bgprocess_url('acknowledge'),
cache: false,
async: true,
contentType: "application/json",
success: function(res) {
contentType: 'application/json',
success: function() {
return;
},
error: function(res) {
}
error: function() {
console.warn(arguments);
},
});
}
},
});
_.extend(
@@ -449,7 +465,7 @@ define('misc.bgprocess', [
}, 1000
);
}
)
);
},
update_process_list: function(recheck) {
@@ -461,9 +477,8 @@ define('misc.bgprocess', [
url: url_for('bgprocess.list'),
cache: false,
async: true,
contentType: "application/json",
contentType: 'application/json',
success: function(res) {
var cnt = 0;
if (!res || !_.isArray(res)) {
return;
}
@@ -484,9 +499,10 @@ define('misc.bgprocess', [
);
}
},
error: function(res) {
error: function() {
// FIXME:: What to do now?
}
console.warn(arguments);
},
});
},
@@ -498,11 +514,11 @@ define('misc.bgprocess', [
wcDocker.DOCK.FLOAT,
null, {
w: (screen.width < 700 ?
screen.width * 0.95 : screen.width * 0.5),
h: (screen.height < 500 ?
screen.height * 0.95 : screen.height * 0.5),
x: (screen.width < 700 ? '2%' : '25%'),
y: (screen.height < 500 ? '2%' : '25%')
screen.width * 0.95 : screen.width * 0.5),
h: (screen.height < 500 ?
screen.height * 0.95 : screen.height * 0.5),
x: (screen.width < 700 ? '2%' : '25%'),
y: (screen.height < 500 ? '2%' : '25%'),
});
},
@@ -510,40 +526,40 @@ define('misc.bgprocess', [
var w = pgBrowser.docker,
panels = w.findPanels('bg_process_watcher');
if (panels && panels.length >= 1)
return;
if (panels && panels.length >= 1)
return;
var p = new pgBrowser.Panel({
name: 'bg_process_watcher',
showTitle: true,
isCloseable: true,
isPrivate: true,
content: '<div class="bg-process-details col-xs-12">'+
'<p class="bg-detailed-desc"></p>'+
'<div class="bg-process-stats">'+
'<span><b>' + gettext('Start time') + ': </b>'+
'<span class="bgprocess-start-time"></span>'+
'</span></div>'+
'</div>'+
'<div class="bg-process-watcher col-xs-12">'+
'</div>'+
'<div class="bg-process-footer col-xs-12">'+
'<div class="bg-process-status col-xs-6">'+
'<span><b>' + gettext('Status') + ':</b></span><p></p>'+
'</div>'+
'<div class="bg-process-exec-time col-xs-6">'+
'<div class="exec-div pull-right">'+
'<span><b>' + gettext('Execution time') + ':</b></span><p></p>'+
'</div>'+
'</div>'+
'</div>',
onCreate: function(myPanel, $container) {
$container.addClass('pg-no-overflow');
}
});
p.load(pgBrowser.docker);
}
var p = new pgBrowser.Panel({
name: 'bg_process_watcher',
showTitle: true,
isCloseable: true,
isPrivate: true,
content: '<div class="bg-process-details col-xs-12">' +
'<p class="bg-detailed-desc"></p>' +
'<div class="bg-process-stats">' +
'<span><b>' + gettext('Start time') + ': </b>' +
'<span class="bgprocess-start-time"></span>' +
'</span></div>' +
'</div>' +
'<div class="bg-process-watcher col-xs-12">' +
'</div>' +
'<div class="bg-process-footer col-xs-12">' +
'<div class="bg-process-status col-xs-6">' +
'<span><b>' + gettext('Status') + ':</b></span><p></p>' +
'</div>' +
'<div class="bg-process-exec-time col-xs-6">' +
'<div class="exec-div pull-right">' +
'<span><b>' + gettext('Execution time') + ':</b></span><p></p>' +
'</div>' +
'</div>' +
'</div>',
onCreate: function(myPanel, $container) {
$container.addClass('pg-no-overflow');
},
});
p.load(pgBrowser.docker);
},
});
return pgBrowser.BackgroundProcessObsorver;
});
});

View File

@@ -1,7 +1,7 @@
define('misc.depends', [
'sources/gettext', 'underscore', 'underscore.string', 'jquery', 'pgadmin.browser',
'alertify', 'pgadmin.alertifyjs'
], function(gettext, _, S, $, pgBrowser, Alertify) {
'sources/gettext', 'underscore', 'underscore.string', 'jquery', 'backbone',
'pgadmin.browser', 'pgadmin.alertifyjs', 'pgadmin.backgrid',
], function(gettext, _, S, $, Backbone, pgBrowser, Alertify, Backgrid) {
if (pgBrowser.ShowNodeDepends)
return pgBrowser.ShowNodeDepends;
@@ -20,19 +20,15 @@ define('misc.depends', [
/* Parameter is used to set the proper label of the
* backgrid header cell.
*/
var dependent = true,
dependentGrid = null, // Refer to the backgrid object render under Dependents tab
dependenciesGrid = null; // Refer to the backgrid object render under Dependencies tab
_.bindAll(this, 'showDependents', 'dependentsPanelVisibilityChanged',
'showDependencies', 'dependenciesPanelVisibilityChanged', '__updateCollection'
'showDependencies', 'dependenciesPanelVisibilityChanged', '__updateCollection'
);
// We will listened to the visibility change of the Dependencies and Dependents panel
pgBrowser.Events.on('pgadmin-browser:panel-dependencies:' + wcDocker.EVENT.VISIBILITY_CHANGED,
this.dependenciesPanelVisibilityChanged);
this.dependenciesPanelVisibilityChanged);
pgBrowser.Events.on('pgadmin-browser:panel-dependents:' + wcDocker.EVENT.VISIBILITY_CHANGED,
this.dependentsPanelVisibilityChanged);
this.dependentsPanelVisibilityChanged);
// Defining Backbone Model for Dependencies and Dependents.
var Model = Backbone.Model.extend({
@@ -43,28 +39,28 @@ define('misc.depends', [
/* field contains 'Database Name' for 'Tablespace and Role node',
* for other node it contains 'Restriction'.
*/
field: undefined
field: undefined,
},
// This function is used to fetch/set the icon for the type(Function, Role, Database, ....)
parse: function(res) {
var node = pgBrowser.Nodes[res.type];
res.icon = node ? (_.isFunction(node['node_image']) ?
(node['node_image']).apply(node, [null, null]) :
(node['node_image'] || ('icon-' + res.type))) :
('icon-' + res.type);
res.type = S.titleize(res.type.replace(/_/g, " "), true);
(node['node_image']).apply(node, [null, null]) :
(node['node_image'] || ('icon-' + res.type))) :
('icon-' + res.type);
res.type = S.titleize(res.type.replace(/_/g, ' '), true);
return res;
}
},
});
// Defining Backbone Collection for Dependents.
this.dependentCollection = new (Backbone.Collection.extend({
model: Model
this.dependentCollection = new(Backbone.Collection.extend({
model: Model,
}))(null);
// Defining Backbone Collection for Dependencies.
this.dependenciesCollection = new (Backbone.Collection.extend({
model: Model
this.dependenciesCollection = new(Backbone.Collection.extend({
model: Model,
}))(null);
var self = this;
@@ -75,39 +71,40 @@ define('misc.depends', [
*/
var appendGridToPanel = function(collection, panel, is_dependent) {
var $container = panel[0].layout().scene().find('.pg-panel-content'),
$gridContainer = $container.find('.pg-panel-depends-container'),
grid = new Backgrid.Grid({
columns: [
{
name : 'type',
label: gettext('Type'),
// Extend it to render the icon as per the type.
cell: Backgrid.Cell.extend({
render: function() {
Backgrid.Cell.prototype.render.apply(this, arguments);
this.$el.prepend($('<i>', {class: "wcTabIcon " + this.model.get('icon')}));
return this;
}
}),
editable: false
$gridContainer = $container.find('.pg-panel-depends-container'),
grid = new Backgrid.Grid({
columns: [{
name: 'type',
label: gettext('Type'),
// Extend it to render the icon as per the type.
cell: Backgrid.Cell.extend({
render: function() {
Backgrid.Cell.prototype.render.apply(this, arguments);
this.$el.prepend($('<i>', {
class: 'wcTabIcon ' + this.model.get('icon'),
}));
return this;
},
{
name : 'name',
label: gettext('Name'),
cell: 'string',
editable: false
},
{
name : 'field',
label: '', // label kept blank, it will change dynamically
cell: 'string',
editable: false
}
],
}),
editable: false,
},
{
name: 'name',
label: gettext('Name'),
cell: 'string',
editable: false,
},
{
name: 'field',
label: '', // label kept blank, it will change dynamically
cell: 'string',
editable: false,
},
],
collection: collection,
className: "backgrid presentation table backgrid-striped table-bordered table-hover",
});
collection: collection,
className: 'backgrid presentation table backgrid-striped table-bordered table-hover',
});
// Condition is used to save grid object to change the label of the header.
if (is_dependent)
@@ -122,11 +119,12 @@ define('misc.depends', [
// We will listened to the visibility change of the Dependencies and Dependents panel
pgBrowser.Events.on('pgadmin-browser:panel-dependencies:' + wcDocker.EVENT.VISIBILITY_CHANGED,
this.dependenciesPanelVisibilityChanged);
this.dependenciesPanelVisibilityChanged);
pgBrowser.Events.on('pgadmin-browser:panel-dependents:' + wcDocker.EVENT.VISIBILITY_CHANGED,
this.dependentsPanelVisibilityChanged);
this.dependentsPanelVisibilityChanged);
pgBrowser.Events.on(
'pgadmin:browser:node:updated', function() {
'pgadmin:browser:node:updated',
function() {
if (this.dependenciesPanels && this.dependenciesPanels.length) {
$(this.dependenciesPanels[0]).data('node-prop', '');
this.dependenciesPanelVisibilityChanged(this.dependenciesPanels[0]);
@@ -153,10 +151,10 @@ define('misc.depends', [
// If Dependencies panel exists and is focused then we need to listen the browser tree selection events.
if ((dependenciesPanels[0].isVisible()) || dependenciesPanels.length != 1) {
pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showDependencies);
pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showDependencies);
}
}.bind(this)
);
);
} else {
appendGridToPanel(this.dependenciesCollection, this.dependenciesPanels, false);
@@ -178,7 +176,7 @@ define('misc.depends', [
pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showDependents);
}
}.bind(this)
);
);
} else {
appendGridToPanel(this.dependentCollection, this.dependentsPanels, true);
@@ -192,12 +190,11 @@ define('misc.depends', [
// Fetch the actual data and update the collection
__updateCollection: function(collection, panel, url, messages, node, item, type) {
var msg = messages[0],
$container = panel[0].layout().scene().find('.pg-panel-content'),
$msgContainer = $container.find('.pg-panel-depends-message'),
$gridContainer = $container.find('.pg-panel-depends-container'),
treeHierarchy = node.getTreeNodeHierarchy(item),
n_value = -1,
n_type = type;
$container = panel[0].layout().scene().find('.pg-panel-content'),
$msgContainer = $container.find('.pg-panel-depends-message'),
$gridContainer = $container.find('.pg-panel-depends-container'),
treeHierarchy = node.getTreeNodeHierarchy(item),
n_type = type;
// Avoid unnecessary reloads
if (_.isEqual($(panel[0]).data('node-prop'), treeHierarchy)) {
@@ -230,20 +227,26 @@ define('misc.depends', [
* it should be 'Restriction'.
*/
if (this.dependent && (node.type == 'tablespace' || node.type == 'role'))
this.dependentGrid.columns.models[2].set({'label': gettext('Database')});
this.dependentGrid.columns.models[2].set({
'label': gettext('Database'),
});
else {
this.dependenciesGrid.columns.models[2].set({'label': gettext('Restriction')});
this.dependentGrid.columns.models[2].set({'label': gettext('Restriction')});
this.dependenciesGrid.columns.models[2].set({
'label': gettext('Restriction'),
});
this.dependentGrid.columns.models[2].set({
'label': gettext('Restriction'),
});
}
// Hide message container and show grid container.
$msgContainer.addClass('hidden');
$gridContainer.removeClass('hidden');
var timer = setTimeout(function(){
var timer = setTimeout(function() {
// notify user if request is taking longer than 1 second
$msgContainer.text(gettext("Retrieving data from the server..."));
$msgContainer.text(gettext('Retrieving data from the server...'));
$msgContainer.removeClass('hidden');
if ($gridContainer) {
$gridContainer.addClass('hidden');
@@ -266,24 +269,23 @@ define('misc.depends', [
pgBrowser.Events.trigger(
'pgadmin:node:retrieval:error', 'depends', xhr, error, message
);
if (
!Alertify.pgHandleItemError(xhr, error, message, {
item: item, info: treeHierarchy
})
) {
if (!Alertify.pgHandleItemError(xhr, error, message, {
item: item,
info: treeHierarchy,
})) {
Alertify.pgNotifier(
error, xhr,
S(
gettext("Error retrieving the information - %s")
gettext('Error retrieving the information - %s')
).sprintf(message || _label).value(),
function() {
console.log(arguments);
console.warn(arguments);
}
);
}
// show failed message.
$msgContainer.text(gettext("Failed to retrieve data from the server."));
}
$msgContainer.text(gettext('Failed to retrieve data from the server.'));
},
});
}
}
@@ -305,25 +307,23 @@ define('misc.depends', [
if (self.timeout) {
clearTimeout(self.timeout);
}
self.timeout = setTimeout(
self.timeout = setTimeout(
self.__updateCollection(
self.dependentCollection,
self.dependentsPanels,
node.generate_url(item, 'dependent', data, true),
[gettext('No object selected.'), gettext('No dependent information is available for the current object.'),
gettext('Fetching dependent information from the server...')],
node,
item,
data._type
self.dependentCollection, self.dependentsPanels,
node.generate_url(item, 'dependent', data, true), [
gettext('No object selected.'),
gettext('No dependent information is available for the current object.'),
gettext('Fetching dependent information from the server...'),
], node, item, data._type
), 400
);
},
dependentsPanelVisibilityChanged: function(panel) {
if (panel.isVisible()) {
var t = pgBrowser.tree,
i = t.selected(),
d = i && t.itemData(i),
n = i && d && pgBrowser.Nodes[d._type];
i = t.selected(),
d = i && t.itemData(i),
n = i && d && pgBrowser.Nodes[d._type];
pgBrowser.ShowNodeDepends.showDependents.apply(pgBrowser.ShowNodeDepends, [i, d, n]);
@@ -349,13 +349,13 @@ define('misc.depends', [
if (self.timeout) {
clearTimeout(self.timeout);
}
self.timeout = setTimeout(
self.timeout = setTimeout(
self.__updateCollection(
self.dependenciesCollection,
self.dependenciesPanels,
node.generate_url(item, 'dependency', data, true),
[gettext('Please select an object in the tree view.'), gettext('No dependency information is available for the current object.'),
gettext('Fetching dependency information from the server...')],
node.generate_url(item, 'dependency', data, true), [gettext('Please select an object in the tree view.'), gettext('No dependency information is available for the current object.'),
gettext('Fetching dependency information from the server...'),
],
node,
item,
data._type
@@ -365,9 +365,9 @@ define('misc.depends', [
dependenciesPanelVisibilityChanged: function(panel) {
if (panel.isVisible()) {
var t = pgBrowser.tree,
i = t.selected(),
d = i && t.itemData(i),
n = i && d && pgBrowser.Nodes[d._type];
i = t.selected(),
d = i && t.itemData(i),
n = i && d && pgBrowser.Nodes[d._type];
pgBrowser.ShowNodeDepends.showDependencies.apply(pgBrowser.ShowNodeDepends, [i, d, n]);
@@ -377,8 +377,8 @@ define('misc.depends', [
// We don't need to listen the tree item selection event.
pgBrowser.Events.off('pgadmin-browser:tree:selected', pgBrowser.ShowNodeDepends.showDependencies);
}
}
},
});
return pgBrowser.ShowNodeDepends;
});
});

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
define('misc.sql', [
'sources/gettext', 'underscore', 'underscore.string', 'jquery', 'pgadmin.browser',
'alertify', 'pgadmin.alertifyjs'
], function(gettext, _, S, $, pgBrowser, Alertify) {
'sources/gettext', 'underscore', 'underscore.string', 'jquery',
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.alertifyjs',
], function(gettext, _, S, $, pgAdmin, pgBrowser, Alertify) {
pgBrowser.ShowNodeSQL = pgBrowser.ShowNodeSQL || {};
@@ -28,7 +28,8 @@ define('misc.sql', [
);
pgBrowser.Events.on(
'pgadmin:browser:node:updated', function() {
'pgadmin:browser:node:updated',
function() {
if (this.sqlPanels && this.sqlPanels.length) {
$(this.sqlPanels[0]).data('node-prop', '');
this.sqlPanelVisibilityChanged(this.sqlPanels[0]);
@@ -49,9 +50,8 @@ define('misc.sql', [
);
}
}.bind(this)
);
}
else {
);
} else {
if ((sqlPanels[0].isVisible()) || sqlPanels.length != 1) {
pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showSQL);
}
@@ -67,15 +67,13 @@ define('misc.sql', [
this.timeout && clearTimeout(this.timeout);
var that = this;
this.timeout = setTimeout(
this.timeout = setTimeout(
function() {
var sql = '';
if (node) {
sql = '-- ' + gettext("No SQL could be generated for the selected object.");
var self = this,
n_type = data._type,
n_value = -1,
treeHierarchy = node.getTreeNodeHierarchy(item);
sql = '-- ' + gettext('No SQL could be generated for the selected object.');
var n_type = data._type,
treeHierarchy = node.getTreeNodeHierarchy(item);
// Avoid unnecessary reloads
if (_.isEqual($(that.sqlPanels[0]).data('node-prop'), treeHierarchy)) {
@@ -88,19 +86,19 @@ define('misc.sql', [
sql = '';
var url = node.generate_url(item, 'sql', data, true),
timer;
timer;
$.ajax({
url: url,
type:'GET',
beforeSend: function(jqXHR, settings) {
type: 'GET',
beforeSend: function() {
// Generate a timer for the request
timer = setTimeout(function(){
// notify user if request is taking longer than 1 second
timer = setTimeout(function() {
// Notify user if request is taking longer than 1 second
pgAdmin.Browser.editor.setValue(
gettext("Retrieving data from the server...")
);
pgAdmin.Browser.editor.setValue(
gettext('Retrieving data from the server...')
);
}, 1000);
},
success: function(res) {
@@ -114,22 +112,19 @@ define('misc.sql', [
pgBrowser.Events.trigger(
'pgadmin:node:retrieval:error', 'sql', xhr, error, message, item
);
if (
!Alertify.pgHandleItemError(xhr, error, message, {
item: item, info: treeHierarchy
})
) {
if (!Alertify.pgHandleItemError(xhr, error, message, {
item: item,
info: treeHierarchy,
})) {
Alertify.pgNotifier(
error, xhr,
S(gettext("Error retrieving the information - %s")).sprintf(
S(gettext('Error retrieving the information - %s')).sprintf(
message || _label
).value(),
function() {
console.log(arguments);
}
function() {}
);
}
}
},
});
}
}
@@ -142,9 +137,9 @@ define('misc.sql', [
sqlPanelVisibilityChanged: function(panel) {
if (panel.isVisible()) {
var t = pgBrowser.tree,
i = t.selected(),
d = i && t.itemData(i),
n = i && d && pgBrowser.Nodes[d._type];
i = t.selected(),
d = i && t.itemData(i),
n = i && d && pgBrowser.Nodes[d._type];
pgBrowser.ShowNodeSQL.showSQL.apply(pgBrowser.ShowNodeSQL, [i, d, n]);
@@ -154,8 +149,8 @@ define('misc.sql', [
// We don't need to listen the tree item selection event.
pgBrowser.Events.off('pgadmin-browser:tree:selected', pgBrowser.ShowNodeSQL.showSQL);
}
}
},
});
return pgBrowser.ShowNodeSQL;
});
});

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,9 @@
define('misc.statistics', [
'sources/gettext', 'underscore', 'underscore.string', 'jquery',
'pgadmin.browser', 'backgrid',
'alertify', 'sources/size_prettify'
], function(gettext, _, S, $, pgBrowser, Backgrid, Alertify, sizePrettify) {
'sources/gettext', 'underscore', 'underscore.string', 'jquery', 'backbone',
'pgadmin.browser', 'pgadmin.backgrid', 'alertify', 'sources/size_prettify',
], function(
gettext, _, S, $, Backbone, pgBrowser, Backgrid, Alertify, sizePrettify
) {
if (pgBrowser.NodeStatistics)
return pgBrowser.NodeStatistics;
@@ -13,69 +14,78 @@ define('misc.statistics', [
return pgBrowser.NodeStatistics;
}
var SizeFormatter = Backgrid.SizeFormatter = function () {};
var SizeFormatter = Backgrid.SizeFormatter = function() {};
_.extend(SizeFormatter.prototype, {
/**
Takes a raw value from a model and returns the human readable formatted
string for display.
/**
Takes a raw value from a model and returns the human readable formatted
string for display.
@member Backgrid.SizeFormatter
@param {*} rawData
@param {Backbone.Model} model Used for more complicated formatting
@return {*}
*/
fromRaw: function (rawData, model) {
return sizePrettify(rawData);
},
toRaw: function (formattedData, model) {
return formattedData;
}
@member Backgrid.SizeFormatter
@param {*} rawData
@param {Backbone.Model} model Used for more complicated formatting
@return {*}
*/
fromRaw: function(rawData) {
return sizePrettify(rawData);
},
toRaw: function(formattedData) {
return formattedData;
},
});
var PGBooleanCell = Backgrid.Extension.SwitchCell.extend({
defaults: _.extend({}, Backgrid.Extension.SwitchCell.prototype.defaults)
}),
typeCellMapper = {
// boolean
16: PGBooleanCell,
// int8
20: Backgrid.IntegerCell,
// int2
21: Backgrid.IntegerCell,
// int4
23: Backgrid.IntegerCell,
// float4
700: Backgrid.NumberCell,
// float8
701: Backgrid.NumberCell,
// numeric
1700: Backgrid.NumberCell,
// abstime
702: Backgrid.DatetimeCell,
// reltime
703: Backgrid.DatetimeCell,
// date
1082: Backgrid.DatetimeCell.extend({
includeDate: true, includeTime: false, includeMilli: false
defaults: _.extend({}, Backgrid.Extension.SwitchCell.prototype.defaults),
}),
// time
1083: Backgrid.DatetimeCell.extend({
includeDate: false, includeTime: true, includeMilli: true
}),
// timestamp
1114: Backgrid.DatetimeCell.extend({
includeDate: true, includeTime: true, includeMilli: true
}),
// timestamptz
1184: 'string'/* Backgrid.DatetimeCell.extend({
includeDate: true, includeTime: true, includeMilli: true
}) */,
1266: 'string'/* Backgrid.DatetimeCell.extend({
includeDate: false, includeTime: true, includeMilli: true
}) */
},
GRID_CLASSES = "backgrid presentation table backgrid-striped table-bordered table-hover",
wcDocker = window.wcDocker;
typeCellMapper = {
// boolean
16: PGBooleanCell,
// int8
20: Backgrid.IntegerCell,
// int2
21: Backgrid.IntegerCell,
// int4
23: Backgrid.IntegerCell,
// float4
700: Backgrid.NumberCell,
// float8
701: Backgrid.NumberCell,
// numeric
1700: Backgrid.NumberCell,
// abstime
702: Backgrid.DatetimeCell,
// reltime
703: Backgrid.DatetimeCell,
// date
1082: Backgrid.DatetimeCell.extend({
includeDate: true,
includeTime: false,
includeMilli: false,
}),
// time
1083: Backgrid.DatetimeCell.extend({
includeDate: false,
includeTime: true,
includeMilli: true,
}),
// timestamp
1114: Backgrid.DatetimeCell.extend({
includeDate: true,
includeTime: true,
includeMilli: true,
}),
// timestamptz
1184: 'string'
/* Backgrid.DatetimeCell.extend({
includeDate: true, includeTime: true, includeMilli: true
}) */
,
1266: 'string',
/* Backgrid.DatetimeCell.extend({
includeDate: false, includeTime: true, includeMilli: true
}) */
},
GRID_CLASSES = 'backgrid presentation table backgrid-striped table-bordered table-hover',
wcDocker = window.wcDocker;
_.extend(
PGBooleanCell.prototype.defaults.options, {
@@ -83,7 +93,7 @@ define('misc.statistics', [
offText: gettext('False'),
onColor: 'success',
offColor: 'primary',
size: 'mini'
size: 'mini',
}
);
@@ -101,23 +111,23 @@ define('misc.statistics', [
_.extend(
this, {
initialized: true,
collection: new (Backbone.Collection)(null),
collection: new(Backbone.Collection)(null),
statistic_columns: [{
editable: false,
name: 'statistics',
label: gettext("Statistics"),
label: gettext('Statistics'),
cell: 'string',
headerCell: Backgrid.Extension.CustomHeaderCell,
cellHeaderClasses: 'width_percent_25'
},{
cellHeaderClasses: 'width_percent_25',
}, {
editable: false,
name: 'value',
label: gettext("Value"),
cell: 'string'
label: gettext('Value'),
cell: 'string',
}],
panel: pgBrowser.docker.findPanels('statistics'),
columns: null,
grid: null
grid: null,
});
var self = this;
@@ -125,12 +135,13 @@ define('misc.statistics', [
// We will listen to the visibility change of the statistics panel
pgBrowser.Events.on(
'pgadmin-browser:panel-statistics:' +
wcDocker.EVENT.VISIBILITY_CHANGED,
this.panelVisibilityChanged
wcDocker.EVENT.VISIBILITY_CHANGED,
this.panelVisibilityChanged
);
pgBrowser.Events.on(
'pgadmin:browser:node:updated', function() {
'pgadmin:browser:node:updated',
function() {
if (this.panel && this.panel.length) {
$(this.panel[0]).data('node-prop', '');
this.panelVisibilityChanged(this.panel[0]);
@@ -147,16 +158,16 @@ define('misc.statistics', [
function() {
self.panel = pgBrowser.docker.findPanels('statistics');
if (self.panel[0].isVisible() ||
self.panel.length != 1) {
self.panel.length != 1) {
pgBrowser.Events.on(
'pgadmin-browser:tree:selected', this.showStatistics
);
}
}.bind(this)
);
);
} else {
if (self.panel[0].isVisible() ||
self.panel.length != 1) {
self.panel.length != 1) {
pgBrowser.Events.on(
'pgadmin-browser:tree:selected', this.showStatistics
);
@@ -164,7 +175,7 @@ define('misc.statistics', [
}
if (self.panel.length > 0 && self.panel[0].isVisible()) {
pgBrowser.Events.on(
'pgadmin-browser:tree:selected', this.showStatistics
'pgadmin-browser:tree:selected', this.showStatistics
);
}
},
@@ -172,31 +183,30 @@ define('misc.statistics', [
// Fetch the actual data and update the collection
__updateCollection: function(url, node, item, node_type) {
var $container = this.panel[0].layout().scene().find('.pg-panel-content'),
$msgContainer = $container.find('.pg-panel-statistics-message'),
$gridContainer = $container.find('.pg-panel-statistics-container'),
collection = this.collection,
panel = this.panel,
self = this,
msg = '',
n_type = node_type;
$msgContainer = $container.find('.pg-panel-statistics-message'),
$gridContainer = $container.find('.pg-panel-statistics-container'),
panel = this.panel,
self = this,
msg = '',
n_type = node_type;
if (node) {
msg = gettext("No statistics are available for the selected object.");
msg = gettext('No statistics are available for the selected object.');
/* We fetch the statistics only for those node who set the parameter
* showStatistics function.
*/
// Avoid unnecessary reloads
var treeHierarchy = node.getTreeNodeHierarchy(item);
var cache_flag = {
node_type: node_type,
url: url
};
if (_.isEqual($(panel[0]).data('node-prop'), cache_flag)) {
return;
}
// Cache the current IDs for next time
$(panel[0]).data('node-prop', cache_flag);
// Avoid unnecessary reloads
var treeHierarchy = node.getTreeNodeHierarchy(item);
var cache_flag = {
node_type: node_type,
url: url,
};
if (_.isEqual($(panel[0]).data('node-prop'), cache_flag)) {
return;
}
// Cache the current IDs for next time
$(panel[0]).data('node-prop', cache_flag);
if (node.hasStatistics) {
msg = '';
@@ -204,13 +214,13 @@ define('misc.statistics', [
// Set the url, fetch the data and update the collection
$.ajax({
url: url,
type:'GET',
beforeSend: function(jqXHR, settings) {
type: 'GET',
beforeSend: function() {
// Generate a timer for the request
timer = setTimeout(function(){
timer = setTimeout(function() {
// notify user if request is taking longer than 1 second
$msgContainer.text(gettext("Retrieving data from the server..."));
$msgContainer.text(gettext('Retrieving data from the server...'));
$msgContainer.removeClass('hidden');
if (self.grid) {
self.grid.remove();
@@ -237,20 +247,20 @@ define('misc.statistics', [
self.grid = new Backgrid.Grid({
columns: self.columns,
collection: self.collection,
className: GRID_CLASSES
className: GRID_CLASSES,
});
self.grid.render();
$gridContainer.empty();
$gridContainer.append(self.grid.$el);
if (!$msgContainer.hasClass('hidden')) {
$msgContainer.addClass('hidden')
$msgContainer.addClass('hidden');
}
$gridContainer.removeClass('hidden');
} else if (res.info) {
if (!$gridContainer.hasClass('hidden')) {
$gridContainer.addClass('hidden')
$gridContainer.addClass('hidden');
}
$msgContainer.text(res.info);
$msgContainer.removeClass('hidden');
@@ -261,24 +271,21 @@ define('misc.statistics', [
pgBrowser.Events.trigger(
'pgadmin:node:retrieval:error', 'statistics', xhr, error, message, item
);
if (
!Alertify.pgHandleItemError(xhr, error, message, {
item: item, info: treeHierarchy
})
) {
if (!Alertify.pgHandleItemError(xhr, error, message, {
item: item,
info: treeHierarchy,
})) {
Alertify.pgNotifier(
error, xhr,
S(gettext("Error retrieving the information - %s")).sprintf(
S(gettext('Error retrieving the information - %s')).sprintf(
message || _label
).value(),
function() {
console.log(arguments);
}
function() {}
);
}
// show failed message.
$msgContainer.text(gettext("Failed to retrieve data from the server."));
}
$msgContainer.text(gettext('Failed to retrieve data from the server.'));
},
});
}
}
@@ -309,38 +316,38 @@ define('misc.statistics', [
if (self.timeout) {
clearTimeout(self.timeout);
}
self.timeout = setTimeout(
self.timeout = setTimeout(
function() {
self.__updateCollection.call(
self, node.generate_url(item, 'stats', data, true), node, item, data._type
);
}, 400);
}
}
},
__createMultiLineStatistics: function(data, prettifyFields) {
var rows = data['rows'],
columns = data['columns'];
columns = data['columns'];
this.columns = [];
for (var idx in columns) {
var rawColumn = columns[idx],
cell_type = typeCellMapper[rawColumn['type_code']] || 'string';
cell_type = typeCellMapper[rawColumn['type_code']] || 'string';
// Don't show PID comma separated
if(rawColumn['name'] == 'PID') {
if (rawColumn['name'] == 'PID') {
cell_type = cell_type.extend({
orderSeparator: ''
orderSeparator: '',
});
}
var col = {
editable: false,
name: rawColumn['name'],
cell: cell_type
editable: false,
name: rawColumn['name'],
cell: cell_type,
};
if (_.indexOf(prettifyFields, rawColumn['name']) != -1) {
col['formatter'] = SizeFormatter
col['formatter'] = SizeFormatter;
}
this.columns.push(col);
@@ -351,8 +358,9 @@ define('misc.statistics', [
__createSingleLineStatistics: function(data, prettifyFields) {
var row = data['rows'][0],
columns = data['columns'],
res = [];
columns = data['columns'],
res = [],
name;
this.columns = this.statistic_columns;
for (var idx in columns) {
@@ -360,7 +368,9 @@ define('misc.statistics', [
res.push({
'statistics': name,
// Check if row is undefined?
'value': row && row[name] ? ((_.indexOf(prettifyFields, name) != -1) ? sizePrettify(row[name]) : row[name]) : null
'value': row && row[name] ?
((_.indexOf(prettifyFields, name) != -1) ?
sizePrettify(row[name]) : row[name]) : null,
});
}
@@ -370,9 +380,9 @@ define('misc.statistics', [
panelVisibilityChanged: function(panel) {
if (panel.isVisible()) {
var t = pgBrowser.tree,
i = t.selected(),
d = i && t.itemData(i),
n = i && d && pgBrowser.Nodes[d._type];
i = t.selected(),
d = i && t.itemData(i),
n = i && d && pgBrowser.Nodes[d._type];
pgBrowser.NodeStatistics.showStatistics.apply(
pgBrowser.NodeStatistics, [i, d, n]
@@ -390,7 +400,7 @@ define('misc.statistics', [
pgBrowser.NodeStatistics.showStatistics
);
}
}
},
});
return pgBrowser.NodeStatistics;