Static action for UI definition parameters

Now it is possible to specify ParametersSource key
in the UI definition for a method that should be
called to obtain UI parameters in addition to those
explicitly specified in ui.yaml

ParametersSource either should be a method name
or a className.methodName (com.example.MyClass.myMethod).
If class name is not provided it is taken from the Application section
or package FQN is used

Change-Id: I18b5f6081aaca1dce5655881ab896f6aac3003fe
This commit is contained in:
Stan Lagun 2016-10-20 01:39:40 -07:00
parent a4bcaa1e60
commit cddd563994
3 changed files with 52 additions and 8 deletions

View File

@ -115,13 +115,14 @@ def get_app_supplier_logo(request, app_id):
return api.muranoclient(request).packages.get_supplier_logo(app_id)
@cache.with_cache('package_fqn')
def get_app_fqn(request, app_id):
package = api.muranoclient(request).packages.get(app_id)
return package.fully_qualified_name
return get_package_details(request, app_id).fully_qualified_name
@cache.with_cache('package_name')
def get_service_name(request, app_id):
package = api.muranoclient(request).packages.get(app_id)
return package.name
return get_package_details(request, app_id).name
@cache.with_cache('package_details')
def get_package_details(request, app_id):
return api.muranoclient(request).packages.get(app_id)

View File

@ -22,6 +22,7 @@ from oslo_log import log as logging
import six
from yaql import legacy
from muranodashboard import api
from muranodashboard.api import packages as pkg_api
from muranodashboard.catalog import forms as catalog_forms
from muranodashboard.dynamic_ui import helpers
@ -71,8 +72,9 @@ class Service(object):
self.context = legacy.create_context()
yaql_functions.register(self.context)
params = parameters or {}
self.parameters = {}
for k, v in six.iteritems(parameters or {}):
for k, v in six.iteritems(params):
if not k or not k[0].isalpha():
continue
v = helpers.evaluate(v, self.context)
@ -163,7 +165,35 @@ def import_app(request, app_id):
version.check_version(app_version)
service = dict(
(helpers.decamelize(k), v) for (k, v) in six.iteritems(ui_desc))
return Service(app_data, app_version, fqn, **service)
parameters = service.pop('parameters', {})
parameters_source = service.pop('parameters_source', None)
if parameters_source is not None:
parts = parameters_source.rsplit('.', 1)
if 2 >= len(parts) > 0:
if len(parts) == 2:
class_name, method_name = parts
else:
method_name = parts[0]
class_name = service.get('application', {}).get('?', {}).get(
'type', fqn)
details = pkg_api.get_package_details(request, app_id)
pkg_version = getattr(details, 'version', '*')
request_body = {
'className': class_name,
'methodName': method_name,
'packageName': fqn,
'classVersion': pkg_version,
'parameters': {}
}
result = api.muranoclient(request).static_actions.call(
request_body).get_result()
if result and isinstance(result, dict):
parameters.update(result)
return Service(app_data, app_version, fqn, parameters=parameters,
**service)
def condition_getter(request, kwargs):

View File

@ -9,6 +9,19 @@ features:
expressions. The difference between Templates and Parameters is that
Parameters are evaluated once before form render whereas Templates are
evaluated on each access.
- >
It is possible to specify static action (MuranoPL method) that is going to
be called before form is rendered. This allows MuranoPL class to provide
parameter values to the form. Because parameters can be used as initial
control values this also allows to have dynamic content in the form.
Parameters source method can be specified in ``ParametersSource`` attribute
of UI definition markup: ``ParametersSource: com.namespace.MyClass.myMethod``.
If class name is not specified dashboard will try to infer it from the
``Application`` section or the package FQN.
If specified, static action must be present in one of the classes in the
same package that was used to obtain UI definition file. The method
must return a dictionary which will be combined with Parameters that are
already present in the file.
- >
``choice`` field type now can accept list of choices in a form of
dictionary. I.e. in addition to [[key1, value1], [key2, value2]] one can