Fixed an issue where the validation error message is shown twice. Fixes #5736

This commit is contained in:
Rahul Shirsat 2020-10-30 14:59:22 +05:30 committed by Akshay Joshi
parent df31fe7dc4
commit 183c83f0d2
4 changed files with 90 additions and 16 deletions

View File

@ -22,6 +22,7 @@ Bug fixes
********* *********
| `Issue #4639 <https://redmine.postgresql.org/issues/4639>`_ - Ensure that some fields should be disabled for the trigger in edit mode. | `Issue #4639 <https://redmine.postgresql.org/issues/4639>`_ - Ensure that some fields should be disabled for the trigger in edit mode.
| `Issue #5736 <https://redmine.postgresql.org/issues/5736>`_ - Fixed an issue where the validation error message is shown twice.
| `Issue #5842 <https://redmine.postgresql.org/issues/5842>`_ - Ensure that query history should be listed by date/time in descending order. | `Issue #5842 <https://redmine.postgresql.org/issues/5842>`_ - Ensure that query history should be listed by date/time in descending order.
| `Issue #5858 <https://redmine.postgresql.org/issues/5858>`_ - Ensure that search object functionality works with case insensitive string. | `Issue #5858 <https://redmine.postgresql.org/issues/5858>`_ - Ensure that search object functionality works with case insensitive string.
| `Issue #5895 <https://redmine.postgresql.org/issues/5895>`_ - Fixed an issue where the suffix for Toast table size is not visible in the Statistics tab. | `Issue #5895 <https://redmine.postgresql.org/issues/5895>`_ - Fixed an issue where the suffix for Toast table size is not visible in the Statistics tab.

View File

