Add common openstack opertation scenarios: network
[yardstick.git] / gui / app / scripts / controllers / pod.controller.js
1 'use strict';
2
3 angular.module('yardStickGui2App')
4     .controller('PodController', ['$scope', '$state', '$stateParams', 'mainFactory', 'Upload', 'toaster', '$location', 'ngDialog',
5         function($scope, $state, $stateParams, mainFactory, Upload, toaster, $location, ngDialog) {
6
7
8             init();
9             $scope.showloading = false;
10             $scope.loadingOPENrc = false;
11
12             function init() {
13
14
15                 $scope.uuid = $stateParams.uuid;
16                 $scope.uploadFiles = uploadFiles;
17                 getItemIdDetail();
18
19             }
20
21             function getItemIdDetail() {
22                 mainFactory.ItemDetail().get({
23                     'envId': $scope.uuid
24                 }).$promise.then(function(response) {
25                     if (response.status == 1) {
26                         $scope.name = response.result.environment.name;
27                         $scope.podId = response.result.environment.pod_id;
28                         if ($scope.podId != null) {
29                             getPodDetail($scope.podId);
30                         } else {
31                             $scope.podData = null;
32                         }
33
34                     }
35                 }, function(error) {
36                     toaster.pop({
37                         type: 'error',
38                         title: 'fail',
39                         body: 'unknow error',
40                         timeout: 3000
41                     });
42                 })
43             }
44
45             function getPodDetail(id) {
46                 mainFactory.getPodDetail().get({
47                     'podId': id
48                 }).$promise.then(function(response) {
49                     if (response.status == 1) {
50                         $scope.podData = response.result;
51
52                     }
53                 }, function(error) {
54                     toaster.pop({
55                         type: 'error',
56                         title: 'fail',
57                         body: 'unknow error',
58                         timeout: 3000
59                     });
60                 })
61
62             }
63
64             //upload pod file
65             function uploadFiles($file, $invalidFiles) {
66                 $scope.loadingOPENrc = true;
67
68                 $scope.displayOpenrcFile = $file;
69                 timeConstruct($scope.displayOpenrcFile.lastModified);
70                 Upload.upload({
71                     url: Base_URL + '/api/v2/yardstick/pods',
72                     data: { file: $file, 'environment_id': $scope.uuid, 'action': 'upload_pod_file' }
73                 }).then(function(response) {
74
75                     $scope.loadingOPENrc = false;
76                     if (response.data.status == 1) {
77                         toaster.pop({
78                             type: 'success',
79                             title: 'upload success',
80                             body: 'you can go next step',
81                             timeout: 3000
82                         });
83
84                         $scope.podData = response.data.result;
85
86                         getItemIdDetail();
87
88
89                     } else {
90
91                     }
92
93                 }, function(error) {
94                     $scope.uploadfile = null;
95                     toaster.pop({
96                         type: 'error',
97                         title: 'fail',
98                         body: 'unknow error',
99                         timeout: 3000
100                     });
101                 })
102             }
103
104             function timeConstruct(array) {
105                 var date = new Date(1398250549490);
106                 var Y = date.getFullYear() + '-';
107                 var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
108                 var D = date.getDate() + ' ';
109                 var h = date.getHours() + ':';
110                 var m = date.getMinutes() + ':';
111                 var s = date.getSeconds();
112                 $scope.filelastModified = Y + M + D + h + m + s;
113
114             }
115             $scope.goBack = function goBack() {
116                 $state.go('app2.projectList');
117             }
118
119
120             $scope.goNext = function goNext() {
121                 $scope.path = $location.path();
122                 $scope.uuid = $scope.path.split('/').pop();
123                 $state.go('app.container', { uuid: $scope.uuid });
124             }
125
126             $scope.openDeleteEnv = function openDeleteEnv(id, name) {
127                 $scope.deleteName = name;
128                 $scope.deleteId = id;
129                 ngDialog.open({
130                     template: 'views/modal/deleteConfirm.html',
131                     scope: $scope,
132                     className: 'ngdialog-theme-default',
133                     width: 500,
134                     showClose: true,
135                     closeByDocument: false
136                 })
137
138             }
139
140             $scope.deletePod = function deletePod() {
141                 mainFactory.deletePod().delete({ 'podId': $scope.podId }).$promise.then(function(response) {
142                     if (response.status == 1) {
143                         toaster.pop({
144                             type: 'success',
145                             title: 'delete pod success',
146                             body: 'you can go next step',
147                             timeout: 3000
148                         });
149                         ngDialog.close();
150                         $scope.uuid = $stateParams.uuid;
151                         $scope.uploadFiles = uploadFiles;
152                         $scope.displayOpenrcFile = null;
153                         getItemIdDetail();
154                     } else {
155                         toaster.pop({
156                             type: 'error',
157                             title: 'Wrong',
158                             body: response.result,
159                             timeout: 3000
160                         });
161                     }
162
163                 }, function(error) {
164                     toaster.pop({
165                         type: 'error',
166                         title: 'fail',
167                         body: 'unknow error',
168                         timeout: 3000
169                     });
170
171                 })
172             }
173
174
175
176
177
178         }
179     ]);