Introduced dynamic workflow properties in VID FE
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / modals / new-change-management / new-change-management.controller.js
index 9a758cc..c85f0fc 100644 (file)
@@ -43,6 +43,7 @@
 
         var init = function () {
             vm.changeManagement = {};
+            vm.changeManagement.workflowParameters = new Map();
 
             loadServicesCatalog();
             fetchAttUid().then(registerVNFNamesWatcher);
         };
 
         vm.loadWorkFlows = function () {
-            changeManagementService.getWorkflows(vm.changeManagement.vnfNames)
-                .then(function(response) {
-                    vm.workflows = response.data.workflows;
-                })
-                .catch(function(error) {
-                    $log.error(error);
-                });
+          // Should be corrected when VID-397 will be closed. At the moment there is a need
+          // to merge local and remote workflows not to broke current functionality.
+          return vm.loadLocalWorkFlows()
+          .then(vm.loadRemoteWorkFlows)
+          .then(function () {
+            vm.workflows = vm.localWorkflows.concat(vm.remoteWorkflows.map(item => item.name));
+          }).then(function () {
+            vm.loadRemoteWorkFlowsParameters();
+          });
+        };
+
+        vm.loadLocalWorkFlows = function () {
+          return changeManagementService.getWorkflows(vm.changeManagement.vnfNames)
+          .then(function (response) {
+            vm.localWorkflows = response.data.workflows || [];
+          }).catch(function (error) {
+            $log.error(error);
+          });
+        };
+
+        vm.loadRemoteWorkFlows = function () {
+          let vnfNames = vm.changeManagement.vnfNames.map(vnfName => vnfName.name);
+          return changeManagementService.getSOWorkflows(vnfNames)
+          .then(function (response) {
+            vm.remoteWorkflows = response.data || [];
+          }).catch(function (error) {
+            $log.error(error);
+          });
+        };
+
+        vm.loadRemoteWorkFlowsParameters = function () {
+          vm.remoteWorkflowsParameters = new Map();
+          vm.remoteWorkflows.forEach(function(workflow) {
+            vm.loadRemoteWorkFlowParameters(workflow);
+          });
+        };
+
+        vm.loadRemoteWorkFlowParameters = function (workflow) {
+          changeManagementService.getSOWorkflowParameter(workflow.id)
+          .then(function (response) {
+            vm.remoteWorkflowsParameters.set(workflow.name, response.data.parameterDefinitions);
+          })
+          .catch(function (error) {
+            $log.error(error);
+          });
+        };
+
+        vm.getRemoteWorkFlowParameters = function (workflow) {
+          if (workflow && vm.remoteWorkflowsParameters.has(workflow)) {
+            return vm.remoteWorkflowsParameters.get(workflow)
+          }
+          return [];
         };
 
         //Must be $scope because we bind to the onchange of the html (cannot attached to vm variable).
 
         vm.isConfigUpdate = function () {
             return vm.changeManagement.workflow === COMPONENT.WORKFLOWS.vnfConfigUpdate;
-        }
+        };
 
         vm.isScaleOut = function () {
             return vm.changeManagement.workflow === COMPONENT.WORKFLOWS.vnfScaleOut;
-        }
+        };
 
         vm.shouldShowVnfInPlaceFields = function () {
             return vm.changeManagement.workflow === COMPONENT.WORKFLOWS.vnfInPlace;