3 angular.module('yardStickGui2App')
4 .controller('ProjectDetailController', ['$scope', '$state', '$stateParams', 'mainFactory', 'Upload', 'toaster', 'ngDialog', '$localStorage', '$loading', '$interval',
5 function($scope, $state, $stateParams, mainFactory, Upload, toaster, ngDialog, $localStorage, $loading, $interval) {
9 // $scope.taskListDisplay = [];
10 $scope.blisterPackTemplates = [{ id: 1, name: "Test Case" }, { id: 2, name: "Test Suite" }]
11 $scope.selectType = null;
12 $scope.ifHasEnv = false;
13 $scope.ifHasCase = false;
14 $scope.ifHasSuite = false;
15 $scope.$on('$destroy', function() {
16 $interval.cancel($scope.intervalCount)
18 $scope.finalTaskListDisplay = [];
26 $scope.openCreate = openCreate;
27 $scope.createTask = createTask;
28 $scope.constructTestSuit = constructTestSuit;
29 $scope.addEnvToTask = addEnvToTask;
30 $scope.triggerContent = triggerContent;
31 $scope.constructTestCase = constructTestCase;
32 $scope.getTestDeatil = getTestDeatil;
33 $scope.confirmAddCaseOrSuite = confirmAddCaseOrSuite;
34 $scope.runAtask = runAtask;
35 $scope.gotoDetail = gotoDetail;
36 $scope.gotoReport = gotoReport;
37 $scope.gotoModify = gotoModify;
38 $scope.goBack = goBack;
39 $scope.goToExternal = goToExternal;
44 function getProjectDetail() {
45 if ($scope.intervalCount != undefined) {
46 $interval.cancel($scope.intervalCount);
48 $loading.start('key');
49 $scope.taskListDisplay = [];
50 $scope.finalTaskListDisplay = [];
51 mainFactory.getProjectDetail().get({
52 project_id: $stateParams.projectId
53 }).$promise.then(function(response) {
54 $loading.finish('key');
55 if (response.status == 1) {
57 $scope.projectData = response.result.project;
58 if ($scope.projectData.tasks.length != 0) {
61 for (var i = 0; i < $scope.projectData.tasks.length; i++) {
62 getDetailTaskForList($scope.projectData.tasks[i]);
64 $scope.intervalCount = $interval(function() {
65 getDetailForEachTask();
69 if ($scope.intervalCount != undefined) {
70 $interval.cancel($scope.intervalCount);
87 // function getProjectDetailSimple() {
88 // getDetailForEachTask();
91 function openCreate() {
92 $scope.newUUID = null;
93 $scope.displayEnvName = null;
94 $scope.selectEnv = null;
95 $scope.selectCase = null;
96 $scope.selectType = null;
97 $scope.contentInfo = null;
98 $scope.ifHasEnv = false;
99 $scope.ifHasCase = false;
100 $scope.ifHasSuite = false;
102 // getEnvironmentList();
103 $scope.selectEnv = null;
105 template: 'views/modal/taskCreate.html',
107 className: 'ngdialog-theme-default',
110 closeByDocument: false,
111 preCloseCallback: function(value) {
117 function createTask(name) {
118 mainFactory.createTask().post({
119 'action': 'create_task',
122 'project_id': $stateParams.projectId
124 }).$promise.then(function(response) {
125 if (response.status == 1) {
128 title: 'create task success',
129 body: 'you can go next step',
132 $scope.newUUID = response.result.uuid;
133 getEnvironmentList();
138 title: 'create task wrong',
139 body: 'you can go next step',
149 title: 'create task wrong',
150 body: 'you can go next step',
156 function getDetailTaskForList(id) {
158 mainFactory.getTaskDetail().get({
160 }).$promise.then(function(response) {
162 if (response.status == 1) {
163 if (response.result.task.status == -1) {
164 response.result.task['stausWidth'] = '5%';
165 } else if (response.result.task.status == 0) {
166 response.result.task['stausWidth'] = '50%';
167 } else if (response.result.task.status == 1) {
168 response.result.task['stausWidth'] = '100%';
169 } else if (response.result.task.status == 2) {
170 response.result.task['stausWidth'] = 'red';
172 $scope.taskListDisplay.push(response.result.task);
173 console.log($scope.taskListDisplay);
175 $scope.finalTaskListDisplay = $scope.taskListDisplay;
182 body: 'unknow error',
189 function getDetailTaskForListSimple(id, index) {
191 mainFactory.getTaskDetail().get({
193 }).$promise.then(function(response) {
195 if (response.status == 1) {
196 if (response.result.task.status == -1) {
198 $scope.finalTaskListDisplay[index].stausWidth = '5%';
199 $scope.finalTaskListDisplay[index].status = response.result.task.status;
200 } else if (response.result.task.status == 0) {
202 $scope.finalTaskListDisplay[index].stausWidth = '50%';
203 $scope.finalTaskListDisplay[index].status = response.result.task.status;
204 } else if (response.result.task.status == 1) {
206 $scope.finalTaskListDisplay[index].stausWidth = '100%';
207 $scope.finalTaskListDisplay[index].status = response.result.task.status;
208 } else if (response.result.task.status == 2) {
210 $scope.finalTaskListDisplay[index].stausWidth = 'red';
211 $scope.finalTaskListDisplay[index].status = response.result.task.status;
220 body: 'unknow error',
227 function getDetailForEachTask() {
228 for (var i = 0; i < $scope.finalTaskListDisplay.length; i++) {
229 if ($scope.finalTaskListDisplay[i].status != 1 && $scope.finalTaskListDisplay[i].status != -1) {
230 getDetailTaskForListSimple($scope.finalTaskListDisplay[i].uuid, i);
235 function getEnvironmentList() {
236 mainFactory.getEnvironmentList().get().$promise.then(function(response) {
237 $scope.environmentList = response.result.environments;
242 body: 'unknow error',
249 function constructTestSuit(id, name) {
250 $scope.displayEnvName = name;
251 $scope.selectEnv = id;
255 function constructTestCase(name) {
257 $scope.selectCase = name;
258 if ($scope.selectType.name == 'Test Case') {
269 function addEnvToTask() {
270 mainFactory.taskAddEnv().put({
271 'taskId': $scope.newUUID,
272 'action': 'add_environment',
274 'task_id': $scope.newUUID,
275 'environment_id': $scope.selectEnv
277 }).$promise.then(function(response) {
278 if (response.status == 1) {
281 title: 'add environment success',
282 body: 'you can go next step',
285 $scope.ifHasEnv = true;
291 title: 'create task wrong',
292 body: 'you can go next step',
302 title: 'create task wrong',
303 body: 'you can go next step',
309 function triggerContent(name) {
310 $scope.selectCase = null;
311 $scope.displayTable = true;
313 $scope.selectType = name;
314 if (name.name == 'Test Case') {
316 } else if (name.name == 'Test Suite') {
321 function getTestcaseList() {
322 mainFactory.getTestcaselist().get({
324 }).$promise.then(function(response) {
325 if (response.status == 1) {
326 $scope.testcaselist = response.result;
334 body: 'unknow error',
340 function getsuiteList() {
341 mainFactory.suiteList().get({
343 }).$promise.then(function(response) {
344 if (response.status == 1) {
345 $scope.testsuitlist = response.result.testsuites;
352 body: 'unknow error',
358 function getTestDeatil() {
361 if ($scope.selectType.name == 'Test Case') {
369 function getCaseInfo() {
373 mainFactory.getTestcaseDetail().get({
374 'testcasename': $scope.selectCase
376 }).$promise.then(function(response) {
377 if (response.status == 1) {
379 $scope.contentInfo = response.result.testcase;
386 body: 'unknow error',
392 function getSuiteInfo() {
393 mainFactory.suiteDetail().get({
394 'suiteName': $scope.selectCase.split('.')[0]
396 }).$promise.then(function(response) {
397 if (response.status == 1) {
398 $scope.contentInfo = response.result.testsuite;
405 body: 'unknow error',
412 function getSuiteDetail() {
413 mainFactory.suiteDetail().get({
414 'suiteName': $scope.selectCase.split('.')[0]
416 }).$promise.then(function(response) {
417 if (response.status == 1) {
418 $scope.displayTable = false;
419 $scope.contentInfo = response.result.testsuite;
426 body: 'unknow error',
433 function getTestcaseDetail() {
434 mainFactory.getTestcaseDetail().get({
435 'testcasename': $scope.selectCase
437 }).$promise.then(function(response) {
438 if (response.status == 1) {
440 $scope.displayTable = false;
441 $scope.contentInfo = response.result.testcase;
448 body: 'unknow error',
454 function addCasetoTask(content) {
455 mainFactory.taskAddEnv().put({
456 'taskId': $scope.newUUID,
457 'action': 'add_case',
459 'task_id': $scope.newUUID,
460 'case_name': $scope.selectCase,
461 'case_content': content
463 }).$promise.then(function(response) {
464 if (response.status == 1) {
467 title: 'add test case success',
468 body: 'you can go next step',
471 $scope.ifHasCase = true;
477 title: 'create task wrong',
478 body: 'you can go next step',
485 title: 'create task wrong',
486 body: 'you can go next step',
492 function addSuitetoTask(content) {
493 mainFactory.taskAddEnv().put({
494 'taskId': $scope.newUUID,
495 'action': 'add_suite',
497 'task_id': $scope.newUUID,
498 'suite_name': $scope.selectCase.split('.')[0],
499 'suite_content': content
501 }).$promise.then(function(response) {
502 if (response.status == 1) {
505 title: 'add test suite success',
506 body: 'you can go next step',
509 $scope.ifHasSuite = true;
515 title: 'create task wrong',
523 title: 'create task wrong',
524 body: 'something wrong',
530 function confirmAddCaseOrSuite(content) {
531 if ($scope.selectType.name == "Test Case") {
532 addCasetoTask(content);
534 addSuitetoTask(content);
538 function runAtask(id) {
539 mainFactory.taskAddEnv().put({
545 }).$promise.then(function(response) {
546 if (response.status == 1) {
549 title: 'run a task success',
550 body: 'you can go next step',
554 // getProjectDetail();
562 body: 'unknow error',
569 $scope.runAtaskForTable = function runAtaskForTable(id) {
570 mainFactory.taskAddEnv().put({
576 }).$promise.then(function(response) {
577 if (response.status == 1) {
580 // title: 'run a task success',
581 // body: 'you can go next step',
590 body: response.result,
599 body: 'unknow error',
606 function gotoDetail(id) {
609 $state.go('app.tasklist', { taskId: id });
613 function gotoReport(id) {
614 $state.go('app.report', { taskId: id });
617 function gotoModify(id) {
618 $state.go('app.taskModify', { taskId: id });
622 window.history.back();
625 function goToExternal() {
626 window.open(External_URL, '_blank');
629 $scope.openDeleteEnv = function openDeleteEnv(id, name) {
630 $scope.deleteName = name;
631 $scope.deleteId = id;
633 template: 'views/modal/deleteConfirm.html',
635 className: 'ngdialog-theme-default',
638 closeByDocument: false
643 $scope.deleteTask = function deleteTask() {
644 mainFactory.deleteTask().delete({ 'task_id': $scope.deleteId }).$promise.then(function(response) {
645 if (response.status == 1) {
648 title: 'delete Task success',
649 body: 'you can go next step',
658 body: response.result,
667 body: 'unknow error',
674 $scope.gotoLog = function gotoLog(task_id) {
675 $state.go('app2.taskLog', { taskId: task_id });