Skip to content

Commit

Permalink
#372 #300 added possibility to adjust parameter width + fixed differe…
Browse files Browse the repository at this point in the history
…nt parameters sizes
  • Loading branch information
bugy committed Feb 24, 2023
1 parent ed9f744 commit dc2b79e
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 40 deletions.
10 changes: 9 additions & 1 deletion samples/configs/parameterized.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
"name": "File upload",
"param": "--file_upload",
"type": "file_upload",
"description": "File upload testing"
"description": "File upload testing",
"ui": {
"width_weight": 2
}
},
{
"name": "Multiple selection",
Expand Down Expand Up @@ -268,6 +271,11 @@
"Value B",
"Value C"
]
},
{
"name": "Multiline test",
"param": "--multiline_text",
"type": "multiline_text"
}
]
}
6 changes: 5 additions & 1 deletion samples/scripts/parameterized.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ echo 'Environment variables:'
echo 'Req_Text='"$Req_Text"
printenv | grep -P '^(PARAM_|EXECUTION)'

sleep 5
trap -- '' SIGINT SIGTERM
while true; do
date +%F_%T
sleep 1
done
5 changes: 4 additions & 1 deletion src/model/external_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def parameter_to_external(parameter):
'secure': parameter.secure,
'fileRecursive': parameter.file_recursive,
'fileType': parameter.file_type,
'requiredParameters': parameter.get_required_parameters()
'requiredParameters': parameter.get_required_parameters(),
'ui': {
'widthWeight': parameter.ui_width_weight
}
}


Expand Down
22 changes: 14 additions & 8 deletions src/model/parameter_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
DependantScriptValuesProvider, NoneValuesProvider, FilesProvider
from model import model_helper
from model.model_helper import resolve_env_vars, replace_auth_vars, is_empty, SECURE_MASK, \
normalize_extension, read_bool_from_config, InvalidValueException, read_str_from_config
normalize_extension, read_bool_from_config, InvalidValueException, read_str_from_config, read_int_from_config
from react.properties import ObservableDict, observable_fields
from utils import file_utils, string_utils
from utils.file_utils import FileMatcher
Expand Down Expand Up @@ -43,7 +43,8 @@
'_list_files_dir', # file_dir, relative to the server path (for listing files)
'file_type',
'file_extensions',
'file_recursive')
'file_recursive',
'ui_width_weight')
class ParameterModel(object):
def __init__(self, parameter_config, username, audit_name, other_params_supplier,
process_invoker: ProcessInvoker,
Expand Down Expand Up @@ -104,6 +105,10 @@ def _reload(self):

self.constant = read_bool_from_config('constant', config, default=False)

ui_config = config.get('ui')
if ui_config:
self.ui_width_weight = read_int_from_config('width_weight', ui_config)

self._validate_config()

values_provider = self._create_values_provider(
Expand Down Expand Up @@ -311,7 +316,7 @@ def validate_value(self, value, *, ignore_required=False):
return 'does not match regex pattern: ' + description
if (not is_empty(self.max_length)) and (len(value) > int(self.max_length)):
return 'is longer than allowed char length (' \
+ str(len(value)) + ' > ' + str(self.max_length) + ')'
+ str(len(value)) + ' > ' + str(self.max_length) + ')'
return None

if self.type == 'file_upload':
Expand All @@ -327,11 +332,11 @@ def validate_value(self, value, *, ignore_required=False):

if (not is_empty(self.max)) and (int_value > int(self.max)):
return 'is greater than allowed value (' \
+ value_string + ' > ' + str(self.max) + ')'
+ value_string + ' > ' + str(self.max) + ')'

if (not is_empty(self.min)) and (int_value < int(self.min)):
return 'is lower than allowed value (' \
+ value_string + ' < ' + str(self.min) + ')'
+ value_string + ' < ' + str(self.min) + ')'
return None

if self.type in ('ip', 'ip4', 'ip6'):
Expand All @@ -351,7 +356,7 @@ def validate_value(self, value, *, ignore_required=False):
if (self.type == 'list') or (self._is_plain_server_file()):
if value not in allowed_values:
return 'has value ' + value_string \
+ ', but should be in ' + repr(allowed_values)
+ ', but should be in ' + repr(allowed_values)
return None

if self.type == PARAM_TYPE_MULTISELECT:
Expand All @@ -361,7 +366,7 @@ def validate_value(self, value, *, ignore_required=False):
if value_element not in allowed_values:
element_str = self.value_to_repr(value_element)
return 'has value ' + element_str \
+ ', but should be in ' + repr(allowed_values)
+ ', but should be in ' + repr(allowed_values)
return None

if self._is_recursive_server_file():
Expand Down Expand Up @@ -544,7 +549,8 @@ def get_sorted_config(param_config):
'file_recursive',
'file_type',
'file_extensions',
'excluded_files']
'excluded_files',
'ui']

def get_order(key):
if key in key_order:
Expand Down
7 changes: 6 additions & 1 deletion src/tests/parameter_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def test_create_full_parameter(self):
'default': default,
'type': type,
'constant': 'false',
'values': values
'values': values,
'ui': {
'width_weight': '3'
}
})

