2017-06-07 05:23:02 -05:00
|
|
|
define([
|
2017-08-08 22:02:16 -05:00
|
|
|
'sources/gettext', 'jquery', 'underscore', 'underscore.string', 'sources/pgadmin',
|
2017-08-17 11:13:07 -05:00
|
|
|
'backbone', 'alertify', 'backform', 'backgrid', 'sources/browser/generate_url', 'pgadmin.backform', 'pgadmin.backgrid',
|
2018-01-12 01:29:51 -06:00
|
|
|
'pgadmin.browser.node',
|
2017-08-17 11:13:07 -05:00
|
|
|
], function(gettext, $, _, S, pgAdmin, Backbone, Alertify, Backform, Backgrid, generateUrl) {
|
2015-11-17 00:21:09 -06:00
|
|
|
|
|
|
|
var pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {};
|
|
|
|
|
|
|
|
// It has already been defined.
|
|
|
|
// Avoid running this script again.
|
|
|
|
if (pgBrowser.Collection)
|
|
|
|
return pgBrowser.Collection;
|
|
|
|
|
2016-04-14 06:15:32 -05:00
|
|
|
pgBrowser.Collection = function() {};
|
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
_.extend(
|
|
|
|
pgBrowser.Collection,
|
|
|
|
_.clone(pgBrowser.Node), {
|
|
|
|
///////
|
|
|
|
// Initialization function
|
|
|
|
// Generally - used to register the menus for this type of node.
|
|
|
|
//
|
|
|
|
// Also, look at pgAdmin.Browser.add_menus(...) function.
|
|
|
|
//
|
|
|
|
// Collection will not have 'Properties' menu.
|
|
|
|
//
|
|
|
|
// NOTE: Override this for each node for initialization purpose
|
|
|
|
Init: function() {
|
|
|
|
if (this.node_initialized)
|
|
|
|
return;
|
|
|
|
this.node_initialized = true;
|
|
|
|
pgAdmin.Browser.add_menus([{
|
|
|
|
name: 'refresh', node: this.type, module: this,
|
|
|
|
applies: ['object', 'context'], callback: 'refresh',
|
|
|
|
priority: 1, label: gettext('Refresh...'),
|
|
|
|
icon: 'fa fa-refresh',
|
|
|
|
}]);
|
2016-06-08 07:18:59 -05:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
// show query tool only in context menu of supported nodes.
|
|
|
|
if (pgAdmin.DataGrid && pgAdmin.unsupported_nodes) {
|
|
|
|
if (_.indexOf(pgAdmin.unsupported_nodes, this.type) == -1) {
|
|
|
|
pgAdmin.Browser.add_menus([{
|
|
|
|
name: 'show_query_tool', node: this.type, module: this,
|
|
|
|
applies: ['context'], callback: 'show_query_tool',
|
|
|
|
priority: 998, label: gettext('Query Tool...'),
|
|
|
|
icon: 'fa fa-bolt',
|
|
|
|
}]);
|
|
|
|
}
|
2016-06-08 07:18:59 -05:00
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
|
|
|
hasId: false,
|
|
|
|
is_collection: true,
|
|
|
|
collection_node: true,
|
|
|
|
// A collection will always have a collection of statistics, when the node
|
|
|
|
// it represent will have some statistics.
|
|
|
|
hasCollectiveStatistics: true,
|
|
|
|
showProperties: function(item, data, panel) {
|
|
|
|
var that = this,
|
|
|
|
j = panel.$container.find('.obj_properties').first(),
|
|
|
|
view = j.data('obj-view'),
|
|
|
|
content = $('<div></div>')
|
2015-11-17 00:21:09 -06:00
|
|
|
.addClass('pg-prop-content col-xs-12'),
|
2018-01-12 01:29:51 -06:00
|
|
|
node = pgBrowser.Nodes[that.node],
|
|
|
|
// This will be the URL, used for object manipulation.
|
|
|
|
urlBase = this.generate_url(item, 'properties', data),
|
|
|
|
collection = new (node.Collection.extend({
|
|
|
|
url: urlBase,
|
|
|
|
model: node.model,
|
|
|
|
}))(),
|
|
|
|
info = this.getTreeNodeHierarchy.apply(this, [item]),
|
|
|
|
gridSchema = Backform.generateGridColumnsFromModel(
|
2015-12-23 06:41:27 -06:00
|
|
|
info, node.model, 'properties', that.columns
|
2015-11-17 00:21:09 -06:00
|
|
|
),
|
2018-01-12 01:29:51 -06:00
|
|
|
// Initialize a new Grid instance
|
|
|
|
grid = new Backgrid.Grid({
|
|
|
|
columns: gridSchema.columns,
|
|
|
|
collection: collection,
|
|
|
|
className: 'backgrid table-bordered',
|
|
|
|
}),
|
|
|
|
gridView = {
|
|
|
|
'remove': function() {
|
|
|
|
if (this.grid) {
|
|
|
|
if (this.grid.collection) {
|
|
|
|
this.grid.collection.reset(null, {silent: true});
|
|
|
|
delete (this.grid.collection);
|
|
|
|
}
|
|
|
|
delete (this.grid);
|
|
|
|
this.grid = null;
|
2016-04-15 05:44:01 -05:00
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
|
|
|
grid: grid,
|
|
|
|
};
|
2015-11-17 00:21:09 -06:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
if (view) {
|
|
|
|
// Avoid unnecessary reloads
|
|
|
|
if (_.isEqual($(panel).data('node-prop'), urlBase)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-29 06:16:02 -05:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
// Cache the current IDs for next time
|
|
|
|
$(panel).data('node-prop', urlBase);
|
2016-06-29 06:16:02 -05:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
// Reset the data object
|
|
|
|
j.data('obj-view', null);
|
|
|
|
}
|
2015-11-17 00:21:09 -06:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
// Make sure the HTML element is empty.
|
|
|
|
j.empty();
|
|
|
|
j.data('obj-view', gridView);
|
2015-11-17 00:21:09 -06:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
// Render subNode grid
|
|
|
|
content.append(grid.render().$el);
|
|
|
|
j.append(content);
|
2015-11-17 00:21:09 -06:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
// Fetch Data
|
|
|
|
collection.fetch({
|
|
|
|
reset: true,
|
2018-06-05 05:36:19 -05:00
|
|
|
error: function(model, error, xhr) {
|
2018-01-12 01:29:51 -06:00
|
|
|
pgBrowser.Events.trigger(
|
|
|
|
'pgadmin:collection:retrieval:error', 'properties', xhr, error,
|
2018-06-05 05:36:19 -05:00
|
|
|
error.message, item, that
|
2017-07-18 09:13:16 -05:00
|
|
|
);
|
2018-01-12 01:29:51 -06:00
|
|
|
if (!Alertify.pgHandleItemError(
|
2018-06-05 05:36:19 -05:00
|
|
|
xhr, error, error.message, {item: item, info: info}
|
2018-01-12 01:29:51 -06:00
|
|
|
)) {
|
|
|
|
Alertify.pgNotifier(error, xhr, S(
|
|
|
|
gettext('Error retrieving properties - %s.')
|
2018-06-05 05:36:19 -05:00
|
|
|
).sprintf(error.message || that.label).value(), function() {
|
2018-01-12 01:29:51 -06:00
|
|
|
console.warn(arguments);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
generate_url: function(item, type) {
|
|
|
|
/*
|
|
|
|
* Using list, and collection functions of a node to get the nodes
|
|
|
|
* under the collection, and properties of the collection respectively.
|
|
|
|
*/
|
|
|
|
var opURL = {
|
|
|
|
'properties': 'obj', 'children': 'nodes',
|
|
|
|
},
|
|
|
|
self = this;
|
|
|
|
var collectionPickFunction = function (treeInfoValue, treeInfoKey) {
|
|
|
|
return (treeInfoKey != self.type);
|
|
|
|
};
|
|
|
|
var treeInfo = this.getTreeNodeHierarchy(item);
|
|
|
|
var actionType = type in opURL ? opURL[type] : type;
|
|
|
|
return generateUrl.generate_url(
|
|
|
|
pgAdmin.Browser.URL, treeInfo, actionType, self.node,
|
|
|
|
collectionPickFunction
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
2015-11-17 00:21:09 -06:00
|
|
|
|
2016-04-14 06:15:32 -05:00
|
|
|
return pgBrowser.Collection;
|
2015-11-17 00:21:09 -06:00
|
|
|
});
|