From eed792fbd8c41f270de8a377005eaa8fff1908d4 Mon Sep 17 00:00:00 2001 From: Luji7 Date: Tue, 25 Oct 2016 16:26:23 +0800 Subject: Issue#GSO-46 Add nesting service template parameters to config for GSO service Change-Id: If853766873fb4e79d1d3fa562a93bca998233f91 Signed-off-by: Luji7 --- .../src/main/webapp/lifecyclemgr/js/gsolcm.js | 84 +++++++++++++++++++++- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/gsolcm.js b/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/gsolcm.js index 4b135f70..49b34e80 100644 --- a/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/gsolcm.js +++ b/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/gsolcm.js @@ -81,16 +81,94 @@ function initParameterTab() { function generateTemplateParametersComponent(templateId) { var defer = $.Deferred(); $.when( - fetchTemplateParameterDefinitions(templateId) + fetchTemplateParameterDefinitions(templateId), + fetchGsoNestingTemplateParameters(templateId) ).then( - function (templateParameterResponse) { - templateParameters = translateToTemplateParameters(templateParameterResponse.inputs); + function (templateParameterResponse, nestingTempatesParas) { + var inputParas = concat(templateParameterResponse[0].inputs, nestingTempatesParas); + templateParameters = translateToTemplateParameters(inputParas); defer.resolve(transformToComponents(templateParameters.parameters)); } ); return defer; } +function fetchGsoNestingTemplateParameters(templateId) { + var defer = $.Deferred(); + var nestingParams = []; + $.when( + fetchServiceTemplateBy(templateId) + ).then( + function(template) { + if(template.serviceType === 'GSO') { + return fetchNodeTemplates(templateId); + } + // There are no nesting template parameters for non GSO. + defer.reslove([]); + } + ).then( + function(nodeTemplates) { + var count = nodeTemplates.length; + if(count ===0) { + defer.resolve([]); + return; + } + var params = $.Deferred(); + params.progress(function(inputs) { + pushAll(nestingParams, inputs); + count--; + if(count === 0) { + defer.resolve(nestingParams); + } + }); + nodeTemplates.forEach(function(nodeTemplate) { + var nestingNodeUri = '/openoapi/catalog/v1/servicetemplate/nesting?nodeTypeIds=' + nodeTemplate.type; + $.when( + $.ajax({ + type: "GET", + url: nestingNodeUri + }) + ).then( + function(serviceTemplates) { + var oneNodeParameters = [] + serviceTemplates.forEach(function(serviceTemplate) { + pushAll(oneNodeParameters, serviceTemplate.inputs.map(function(input) { + input.name = nodeTemplate.type + '.' + input.name; + return input; + })); + }) + params.notify(oneNodeParameters); + } + ); + }); + } + ); + return defer; +} + +function fetchNodeTemplates(templateId) { + var nodeTemplateUri = '/openoapi/catalog/v1/servicetemplates/'+ templateId +'/nodetemplates'; + return $.ajax({ + type: "GET", + url: nodeTemplateUri + }); +} + +function concat(array1, array2) { + var result = []; + pushAll(result, array1); + pushAll(result, array2); + return result; +} + +function pushAll(acc, array) { + var result = acc; + array.forEach(function(element) { + result.push(element) + }) + return result; +} + function generateLocationComponent(templateId) { var defer = $.Deferred(); $.when( -- cgit 1.2.3-korg