jathanasiou commented on a change in pull request #228:
URL: https://github.com/apache/brooklyn-ui/pull/228#discussion_r669831667



##########
File path: ui-modules/home/app/views/about/about.controller.js
##########
@@ -55,17 +61,141 @@ export function aboutStateConfig($stateProvider) {
     $stateProvider.state(aboutState);
 }
 
-export function aboutStateController($scope, brBrandInfo, version, states) {
+export function aboutStateController($scope, $element, $q, $uibModal, 
brBrandInfo, version, states, serverApi) {
     $scope.$emit(HIDE_INTERSTITIAL_SPINNER_EVENT);
     $scope.getBrandedText = brBrandInfo.getBrandedText;
-
     $scope.serverVersion = version.data;
-    this.states = states.data;
-    this.buildInfo = {
+    $scope.states = states.data;
+    $scope.buildInfo = {
         buildVersion: BUILD_VERSION,
         buildName: BUILD_NAME,
         buildBranch: BUILD_BRANCH,
         buildCommitId: BUILD_COMMIT_ID,
         brooklynVersion: BROOKLYN_VERSION,
     };
+
+    $scope.container = $element[0];
+    $scope.now = Date.now();
+    $scope.expectedNodeCounter = Object.keys($scope.states.nodes).length;
+    $scope.template = 'haStatusTemplate';
+
+    let modalInstance = null;
+
+    $scope.openDialog = function (states, container) {
+        if (!modalInstance) {
+            modalInstance = $uibModal.open({
+                template: nodeManagementTemplate,
+                controller: ['$scope', '$uibModalInstance', 'node', 
nodeManagementModalController],
+                controllerAs: 'vm',
+                backdrop: 'static',
+                windowClass: 'quick-launch-modal',
+                size: 'md',
+                resolve: {
+                    node: function () {
+                        return states.nodes[states.ownId];
+                    }
+                }
+            });
+            modalInstance.result.then(
+                (promiseList) => {
+                    $scope.template = 'spinnerTemplate';
+                    Promise.allSettled(promiseList).then((values) => {
+                        let event = new CustomEvent('update-states', {});
+                        container.dispatchEvent(event);
+                    });
+                    modalInstance = null;
+                },
+                () => {
+                    $scope.template = 'spinnerTemplate';
+                    let event = new CustomEvent('update-states', {});
+                    container.dispatchEvent(event);
+                    modalInstance = null;
+                }
+            );
+        }
+
+    };
+
+    function nodeManagementModalController($scope, $uibModalInstance, node) {
+
+        // newStatus and newPriority are required to belong to the instance of 
the modal
+        let vm = this;
+        vm.newPriority = node.priority;
+        vm.newStatus = node.status;
+        
+        $scope.node = node;
+        $scope.statuses = ["MASTER", "STANDBY", "HOT_STANDBY", "HOT_BACKUP"];
+        $scope.now = Date.now();
+        $scope.showEditOptions = false;
+
+        $scope.applyChangesAndQuit = function () {
+            let promiseList = [];
+            if ($scope.node.priority !== vm.newPriority) {
+                let result = serverApi.setHaPriority(vm.newPriority);
+                promiseList.push(result);
+            }
+            if ($scope.node.status !== vm.newStatus) {
+                let result = serverApi.setHaStatus(vm.newStatus);
+                promiseList.push(result);
+            }
+            $uibModalInstance.close(promiseList);
+
+        }
+
+        $scope.cancelAndQuit = function () {
+            vm.newPriority = $scope.node.priority;
+            vm.newStatus = $scope.node.status;
+            $uibModalInstance.dismiss();
+        }
+
+        $scope.doShowEditOptions = function () {
+            $scope.showEditOptions = true;
+        }
+
+    }
+
+    $scope.removeNode = function (nodeId) {
+        $scope.template = 'spinnerTemplate';
+        let removeNode = serverApi.removeHaTerminatedNode(nodeId);
+        removeNode.then(data => {
+            $scope.expectedNodeCounter--;
+            let event = new CustomEvent('update-states', {});
+            $scope.container.dispatchEvent(event);
+        });
+    }
+
+    $scope.removeAllTerminatedNodes = function () {
+        $scope.template = 'spinnerTemplate';
+        let removeNodes = serverApi.removeHaTerminatedNodes();
+        removeNodes.then(data => {
+            for (const node in $scope.states.nodes) {

Review comment:
       consider using `$scope.states.nodes.forEach(node => { logic here )` 
instead for a better syntax




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to