Merge "Add spec cpu2006 test case"
[yardstick.git] / gui / app / scripts / controllers / suitecreate.controller.js
1 'use strict';
2
3 angular.module('yardStickGui2App')
4     .controller('suitcreateController', ['$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
13                 getTestcaseList();
14                 $scope.constructTestSuit = constructTestSuit;
15                 $scope.openDialog = openDialog;
16                 $scope.createSuite = createSuite;
17
18             }
19
20             function getTestcaseList() {
21                 mainFactory.getTestcaselist().get({
22
23                 }).$promise.then(function(response) {
24                     if (response.status == 1) {
25                         $scope.testcaselist = response.result;
26
27
28                     }
29                 }, function(error) {
30                     toaster.pop({
31                         type: 'error',
32                         title: 'fail',
33                         body: 'unknow error',
34                         timeout: 3000
35                     });
36                 })
37             }
38
39             $scope.testsuiteList = [];
40             $scope.suitReconstructList = [];
41
42             function constructTestSuit(name) {
43
44                 var index = $scope.testsuiteList.indexOf(name);
45                 if (index > -1) {
46                     $scope.testsuiteList.splice(index, 1);
47                 } else {
48                     $scope.testsuiteList.push(name);
49                 }
50
51
52                 $scope.suitReconstructList = $scope.testsuiteList;
53
54             }
55
56             function createSuite(name) {
57                 mainFactory.suiteCreate().post({
58                     'action': 'create_suite',
59                     'args': {
60                         'name': name,
61                         'testcases': $scope.testsuiteList
62                     }
63                 }).$promise.then(function(response) {
64                     if (response.status == 1) {
65                         toaster.pop({
66                             type: 'success',
67                             title: 'create suite success',
68                             body: 'you can go next step',
69                             timeout: 3000
70                         });
71                         ngDialog.close();
72                     } else {
73
74                     }
75                 }, function(error) {
76                     toaster.pop({
77                         type: 'error',
78                         title: 'fail',
79                         body: 'unknow error',
80                         timeout: 3000
81                     });
82                 })
83             }
84
85             function openDialog() {
86                 ngDialog.open({
87                     template: 'views/modal/suiteName.html',
88                     className: 'ngdialog-theme-default',
89                     scope: $scope,
90                     width: 314,
91                     showClose: true,
92                     closeByDocument: false
93                 })
94             }
95
96
97
98
99
100
101
102
103         }
104     ]);