Merge "Add spec cpu2006 test case"
[yardstick.git] / gui / app / scripts / controllers / taskModify.controller.js
1 'use strict';
2
3 angular.module('yardStickGui2App')
4     .controller('TaskModifyController', ['$scope', '$state', '$stateParams', 'mainFactory', 'Upload', 'toaster',
5         function($scope, $state, $stateParams, mainFactory, Upload, toaster) {
6
7
8             init();
9             $scope.blisterPackTemplates = [{ id: 1, name: "Test Case" }, { id: 2, name: "Test Suite" }]
10             $scope.selectType = null;
11
12             $scope.sourceShow = null;
13
14
15
16             function init() {
17                 getDetailTaskForList();
18                 getEnvironmentList();
19                 $scope.triggerContent = triggerContent;
20                 $scope.constructTestSuit = constructTestSuit;
21                 $scope.constructTestCase = constructTestCase;
22                 $scope.getTestDeatil = getTestDeatil;
23                 $scope.confirmToServer = confirmToServer;
24                 $scope.addEnvToTask = addEnvToTask;
25             }
26
27             function getDetailTaskForList() {
28                 mainFactory.getTaskDetail().get({
29                     'taskId': $stateParams.taskId
30                 }).$promise.then(function(response) {
31                     if (response.status == 1) {
32                         if (response.result.task.status == -1) {
33                             response.result.task['stausWidth'] = '5%';
34                         } else if (response.result.task.status == 0) {
35                             response.result.task['stausWidth'] = '50%';
36                         } else if (response.result.task.status == 1) {
37                             response.result.task['stausWidth'] = '100%';
38                         } else if (response.result.task.status == 2) {
39                             response.result.task['stausWidth'] = 'red';
40                         }
41
42                         $scope.taskDetailData = response.result.task;
43                         $scope.selectEnv = $scope.taskDetailData.environment_id;
44
45                         if ($scope.taskDetailData.environment_id != null) {
46                             getItemIdDetail($scope.taskDetailData.environment_id);
47                         }
48
49                     }
50                 }, function(error) {
51                     toaster.pop({
52                         type: 'error',
53                         title: 'fail',
54                         body: 'unknow error',
55                         timeout: 3000
56                     });
57                 })
58             }
59
60             function getItemIdDetail(id) {
61                 mainFactory.ItemDetail().get({
62                     'envId': id
63                 }).$promise.then(function(response) {
64                     if (response.status == 1) {
65                         $scope.envName = response.result.environment.name;
66                         // $scope.selectEnv = $scope.envName;
67                     } else {
68                         alert('Something Wrong!');
69                     }
70                 }, function(error) {
71                     toaster.pop({
72                         type: 'error',
73                         title: 'fail',
74                         body: 'unknow error',
75                         timeout: 3000
76                     });
77                 })
78             }
79
80             //getopenRcid
81             function getOpenrcDetail(openrcId) {
82                 mainFactory.getEnvironmentDetail().get({
83                     'openrc_id': openrcId
84                 }).$promise.then(function(response) {
85                     $scope.openrcInfo = response.result;
86                     // buildToEnvInfo($scope.openrcInfo.openrc)
87                 }, function(response) {
88
89                 })
90             }
91
92
93             //getImgDetail
94             function getImageDetail(id) {
95                 mainFactory.ImageDetail().get({
96                     'image_id': id
97                 }).$promise.then(function(response) {
98                     if (response.status == 1) {
99                         $scope.imageDetail = response.result.image;
100
101                     }
102                 }, function(error) {
103                     toaster.pop({
104                         type: 'error',
105                         title: 'fail',
106                         body: 'unknow error',
107                         timeout: 3000
108                     });
109                 })
110             }
111
112             //getPodDetail
113             function getPodDetail(id) {
114                 mainFactory.podDeatil().get({
115                     'podId': id
116                 }).$promise.then(function(response) {
117                     if (response.status == 1) {
118                         $scope.podDetail = response.result.pod;
119                     }
120                 }, function(error) {
121                     toaster.pop({
122                         type: 'error',
123                         title: 'fail',
124                         body: 'unknow error',
125                         timeout: 3000
126                     });
127                 })
128             }
129             //getContainerDetail
130             function getContainerId(containerId) {
131                 mainFactory.containerDetail().get({
132                     'containerId': containerId
133                 }).$promise.then(function(response) {
134                     if (response.status == 1) {
135                         $scope.container = response.result.container;
136                         $scope.displayContainerDetail.push($scope.container);
137
138                     } else {
139
140                     }
141                 }, function(error) {
142                     toaster.pop({
143                         type: 'error',
144                         title: 'fail',
145                         body: 'unknow error',
146                         timeout: 3000
147                     });
148                 })
149             }
150
151             function getEnvironmentList() {
152                 mainFactory.getEnvironmentList().get().$promise.then(function(response) {
153                     $scope.environmentList = response.result.environments;
154                 }, function(error) {
155                     toaster.pop({
156                         type: 'error',
157                         title: 'fail',
158                         body: 'unknow error',
159                         timeout: 3000
160                     });
161                 })
162             }
163
164
165             function triggerContent(name) {
166                 $scope.selectCase = null;
167                 $scope.displayTable = true;
168
169                 $scope.selectType = name;
170                 if (name.name == 'Test Case') {
171                     $scope.taskDetailData.suite = false;
172                     getTestcaseList();
173                 } else if (name.name == 'Test Suite') {
174                     $scope.taskDetailData.suite = true;
175                     getsuiteList();
176                 }
177             }
178
179             function getTestcaseList() {
180                 mainFactory.getTestcaselist().get({
181
182                 }).$promise.then(function(response) {
183                     if (response.status == 1) {
184                         $scope.testcaselist = response.result;
185
186
187                     }
188                 }, function(error) {
189                     toaster.pop({
190                         type: 'error',
191                         title: 'fail',
192                         body: 'unknow error',
193                         timeout: 3000
194                     });
195                 })
196             }
197
198             function getsuiteList() {
199                 mainFactory.suiteList().get({
200
201                 }).$promise.then(function(response) {
202                     if (response.status == 1) {
203                         $scope.testsuitlist = response.result.testsuites;
204
205                     }
206                 }, function(error) {
207                     toaster.pop({
208                         type: 'error',
209                         title: 'fail',
210                         body: 'unknow error',
211                         timeout: 3000
212                     });
213                 })
214             }
215
216
217             function constructTestSuit(id, name) {
218
219                 $scope.envName = name;
220                 $scope.selectEnv = id;
221
222             }
223
224             function constructTestCase(name) {
225
226                 $scope.selectCase = name;
227                 if ($scope.selectType.name == 'Test Case') {
228                     getCaseInfo();
229                 } else {
230                     getSuiteInfo();
231                 }
232
233             }
234
235             function getCaseInfo() {
236
237
238
239                 mainFactory.getTestcaseDetail().get({
240                     'testcasename': $scope.selectCase
241
242                 }).$promise.then(function(response) {
243                     if (response.status == 1) {
244
245                         $scope.contentInfo = response.result.testcase;
246
247                     }
248                 }, function(error) {
249                     toaster.pop({
250                         type: 'error',
251                         title: 'fail',
252                         body: 'unknow error',
253                         timeout: 3000
254                     });
255                 })
256             }
257
258             function getSuiteInfo() {
259                 mainFactory.suiteDetail().get({
260                     'suiteName': $scope.selectCase.split('.')[0]
261
262                 }).$promise.then(function(response) {
263                     if (response.status == 1) {
264                         $scope.contentInfo = response.result.testsuite;
265
266                     }
267                 }, function(error) {
268                     toaster.pop({
269                         type: 'error',
270                         title: 'fail',
271                         body: 'unknow error',
272                         timeout: 3000
273                     });
274                 })
275             }
276
277
278             function getTestDeatil() {
279
280
281                 if ($scope.selectType.name == 'Test Case') {
282                     getTestcaseDetail();
283                 } else {
284                     getSuiteDetail();
285                 }
286
287             }
288
289             function getSuiteDetail() {
290                 mainFactory.suiteDetail().get({
291                     'suiteName': $scope.selectCase.split('.')[0]
292
293                 }).$promise.then(function(response) {
294                     if (response.status == 1) {
295                         $scope.displayTable = false;
296                         $scope.contentInfo = response.result.testsuite;
297
298                     }
299                 }, function(error) {
300                     toaster.pop({
301                         type: 'error',
302                         title: 'fail',
303                         body: 'unknow error',
304                         timeout: 3000
305                     });
306                 })
307             }
308
309
310             function getTestcaseDetail() {
311                 mainFactory.getTestcaseDetail().get({
312                     'testcasename': $scope.selectCase
313
314                 }).$promise.then(function(response) {
315                     if (response.status == 1) {
316
317                         $scope.displayTable = false;
318                         $scope.contentInfo = response.result.testcase;
319
320                     }
321                 }, function(error) {
322                     toaster.pop({
323                         type: 'error',
324                         title: 'fail',
325                         body: 'unknow error',
326                         timeout: 3000
327                     });
328                 })
329             }
330
331
332
333             function addCasetoTask(content) {
334                 mainFactory.taskAddEnv().put({
335                     'taskId': $stateParams.taskId,
336                     'action': 'add_case',
337                     'args': {
338                         'task_id': $stateParams.taskId,
339                         'case_name': $scope.selectCase,
340                         'case_content': content
341                     }
342                 }).$promise.then(function(response) {
343                     if (response.status == 1) {
344                         toaster.pop({
345                             type: 'success',
346                             title: 'add test case success',
347                             body: 'you can go next step',
348                             timeout: 3000
349                         });
350                         $scope.ifHasCase = true;
351
352
353                     } else {
354                         toaster.pop({
355                             type: 'error',
356                             title: 'create task wrong',
357                             body: '',
358                             timeout: 3000
359                         });
360                     }
361                 }, function(error) {
362                     toaster.pop({
363                         type: 'error',
364                         title: 'create task wrong',
365                         body: '',
366                         timeout: 3000
367                     });
368                 })
369             }
370
371             function addSuitetoTask(content) {
372                 mainFactory.taskAddEnv().put({
373                     'taskId': $stateParams.taskId,
374                     'action': 'add_suite',
375                     'args': {
376                         'task_id': $stateParams.taskId,
377                         'suite_name': $scope.selectCase.split('.')[0],
378                         'suite_content': content
379                     }
380                 }).$promise.then(function(response) {
381                     if (response.status == 1) {
382                         toaster.pop({
383                             type: 'success',
384                             title: 'add test suite success',
385                             body: 'you can go next step',
386                             timeout: 3000
387                         });
388                         $scope.ifHasSuite = true;
389
390
391                     } else {
392                         toaster.pop({
393                             type: 'error',
394                             title: 'create task wrong',
395                             body: 'wrong',
396                             timeout: 3000
397                         });
398                     }
399                 }, function(error) {
400                     toaster.pop({
401                         type: 'error',
402                         title: 'create task wrong',
403                         body: 'something wrong',
404                         timeout: 3000
405                     });
406                 })
407             }
408             $scope.changeStatussourceTrue = function changeStatussourceTrue() {
409                 $scope.selectCase = null;
410                 $scope.sourceShow = true;
411             }
412
413             $scope.changeStatussourceFalse = function changeStatussourceFalse() {
414                 $scope.sourceShow = false;
415             }
416
417             function confirmToServer(content1, content2) {
418
419                 var content;
420                 if ($scope.sourceShow == false) {
421                     content = content2;
422                     $scope.selectCase = $scope.taskDetailData.case_name;
423                 } else if ($scope.sourceShow == true) {
424                     content = content1;
425                 }
426                 if ($scope.selectCase == 'Test Case' || $scope.taskDetailData.suite == false) {
427
428                     addCasetoTask(content);
429                 } else {
430                     addSuitetoTask(content);
431                 }
432             }
433
434
435             function addEnvToTask() {
436
437                 mainFactory.taskAddEnv().put({
438                     'taskId': $stateParams.taskId,
439                     'action': 'add_environment',
440                     'args': {
441                         'task_id': $stateParams.taskId,
442                         'environment_id': $scope.selectEnv
443                     }
444                 }).$promise.then(function(response) {
445                     if (response.status == 1) {
446                         toaster.pop({
447                             type: 'success',
448                             title: 'add environment success',
449                             body: 'you can go next step',
450                             timeout: 3000
451                         });
452                         $scope.ifHasEnv = true;
453
454
455                     } else {
456                         toaster.pop({
457                             type: 'error',
458                             title: 'create task wrong',
459                             body: 'you can go next step',
460                             timeout: 3000
461                         });
462                     }
463
464
465
466                 }, function(error) {
467                     toaster.pop({
468                         type: 'error',
469                         title: 'create task wrong',
470                         body: 'you can go next step',
471                         timeout: 3000
472                     });
473                 })
474             }
475
476             $scope.goBack = function goBack() {
477                 window.history.back();
478             }
479
480             $scope.runAtask = function runAtask() {
481                 mainFactory.taskAddEnv().put({
482                     'taskId': $stateParams.taskId,
483                     'action': 'run',
484                     'args': {
485                         'task_id': $stateParams.taskId
486                     }
487                 }).$promise.then(function(response) {
488                     if (response.status == 1) {
489                         toaster.pop({
490                             type: 'success',
491                             title: 'run a task success',
492                             body: 'go to task list page...',
493                             timeout: 3000
494                         });
495                         setTimeout(function() {
496                             window.history.back();
497                         }, 2000);
498
499
500
501                     } else {
502                         toaster.pop({
503                             type: 'error',
504                             title: 'fail',
505                             body: response.error_msg,
506                             timeout: 3000
507                         });
508                     }
509                 }, function(error) {
510                     toaster.pop({
511                         type: 'error',
512                         title: 'fail',
513                         body: 'unknow error',
514                         timeout: 3000
515                     });
516                 })
517             }
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532         }
533     ]);