Get selected profile vars despite pinned custom

This commit is contained in:
Norbert Renner 2022-02-16 16:12:24 +01:00
parent 4d44153316
commit 7bbbffbd3f

View file

@ -41,47 +41,34 @@ BR.Profile = L.Evented.extend({
update: function (options, cb) { update: function (options, cb) {
var profileName = options.profile, var profileName = options.profile,
profileUrl, profileUrl,
empty = !this.editor.getValue(),
clean = this.editor.isClean(),
loading = false; loading = false;
if (profileName && BR.conf.profilesUrl) { if (profileName && BR.conf.profilesUrl) {
// only synchronize profile editor/parameters with selection if no manual changes in full editor, this.selectedProfileName = profileName;
// else keep custom profile pinned - to prevent changes in another profile overwriting previous ones
if (empty || clean) {
this.profileName = profileName;
if (!(profileName in this.cache)) {
profileUrl = BR.conf.profilesUrl + profileName + '.brf';
loading = true;
BR.Util.get(
profileUrl,
L.bind(function (err, profileText) {
if (err) {
console.warn('Error getting profile from "' + profileUrl + '": ' + err);
if (cb) cb();
return;
}
this.cache[profileName] = profileText; if (!(profileName in this.cache)) {
profileUrl = BR.conf.profilesUrl + profileName + '.brf';
// don't set when option has changed while loading loading = true;
if (!this.profileName || this.profileName === profileName) { BR.Util.get(
this._setValue(profileText); profileUrl,
} L.bind(function (err, profileText) {
if (err) {
console.warn('Error getting profile from "' + profileUrl + '": ' + err);
if (cb) cb(); if (cb) cb();
}, this) return;
); }
} else {
this._setValue(this.cache[profileName]);
}
if (!this.pinned.hidden) { this.cache[profileName] = profileText;
this.pinned.hidden = true;
} // don't set when option has changed while loading
if (!this.profileName || this.selectedProfileName === profileName) {
this._updateProfile(profileName, profileText);
}
if (cb) cb();
}, this)
);
} else { } else {
if (this.pinned.hidden) { this._updateProfile(profileName, this.cache[profileName]);
this.pinned.hidden = false;
}
} }
} }
@ -107,7 +94,7 @@ BR.Profile = L.Evented.extend({
} }
} }
const profileText = this._getProfileText(); const profileText = this._getSelectedProfileText();
if (!profileText) return value; if (!profileText) return value;
const regex = new RegExp(`assign\\s*${name}\\s*=?\\s*([\\w\\.]*)`); const regex = new RegExp(`assign\\s*${name}\\s*=?\\s*([\\w\\.]*)`);
@ -194,6 +181,26 @@ BR.Profile = L.Evented.extend({
}); });
}, },
_updateProfile: function (profileName, profileText) {
const empty = !this.editor.getValue();
const clean = this.editor.isClean();
// only synchronize profile editor/parameters with selection if no manual changes in full editor,
// else keep custom profile pinned - to prevent changes in another profile overwriting previous ones
if (empty || clean) {
this.profileName = profileName;
this._setValue(profileText);
if (!this.pinned.hidden) {
this.pinned.hidden = true;
}
} else {
if (this.pinned.hidden) {
this.pinned.hidden = false;
}
}
},
_setValue: function (profileText) { _setValue: function (profileText) {
profileText = profileText || ''; profileText = profileText || '';
@ -369,4 +376,8 @@ BR.Profile = L.Evented.extend({
_getProfileText: function () { _getProfileText: function () {
return this.editor.getValue(); return this.editor.getValue();
}, },
_getSelectedProfileText: function () {
return this.cache[this.selectedProfileName] ?? this.editor.getValue();
},
}); });