mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Sequence related validation/fixes. Fixes #1119
1) Add proper validation checks for fields. 2) Fixed wrong sql generation due to incorrect conditions in template.
This commit is contained in:
committed by
Dave Page
parent
7cf4ac2474
commit
5900848842
@@ -146,7 +146,8 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
|
|||||||
mode: ['properties', 'create', 'edit']
|
mode: ['properties', 'create', 'edit']
|
||||||
},{
|
},{
|
||||||
id: 'increment', label: '{{ _('Increment') }}', type: 'int',
|
id: 'increment', label: '{{ _('Increment') }}', type: 'int',
|
||||||
mode: ['properties', 'create', 'edit'], group: '{{ _('Definition') }}'
|
mode: ['properties', 'create', 'edit'], group: '{{ _('Definition') }}',
|
||||||
|
min: 1
|
||||||
},{
|
},{
|
||||||
id: 'start', label: '{{ _('Start') }}', type: 'int',
|
id: 'start', label: '{{ _('Start') }}', type: 'int',
|
||||||
mode: ['create'], group: '{{ _('Definition') }}'
|
mode: ['create'], group: '{{ _('Definition') }}'
|
||||||
@@ -161,7 +162,8 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
|
|||||||
mode: ['properties', 'create', 'edit'], group: '{{ _('Definition') }}'
|
mode: ['properties', 'create', 'edit'], group: '{{ _('Definition') }}'
|
||||||
},{
|
},{
|
||||||
id: 'cache', label: '{{ _('Cache') }}', type: 'int',
|
id: 'cache', label: '{{ _('Cache') }}', type: 'int',
|
||||||
mode: ['properties', 'create', 'edit'], group: '{{ _('Definition') }}'
|
mode: ['properties', 'create', 'edit'], group: '{{ _('Definition') }}',
|
||||||
|
min: 1
|
||||||
},{
|
},{
|
||||||
id: 'cycled', label: '{{ _('Cycled') }}', type: 'switch',
|
id: 'cycled', label: '{{ _('Cycled') }}', type: 'switch',
|
||||||
mode: ['properties', 'create', 'edit'], group: '{{ _('Definition') }}',
|
mode: ['properties', 'create', 'edit'], group: '{{ _('Definition') }}',
|
||||||
@@ -193,11 +195,12 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
|
|||||||
* the GUI for the respective control.
|
* the GUI for the respective control.
|
||||||
*/
|
*/
|
||||||
validate: function() {
|
validate: function() {
|
||||||
var msg = undefined;
|
var msg = undefined,
|
||||||
|
minimum = this.get('minimum'),
|
||||||
|
maximum = this.get('maximum');
|
||||||
|
start = this.get('start');
|
||||||
// Clear any existing error msg.
|
// Clear any existing error msg.
|
||||||
this.errorModel.unset('name');
|
this.errorModel.clear();
|
||||||
this.errorModel.unset('seqowner');
|
|
||||||
this.errorModel.unset('schema');
|
|
||||||
|
|
||||||
if (_.isUndefined(this.get('name'))
|
if (_.isUndefined(this.get('name'))
|
||||||
|| String(this.get('name')).replace(/^\s+|\s+$/g, '') == '') {
|
|| String(this.get('name')).replace(/^\s+|\s+$/g, '') == '') {
|
||||||
@@ -219,6 +222,26 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
|
|||||||
this.errorModel.set('schema', msg);
|
this.errorModel.set('schema', msg);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var min_lt = '{{ _('Minimum value must be less than maximum value.') }}',
|
||||||
|
start_lt = '{{ _('Start value cannot be less than minimum value.') }}',
|
||||||
|
start_gt = '{{ _('Start value cannot be greater than maximum value.') }}';
|
||||||
|
if ((minimum == 0 && maximum == 0) ||
|
||||||
|
(parseInt(minimum, 10) >= parseInt(maximum, 10))) {
|
||||||
|
msg = min_lt
|
||||||
|
this.errorModel.set('minimum', msg);
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
else if (start < minimum) {
|
||||||
|
msg = start_lt
|
||||||
|
this.errorModel.set('start', msg);
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
else if (start > maximum) {
|
||||||
|
msg = start_gt
|
||||||
|
this.errorModel.set('start', msg);
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,14 +3,16 @@ CREATE SEQUENCE {{ conn|qtIdent(data.schema) }}.{{ conn|qtIdent(data.name) }}
|
|||||||
{% if data.cycled and data.cycled == True %}
|
{% if data.cycled and data.cycled == True %}
|
||||||
CYCLE
|
CYCLE
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if data.increment %}
|
{% if data.increment is defined %}
|
||||||
INCREMENT {{data.increment}}
|
INCREMENT {{data.increment}}
|
||||||
{% endif %}{% if data.start %}
|
{% endif %}{% if data.start is defined %}
|
||||||
START {{data.start}}
|
START {{data.start}}
|
||||||
{% endif %}{% if data.minimum %}
|
{% elif data.current_value is defined %}
|
||||||
|
START {{data.current_value}}
|
||||||
|
{% endif %}{% if data.minimum is defined %}
|
||||||
MINVALUE {{data.minimum}}
|
MINVALUE {{data.minimum}}
|
||||||
{% endif %}{% if data.maximum %}
|
{% endif %}{% if data.maximum is defined %}
|
||||||
MAXVALUE {{data.maximum}}
|
MAXVALUE {{data.maximum}}
|
||||||
{% endif %}{% if data.cache %}
|
{% endif %}{% if data.cache is defined %}
|
||||||
CACHE {{data.cache}}{% endif %};
|
CACHE {{data.cache}}{% endif %};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user