self.assertEqual(name, parameter_model.name)
Expand All @@ -65,6 +68,7 @@ def test_create_full_parameter(self):
self.assertEqual(default, parameter_model.default)
self.assertEqual(type, parameter_model.type)
self.assertEqual(False, parameter_model.constant)
self.assertEqual(3, parameter_model.ui_width_weight)
self.assertCountEqual(values, parameter_model.values)

def test_default_settings(self):
Expand All @@ -76,6 +80,7 @@ def test_default_settings(self):
self.assertEqual(',', parameter_model.separator)
self.assertEqual('text', parameter_model.type)
self.assertEqual(False, parameter_model.constant)
self.assertEqual(None, parameter_model.ui_width_weight)

def test_default_value_from_env(self):
test_utils.set_os_environ_value('my_env_var', 'sky')
Expand Down
15 changes: 10 additions & 5 deletions src/tests/web/script_config_socket_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,23 +257,26 @@ def _text1():
'type': 'text', 'min': None, 'max': None, 'max_length': None, 'values': None, 'secure': False,
'fileRecursive': False, 'fileType': None,
'requiredParameters': [],
'regex': None}
'regex': None,
'ui': {'widthWeight': None}}


def _list1():
return {'name': 'list 1', 'description': None, 'withoutValue': False, 'required': False, 'default': None,
'type': 'list', 'min': None, 'max': None, 'max_length': None, 'values': ['A', 'B', 'C'],
'secure': False, 'fileRecursive': False, 'fileType': None,
'requiredParameters': [],
'regex': None}
'regex': None,
'ui': {'widthWeight': None}}


def _file1():
return {'name': 'file 1', 'description': None, 'withoutValue': False, 'required': False, 'default': None,
'type': 'server_file', 'min': None, 'max': None, 'max_length': None, 'values': ['x', 'y', 'z'],
'secure': False, 'fileRecursive': False, 'fileType': None,
'requiredParameters': [],
'regex': None}
'regex': None,
'ui': {'widthWeight': None}}


def _list2(list2_values):
Expand All @@ -282,13 +285,15 @@ def _list2(list2_values):
'secure': False,
'fileRecursive': False, 'fileType': None,
'requiredParameters': ['file 1'],
'regex': None}
'regex': None,
'ui': {'widthWeight': None}}


def _included_text2():
return {'name': 'included text 2', 'description': None, 'withoutValue': False, 'required': False, 'default': None,
'type': 'text', 'min': None, 'max': None, 'max_length': None, 'values': None, 'secure': False,
'fileRecursive': False, 'fileType': None,
'requiredParameters': [],
'regex': None
'regex': None,
'ui': {'widthWeight': None}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@
<Textfield v-model="max_length" :config="maxLengthField" class="col s4"
@error="handleError(maxLengthField, $event)"/>
</div>

<div v-if="selectedType !== 'multiline_text'" class="row">
<Textfield v-model="uiWidthWeight"
:config="uiWidthWeightField"
class="col s2"
@error="handleError(uiWidthWeightField, $event)"/>
</div>
</form>
</template>

Expand All @@ -105,19 +112,20 @@ import {
fileTypeField,
maxField,
maxLengthField,
regexPatternField,
regexDescriptionField,
minField,
multiselectArgumentTypeField,
nameField,
noValueField,
paramField,
recursiveField,
regexDescriptionField,
regexPatternField,
requiredField,
sameArgParamField,
secureField,
separatorField,
typeField
typeField,
uiWidthWeightField
} from './parameter-fields';
function updateValue(value, configField, newValue) {
Expand Down Expand Up @@ -203,6 +211,7 @@ export default {
fileType: null,
fileExtensions: null,
excludedFiles: null,
uiWidthWeight: null,
nameField,
paramField: Object.assign({}, paramField),
envVarField,
Expand All @@ -226,7 +235,8 @@ export default {
fileDirField,
recursiveField,
fileTypeField,
allowedValuesScriptShellEnabledField: allowedValuesScriptShellEnabledField
allowedValuesScriptShellEnabledField: allowedValuesScriptShellEnabledField,
uiWidthWeightField
}
},
Expand Down Expand Up @@ -257,6 +267,7 @@ export default {
this.fileType = get(config, 'file_type', 'any');
this.fileExtensions = get(config, 'file_extensions', []);
this.excludedFiles = get(config, 'excluded_files', []);
this.uiWidthWeight = config['ui']?.['width_weight']
const defaultValue = get(config, 'default', '');
if (this.isRecursiveFile()) {
Expand Down Expand Up @@ -350,6 +361,15 @@ export default {
} else {
updateValue(this.value, 'default', this.defaultValue);
}
},
uiWidthWeight() {
if (this.uiWidthWeight) {
updateValue(this.value, 'ui', {
'width_weight': parseInt(this.uiWidthWeight)
})
} else {
this.$delete(this.value, 'ui')
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,12 @@ export const fileTypeField = {
type: 'list',
default: 'any',
values: ['any', 'file', 'dir']
};

export const uiWidthWeightField = {
name: 'UI width weight',
description: 'defines field\'s width as a ratio to other fields, e.g. 1 for default, 2 means twice as wide',
type: 'int',
min: 1,
max: 10
};
Loading

0 comments on commit dc2b79e

Please sign in to comment.