Ensure the datatype cache is updated when a domain is added. Fixes #2778

pull/6/head
Murtuza Zabuawala 2017-12-13 15:17:17 +00:00 committed by Dave Page
parent b2e844c0ad
commit c5d1fc8189
8 changed files with 36 additions and 10 deletions

View File

@ -178,9 +178,11 @@ define('pgadmin.node.domain', [
id: 'basetype', label: gettext('Base type'), cell: 'string',
control: 'node-ajax-options', type: 'text', url: 'get_types',
mode:['properties', 'create', 'edit'], group: gettext('Definition'),
cache_level: 'database', cache_node: 'schema', disabled: function(m) {
first_empty: true, cache_node: 'type',
disabled: function(m) {
return !m.isNew();
}, first_empty: true, transform: function(d) {
},
transform: function(d) {
this.model.type_options = d;
return d;
}

View File

@ -94,7 +94,7 @@ define('pgadmin.node.fts_configuration', [
cache_node = this.field.get('cache_node');
cache_node = (cache_node &&
pgAdmin.Browser.Nodes['cache_node'])
pgAdmin.Browser.Nodes[cache_node])
|| node;
/*

View File

@ -297,6 +297,7 @@ define('pgadmin.node.column', [
control: 'node-ajax-options', url: 'get_types', node: 'table',
cellHeaderClasses:'width_percent_30', first_empty: true,
select2: { allowClear: false }, group: gettext('Definition'),
cache_node: 'table',
transform: function(data, cell) {
/* 'transform' function will be called by control, and cell both.
* The way, we use the transform in cell, and control is different.

View File

@ -100,6 +100,14 @@ define('pgadmin.node.table', [
pgBrowser.Events.on(
'pgadmin:browser:node:table:updated', this.onTableUpdated, this
);
pgBrowser.Events.on(
'pgadmin:browser:node:type:cache_cleared',
this.handle_cache, this
);
pgBrowser.Events.on(
'pgadmin:browser:node:domain:cache_cleared',
this.handle_cache, this
);
},
canDrop: pgBrowser.Nodes['schema'].canChildDrop,
canDropCascade: pgBrowser.Nodes['schema'].canChildDrop,
@ -1305,7 +1313,7 @@ define('pgadmin.node.table', [
cache_level = this.field.get('cache_level') || node.type,
cache_node = this.field.get('cache_node');
cache_node = (cache_node && pgBrowser.Nodes['cache_node']) || node;
cache_node = (cache_node && pgBrowser.Nodes[cache_node]) || node;
m.trigger('pgadmin:view:fetching', m, self.field);
// Fetching Columns data for the selected table.
@ -1484,6 +1492,11 @@ define('pgadmin.node.table', [
}
insertChildrenNodes();
}
},
handle_cache: function() {
// Clear Table's cache as column's type is dependent on two node
// 1) Type node 2) Domain node
this.clear_cache.apply(this, null);
}
});
}

View File

@ -86,8 +86,8 @@ define('pgadmin.node.type', [
},{
id: 'type', label: gettext('Type'), control: 'node-ajax-options',
type: 'text', url: 'get_types', disabled: false, node: 'type',
cache_node: 'domain', editable: true,
cell: 'node-ajax-options', select2: {allowClear: false},
editable: true,
transform: function(d, control){
control.model.type_options = d;
return d;

View File

@ -50,7 +50,7 @@ define(['sources/gettext', 'underscore', 'jquery', 'backbone', 'backform',
schema: [{
id: 'grantee', label: gettext('Grantee'), type:'text', group: null,
editable: true, cellHeaderClasses: 'width_percent_40',
node: 'role',
node: 'role', options_cached: false,
disabled : function(m) {
if (!(m instanceof Backbone.Model)) {
// This has been called during generating the header cell

View File

@ -1578,6 +1578,13 @@ define(
* fetches the new data.
*/
this.cached = {};
// Trigger Notify event about node's cache
var self = this;
pgBrowser.Events.trigger(
'pgadmin:browser:node:' + self.type + ':cache_cleared',
item, self
);
},
cache_level: function(node_info, with_id) {
if (node_info) {

View File

@ -343,8 +343,8 @@ function(gettext, $, _, pgAdmin, Backbone, Backform, Alertify, Backgrid) {
Backgrid.Extension.Select2Cell.prototype.initialize.apply(this, arguments);
var url = this.column.get('url') || this.defaults.url,
options_cached = this.column.get('options_cached');
is_options_cached = _.has(this.column.attributes, 'options_cached'),
options_cached = is_options_cached && this.column.get('options_cached');
// Hmm - we found the url option.
// That means - we needs to fetch the options from that node.
if (url && !options_cached) {
@ -362,7 +362,7 @@ function(gettext, $, _, pgAdmin, Backbone, Backform, Alertify, Backgrid) {
cache_level,
cache_node = column.get('cache_node');
cache_node = (cache_node && pgAdmin.Browser.Nodes['cache_node']) || node;
cache_node = (cache_node && pgAdmin.Browser.Nodes[cache_node]) || node;
if (column.has('cache_level')) {
cache_level = column.get('cache_level');
@ -414,7 +414,10 @@ function(gettext, $, _, pgAdmin, Backbone, Backform, Alertify, Backgrid) {
} else {
column.set('options', data);
}
column.set('options_cached', true);
if(is_options_cached) {
column.set('options_cached', true);
}
}
}
});