diff --git a/front-generator/render-params.json b/front-generator/render-params.json index 0e1b2b5..10b995e 100644 --- a/front-generator/render-params.json +++ b/front-generator/render-params.json @@ -22,7 +22,7 @@ "values": [{"label": "Нормальный", "value": "false"}, {"label": "Тест (CW)", "value": "true"}] }, {"widget": "number", "label": "Центральная частота, КГц", "name": "txCentralFreq", "min": 900000, "step": 0.01, "v_show": "paramRxtx.txModulatorIsTest"}, - {"widget": "number", "label": "Ослабление, дБ", "name": "txAttenuation", "min": 0, "step": 1} + {"widget": "number", "label": "Ослабление, дБ", "name": "txAttenuation", "max": 0, "min": -40, "step": 1} ] }, { @@ -154,7 +154,7 @@ "values": [{"label": "Ethernet", "value": "false"}, {"label": "Тест", "value": "true"}] }, {"widget": "h3", "label": "Параметры передачи"}, - {"widget": "number-int", "label": "Центральная частота, КГц", "name": "txCentralFreq", "min": 950000, "max": 6000000}, + {"widget": "number-int", "label": "Центральная частота, КГц", "name": "txCentralFreq", "min": 950000, "max": 6000000, "step": 0.01}, {"widget": "number-int", "label": "Символьная скорость, Бод", "name": "txBaudrate", "min": 200000, "max": 54000000}, { "widget": "select", "label": "Roll-off", "name": "txRolloff", @@ -164,7 +164,7 @@ "widget": "select", "label": "Номер последовательности Голда", "name": "txGoldan", "values": [{"label": "0", "value": "0"}, {"label": "1", "value": "1"}] }, - {"widget": "number", "label": "Ослабление, дБ", "name": "txAttenuation", "min": 0, "step": 1} + {"widget": "number", "label": "Ослабление, дБ", "name": "txAttenuation", "max": 0, "min": -40, "step": 0.25} ] }, { @@ -198,8 +198,8 @@ "childs": [ {"widget": "h3", "label": "Авто-регулировка мощности"}, {"widget": "checkbox", "label": "Авто-регулировка мощности", "name": "aupcEn"}, - {"widget": "number", "label": "Минимальное ослабление, дБ", "name": "aupcMinAttenuation", "min": 0, "step": 0.01, "max": 10}, - {"widget": "number", "label": "Максимальное ослабление, дБ", "name": "aupcMaxAttenuation", "min": 0, "step": 0.01, "max": 10}, + {"widget": "number", "label": "Минимальное ослабление, дБ", "name": "aupcMinAttenuation", "min": 0, "step": 0.1, "max": 10}, + {"widget": "number", "label": "Максимальное ослабление, дБ", "name": "aupcMaxAttenuation", "min": 0, "step": 0.1, "max": 10}, {"widget": "number", "label": "Требуемое ОСШ", "name": "aupcRequiredSnr", "min": 0, "step": 0.01, "max": 10} ] }, @@ -214,7 +214,7 @@ {"widget": "number", "label": "Усиление, дБ", "name": "rxManualGain", "min": -40, "step": 0.01, "max": 40, "v_show": "paramRxtx.rxAgcEn === false"}, {"widget": "watch-expr", "label": "Текущее усиление", "expr": "paramRxtx.rxManualGain", "v_show": "paramRxtx.rxAgcEn === true"}, {"widget": "checkbox", "label": "Инверсия спектра", "name": "rxSpectrumInversion"}, - {"widget": "number-int", "label": "Центральная частота, КГц", "name": "rxCentralFreq", "min": 950000, "max": 6000000}, + {"widget": "number-int", "label": "Центральная частота, КГц", "name": "rxCentralFreq", "min": 950000, "max": 6000000, "step": 0.01}, {"widget": "number-int", "label": "Символьная скорость, Бод", "name": "rxBaudrate", "min": 200000, "max": 54000000}, { "widget": "select", "label": "Roll-off", "name": "rxRolloff", diff --git a/front-generator/render.py b/front-generator/render.py index 43d6d79..5512761 100644 --- a/front-generator/render.py +++ b/front-generator/render.py @@ -22,6 +22,8 @@ def extract_param_names(mc): copy_fields['min'] = widget['min'] if 'max' in widget: copy_fields['max'] = widget['max'] + if 'step' in widget: + copy_fields['step'] = widget['step'] match widget['widget']: case 'select': return [{"initValue": widget['values'][0]['value']} | copy_fields] diff --git a/front-generator/template/common/widgets.j2 b/front-generator/template/common/widgets.j2 index 647f718..923397c 100644 --- a/front-generator/template/common/widgets.j2 +++ b/front-generator/template/common/widgets.j2 @@ -6,11 +6,11 @@ {# https://ru.stackoverflow.com/questions/1241064 #} {% macro build_widget_number(param_group, widget) %}{% endmacro %} -{% macro js_build_number_int_validator(widget) %}{{ '{' }}{% if widget['min'] %}min:{{ widget['min'] }},{% endif %}{% if widget['max'] %}max:{{ widget['max'] }}{% endif %}{{ '}' }}{% endmacro %} +{% macro js_build_number_number_validator(widget) %}{{ '{' }}{% if widget['min'] %}min:{{ widget['min'] }},{% endif %}{% if widget['max'] %}max:{{ widget['max'] }},{% endif %}{% if widget['step'] %}step:{{ widget['step'] }}{% endif %}{{ '}' }}{% endmacro %} {% macro build_widget_number_int(param_group, widget) %}{% endmacro %} @@ -79,15 +79,15 @@ {% macro build_getter_js(param_group, widget) %}{% if widget.widget in ['flex-container', 'settings-container', 'h2', 'h3', 'submit', 'watch', 'watch-expr'] %}null{% elif widget.widget in ['checkbox', 'number', 'select', 'ip-address', 'modulation-modcod', 'modulation-speed'] %}this.param{{ param_group | title }}.{{ widget.name }}{% -elif widget.widget == 'number-int' %}parseInt(this.param{{ param_group | title }}.{{ widget.name }}.replace(/[^0-9]/g, '')){% +elif widget.widget == 'number-int' %}parseFloat(this.param{{ param_group | title }}.{{ widget.name }}.replace(/[^0-9,.]/g, '').replace(',', '.')){% else %}
Widget '{{ widget.widget }}' not defined!
{{ widget }}
{% endif %}{% endmacro %} {% macro build_setter_js(param_group, widget, expr) %}{% if widget.widget in ['flex-container', 'settings-container', 'h2', 'h3', 'submit', 'watch', 'watch-expr'] %}null{% elif widget.widget in ['checkbox', 'number', 'select', 'ip-address', 'modulation-modcod', 'modulation-speed'] %}this.param{{ param_group | title }}.{{ widget.name }} = {{ expr }}{% -elif widget.widget == 'number-int' %}this.param{{ param_group | title }}.{{ widget.name }} = this.inputFormatInt({{ expr }}, {{ js_build_number_int_validator(widget) }}){% +elif widget.widget == 'number-int' %}this.param{{ param_group | title }}.{{ widget.name }} = this.inputFormatNumber({{ expr }}, {{ js_build_number_number_validator(widget) }}){% else %}Widget '{{ widget.widget }}' not defined!
{{ widget }}
{% endif %}{% endmacro %} {% macro build_setter(param_group, widget, expr) %}{% if widget.widget in ['flex-container', 'settings-container', 'h2', 'h3', 'submit', 'watch', 'watch-expr'] %}null{% elif widget.widget in ['checkbox', 'number', 'select', 'ip-address', 'modulation-modcod', 'modulation-speed'] %}param{{ param_group | title }}.{{ widget.name }} = {{ expr }}{% -elif widget.widget == 'number-int' %}param{{ param_group | title }}.{{ widget.name }} = ({{ expr }}).toString(){% +elif widget.widget == 'number-int' %}param{{ param_group | title }}.{{ widget.name }} = inputFormatNumber({{ expr }}, {{ js_build_number_number_validator(widget) }}){% else %}Widget '{{ widget.widget }}' not defined!
{{ widget }}
{% endif %}{% endmacro %} diff --git a/front-generator/template/main.html b/front-generator/template/main.html index be4a111..26be629 100644 --- a/front-generator/template/main.html +++ b/front-generator/template/main.html @@ -153,10 +153,12 @@ return [] } }, - inputFormatInt(src, validation) { + inputFormatNumber(src, validation) { if (validation === null || validation === undefined) { validation = {} } - const rawVal = src.toString().replace(/[^0-9]/g, '') - let result = rawVal === '' ? 0 : parseInt(rawVal) + const rawVal = src.toString().replace(/[^0-9.,]/g, '').replace(',', '.') + let result = rawVal === '' ? 0 : parseFloat(rawVal) + const step = 'step' in validation ? validation['step']: 1.0 + result = Math.round(result / step) * step if ('min' in validation) { if (result <= validation['min']) { result = validation['min'] } } if ('max' in validation) { if (result >= validation['max']) { result = validation['max'] } } return result.toLocaleString() diff --git a/static/main-scpc.html b/static/main-scpc.html index bad893e..40c5633 100644 --- a/static/main-scpc.html +++ b/static/main-scpc.html @@ -160,11 +160,11 @@