3 angular.module('yardStickGui2App')
4 .controller('MainCtrl', ['$scope', '$state', '$stateParams', 'mainFactory', 'Upload', 'toaster', 'ngDialog', '$localStorage', '$loading', '$interval',
5 function($scope, $state, $stateParams, mainFactory, Upload, toaster, ngDialog, $localStorage, $loading, $interval) {
10 $scope.showloading = false;
11 $scope.showEnvrionment = false;
12 $scope.loadingOPENrc = false;
13 $scope.uuidEnv = null;
14 $scope.showPod = null;
15 $scope.showImage = null;
16 $scope.showContainer = null;
17 $scope.showNextOpenRc = null;
18 $scope.showNextPod = null;
19 $scope.displayContainerInfo = [];
20 $scope.containerList = [{ value: 'create_influxdb', name: "InfluxDB" }, { value: 'create_grafana', name: "Grafana" }]
23 'And another choice for you.',
26 $scope.$on('$destroy', function() {
27 $interval.cancel($scope.intervalImgae)
29 $scope.showImageStatus = 0;
39 $scope.gotoProject = gotoProject;
40 $scope.gotoEnvironment = gotoEnvironment;
41 $scope.gotoTask = gotoTask;
42 $scope.gotoExcute = gotoExcute;
43 $scope.gotoReport = gotoReport;
44 $scope.deleteEnvItem = deleteEnvItem;
45 $scope.addInfo = addInfo;
46 $scope.submitOpenRcFile = submitOpenRcFile;
47 $scope.uploadFilesPod = uploadFilesPod;
48 $scope.uploadFiles = uploadFiles;
49 $scope.showEnvriomentStatus = showEnvriomentStatus;
50 $scope.openEnvironmentDialog = openEnvironmentDialog;
51 $scope.getEnvironmentList = getEnvironmentList;
52 $scope.gotoDetail = gotoDetail;
53 $scope.addEnvironment = addEnvironment;
54 $scope.createContainer = createContainer;
55 $scope.chooseResult = chooseResult;
62 function gotoProject() {
66 function gotoEnvironment() {
74 function gotoExcute() {
79 function gotoReport() {
82 $scope.skipPod = function skipPod() {
83 $scope.showContainer = 1;
86 $scope.skipContainer = function skipContainer() {
91 $scope.goToImage = function goToImage() {
95 $scope.goToPod = function goToPod() {
98 $scope.goToPodPrev = function goToPodPrev() {
99 $scope.showImage = null;
102 $scope.skipPodPrev = function skipPodPrev() {
103 $scope.showImage = 1;
104 $scope.showPod = null;
107 $scope.skipContainerPrev = function skipContainerPrev() {
109 $scope.showContainer = null;
113 { name: 'OS_USERNAME', value: '' },
114 { name: 'OS_PASSWORD', value: '' },
115 { name: 'OS_TENANT_NAME', value: '' },
116 { name: 'EXTERNAL_NETWORK', value: '' }
120 function deleteEnvItem(index) {
121 $scope.envInfo.splice(index, 1);
126 var tempValue = null;
131 $scope.envInfo.push(temp);
135 function submitOpenRcFile() {
136 $scope.showloading = true;
139 postData['action'] = 'update_openrc';
141 postData['args'] = {};
142 postData.args["openrc"] = $scope.postEnvInfo;
143 postData.args['environment_id'] = $scope.uuidEnv;
144 mainFactory.postEnvironmentVariable().post(postData).$promise.then(function(response) {
145 $scope.showloading = false;
147 if (response.status == 1) {
149 $scope.openrcInfo = response.result;
152 title: 'create success',
153 body: 'you can go next step',
156 $scope.showEnvrionment = true;
157 // $scope.showImage = response.status;
158 $scope.showNextOpenRc = 1;
163 body: response.error_msg,
172 body: 'unknow error',
179 function uploadFiles($file, $invalidFiles) {
180 $scope.openrcInfo = {};
181 $scope.loadingOPENrc = true;
182 $scope.displayOpenrcFile = $file;
183 timeConstruct($scope.displayOpenrcFile.lastModified);
185 url: Base_URL + '/api/v2/yardstick/openrcs',
186 data: { file: $file, 'environment_id': $scope.uuidEnv, 'action': 'upload_openrc' }
187 }).then(function(response) {
189 $scope.loadingOPENrc = false;
190 if (response.data.status == 1) {
193 title: 'upload success',
194 body: 'you can go next step',
197 $scope.openrcInfo = response.data.result;
199 getItemIdDetailforOpenrc();
200 $scope.showNextOpenRc = 1;
205 body: response.error_msg,
211 $scope.uploadfile = null;
215 body: 'unknow error',
222 function rebuildEnvInfo() {
223 $scope.postEnvInfo = {};
224 for (var i = 0; i < $scope.envInfo.length; i++) {
225 $scope.postEnvInfo[$scope.envInfo[i].name] = $scope.envInfo[i].value;
229 function uploadFilesPod($file, $invalidFiles) {
230 $scope.loadingOPENrc = true;
232 $scope.displayPodFile = $file;
233 timeConstruct($scope.displayPodFile.lastModified);
235 url: Base_URL + '/api/v2/yardstick/pods',
236 data: { file: $file, 'environment_id': $scope.uuidEnv, 'action': 'upload_pod_file' }
237 }).then(function(response) {
239 $scope.loadingOPENrc = false;
240 if (response.data.status == 1) {
243 title: 'upload success',
244 body: 'you can go next step',
248 $scope.podData = response.data.result;
255 body: response.error_msg,
261 $scope.uploadfile = null;
265 body: 'unknow error',
271 function timeConstruct(array) {
272 var date = new Date(1398250549490);
273 var Y = date.getFullYear() + '-';
274 var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
275 var D = date.getDate() + ' ';
276 var h = date.getHours() + ':';
277 var m = date.getMinutes() + ':';
278 var s = date.getSeconds();
279 $scope.filelastModified = Y + M + D + h + m + s;
283 //display environment
284 function showEnvriomentStatus() {
285 $scope.showEnvironment = true;
288 //open Environment dialog
289 function openEnvironmentDialog() {
290 $scope.showEnvrionment = false;
291 $scope.loadingOPENrc = false;
292 $scope.uuidEnv = null;
293 $scope.showPod = null;
294 $scope.showImage = null;
295 $scope.showContainer = null;
296 $scope.showNextOpenRc = null;
297 $scope.showNextPod = null;
298 $scope.displayContainerInfo = [];
300 $scope.displayPodFile = null;
302 $scope.openrcInfo = null;
304 { name: 'OS_USERNAME', value: '' },
305 { name: 'OS_PASSWORD', value: '' },
306 { name: 'OS_TENANT_NAME', value: '' },
307 { name: 'EXTERNAL_NETWORK', value: '' }
309 $scope.displayOpenrcFile = null;
310 $scope.podData = null;
311 $scope.displayContainerInfo = null;
313 preCloseCallback: function(value) {
314 getEnvironmentList();
317 template: 'views/modal/environmentDialog.html',
319 className: 'ngdialog-theme-default',
322 closeByDocument: false
326 function getEnvironmentList() {
327 $loading.start('key');
329 mainFactory.getEnvironmentList().get().$promise.then(function(response) {
330 $scope.environmentList = response.result.environments;
331 $loading.finish('key');
334 $loading.finish('key');
338 body: 'unknow error',
346 function gotoDetail(ifNew, uuid) {
348 $state.go('app.environmentDetail', { uuid: uuid, ifNew: ifNew });
352 function addEnvironment(name) {
353 mainFactory.addEnvName().post({
354 'action': 'create_environment',
358 }).$promise.then(function(response) {
359 if (response.status == 1) {
362 title: 'create name success',
363 body: 'you can go next step',
366 $scope.uuidEnv = response.result.uuid;
375 body: 'unknow error',
383 $scope.goBack = function goBack() {
384 $state.go('app2.projectList');
386 $scope.displayContainerInfo = [];
388 function createContainer(selectContainer) {
390 $scope.showloading = true;
391 mainFactory.runAcontainer().post({
392 'action': selectContainer.value,
394 'environment_id': $scope.uuidEnv,
396 }).$promise.then(function(response) {
397 $scope.showloading = false;
398 if (response.status == 1) {
401 title: 'create container success',
402 body: 'you can go next step',
406 setTimeout(function() {
409 $scope.ifskipOrClose = 1;
414 body: response.result,
423 body: 'unknow error',
429 function getConDetail(id) {
430 mainFactory.containerDetail().get({
432 }).$promise.then(function(response) {
433 if (response.status == 1) {
434 // $scope.podData = response.result;
435 $scope.displayContainerInfo.push(response.result.container);
443 body: 'unknow error',
450 function chooseResult(name) {
451 $scope.selectContainer = name;
454 function getItemIdDetail() {
455 $scope.displayContainerInfo = [];
456 mainFactory.ItemDetail().get({
457 'envId': $scope.uuidEnv
458 }).$promise.then(function(response) {
459 if (response.status == 1) {
460 $scope.envName = response.result.environment.name;
461 $scope.containerId = response.result.environment.container_id;
462 if ($scope.containerId != null) {
464 var keysArray = Object.keys($scope.containerId);
465 for (var k in $scope.containerId) {
466 getConDetail($scope.containerId[k]);
472 $scope.podData = null;
480 body: 'unknow error',
486 $scope.uploadImage = function uploadImage() {
487 $scope.imageStatus = 0;
488 $scope.showImageStatus = 1;
489 $scope.showloading = true;
490 mainFactory.uploadImage().post({
491 'action': 'load_image',
493 'environment_id': $scope.uuid
496 }).$promise.then(function(response) {
497 $scope.showloading = false;
498 if (response.status == 1) {
501 title: 'create success',
502 body: 'you can go next step',
505 setTimeout(function() {
508 $scope.showNextPod = 1;
514 body: 'something wrong',
523 body: 'something wrong',
529 function getImageList() {
530 if ($scope.intervalImgae != undefined) {
531 $interval.cancel($scope.intervalImgae);
533 mainFactory.ImageList().get({}).$promise.then(function(response) {
534 if (response.status == 1) {
535 $scope.imageListData = response.result.images;
536 $scope.imageStatus = response.result.status;
538 if ($scope.imageStatus == 0) {
539 $scope.intervalImgae = $interval(function() {
542 } else if ($scope.intervalImgae != undefined) {
543 $interval.cancel($scope.intervalImgae);
549 title: 'get data failed',
550 body: 'please retry',
557 title: 'get data failed',
558 body: 'please retry',
564 function getImageListSimple() {
566 mainFactory.ImageList().get({}).$promise.then(function(response) {
567 if (response.status == 1) {
568 $scope.imageListData = response.result.images;
569 $scope.imageStatus = response.result.status;
574 title: 'get data failed',
575 body: 'please retry',
582 title: 'get data failed',
583 body: 'please retry',
589 $scope.openDeleteEnv = function openDeleteEnv(id, name) {
590 $scope.deleteName = name;
591 $scope.deleteId = id;
593 template: 'views/modal/deleteConfirm.html',
595 className: 'ngdialog-theme-default',
598 closeByDocument: false
603 $scope.deleteEnv = function deleteEnv() {
604 mainFactory.deleteEnv().delete({ 'env_id': $scope.deleteId }).$promise.then(function(response) {
605 if (response.status == 1) {
608 title: 'delete environment success',
609 body: 'you can go next step',
613 getEnvironmentList();
618 body: response.result,
627 body: 'unknow error',
638 function getItemIdDetailforOpenrc() {
640 mainFactory.ItemDetail().get({
641 'envId': $scope.uuidEnv
642 }).$promise.then(function(response) {
643 if (response.status == 1) {
644 $scope.baseElementInfo = response.result.environment;
647 if ($scope.ifNew != 'true') {
648 $scope.baseElementInfo = response.result.environment;
649 if ($scope.baseElementInfo.openrc_id != null) {
650 getOpenrcDetailForOpenrc($scope.baseElementInfo.openrc_id);
658 body: response.error_msg,
668 body: 'unknow error',
678 function getOpenrcDetailForOpenrc(openrcId) {
679 mainFactory.getEnvironmentDetail().get({
680 'openrc_id': openrcId
681 }).$promise.then(function(response) {
682 $scope.openrcInfo = response.result;
683 buildToEnvInfoOpenrc($scope.openrcInfo.openrc)
684 }, function(response) {
688 body: 'unknow error',
695 function buildToEnvInfoOpenrc(object) {
696 var tempKeyArray = Object.keys(object);
700 for (var i = 0; i < tempKeyArray.length; i++) {
701 var tempkey = tempKeyArray[i];
702 var tempValue = object[tempKeyArray[i]];
707 $scope.envInfo.push(temp);