1
0
mirror of https://github.com/gsi-upm/soil synced 2024-11-26 21:02:29 +00:00
soil/templates/js/template.js

99 lines
4.9 KiB
JavaScript
Raw Normal View History

2018-01-30 18:37:46 +00:00
// Add model parameters that can be edited prior to a model run
var initGUI = function(model_params) {
var addBooleanInput = function(name, value) {
var checked = (value) ? 'checked' : 'value';
2018-01-31 10:33:36 +00:00
var wrapper = $('<div>').attr('class', 'col-sm-6').height('110px');
2018-01-30 18:37:46 +00:00
var input_group = $('<div>').attr('class', 'input-group').appendTo(wrapper);
var label = $('<label>').attr('for', name).attr('class', 'checkbox').appendTo(input_group);
var input = $('<input>') .attr('class', 'form-check-input').attr('id', name).attr('type', 'checkbox').attr(checked, checked).appendTo(label);
input.after(name);
$('#wrapper-settings').append(wrapper);
};
var addSliderInput = function(name, value) {
2018-01-31 10:33:36 +00:00
var wrapper = $('<div>').attr('class', 'col-sm-6').height('110px');
2018-01-30 18:37:46 +00:00
var label = $('<div>').width('100%').text(name).css('text-align', 'center').css('font-weight', 'bolder').appendTo(wrapper);
var input = $('<input>').attr('id', name).attr('type', 'text').attr('data-slider-min', '0.001').attr('data-slider-max', '1').attr('data-slider-step', '0.001').attr('data-slider-value', value).attr('data-slider-tooltip', 'hide').css('padding', '0 10px').appendTo(wrapper);
var span = $('<div>').attr('id', name + '_value').text('Current value: ').width('100%').css('padding-top', '10px').appendTo(wrapper);
var current_value = $('<span>').attr('id', name + '_number').text(value).appendTo(span);
var button_group = $('<div>').attr('class', 'btn-group').attr('role', 'group').css('position', 'absolute').css('right', '15px').appendTo(span);
var button_down = $('<button>').attr('type', 'button').attr('class', 'btn btn-default btn-default-down').appendTo(button_group);
var button_up = $('<button>').attr('type', 'button').attr('class', 'btn btn-default btn-default-down').appendTo(button_group);
$('<span>').attr('class', 'glyphicon glyphicon-chevron-down').attr('aria-hidden', 'true').appendTo(button_down);
$('<span>').attr('class', 'glyphicon glyphicon-chevron-up').attr('aria-hidden', 'true').appendTo(button_up);
$('#wrapper-settings').append(wrapper);
input.slider().on('change', function(slideEvt) {
current_value.text(slideEvt.value.newValue);
});
2018-02-01 12:46:51 +00:00
var timeout, interval;
button_down.on('mousedown', function() {
2018-01-30 18:37:46 +00:00
input.slider('setValue', input.slider('getValue') - 0.001);
current_value.text(input.slider('getValue'));
2018-02-01 12:46:51 +00:00
timeout = setTimeout(function() {
interval = setInterval(function() {
input.slider('setValue', input.slider('getValue') - 0.001);
current_value.text(input.slider('getValue'));
}, 30);
}, 500);
2018-01-30 18:37:46 +00:00
});
2018-02-01 12:46:51 +00:00
button_down.on('mouseup', function() {
clearTimeout(timeout);
clearInterval(interval);
});
button_up.on('mousedown', function() {
2018-01-30 18:37:46 +00:00
input.slider('setValue', input.slider('getValue') + 0.001);
current_value.text(input.slider('getValue'));
2018-02-01 12:46:51 +00:00
timeout = setTimeout(function() {
interval = setInterval(function() {
input.slider('setValue', input.slider('getValue') + 0.001);
current_value.text(input.slider('getValue'));
}, 30);
}, 500);
});
button_up.on('mouseup', function() {
clearTimeout(timeout);
clearInterval(interval);
});
2018-01-30 18:37:46 +00:00
};
2018-04-11 17:40:59 +00:00
var addNumberInput = function(name, value) {
var wrapper = $('<div>').attr('class', 'col-sm-6').height('110px');
var label = $('<div>').width('100%').text(name).css('text-align', 'center').css('font-weight', 'bolder').appendTo(wrapper);
var input = $('<input>').attr('id', name).attr('type', 'number').attr('class', 'form-control').attr('value', value).attr('min', 0).css('margin-top', '18px').appendTo(wrapper);
$('#wrapper-settings').append(wrapper);
}
2018-01-30 18:37:46 +00:00
var addTextBox = function(param, obj) {
var well = $('<div class="well">' + obj.value + '</div>')[0];
sidebar.append(well);
};
for (var option in model_params) {
2018-04-10 16:26:24 +00:00
2018-01-30 18:37:46 +00:00
var type = typeof(model_params[option]);
var param_str = String(option);
switch (model_params[option]['type']) {
2018-02-01 18:37:10 +00:00
case 'boolean':
2018-01-30 18:37:46 +00:00
addBooleanInput(model_params[option]['label'], model_params[option]['value']);
break;
2018-02-01 18:37:10 +00:00
case 'number':
2018-01-30 18:37:46 +00:00
addSliderInput(model_params[option]['label'], model_params[option]['value']);
break;
2018-04-11 17:40:59 +00:00
case 'great_number':
addNumberInput(model_params[option]['label'], model_params[option]['value']);
break;
2018-02-01 18:37:10 +00:00
default:
2018-04-11 17:40:59 +00:00
console.warn(model_params[option]['label'] + ' not defined!');
2018-01-30 18:37:46 +00:00
break;
}
}
};