mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-20 11:48:31 -06:00
The changed value of a multiline/text control was not saved in the
configuration database due to unable to identify the change properly. Thanks Dave for reporting. This also includes a support to use a 'text' type of preference, and show help string next to the control.
This commit is contained in:
parent
a28df1e0a2
commit
7bce6dd903
@ -49,22 +49,34 @@ define(
|
|||||||
* We will use only one collection object to keep track of all the
|
* We will use only one collection object to keep track of all the
|
||||||
* preferences.
|
* preferences.
|
||||||
*/
|
*/
|
||||||
var preferences = this.preferences = new (Backbone.Collection.extend({
|
var changed = {},
|
||||||
model: PreferenceModel,
|
preferences = this.preferences = new (Backbone.Collection.extend({
|
||||||
url: "{{ url_for('preferences.preferences') }}",
|
model: PreferenceModel,
|
||||||
updateAll: function() {
|
url: "{{ url_for('preferences.preferences') }}",
|
||||||
// We will send only the modified data to the server.
|
updateAll: function() {
|
||||||
this.each(function(m) {
|
// We will send only the modified data to the server.
|
||||||
if (m.hasChanged()) {
|
for (var key in changed) {
|
||||||
m.save({
|
this.get(key).save();
|
||||||
fail: function() {
|
}
|
||||||
}
|
return true;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
}))(null);
|
||||||
return true;
|
|
||||||
|
preferences.on('reset', function() {
|
||||||
|
// Reset the changed variables
|
||||||
|
changed = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
preferences.on('change', function(m) {
|
||||||
|
var id = m.get('id');
|
||||||
|
if (!(id in changed)) {
|
||||||
|
// Keep track of the original value
|
||||||
|
changed[id] = m._previousAttributes.value;
|
||||||
|
} else if (_.isEqual(m.get('value'), changed[id])) {
|
||||||
|
// Remove unchanged models.
|
||||||
|
delete changed[id];
|
||||||
}
|
}
|
||||||
}))(null);
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function: renderPreferencePanel
|
* Function: renderPreferencePanel
|
||||||
@ -96,7 +108,9 @@ define(
|
|||||||
_.each(prefs, function(p) {
|
_.each(prefs, function(p) {
|
||||||
|
|
||||||
var m = preferences.get(p.id),
|
var m = preferences.get(p.id),
|
||||||
f = new Backform.Field(_.extend({}, p, {id: 'value', name: 'value'})),
|
f = new Backform.Field(
|
||||||
|
_.extend({}, p, {id: 'value', name: 'value'})
|
||||||
|
),
|
||||||
cntr = new (f.get("control")) ({
|
cntr = new (f.get("control")) ({
|
||||||
field: f,
|
field: f,
|
||||||
model: m
|
model: m
|
||||||
@ -171,6 +185,8 @@ define(
|
|||||||
*/
|
*/
|
||||||
getControlMappedForType = function(p) {
|
getControlMappedForType = function(p) {
|
||||||
switch(p.type) {
|
switch(p.type) {
|
||||||
|
case 'text':
|
||||||
|
return 'input';
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
p.options = {
|
p.options = {
|
||||||
onText: '{{ _('True') }}',
|
onText: '{{ _('True') }}',
|
||||||
@ -283,6 +299,9 @@ define(
|
|||||||
if (!p.control) {
|
if (!p.control) {
|
||||||
p.control = getControlMappedForType(p);
|
p.control = getControlMappedForType(p);
|
||||||
}
|
}
|
||||||
|
if (p.help_str) {
|
||||||
|
p.helpMessage = p.help_str;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
d.sortable = false;
|
d.sortable = false;
|
||||||
|
@ -368,7 +368,7 @@ class Preferences(object):
|
|||||||
assert _type is not None, "Type for a preference can not be none!"
|
assert _type is not None, "Type for a preference can not be none!"
|
||||||
assert _type in (
|
assert _type in (
|
||||||
'boolean', 'integer', 'numeric', 'date', 'datetime',
|
'boolean', 'integer', 'numeric', 'date', 'datetime',
|
||||||
'options', 'multiline', 'switch', 'node'
|
'options', 'multiline', 'switch', 'node', 'text'
|
||||||
), "Type can not be found in the defined list!"
|
), "Type can not be found in the defined list!"
|
||||||
|
|
||||||
(cat['preferences'])[name] = res = _Preference(
|
(cat['preferences'])[name] = res = _Preference(
|
||||||
@ -523,6 +523,7 @@ Did you forget to register it?"""
|
|||||||
try:
|
try:
|
||||||
pref.set(value)
|
pref.set(value)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
current_app.logger.exeception(e)
|
||||||
return False, str(e)
|
return False, str(e)
|
||||||
|
|
||||||
return True, None
|
return True, None
|
||||||
|
Loading…
Reference in New Issue
Block a user