@ -539,6 +539,8 @@ define([
// Let me listen to the my child invalid/valid messages // Let me listen to the my child invalid/valid messages
self.on('pgadmin-session:model:invalid', self.onChildInvalid); self.on('pgadmin-session:model:invalid', self.onChildInvalid);
self.on('pgadmin-session:collection:changed', self.onChildCollectionChanged);
self.on('pgadmin-session:model-msg:changed', self.onModelChangedMsg);
self.on('pgadmin-session:model:valid', self.onChildValid); self.on('pgadmin-session:model:valid', self.onChildValid);
self.on('pgadmin-session:changed', self.onChildChanged); self.on('pgadmin-session:changed', self.onChildChanged);
self.on('pgadmin-session:added', self.onChildChanged); self.on('pgadmin-session:added', self.onChildChanged);
@ -674,10 +676,14 @@ define([
!validate(self, (objName && [objName]))) { !validate(self, (objName && [objName]))) {
if (self.handler) { if (self.handler) {
(self.handler).trigger('pgadmin-session:model:valid', self, self.handler); (self.handler).trigger('pgadmin-session:model:valid', self, self.handler);
(self.handler).trigger('pgadmin-session:collection:changed', self, self.handler);
} else { } else {
self.trigger( self.trigger(
'pgadmin-session:valid', self.sessChanged(), self 'pgadmin-session:valid', self.sessChanged(), self
); );
self.trigger(
'pgadmin-session:collection:changed', self.sessChanged(), self
);
} }
} else { } else {
msg = msg || _.values(self.errorModel.attributes)[0]; msg = msg || _.values(self.errorModel.attributes)[0];
@ -686,19 +692,84 @@ define([
(self.handler).trigger( (self.handler).trigger(
'pgadmin-session:model:invalid', msg, self, self.handler 'pgadmin-session:model:invalid', msg, self, self.handler
); );
(self.handler).trigger('pgadmin-session:collection:changed', self, self.handler);
} else { } else {
self.trigger('pgadmin-session:invalid', msg, self); self.trigger('pgadmin-session:invalid', msg, self);
self.trigger('pgadmin-session:collection:changed', self);
} }
} }
} }
}, },
onChildChanged: function() { onChildCollectionChanged: function(obj, obj_hand) {
var self = this;
setTimeout(() => {
var msg = null,
validate = function(m, attrs) {
if ('default_validate' in m && typeof(m.default_validate) == 'function') {
msg = m.default_validate();
if (_.isString(msg)) {
return msg;
}
}
if ('validate' in m && typeof(m.validate) == 'function') {
msg = m.validate(attrs);
return msg;
}
return null;
};
let handler, parentTr;
let collection = self.collection || obj_hand;
if(collection) {
var collection_selector = collection.attrName || collection.name;
let activeTab = $('.show.active div.'+collection_selector);
$(activeTab).find('.error-in-grid').removeClass('error-in-grid');
model_collection_exit : if (collection instanceof Backbone.Collection) {
for (var cid in collection.models) {
let model = collection.models[cid];
for(let mod_obj of model.objects) {
let mod_attr = model.attributes[mod_obj];
if (mod_attr && mod_attr.models.length > 0) {
for(let mod_attr_prop in mod_attr.models) {
if(validate(mod_attr.models[mod_attr_prop])) {
handler = mod_attr.models[mod_attr_prop];
parentTr = model.parentTr;
break model_collection_exit;
}
}
}
}
}
}
}
if(msg && handler) {
msg = msg || _.values(handler.errorModel.attributes)[0];
handler.trigger('pgadmin-session:model:invalid', msg, handler);
$(parentTr).addClass('error-in-grid');
}
return this;
}, 120);
},
onChildChanged: function(obj) {
var self = this; var self = this;
if (self.trackChanges && self.collection) { if (self.trackChanges && self.collection) {
(self.collection).trigger('change', self); (self.collection).trigger('change', self);
} }
self.trigger('pgadmin-session:collection:changed', self, obj);
}, },
stopSession: function() { stopSession: function() {
@ -710,6 +781,7 @@ define([
self.off('pgadmin-session:changed', self.onChildChanged); self.off('pgadmin-session:changed', self.onChildChanged);
self.off('pgadmin-session:added', self.onChildChanged); self.off('pgadmin-session:added', self.onChildChanged);
self.off('pgadmin-session:removed', self.onChildChanged); self.off('pgadmin-session:removed', self.onChildChanged);
self.off('pgadmin-session:collection:changed', self.onChildCollectionChanged);
} }
self.trackChanges = false; self.trackChanges = false;
@ -1090,6 +1162,7 @@ define([
// Let the parent/listener know about my status (valid/invalid). // Let the parent/listener know about my status (valid/invalid).
this.triggerValidationEvent.apply(this); this.triggerValidationEvent.apply(this);
self.trigger('pgadmin-session:collection:changed', self);
} }
return true; return true;

View File

@ -1170,6 +1170,7 @@ define([
var uniqueCol = this.field.get('uniqueCol') || [], var uniqueCol = this.field.get('uniqueCol') || [],
uniqueChangedAttr = [], uniqueChangedAttr = [],
self = this; self = this;
// Check if changed model attributes are also in unique columns. And then only check for uniqueness. // Check if changed model attributes are also in unique columns. And then only check for uniqueness.
if (newModel.attributes) { if (newModel.attributes) {
_.each(uniqueCol, function(col) { _.each(uniqueCol, function(col) {
@ -1386,6 +1387,10 @@ define([
}, },
}); });
for(let i = 0; i < (collection.length); i++) {
collection.at(i).parentTr = self.grid.body.rows[i].$el;
}
// Render subNode grid // Render subNode grid
var subNodeGrid = self.grid.render().$el; var subNodeGrid = self.grid.render().$el;
@ -1461,6 +1466,9 @@ define([
var idx = collection.indexOf(m), var idx = collection.indexOf(m),
newRow = self.grid.body.rows[idx].$el; newRow = self.grid.body.rows[idx].$el;
collection.get(m).parentTr = newRow;
m.parentTr = newRow;
newRow.addClass('new'); newRow.addClass('new');
if(!$(newRow).pgMakeBackgridVisible('.backform-tab')){ if(!$(newRow).pgMakeBackgridVisible('.backform-tab')){
// We can have subnode controls in Panels // We can have subnode controls in Panels
@ -1480,25 +1488,11 @@ define([
}, },
updateInvalid: function() { updateInvalid: function() {
var self = this, var self = this,
errorModel = this.model.errorModel; errorModel = self.model.errorModel;
if (!(errorModel instanceof Backbone.Model)) return this; if (!(errorModel instanceof Backbone.Model)) return this;
this.clearInvalid(); this.clearInvalid();
this.$el.find('.subnode-body').each(function() {
var error = self.keyPathAccessor(
errorModel.toJSON(), self.field.get('name')
);
if (_.isEmpty(error)) return;
self.$el.addClass('subnode-error').append(
$('<div></div>').addClass(
'pgadmin-control-error-message pg-el-offset-4 pg-el-8 help-block'
).text(error)
);
});
}, },
}); });

View File

@ -95,6 +95,12 @@
z-index: 1; z-index: 1;
} }
.error-in-grid {
border-radius: $border-radius !important;
background: $alert-danger-bg !important;
color: $alert-danger-color !important;
}
.pg-prop-status-bar { .pg-prop-status-bar {
padding: 5px; padding: 5px;