3 angular.module('yardStickGui2App')
4 .controller('TaskModifyController', ['$scope', '$state', '$stateParams', 'mainFactory', 'Upload', 'toaster',
5 function($scope, $state, $stateParams, mainFactory, Upload, toaster) {
9 $scope.blisterPackTemplates = [{ id: 1, name: "Test Case" }, { id: 2, name: "Test Suite" }]
10 $scope.selectType = null;
12 $scope.sourceShow = null;
17 getDetailTaskForList();
19 $scope.triggerContent = triggerContent;
20 $scope.constructTestSuit = constructTestSuit;
21 $scope.constructTestCase = constructTestCase;
22 $scope.getTestDeatil = getTestDeatil;
23 $scope.confirmToServer = confirmToServer;
24 $scope.addEnvToTask = addEnvToTask;
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';
42 $scope.taskDetailData = response.result.task;
43 $scope.selectEnv = $scope.taskDetailData.environment_id;
45 if ($scope.taskDetailData.environment_id != null) {
46 getItemIdDetail($scope.taskDetailData.environment_id);
60 function getItemIdDetail(id) {
61 mainFactory.ItemDetail().get({
63 }).$promise.then(function(response) {
64 if (response.status == 1) {
65 $scope.envName = response.result.environment.name;
66 // $scope.selectEnv = $scope.envName;
68 alert('Something Wrong!');
81 function getOpenrcDetail(openrcId) {
82 mainFactory.getEnvironmentDetail().get({
84 }).$promise.then(function(response) {
85 $scope.openrcInfo = response.result;
86 // buildToEnvInfo($scope.openrcInfo.openrc)
87 }, function(response) {
94 function getImageDetail(id) {
95 mainFactory.ImageDetail().get({
97 }).$promise.then(function(response) {
98 if (response.status == 1) {
99 $scope.imageDetail = response.result.image;
106 body: 'unknow error',
113 function getPodDetail(id) {
114 mainFactory.podDeatil().get({
116 }).$promise.then(function(response) {
117 if (response.status == 1) {
118 $scope.podDetail = response.result.pod;
124 body: 'unknow error',
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);
145 body: 'unknow error',
151 function getEnvironmentList() {
152 mainFactory.getEnvironmentList().get().$promise.then(function(response) {
153 $scope.environmentList = response.result.environments;
158 body: 'unknow error',
165 function triggerContent(name) {
166 $scope.selectCase = null;
167 $scope.displayTable = true;
169 $scope.selectType = name;
170 if (name.name == 'Test Case') {
171 $scope.taskDetailData.suite = false;
173 } else if (name.name == 'Test Suite') {
174 $scope.taskDetailData.suite = true;
179 function getTestcaseList() {
180 mainFactory.getTestcaselist().get({
182 }).$promise.then(function(response) {
183 if (response.status == 1) {
184 $scope.testcaselist = response.result;
192 body: 'unknow error',
198 function getsuiteList() {
199 mainFactory.suiteList().get({
201 }).$promise.then(function(response) {
202 if (response.status == 1) {
203 $scope.testsuitlist = response.result.testsuites;
210 body: 'unknow error',
217 function constructTestSuit(id, name) {
219 $scope.envName = name;
220 $scope.selectEnv = id;
224 function constructTestCase(name) {
226 $scope.selectCase = name;
227 if ($scope.selectType.name == 'Test Case') {
235 function getCaseInfo() {
239 mainFactory.getTestcaseDetail().get({
240 'testcasename': $scope.selectCase
242 }).$promise.then(function(response) {
243 if (response.status == 1) {
245 $scope.contentInfo = response.result.testcase;
252 body: 'unknow error',
258 function getSuiteInfo() {
259 mainFactory.suiteDetail().get({
260 'suiteName': $scope.selectCase.split('.')[0]
262 }).$promise.then(function(response) {
263 if (response.status == 1) {
264 $scope.contentInfo = response.result.testsuite;
271 body: 'unknow error',
278 function getTestDeatil() {
281 if ($scope.selectType.name == 'Test Case') {
289 function getSuiteDetail() {
290 mainFactory.suiteDetail().get({
291 'suiteName': $scope.selectCase.split('.')[0]
293 }).$promise.then(function(response) {
294 if (response.status == 1) {
295 $scope.displayTable = false;
296 $scope.contentInfo = response.result.testsuite;
303 body: 'unknow error',
310 function getTestcaseDetail() {
311 mainFactory.getTestcaseDetail().get({
312 'testcasename': $scope.selectCase
314 }).$promise.then(function(response) {
315 if (response.status == 1) {
317 $scope.displayTable = false;
318 $scope.contentInfo = response.result.testcase;
325 body: 'unknow error',
333 function addCasetoTask(content) {
334 mainFactory.taskAddEnv().put({
335 'taskId': $stateParams.taskId,
336 'action': 'add_case',
338 'task_id': $stateParams.taskId,
339 'case_name': $scope.selectCase,
340 'case_content': content
342 }).$promise.then(function(response) {
343 if (response.status == 1) {
346 title: 'add test case success',
347 body: 'you can go next step',
350 $scope.ifHasCase = true;
356 title: 'create task wrong',
364 title: 'create task wrong',
371 function addSuitetoTask(content) {
372 mainFactory.taskAddEnv().put({
373 'taskId': $stateParams.taskId,
374 'action': 'add_suite',
376 'task_id': $stateParams.taskId,
377 'suite_name': $scope.selectCase.split('.')[0],
378 'suite_content': content
380 }).$promise.then(function(response) {
381 if (response.status == 1) {
384 title: 'add test suite success',
385 body: 'you can go next step',
388 $scope.ifHasSuite = true;
394 title: 'create task wrong',
402 title: 'create task wrong',
403 body: 'something wrong',
408 $scope.changeStatussourceTrue = function changeStatussourceTrue() {
409 $scope.selectCase = null;
410 $scope.sourceShow = true;
413 $scope.changeStatussourceFalse = function changeStatussourceFalse() {
414 $scope.sourceShow = false;
417 function confirmToServer(content1, content2) {
420 if ($scope.sourceShow == false) {
422 $scope.selectCase = $scope.taskDetailData.case_name;
423 } else if ($scope.sourceShow == true) {
426 if ($scope.selectCase == 'Test Case' || $scope.taskDetailData.suite == false) {
428 addCasetoTask(content);
430 addSuitetoTask(content);
435 function addEnvToTask() {
437 mainFactory.taskAddEnv().put({
438 'taskId': $stateParams.taskId,
439 'action': 'add_environment',
441 'task_id': $stateParams.taskId,
442 'environment_id': $scope.selectEnv
444 }).$promise.then(function(response) {
445 if (response.status == 1) {
448 title: 'add environment success',
449 body: 'you can go next step',
452 $scope.ifHasEnv = true;
458 title: 'create task wrong',
459 body: 'you can go next step',
469 title: 'create task wrong',
470 body: 'you can go next step',
476 $scope.goBack = function goBack() {
477 window.history.back();
480 $scope.runAtask = function runAtask() {
481 mainFactory.taskAddEnv().put({
482 'taskId': $stateParams.taskId,
485 'task_id': $stateParams.taskId
487 }).$promise.then(function(response) {
488 if (response.status == 1) {
491 title: 'run a task success',
492 body: 'go to task list page...',
495 setTimeout(function() {
496 window.history.back();
505 body: response.error_msg,
513 body: 'unknow error',