First PoC for UI for customizing profile
This commit is contained in:
parent
029bdad4ff
commit
fadf2d1a70
2 changed files with 47 additions and 0 deletions
|
|
@ -646,6 +646,7 @@
|
||||||
><span data-i18n="sidebar.custom-profile.title">Custom profile</span>
|
><span data-i18n="sidebar.custom-profile.title">Custom profile</span>
|
||||||
</h1>
|
</h1>
|
||||||
<form class="flexcolumn flexgrow">
|
<form class="flexcolumn flexgrow">
|
||||||
|
<div id="profile_params"></div>
|
||||||
<textarea
|
<textarea
|
||||||
class="form-control flexgrow"
|
class="form-control flexgrow"
|
||||||
id="profile_upload"
|
id="profile_upload"
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,52 @@ BR.Profile = L.Evented.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
_setValue: function(profileText) {
|
_setValue: function(profileText) {
|
||||||
|
var global = profileText.split('---context:').filter(function(e) {
|
||||||
|
return e.startsWith('global');
|
||||||
|
});
|
||||||
|
if (global) {
|
||||||
|
global = global[0].split('\n').slice(1);
|
||||||
|
var assignRegex = /assign\s*(\w*)\s*=?\s*([\w\.]*)\s*(#.*)?$/;
|
||||||
|
var params = {};
|
||||||
|
global.forEach(function(item) {
|
||||||
|
var match = item.match(assignRegex);
|
||||||
|
if (match) {
|
||||||
|
if (match[2] == 'true') {
|
||||||
|
match[2] = 1;
|
||||||
|
} else if (match[2] == 'false') {
|
||||||
|
match[2] = 0;
|
||||||
|
} else {
|
||||||
|
match[2] = Number.parseFloat(match[2]);
|
||||||
|
}
|
||||||
|
if (Number.isNaN(match[2])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
params[match[1]] = {
|
||||||
|
comment: match[3] ? match[3].replace(/^#\s+|\s+$/g, '') : null,
|
||||||
|
value: match[2]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var paramsSection = L.DomUtil.get('profile_params');
|
||||||
|
paramsSection.innerHTML = '';
|
||||||
|
Object.keys(params).forEach(function(param) {
|
||||||
|
var p = document.createElement('p');
|
||||||
|
var label = document.createElement('label');
|
||||||
|
label.innerHTML = param;
|
||||||
|
var input = document.createElement('input');
|
||||||
|
input.type = 'text';
|
||||||
|
input.value = params[param].value;
|
||||||
|
p.appendChild(label);
|
||||||
|
label.appendChild(input);
|
||||||
|
paramsSection.appendChild(label);
|
||||||
|
if (params[param].comment) {
|
||||||
|
var p = document.createElement('p');
|
||||||
|
p.innerHTML = params[param].comment;
|
||||||
|
paramsSection.append(p);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.editor.setValue(profileText);
|
this.editor.setValue(profileText);
|
||||||
this.editor.markClean();
|
this.editor.markClean();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue