Correct the validation logic when modifying indexes/exclusion constraints. Fixes #2113

REL-1_X
Dave Page 2017-06-06 11:15:51 +01:00
parent d21cbb8b1f
commit 4c2004d479
2 changed files with 57 additions and 68 deletions

View File

@ -24,7 +24,22 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
},{
id: 'oper_class', label:'{{ _('Operator class') }}', type:'text',
node: 'table', url: 'get_oper_class', first_empty: true,
editable: true,
editable: function(m) {
if (m instanceof Backbone.Collection) {
return true;
} else if ((_.has(m.collection, 'handler') &&
!_.isUndefined(m.collection.handler) &&
!_.isUndefined(m.collection.handler.get('oid')))) {
return false;
} else if (_.has(m.collection, 'handler') &&
!_.isUndefined(m.collection.handler) &&
!_.isUndefined(m.collection.handler.get('amname')) &&
m.collection.handler.get('amname') != 'btree') {
// Disable if access method is not btree
return false;
}
return true;
},
select2: {
allowClear: true, width: 'style', tags: true,
placeholder: '{{ _("Select the operator class") }}'
@ -65,6 +80,7 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
url: full_url,
success: function(res) {
data = res.data;
self.column.set('options', data);
},
error: function() {
eventHandler.trigger('pgadmin:view:fetch:error', m, self.column);
@ -72,18 +88,6 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
});
eventHandler.trigger('pgadmin:view:fetched', m, self.column);
}
/*
* Transform the data
*/
transform = self.column.get('transform') || self.defaults.transform;
if (transform && _.isFunction(transform)) {
// We will transform the data later, when rendering.
// It will allow us to generate different data based on the
// dependencies.
self.column.set('options', transform.bind(self, data));
} else {
self.column.set('options', data);
}
} else {
self.column.set('options', []);
}
@ -94,49 +98,42 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
options: {
onText: 'ASC',
offText: 'DESC',
},editable: function(m) {
},
editable: function(m) {
if (m instanceof Backbone.Collection) {
return true;
}
else {
if (m.top.get('amname') === 'btree') {
m.set('is_sort_nulls_applicable', true);
return true;
}
m.set('is_sort_nulls_applicable', false);
return false;
}
if ((_.has(m.collection, 'handler') &&
} else if ((_.has(m.collection, 'handler') &&
!_.isUndefined(m.collection.handler) &&
!_.isUndefined(m.collection.handler.get('oid')))) {
return false;
} else if (m.top.get('amname') === 'btree') {
m.set('is_sort_nulls_applicable', true);
return true;
} else {
m.set('is_sort_nulls_applicable', false);
return false;
}
return true;
}
},{
id: 'nulls_order', label:'{{ _('NULLs order') }}', type:"switch",
options: {
onText: 'FIRST',
offText: 'LAST',
},editable: function(m) {
},
editable: function(m) {
if (m instanceof Backbone.Collection) {
return true;
}
else {
if (m.top.get('amname') === 'btree') {
m.set('is_sort_nulls_applicable', true);
return true;
}
m.set('is_sort_nulls_applicable', false);
return false;
}
if ((_.has(m.collection, 'handler') &&
} else if ((_.has(m.collection, 'handler') &&
!_.isUndefined(m.collection.handler) &&
!_.isUndefined(m.collection.handler.get('oid')))) {
return false;
} else if (m.top.get('amname') === 'btree') {
m.set('is_sort_nulls_applicable', true);
return true;
} else {
m.set('is_sort_nulls_applicable', false);
return false;
}
return true;
}
},{
id: 'operator', label:'{{ _('Operator') }}', type: 'text',
@ -184,6 +181,7 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
url: full_url,
success: function(res) {
data = res.data;
self.column.set('options', data);
},
error: function() {
eventHandler.trigger('pgadmin:view:fetch:error', m, self.column);
@ -191,18 +189,6 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
});
eventHandler.trigger('pgadmin:view:fetched', m, self.column);
}
/*
* Transform the data
*/
transform = self.column.get('transform') || self.defaults.transform;
if (transform && _.isFunction(transform)) {
// We will transform the data later, when rendering.
// It will allow us to generate different data based on the
// dependencies.
self.column.set('options', transform.bind(self, data));
} else {
self.column.set('options', data);
}
}
}
})

View File

@ -11,6 +11,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
type: 'coll-index',
sqlAlterHelp: 'sql-alterindex.html',
sqlCreateHelp: 'sql-createindex.html',
dialogHelp: '{{ url_for('help.static', filename='index_dialog.html') }}',
columns: ['name', 'description'],
hasStatistics: true,
statsPrettifyFields: ['Size', 'Index size']
@ -84,7 +85,9 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
editable: function(m) {
// Header cell then skip
if (m instanceof Backbone.Collection) {
return false;
return false;
} else if (m.inSchemaWithModelCheck.apply(this, arguments)) {
return false;
}
return !(m.checkAccessMethod.apply(this, arguments));
},
@ -114,12 +117,12 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
// Header cell then skip
if (m instanceof Backbone.Collection) {
return false;
}
else {
if (m.top.get('amname') === 'btree') {
m.set('is_sort_nulls_applicable', true);
return true;
}
} else if (m.inSchemaWithModelCheck.apply(this, arguments)) {
return false;
} else if (m.top.get('amname') === 'btree') {
m.set('is_sort_nulls_applicable', true);
return true;
} else {
m.set('is_sort_nulls_applicable', false);
return false;
}
@ -136,14 +139,15 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
editable: function(m) {
// Header cell then skip
if (m instanceof Backbone.Collection) {
return true;
} else {
if (m.top.get('amname') === 'btree') {
m.set('is_sort_nulls_applicable', true);
return true;
}
m.set('is_sort_nulls_applicable', false);
return false;
} else if (m.inSchemaWithModelCheck.apply(this, arguments)) {
return false;
} else if (m.top.get('amname') === 'btree') {
m.set('is_sort_nulls_applicable', true);
return true;
} else {
m.set('is_sort_nulls_applicable', false);
return false;
}
},
deps: ['amname', 'sort_order'],
@ -187,11 +191,10 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
checkAccessMethod: function(m) {
//Access method is empty or btree then do not disable field
var parent_model = m.top;
if(!m.inSchemaWithModelCheck.apply(this, [m]) &&
(_.isUndefined(parent_model.get('amname')) ||
if(_.isUndefined(parent_model.get('amname')) ||
_.isNull(parent_model.get('amname')) ||
String(parent_model.get('amname')).replace(/^\s+|\s+$/g, '') == '' ||
parent_model.get('amname') === 'btree')) {
parent_model.get('amname') === 'btree') {
// We need to set nulls to true if sort_order is set to desc
// nulls first is default for desc
if(m.get('sort_order') == true && m.previous('sort_order') == false) {
@ -202,7 +205,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
m.set('is_sort_nulls_applicable', false);
}
return false;
},
}
});
if (!pgBrowser.Nodes['index']) {