Adapting GUI for error report managing
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / controller / msoCommitController.js
index 65fac28..a5c0388 100755 (executable)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================\r
  * VID\r
  * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.\r
  * ================================================================================\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * "$scope.popup".\r
  */\r
 \r
-var msoCommitController = function(COMPONENT, FIELD, $scope, $http, $timeout, $window, $log,\r
-               MsoService, PropertyService, UtilityService, DataService) {\r
+var msoCommitController = function(COMPONENT, FIELD, $scope, $http, $timeout, $window, $log, $uibModal,\r
+               MsoService, PropertyService, UtilityService, TestEnvironmentsService, DataService) {\r
 \r
        $scope.isViewVisible = false;\r
        $scope.progressBarControl = {};\r
        $scope.popupWindowControl = {};\r
-\r
+    var getRequestStatusFunc = getOrchestrationRequestStatus; //default\r
        var _this = this;\r
 \r
+       $scope.showReportWindow = function() {\r
+               let requestInfo = {};\r
+               requestInfo.requestId = _this.requestId;\r
+               requestInfo.serviceUuid = $scope.instanceId;\r
+\r
+               const modalWindow = $uibModal.open({\r
+                       templateUrl: 'app/vid/scripts/modals/report-modal/report-modal.html',\r
+                       controller: 'reportModalInstanceController',\r
+                       controllerAs: 'vm',\r
+                       resolve: {\r
+                               errorMsg: function () {\r
+                                       return $scope.log;\r
+                               },\r
+                               requestInfo: function () {\r
+                                       return requestInfo;\r
+                               }\r
+                       }\r
+               });\r
+\r
+               $scope.isViewVisible = false;\r
+               $scope.popup.isVisible = false;\r
+       };\r
+\r
        $scope.$on("createInstance", function(event, request) {\r
-               init(request, COMPONENT.MSO_CREATE_REQ );\r
+               init(request, COMPONENT.MSO_CREATE_REQ, getOrchestrationRequestStatus );\r
                MsoService.createInstance(request, handleInitialResponse);\r
        });\r
 \r
        $scope.$on("deleteInstance", function(event, request) {\r
-               init(request, COMPONENT.MSO_DELETE_REQ);\r
+        init(request, COMPONENT.MSO_DELETE_REQ, getOrchestrationRequestStatus);\r
                MsoService.deleteInstance(request, handleInitialResponse);\r
        });\r
 \r
-       var init = function(request, msoRequestType ) {\r
+    $scope.$on(COMPONENT.MSO_CREATE_ENVIRONMENT, function(event, request) {\r
+        init(request, COMPONENT.MSO_CREATE_ENVIRONMENT, getCloudResourcesRequestStatus);\r
+        TestEnvironmentsService.createApplicationEnv(request).then(handleInitialResponse);\r
+    });\r
+\r
+    $scope.$on(COMPONENT.MSO_DEACTIVATE_ENVIRONMENT, function(event, request) {\r
+        init(request, COMPONENT.MSO_DEACTIVATE_ENVIRONMENT, getCloudResourcesRequestStatus);\r
+        TestEnvironmentsService.deactivateApplicationEnv(request).then(handleInitialResponse)\r
+    });\r
+\r
+    $scope.$on(COMPONENT.MSO_ACTIVATE_ENVIRONMENT, function(event, request) {\r
+        init(request, COMPONENT.MSO_ACTIVATE_ENVIRONMENT, getCloudResourcesRequestStatus);\r
+        TestEnvironmentsService.activateApplicationEnv(request).then(handleInitialResponse)\r
+    });\r
+\r
+\r
+    var init = function(request, msoRequestType, getStatusRequest ) {\r
+       getRequestStatusFunc = getStatusRequest;\r
                $scope.status = FIELD.STATUS.SUBMITTING_REQUEST;\r
                $scope.isSpinnerVisible = true;\r
                $scope.isProgressVisible = true;\r
@@ -109,13 +149,13 @@ var msoCommitController = function(COMPONENT, FIELD, $scope, $http, $timeout, $w
                        showError(FIELD.ERROR.SYSTEM_FAILURE, UtilityService\r
                                        .getHttpErrorMessage(response));\r
                });\r
-       }\r
+       };\r
 \r
        var handleInitialResponse = function(response) {\r
                try {\r
                        updateViewAfterInitialResponse(response);\r
                        \r
-                       _this.timer = $timeout(getRequestStatus, PropertyService\r
+                       _this.timer = $timeout(getRequestStatusFunc, PropertyService\r
                                        .getMsoMaxPollingIntervalMsec());\r
 \r
                        $scope.instanceId = response.data.entity.instanceId;\r
@@ -133,11 +173,16 @@ var msoCommitController = function(COMPONENT, FIELD, $scope, $http, $timeout, $w
                }\r
        }\r
 \r
-       var getRequestStatus = function() {\r
-               MsoService.getOrchestrationRequest(_this.requestId, handleGetResponse);\r
+       function getOrchestrationRequestStatus() {\r
+               MsoService.getOrchestrationRequest(_this.requestId, handleGetStatusResponse);\r
        }\r
 \r
-       var handleGetResponse = function(response) {\r
+       function getCloudResourcesRequestStatus() {\r
+        TestEnvironmentsService.getRequestStatus(_this.requestId, handleGetStatusResponse);\r
+    }\r
+\r
+\r
+    var handleGetStatusResponse = function(response) {\r
                try {\r
                        if (isUpdateViewAfterGetResponseComplete(response)) {\r
                                return;\r
@@ -147,7 +192,7 @@ var msoCommitController = function(COMPONENT, FIELD, $scope, $http, $timeout, $w
                                _this.isMsoError = true;\r
                                showError(FIELD.ERROR.MAX_POLLS_EXCEEDED);\r
                        } else {\r
-                               _this.timer = $timeout(getRequestStatus, PropertyService\r
+                               _this.timer = $timeout(getRequestStatusFunc, PropertyService\r
                                                .getMsoMaxPollingIntervalMsec());\r
                        }\r
                } catch (error) {\r
@@ -296,5 +341,5 @@ var msoCommitController = function(COMPONENT, FIELD, $scope, $http, $timeout, $w
 }\r
 \r
 appDS2.controller("msoCommitController", [ "COMPONENT", "FIELD", "$scope", "$http", "$timeout",\r
-               "$window", "$log", "MsoService", "PropertyService", "UtilityService",\r
+               "$window", "$log", "$uibModal", "MsoService", "PropertyService", "UtilityService", "TestEnvironmentsService", "DataService",\r
                msoCommitController ]);\r