implement field sorting

This commit is contained in:
Jakob Ketterl 2020-05-17 20:25:49 +02:00
parent 9dd7a7e653
commit 63475dda78

View File

@ -114,11 +114,13 @@ SdrDevice.prototype.getMappings = function() {
label: "Profiles", label: "Profiles",
initialValue: [], initialValue: [],
includeInDefault: true, includeInDefault: true,
position: 100
}, },
"scheduler": { "scheduler": {
constructor: SchedulerInput, constructor: SchedulerInput,
label: "Scheduler", label: "Scheduler",
initialValue: {} initialValue: {},
position: 101
}, },
"rf_gain": { "rf_gain": {
constructor: TextInput, constructor: TextInput,
@ -148,10 +150,19 @@ SdrDevice.prototype.getInitialValue = function(key) {
return mapping && ('initialValue' in mapping) ? mapping['initialValue'] : false; return mapping && ('initialValue' in mapping) ? mapping['initialValue'] : false;
}; };
SdrDevice.prototype.getPosition = function(key) {
var mapping = this.getMapping(key);
return mapping && mapping.position || 10;
};
SdrDevice.prototype.render = function() { SdrDevice.prototype.render = function() {
var self = this; var self = this;
self.el.empty(); self.el.empty();
$.each(this.getData(), function(key, value) { var data = this.getData();
Object.keys(data).sort(function(a, b){
return self.getPosition(a) - self.getPosition(b);
}).forEach(function(key){
var value = data[key];
var inputClass = self.getInputClass(key); var inputClass = self.getInputClass(key);
var input = new inputClass(key, value, self.getLabel(key)); var input = new inputClass(key, value, self.getLabel(key));
self.inputs[key] = input; self.inputs[key] = input;