Better ordering of HOT parameters in generated UI form
This commit makes UI generator respect parameter_groups section of HOT template (if present). Application name input was moved to a separate step before HOT parameters. Also respect label attribute of HOT parameters Implements blueprint hot-parameters-ui-improvements Change-Id: I43720c541d2b50660514a343f0dbe6f496ceedfd
This commit is contained in:
parent
1fb35e964d
commit
f0d130a8e9
@ -224,7 +224,6 @@ class HotPackage(murano.packages.application_package.ApplicationPackage):
|
||||
"new('io.murano.system.HeatStack', "
|
||||
"name => $.getAttr(generatedHeatStackName))")},
|
||||
|
||||
|
||||
YAQL("$reporter.report($this, "
|
||||
"'Application deployment has started')"),
|
||||
|
||||
@ -234,8 +233,7 @@ class HotPackage(murano.packages.application_package.ApplicationPackage):
|
||||
YAQL('$stack.setTemplate($template)'),
|
||||
YAQL('$stack.setParameters($parameters)'),
|
||||
|
||||
YAQL("$reporter.report($this, "
|
||||
"'Stack creation has started')"),
|
||||
YAQL("$reporter.report($this, 'Stack creation has started')"),
|
||||
{
|
||||
'Try': [YAQL('$stack.push()')],
|
||||
'Catch': [
|
||||
@ -279,7 +277,10 @@ class HotPackage(murano.packages.application_package.ApplicationPackage):
|
||||
|
||||
@staticmethod
|
||||
def _translate_ui_parameters(hot, title):
|
||||
result = [
|
||||
groups = hot.get('parameter_groups', [])
|
||||
result_groups = []
|
||||
|
||||
predefined_fields = [
|
||||
{
|
||||
'name': 'title',
|
||||
'type': 'string',
|
||||
@ -297,9 +298,32 @@ class HotPackage(murano.packages.application_package.ApplicationPackage):
|
||||
' Just A-Z, a-z, 0-9, and dash are allowed'
|
||||
}
|
||||
]
|
||||
for key, value in (hot.get('parameters') or {}).items():
|
||||
result.append(HotPackage._translate_ui_parameter(key, value))
|
||||
return result
|
||||
used_parameters = set()
|
||||
hot_parameters = hot.get('parameters') or {}
|
||||
for group in groups:
|
||||
fields = []
|
||||
properties = []
|
||||
for parameter in group.get('parameters', []):
|
||||
parameter_value = hot_parameters.get(parameter)
|
||||
if parameter_value:
|
||||
fields.append(HotPackage._translate_ui_parameter(
|
||||
parameter, parameter_value))
|
||||
used_parameters.add(parameter)
|
||||
properties.append(parameter)
|
||||
result_groups.append((fields, properties))
|
||||
|
||||
rest_group = []
|
||||
properties = []
|
||||
for key, value in hot_parameters.iteritems():
|
||||
if key not in used_parameters:
|
||||
rest_group.append(HotPackage._translate_ui_parameter(
|
||||
key, value))
|
||||
properties.append(key)
|
||||
if rest_group:
|
||||
result_groups.append((rest_group, properties))
|
||||
|
||||
result_groups.insert(0, (predefined_fields, ['name']))
|
||||
return result_groups
|
||||
|
||||
@staticmethod
|
||||
def _translate_ui_parameter(name, parameter_spec):
|
||||
@ -313,6 +337,10 @@ class HotPackage(murano.packages.application_package.ApplicationPackage):
|
||||
elif parameter_type == 'number':
|
||||
translated['type'] = 'integer'
|
||||
|
||||
label = parameter_spec.get('label')
|
||||
if label:
|
||||
translated['label'] = label
|
||||
|
||||
if 'description' in parameter_spec:
|
||||
translated['description'] = parameter_spec['description']
|
||||
|
||||
@ -383,15 +411,17 @@ class HotPackage(murano.packages.application_package.ApplicationPackage):
|
||||
return translated
|
||||
|
||||
@staticmethod
|
||||
def _generate_application_ui(hot, type_name):
|
||||
def _generate_application_ui(groups, type_name):
|
||||
app = {
|
||||
'?': {
|
||||
'type': type_name
|
||||
}
|
||||
}
|
||||
for key in (hot.get('parameters') or {}).keys():
|
||||
app[key] = YAQL('$.appConfiguration.' + key)
|
||||
app['name'] = YAQL('$.appConfiguration.name')
|
||||
for i, record in enumerate(groups):
|
||||
for property_name in record[1]:
|
||||
app[property_name] = YAQL(
|
||||
'$.group{0}.{1}'.format(i, property_name))
|
||||
app['name'] = YAQL('$.group0.name')
|
||||
|
||||
return app
|
||||
|
||||
@ -404,17 +434,15 @@ class HotPackage(murano.packages.application_package.ApplicationPackage):
|
||||
with open(template_file) as stream:
|
||||
hot = yaml.safe_load(stream)
|
||||
|
||||
groups = HotPackage._translate_ui_parameters(hot, self.description)
|
||||
forms = []
|
||||
for i, record in enumerate(groups):
|
||||
forms.append({'group{0}'.format(i): {'fields': record[0]}})
|
||||
|
||||
translated = {
|
||||
'Version': 2,
|
||||
'Application': HotPackage._generate_application_ui(
|
||||
hot, self.full_name),
|
||||
'Forms': [
|
||||
{
|
||||
'appConfiguration': {
|
||||
'fields': HotPackage._translate_ui_parameters(
|
||||
hot, self.description)
|
||||
}
|
||||
}
|
||||
]
|
||||
groups, self.full_name),
|
||||
'Forms': forms
|
||||
}
|
||||
return translated
|
||||
|
Loading…
Reference in New Issue
Block a user