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', "
|
"new('io.murano.system.HeatStack', "
|
||||||
"name => $.getAttr(generatedHeatStackName))")},
|
"name => $.getAttr(generatedHeatStackName))")},
|
||||||
|
|
||||||
|
|
||||||
YAQL("$reporter.report($this, "
|
YAQL("$reporter.report($this, "
|
||||||
"'Application deployment has started')"),
|
"'Application deployment has started')"),
|
||||||
|
|
||||||
@ -234,8 +233,7 @@ class HotPackage(murano.packages.application_package.ApplicationPackage):
|
|||||||
YAQL('$stack.setTemplate($template)'),
|
YAQL('$stack.setTemplate($template)'),
|
||||||
YAQL('$stack.setParameters($parameters)'),
|
YAQL('$stack.setParameters($parameters)'),
|
||||||
|
|
||||||
YAQL("$reporter.report($this, "
|
YAQL("$reporter.report($this, 'Stack creation has started')"),
|
||||||
"'Stack creation has started')"),
|
|
||||||
{
|
{
|
||||||
'Try': [YAQL('$stack.push()')],
|
'Try': [YAQL('$stack.push()')],
|
||||||
'Catch': [
|
'Catch': [
|
||||||
@ -279,7 +277,10 @@ class HotPackage(murano.packages.application_package.ApplicationPackage):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _translate_ui_parameters(hot, title):
|
def _translate_ui_parameters(hot, title):
|
||||||
result = [
|
groups = hot.get('parameter_groups', [])
|
||||||
|
result_groups = []
|
||||||
|
|
||||||
|
predefined_fields = [
|
||||||
{
|
{
|
||||||
'name': 'title',
|
'name': 'title',
|
||||||
'type': 'string',
|
'type': 'string',
|
||||||
@ -297,9 +298,32 @@ class HotPackage(murano.packages.application_package.ApplicationPackage):
|
|||||||
' Just A-Z, a-z, 0-9, and dash are allowed'
|
' Just A-Z, a-z, 0-9, and dash are allowed'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
for key, value in (hot.get('parameters') or {}).items():
|
used_parameters = set()
|
||||||
result.append(HotPackage._translate_ui_parameter(key, value))
|
hot_parameters = hot.get('parameters') or {}
|
||||||
return result
|
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
|
@staticmethod
|
||||||
def _translate_ui_parameter(name, parameter_spec):
|
def _translate_ui_parameter(name, parameter_spec):
|
||||||
@ -313,6 +337,10 @@ class HotPackage(murano.packages.application_package.ApplicationPackage):
|
|||||||
elif parameter_type == 'number':
|
elif parameter_type == 'number':
|
||||||
translated['type'] = 'integer'
|
translated['type'] = 'integer'
|
||||||
|
|
||||||
|
label = parameter_spec.get('label')
|
||||||
|
if label:
|
||||||
|
translated['label'] = label
|
||||||
|
|
||||||
if 'description' in parameter_spec:
|
if 'description' in parameter_spec:
|
||||||
translated['description'] = parameter_spec['description']
|
translated['description'] = parameter_spec['description']
|
||||||
|
|
||||||
@ -383,15 +411,17 @@ class HotPackage(murano.packages.application_package.ApplicationPackage):
|
|||||||
return translated
|
return translated
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _generate_application_ui(hot, type_name):
|
def _generate_application_ui(groups, type_name):
|
||||||
app = {
|
app = {
|
||||||
'?': {
|
'?': {
|
||||||
'type': type_name
|
'type': type_name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for key in (hot.get('parameters') or {}).keys():
|
for i, record in enumerate(groups):
|
||||||
app[key] = YAQL('$.appConfiguration.' + key)
|
for property_name in record[1]:
|
||||||
app['name'] = YAQL('$.appConfiguration.name')
|
app[property_name] = YAQL(
|
||||||
|
'$.group{0}.{1}'.format(i, property_name))
|
||||||
|
app['name'] = YAQL('$.group0.name')
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
@ -404,17 +434,15 @@ class HotPackage(murano.packages.application_package.ApplicationPackage):
|
|||||||
with open(template_file) as stream:
|
with open(template_file) as stream:
|
||||||
hot = yaml.safe_load(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 = {
|
translated = {
|
||||||
'Version': 2,
|
'Version': 2,
|
||||||
'Application': HotPackage._generate_application_ui(
|
'Application': HotPackage._generate_application_ui(
|
||||||
hot, self.full_name),
|
groups, self.full_name),
|
||||||
'Forms': [
|
'Forms': forms
|
||||||
{
|
|
||||||
'appConfiguration': {
|
|
||||||
'fields': HotPackage._translate_ui_parameters(
|
|
||||||
hot, self.description)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
return translated
|
return translated
|
||||||
|
Loading…
Reference in New Issue
Block a user