Merge "Sample ACL VNF"
[yardstick.git] / gui / app / scripts / controllers / task.controller.js
1 'use strict';
2
3 angular.module('yardStickGui2App')
4     .controller('TaskController', ['$scope', '$state', '$stateParams', 'mainFactory', 'Upload', 'toaster', 'ngDialog',
5         function($scope, $state, $stateParams, mainFactory, Upload, toaster, ngDialog) {
6
7
8             init();
9
10
11             function init() {
12                 getDetailTaskForList();
13
14             }
15
16             function getDetailTaskForList() {
17                 mainFactory.getTaskDetail().get({
18                     'taskId': $stateParams.taskId
19                 }).$promise.then(function(response) {
20                     if (response.status == 1) {
21                         if (response.result.task.status == -1) {
22                             response.result.task['stausWidth'] = '5%';
23                         } else if (response.result.task.status == 0) {
24                             response.result.task['stausWidth'] = '50%';
25                         } else if (response.result.task.status == 1) {
26                             response.result.task['stausWidth'] = '100%';
27                         } else if (response.result.task.status == 2) {
28                             response.result.task['stausWidth'] = 'red';
29                         }
30
31                         $scope.taskDetailData = response.result.task;
32                         if ($scope.taskDetailData.environment_id != null) {
33                             getItemIdDetail($scope.taskDetailData.environment_id);
34                         }
35
36                     }
37                 }, function(error) {
38                     toaster.pop({
39                         type: 'error',
40                         title: 'fail',
41                         body: 'unknow error',
42                         timeout: 3000
43                     });
44                 })
45             }
46
47
48             function getItemIdDetail(id) {
49                 mainFactory.ItemDetail().get({
50                     'envId': id
51                 }).$promise.then(function(response) {
52                     if (response.status == 1) {
53                         $scope.displayEnv = response.result.environment;
54
55                         if (response.result.environment.pod_id != null) {
56                             getPodDetail(response.result.environment.pod_id);
57                         } else if (response.result.environment.image_id != null) {
58                             getImageDetail(response.result.environment.image_id);
59                         } else if (response.result.environment.openrc_id != null) {
60                             getOpenrcDetail(response.result.environment.openrc_id != null);
61                         } else if (response.result.environment.container_id.length != 0) {
62                             $scope.displayContainerDetail = [];
63                             var containerArray = response.result.environment.container_id;
64                             for (var i = 0; i < containerArray.length; i++) {
65                                 getContainerId(containerArray[i]);
66                             }
67
68                         }
69                     } else {
70                         toaster.pop({
71                             type: 'error',
72                             title: 'fail',
73                             body: response.error_msg,
74                             timeout: 3000
75                         });
76                     }
77                 }, function(error) {
78                     toaster.pop({
79                         type: 'error',
80                         title: 'fail',
81                         body: 'unknow error',
82                         timeout: 3000
83                     });
84                 })
85             }
86
87             //getopenRcid
88             function getOpenrcDetail(openrcId) {
89                 mainFactory.getEnvironmentDetail().get({
90                     'openrc_id': openrcId
91                 }).$promise.then(function(response) {
92                     //openrc数据
93                     $scope.openrcInfo = response.result;
94                     // buildToEnvInfo($scope.openrcInfo.openrc)
95                 }, function(response) {
96
97                 })
98             }
99
100
101             //getImgDetail
102             function getImageDetail(id) {
103                 mainFactory.ImageDetail().get({
104                     'image_id': id
105                 }).$promise.then(function(response) {
106                     if (response.status == 1) {
107                         $scope.imageDetail = response.result.image;
108
109                     }
110                 }, function(error) {
111                     toaster.pop({
112                         type: 'error',
113                         title: 'fail',
114                         body: 'unknow error',
115                         timeout: 3000
116                     });
117                 })
118             }
119
120             //getPodDetail
121             function getPodDetail(id) {
122                 mainFactory.podDeatil().get({
123                     'podId': id
124                 }).$promise.then(function(response) {
125                     if (response.status == 1) {
126                         $scope.podDetail = response.result.pod;
127                     }
128                 }, function(error) {
129                     toaster.pop({
130                         type: 'error',
131                         title: 'fail',
132                         body: 'unknow error',
133                         timeout: 3000
134                     });
135                 })
136             }
137             //getContainerDetail
138             function getContainerId(containerId) {
139                 mainFactory.containerDetail().get({
140                     'containerId': containerId
141                 }).$promise.then(function(response) {
142                     if (response.status == 1) {
143                         $scope.container = response.result.container;
144                         $scope.displayContainerDetail.push($scope.container);
145
146                     } else {
147                         toaster.pop({
148                             type: 'error',
149                             title: 'fail',
150                             body: response.error_msg,
151                             timeout: 3000
152                         });
153                     }
154                 }, function(error) {
155                     toaster.pop({
156                         type: 'error',
157                         title: 'fail',
158                         body: 'unknow error',
159                         timeout: 3000
160                     });
161                 })
162             }
163             $scope.goBack = function goBack() {
164                 window.history.back();
165             }
166
167
168
169
170
171
172
173
174         }
175     ]);