Merge "Update NSBPerf CLI to adapt to new output format"
[yardstick.git] / gui / app / scripts / controllers / image.controller.js
1 'use strict';
2
3 angular.module('yardStickGui2App')
4     .controller('ImageController', ['$scope', '$state', '$stateParams', 'mainFactory', 'Upload', 'toaster', '$location', '$interval',
5         function($scope, $state, $stateParams, mainFactory, Upload, toaster, $location, $interval) {
6
7
8             init();
9             $scope.showloading = false;
10             $scope.ifshowStatus = 0;
11
12             function init() {
13
14
15                 $scope.uuid = $stateParams.uuid;
16                 $scope.uploadImage = uploadImage;
17                 getItemIdDetail();
18                 getImageListSimple();
19             }
20
21             function getItemIdDetail() {
22                 mainFactory.ItemDetail().get({
23                     'envId': $stateParams.uuid
24                 }).$promise.then(function(response) {
25                     if (response.status == 1) {
26                         $scope.baseElementInfo = response.result.environment;
27
28
29                     } else {
30                         toaster.pop({
31                             type: 'error',
32                             title: 'fail',
33                             body: response.error_msg,
34                             timeout: 3000
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             function getImageListSimple() {
48
49                 mainFactory.ImageList().get({}).$promise.then(function(response) {
50                     if (response.status == 1) {
51                         $scope.imageListData = response.result.images;
52                         // $scope.imageStatus = response.result.status;
53
54                     } else {
55                         toaster.pop({
56                             type: 'error',
57                             title: 'get data failed',
58                             body: 'please retry',
59                             timeout: 3000
60                         });
61                     }
62                 }, function(error) {
63                     toaster.pop({
64                         type: 'error',
65                         title: 'get data failed',
66                         body: 'please retry',
67                         timeout: 3000
68                     });
69                 })
70             }
71
72
73             function getImageList() {
74                 if ($scope.intervalImgae != undefined) {
75                     $interval.cancel($scope.intervalImgae);
76                 }
77                 mainFactory.ImageList().get({}).$promise.then(function(response) {
78                     if (response.status == 1) {
79                         $scope.imageListData = response.result.images;
80                         $scope.imageStatus = response.result.status;
81
82                         if ($scope.imageStatus == 0) {
83                             $scope.intervalImgae = $interval(function() {
84                                 getImageList();
85                             }, 5000);
86                         } else if ($scope.intervalImgae != undefined) {
87                             $interval.cancel($scope.intervalImgae);
88                         }
89
90                     } else {
91                         toaster.pop({
92                             type: 'error',
93                             title: 'get data failed',
94                             body: 'please retry',
95                             timeout: 3000
96                         });
97                     }
98                 }, function(error) {
99                     toaster.pop({
100                         type: 'error',
101                         title: 'get data failed',
102                         body: 'please retry',
103                         timeout: 3000
104                     });
105                 })
106             }
107
108             function uploadImage() {
109                 $scope.imageStatus = 0;
110                 $interval.cancel($scope.intervalImgae);
111                 $scope.ifshowStatus = 1;
112                 $scope.showloading = true;
113                 mainFactory.uploadImage().post({
114                     'action': 'load_image',
115                     'args': {
116                         'environment_id': $scope.uuid
117
118                     }
119                 }).$promise.then(function(response) {
120                     $scope.showloading = false;
121                     if (response.status == 1) {
122                         toaster.pop({
123                             type: 'success',
124                             title: 'create success',
125                             body: 'you can go next step',
126                             timeout: 3000
127                         });
128                         setTimeout(function() {
129                             getImageList();
130                         }, 10000);
131
132                     } else {
133                         toaster.pop({
134                             type: 'error',
135                             title: 'failed',
136                             body: 'something wrong',
137                             timeout: 3000
138                         });
139
140                     }
141                 }, function(error) {
142                     toaster.pop({
143                         type: 'error',
144                         title: 'failed',
145                         body: 'something wrong',
146                         timeout: 3000
147                     });
148                 })
149             }
150
151             $scope.goBack = function goBack() {
152                 $state.go('app2.projectList');
153             }
154
155             $scope.goNext = function goNext() {
156                 $scope.path = $location.path();
157                 $scope.uuid = $scope.path.split('/').pop();
158                 $state.go('app.podUpload', { uuid: $scope.uuid });
159             }
160
161
162
163
164
165         }
166     ]);