Merge "Add spec cpu2006 test case"
[yardstick.git] / gui / app / scripts / controllers / testcase.controller.js
1 'use strict';
2
3 angular.module('yardStickGui2App')
4     .controller('TestcaseController', ['$scope', '$state', '$stateParams', 'mainFactory', 'Upload', 'toaster', 'ngDialog', '$loading',
5         function($scope, $state, $stateParams, mainFactory, Upload, toaster, ngDialog, $loading) {
6
7
8             init();
9             $scope.loadingOPENrc = false;
10
11
12             function init() {
13                 $scope.testcaselist = [];
14                 getTestcaseList();
15                 $scope.gotoDetail = gotoDetail;
16                 $scope.uploadFiles = uploadFiles;
17
18
19             }
20
21             function getTestcaseList() {
22                 $loading.start('key');
23                 mainFactory.getTestcaselist().get({
24
25                 }).$promise.then(function(response) {
26                     $loading.finish('key');
27                     if (response.status == 1) {
28                         $scope.testcaselist = response.result;
29
30
31                     }
32                 }, function(error) {
33                     $loading.finish('key');
34                     toaster.pop({
35                         type: 'error',
36                         title: 'fail',
37                         body: 'unknow error',
38                         timeout: 3000
39                     });
40                 })
41             }
42
43             function gotoDetail(name) {
44                 $state.go('app2.testcasedetail', { name: name });
45             }
46
47
48             function uploadFiles($file, $invalidFiles) {
49                 $scope.loadingOPENrc = true;
50
51                 $scope.displayOpenrcFile = $file;
52                 timeConstruct($scope.displayOpenrcFile.lastModified);
53                 Upload.upload({
54                     url: Base_URL + '/api/v2/yardstick/testcases',
55                     data: { file: $file, 'action': 'upload_case' }
56                 }).then(function(response) {
57
58                     $scope.loadingOPENrc = false;
59                     if (response.data.status == 1) {
60                         toaster.pop({
61                             type: 'success',
62                             title: 'upload success',
63                             body: 'you can go next step',
64                             timeout: 3000
65                         });
66
67
68
69                     } else {
70
71                     }
72
73                 }, function(error) {
74                     $scope.uploadfile = null;
75                     toaster.pop({
76                         type: 'error',
77                         title: 'fail',
78                         body: 'unknow error',
79                         timeout: 3000
80                     });
81                 })
82             }
83
84             function timeConstruct(array) {
85                 var date = new Date(1398250549490);
86                 var Y = date.getFullYear() + '-';
87                 var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
88                 var D = date.getDate() + ' ';
89                 var h = date.getHours() + ':';
90                 var m = date.getMinutes() + ':';
91                 var s = date.getSeconds();
92                 $scope.filelastModified = Y + M + D + h + m + s;
93
94             }
95             $scope.goBack = function goBack() {
96                 $state.go('app2.projectList');
97             }
98
99             $scope.openDeleteEnv = function openDeleteEnv(id, name) {
100                 $scope.deleteName = name;
101                 $scope.deleteId = id;
102                 ngDialog.open({
103                     template: 'views/modal/deleteConfirm.html',
104                     scope: $scope,
105                     className: 'ngdialog-theme-default',
106                     width: 500,
107                     showClose: true,
108                     closeByDocument: false
109                 })
110
111             }
112
113             $scope.deleteTestCase = function deleteTestCase() {
114                 mainFactory.deleteTestCase().delete({ 'caseName': $scope.deleteId }).$promise.then(function(response) {
115                     if (response.status == 1) {
116                         toaster.pop({
117                             type: 'success',
118                             title: 'delete Test Case success',
119                             body: 'you can go next step',
120                             timeout: 3000
121                         });
122                         ngDialog.close();
123                         getTestcaseList();
124                     } else {
125                         toaster.pop({
126                             type: 'error',
127                             title: 'Wrong',
128                             body: response.result,
129                             timeout: 3000
130                         });
131                     }
132
133                 }, function(error) {
134                     toaster.pop({
135                         type: 'error',
136                         title: 'fail',
137                         body: 'unknow error',
138                         timeout: 3000
139                     });
140
141                 })
142             }
143
144
145
146
147
148
149
150
151
152
153         }
154     ]);