Merge "Add spec cpu2006 test case"
[yardstick.git] / gui / app / scripts / controllers / container.controller.js
1 'use strict';
2
3 angular.module('yardStickGui2App')
4     .controller('ContainerController', ['$scope', '$state', '$stateParams', 'mainFactory', 'Upload', 'toaster', 'ngDialog',
5         function($scope, $state, $stateParams, mainFactory, Upload, toaster, ngDialog) {
6
7
8             init();
9             $scope.showloading = false;
10
11             $scope.displayContainerInfo = [];
12             $scope.containerList = [{ value: 'create_influxdb', name: "InfluxDB" }, { value: 'create_grafana', name: "Grafana" }]
13
14             function init() {
15
16
17                 $scope.uuid = $stateParams.uuid;
18                 $scope.createContainer = createContainer;
19                 $scope.openChooseContainnerDialog = openChooseContainnerDialog;
20
21
22                 getItemIdDetail();
23
24             }
25
26             function getItemIdDetail() {
27                 $scope.displayContainerInfo = [];
28                 mainFactory.ItemDetail().get({
29                     'envId': $scope.uuid
30                 }).$promise.then(function(response) {
31                     if (response.status == 1) {
32                         $scope.envName = response.result.environment.name;
33                         $scope.containerId = response.result.environment.container_id;
34                         if ($scope.containerId != null) {
35
36                             var keysArray = Object.keys($scope.containerId);
37                             for (var k in $scope.containerId) {
38                                 getConDetail($scope.containerId[k]);
39                             }
40                         } else {
41                             $scope.podData = null;
42                         }
43
44                     }
45                 }, function(error) {
46                     toaster.pop({
47                         type: 'error',
48                         title: 'fail',
49                         body: 'unknow error',
50                         timeout: 3000
51                     });
52                 })
53             }
54
55             function getConDetail(id) {
56                 mainFactory.containerDetail().get({
57                     'containerId': id
58                 }).$promise.then(function(response) {
59                     if (response.status == 1) {
60                         // $scope.podData = response.result;
61                         response.result.container['id'] = id;
62                         $scope.displayContainerInfo.push(response.result.container);
63
64                     }
65
66                 }, function(error) {
67                     toaster.pop({
68                         type: 'error',
69                         title: 'fail',
70                         body: 'unknow error',
71                         timeout: 3000
72                     });
73                 })
74
75             }
76
77             function createContainer() {
78
79                 $scope.showloading = true;
80                 mainFactory.runAcontainer().post({
81                     'action': $scope.selectContainer.value,
82                     'args': {
83                         'environment_id': $scope.uuid,
84                     }
85                 }).$promise.then(function(response) {
86                     $scope.showloading = false;
87                     if (response.status == 1) {
88                         toaster.pop({
89                             type: 'success',
90                             title: 'create container success',
91                             body: 'you can go next step',
92                             timeout: 3000
93                         });
94                         setTimeout(function() {
95                             getItemIdDetail();
96                         }, 10000);
97                     } else {
98                         toaster.pop({
99                             type: 'error',
100                             title: 'Wrong',
101                             body: response.error_msg,
102                             timeout: 3000
103                         });
104                     }
105                 }, function(error) {
106                     toaster.pop({
107                         type: 'error',
108                         title: 'fail',
109                         body: 'unknow error',
110                         timeout: 3000
111                     });
112
113                 })
114             }
115
116             function openChooseContainnerDialog() {
117                 ngDialog.open({
118                     template: 'views/modal/chooseContainer.html',
119                     scope: $scope,
120                     className: 'ngdialog-theme-default',
121                     width: 500,
122                     showClose: true,
123                     closeByDocument: false
124                 })
125             }
126
127             function chooseResult(name) {
128                 $scope.selectContainer = name;
129             }
130             $scope.goBack = function goBack() {
131                 $state.go('app2.projectList');
132             }
133
134             $scope.openDeleteEnv = function openDeleteEnv(id, name) {
135                 $scope.deleteName = name;
136                 $scope.deleteId = id;
137                 ngDialog.open({
138                     template: 'views/modal/deleteConfirm.html',
139                     scope: $scope,
140                     className: 'ngdialog-theme-default',
141                     width: 500,
142                     showClose: true,
143                     closeByDocument: false
144                 })
145
146             }
147
148             $scope.deleteContainer = function deleteContainer() {
149                 mainFactory.deleteContainer().delete({ 'containerId': $scope.deleteId }).$promise.then(function(response) {
150                     if (response.status == 1) {
151                         toaster.pop({
152                             type: 'success',
153                             title: 'delete container success',
154                             body: 'you can go next step',
155                             timeout: 3000
156                         });
157                         ngDialog.close();
158                         getItemIdDetail();
159
160                     } else {
161                         toaster.pop({
162                             type: 'error',
163                             title: 'Wrong',
164                             body: response.error_msg,
165                             timeout: 3000
166                         });
167                     }
168
169                 }, function(error) {
170                     toaster.pop({
171                         type: 'error',
172                         title: 'fail',
173                         body: 'unknow error',
174                         timeout: 3000
175                     });
176                 })
177             }
178
179
180
181         }
182     ]);