Merge pull request #277 from nrenner/275-custom-profile-cache
Prevent overwriting profile changes
This commit is contained in:
commit
6178898815
3 changed files with 70 additions and 30 deletions
|
|
@ -483,6 +483,12 @@ table.dataTable.display tbody tr:hover.selected {
|
||||||
color: #737373;
|
color: #737373;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#profile-pinned {
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: 4px;
|
||||||
|
color: #777;
|
||||||
|
}
|
||||||
|
|
||||||
.leaflet-sidebar-content {
|
.leaflet-sidebar-content {
|
||||||
/* for optional-layers-tree */
|
/* for optional-layers-tree */
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
|
|
|
||||||
|
|
@ -686,6 +686,7 @@
|
||||||
>Profile</a
|
>Profile</a
|
||||||
>
|
>
|
||||||
</li>
|
</li>
|
||||||
|
<span id="profile-pinned" hidden><i class="fa fa-thumb-tack"></i></span>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content flexcolumn flexgrow" id="profileEditorTabsContent">
|
<div class="tab-content flexcolumn flexgrow" id="profileEditorTabsContent">
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ BR.Profile = L.Evented.extend({
|
||||||
L.DomUtil.get('upload').onclick = L.bind(this._upload, this);
|
L.DomUtil.get('upload').onclick = L.bind(this._upload, this);
|
||||||
L.DomUtil.get('clear').onclick = L.bind(this.clear, this);
|
L.DomUtil.get('clear').onclick = L.bind(this.clear, this);
|
||||||
|
|
||||||
|
this.pinned = L.DomUtil.get('profile-pinned');
|
||||||
|
|
||||||
this.message = new BR.Message('profile_message', {
|
this.message = new BR.Message('profile_message', {
|
||||||
alert: true
|
alert: true
|
||||||
});
|
});
|
||||||
|
|
@ -28,6 +30,8 @@ BR.Profile = L.Evented.extend({
|
||||||
var button = evt.target || evt.srcElement;
|
var button = evt.target || evt.srcElement;
|
||||||
|
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
||||||
|
this.editor.markClean();
|
||||||
this._setValue('');
|
this._setValue('');
|
||||||
|
|
||||||
this.fire('clear');
|
this.fire('clear');
|
||||||
|
|
@ -40,28 +44,40 @@ BR.Profile = L.Evented.extend({
|
||||||
empty = !this.editor.getValue(),
|
empty = !this.editor.getValue(),
|
||||||
clean = this.editor.isClean();
|
clean = this.editor.isClean();
|
||||||
|
|
||||||
if (profileName && BR.conf.profilesUrl && (empty || clean)) {
|
if (profileName && BR.conf.profilesUrl) {
|
||||||
this.profileName = profileName;
|
// only synchronize profile editor/parameters with selection if no manual changes in full editor,
|
||||||
if (!(profileName in this.cache)) {
|
// else keep custom profile pinned - to prevent changes in another profile overwriting previous ones
|
||||||
profileUrl = BR.conf.profilesUrl + profileName + '.brf';
|
if (empty || clean) {
|
||||||
BR.Util.get(
|
this.profileName = profileName;
|
||||||
profileUrl,
|
if (!(profileName in this.cache)) {
|
||||||
L.bind(function(err, profileText) {
|
profileUrl = BR.conf.profilesUrl + profileName + '.brf';
|
||||||
if (err) {
|
BR.Util.get(
|
||||||
console.warn('Error getting profile from "' + profileUrl + '": ' + err);
|
profileUrl,
|
||||||
return;
|
L.bind(function(err, profileText) {
|
||||||
}
|
if (err) {
|
||||||
|
console.warn('Error getting profile from "' + profileUrl + '": ' + err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.cache[profileName] = profileText;
|
this.cache[profileName] = profileText;
|
||||||
|
|
||||||
// don't set when option has changed while loading
|
// don't set when option has changed while loading
|
||||||
if (!this.profileName || this.profileName === profileName) {
|
if (!this.profileName || this.profileName === profileName) {
|
||||||
this._setValue(profileText);
|
this._setValue(profileText);
|
||||||
}
|
}
|
||||||
}, this)
|
}, this)
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
this._setValue(this.cache[profileName]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.pinned.hidden) {
|
||||||
|
this.pinned.hidden = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this._setValue(this.cache[profileName]);
|
if (this.pinned.hidden) {
|
||||||
|
this.pinned.hidden = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -86,6 +102,7 @@ BR.Profile = L.Evented.extend({
|
||||||
callback: L.bind(function(err, profileId, profileText) {
|
callback: L.bind(function(err, profileId, profileText) {
|
||||||
$(button).blur();
|
$(button).blur();
|
||||||
if (!err) {
|
if (!err) {
|
||||||
|
this.profileName = profileId;
|
||||||
this.cache[profileId] = profileText;
|
this.cache[profileId] = profileText;
|
||||||
|
|
||||||
if (!this.saveWarningShown) {
|
if (!this.saveWarningShown) {
|
||||||
|
|
@ -97,8 +114,7 @@ BR.Profile = L.Evented.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_buildCustomProfile: function() {
|
_buildCustomProfile: function(profileText) {
|
||||||
var profileText = this.cache[this.profileName];
|
|
||||||
document.querySelectorAll('#profile_params input, #profile_params select').forEach(function(input) {
|
document.querySelectorAll('#profile_params input, #profile_params select').forEach(function(input) {
|
||||||
var name = input.name;
|
var name = input.name;
|
||||||
var value;
|
var value;
|
||||||
|
|
@ -121,28 +137,39 @@ BR.Profile = L.Evented.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
_save: function(evt) {
|
_save: function(evt) {
|
||||||
var profileText = this._buildCustomProfile();
|
var profileText = this._buildCustomProfile(this.editor.getValue());
|
||||||
var that = this;
|
var that = this;
|
||||||
this.fire('update', {
|
this.fire('update', {
|
||||||
profileText: profileText,
|
profileText: profileText,
|
||||||
callback: function(err, profileId, profileText) {
|
callback: function(err, profileId, profileText) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
|
that.profileName = profileId;
|
||||||
that.cache[profileId] = profileText;
|
that.cache[profileId] = profileText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_setValue: function(profileText, profileEditorActivated) {
|
_setValue: function(profileText) {
|
||||||
profileText = profileText || '';
|
profileText = profileText || '';
|
||||||
|
|
||||||
if (L.DomUtil.get('profile_editor').classList.contains('active')) {
|
var clean = this.editor.isClean();
|
||||||
// Set value of the full editor and exit
|
|
||||||
this.editor.setValue(profileText);
|
// Always set value of the full editor, even if not active.
|
||||||
|
// Full editor is master, the parameter form always gets the text from it (not cache).
|
||||||
|
this.editor.setValue(profileText);
|
||||||
|
|
||||||
|
// keep dirty state (manually modified; setValue also sets dirty)
|
||||||
|
if (clean) {
|
||||||
this.editor.markClean();
|
this.editor.markClean();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._isParamsFormActive()) {
|
||||||
|
this._buildParamsForm(profileText);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_buildParamsForm: function(profileText) {
|
||||||
if (!profileText) return;
|
if (!profileText) return;
|
||||||
|
|
||||||
// Otherwise, create user friendly form
|
// Otherwise, create user friendly form
|
||||||
|
|
@ -278,11 +305,17 @@ BR.Profile = L.Evented.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_isParamsFormActive: function() {
|
||||||
|
return L.DomUtil.get('profile_params_container').classList.contains('active');
|
||||||
|
},
|
||||||
|
|
||||||
_activateSecondaryTab: function() {
|
_activateSecondaryTab: function() {
|
||||||
if (L.DomUtil.get('profile_params_container').classList.contains('active')) {
|
var profileText = this.editor.getValue();
|
||||||
this._setValue(this.editor.getValue());
|
|
||||||
|
if (this._isParamsFormActive()) {
|
||||||
|
this._buildParamsForm(profileText);
|
||||||
} else {
|
} else {
|
||||||
this._setValue(this._buildCustomProfile());
|
this._setValue(this._buildCustomProfile(profileText));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue