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" }]
22 $scope.$on('$destroy', function() {
23 $interval.cancel($scope.intervalImgae)
25 $scope.showImageStatus = 0;
35 $scope.gotoProject = gotoProject;
36 $scope.gotoEnvironment = gotoEnvironment;
37 $scope.gotoTask = gotoTask;
38 $scope.gotoExcute = gotoExcute;
39 $scope.gotoReport = gotoReport;
40 $scope.deleteEnvItem = deleteEnvItem;
41 $scope.addInfo = addInfo;
42 $scope.submitOpenRcFile = submitOpenRcFile;
43 $scope.uploadFilesPod = uploadFilesPod;
44 $scope.uploadFiles = uploadFiles;
45 $scope.showEnvriomentStatus = showEnvriomentStatus;
46 $scope.openEnvironmentDialog = openEnvironmentDialog;
47 $scope.getEnvironmentList = getEnvironmentList;
48 $scope.gotoDetail = gotoDetail;
49 $scope.addEnvironment = addEnvironment;
50 $scope.createContainer = createContainer;
51 $scope.chooseResult = chooseResult;
58 function gotoProject() {
62 function gotoEnvironment() {
70 function gotoExcute() {
75 function gotoReport() {
78 $scope.skipPod = function skipPod() {
79 $scope.showContainer = 1;
82 $scope.skipContainer = function skipContainer() {
87 $scope.goToImage = function goToImage() {
91 $scope.goToPod = function goToPod() {
94 $scope.goToPodPrev = function goToPodPrev() {
95 $scope.showImage = null;
98 $scope.skipPodPrev = function skipPodPrev() {
100 $scope.showPod = null;
103 $scope.skipContainerPrev = function skipContainerPrev() {
105 $scope.showContainer = null;
109 { name: 'OS_USERNAME', value: '' },
110 { name: 'OS_PASSWORD', value: '' },
111 { name: 'OS_TENANT_NAME', value: '' },
112 { name: 'EXTERNAL_NETWORK', value: '' }
116 function deleteEnvItem(index) {
117 $scope.envInfo.splice(index, 1);
122 var tempValue = null;
127 $scope.envInfo.push(temp);
131 function submitOpenRcFile() {
132 $scope.showloading = true;
135 postData['action'] = 'update_openrc';
137 postData['args'] = {};
138 postData.args["openrc"] = $scope.postEnvInfo;
139 postData.args['environment_id'] = $scope.uuidEnv;
140 mainFactory.postEnvironmentVariable().post(postData).$promise.then(function(response) {
141 $scope.showloading = false;
143 if (response.status == 1) {
145 $scope.openrcInfo = response.result;
148 title: 'create success',
149 body: 'you can go next step',
152 $scope.showEnvrionment = true;
153 // $scope.showImage = response.status;
154 $scope.showNextOpenRc = 1;
159 body: response.error_msg,
168 body: 'unknow error',
175 function uploadFiles($file, $invalidFiles) {
176 $scope.openrcInfo = {};
177 $scope.loadingOPENrc = true;
178 $scope.displayOpenrcFile = $file;
179 timeConstruct($scope.displayOpenrcFile.lastModified);
181 url: Base_URL + '/api/v2/yardstick/openrcs',
182 data: { file: $file, 'environment_id': $scope.uuidEnv, 'action': 'upload_openrc' }
183 }).then(function(response) {
185 $scope.loadingOPENrc = false;
186 if (response.data.status == 1) {
189 title: 'upload success',
190 body: 'you can go next step',
193 $scope.openrcInfo = response.data.result;
195 getItemIdDetailforOpenrc();
196 $scope.showNextOpenRc = 1;
201 body: response.error_msg,
207 $scope.uploadfile = null;
211 body: 'unknow error',
218 function rebuildEnvInfo() {
219 $scope.postEnvInfo = {};
220 for (var i = 0; i < $scope.envInfo.length; i++) {
221 $scope.postEnvInfo[$scope.envInfo[i].name] = $scope.envInfo[i].value;
225 function uploadFilesPod($file, $invalidFiles) {
226 $scope.loadingOPENrc = true;
228 $scope.displayPodFile = $file;
229 timeConstruct($scope.displayPodFile.lastModified);
231 url: Base_URL + '/api/v2/yardstick/pods',
232 data: { file: $file, 'environment_id': $scope.uuidEnv, 'action': 'upload_pod_file' }
233 }).then(function(response) {
235 $scope.loadingOPENrc = false;
236 if (response.data.status == 1) {
239 title: 'upload success',
240 body: 'you can go next step',
244 $scope.podData = response.data.result;
251 body: response.error_msg,
257 $scope.uploadfile = null;
261 body: 'unknow error',
267 function timeConstruct(array) {
268 var date = new Date(1398250549490);
269 var Y = date.getFullYear() + '-';
270 var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
271 var D = date.getDate() + ' ';
272 var h = date.getHours() + ':';
273 var m = date.getMinutes() + ':';
274 var s = date.getSeconds();
275 $scope.filelastModified = Y + M + D + h + m + s;
279 //display environment
280 function showEnvriomentStatus() {
281 $scope.showEnvironment = true;
284 //open Environment dialog
285 function openEnvironmentDialog() {
286 $scope.showEnvrionment = false;
287 $scope.loadingOPENrc = false;
288 $scope.uuidEnv = null;
289 $scope.showPod = null;
290 $scope.showImage = null;
291 $scope.showContainer = null;
292 $scope.showNextOpenRc = null;
293 $scope.showNextPod = null;
294 $scope.displayContainerInfo = [];
296 $scope.displayPodFile = null;
298 $scope.openrcInfo = null;
300 { name: 'OS_USERNAME', value: '' },
301 { name: 'OS_PASSWORD', value: '' },
302 { name: 'OS_TENANT_NAME', value: '' },
303 { name: 'EXTERNAL_NETWORK', value: '' }
305 $scope.displayOpenrcFile = null;
306 $scope.podData = null;
307 $scope.displayContainerInfo = null;
309 preCloseCallback: function(value) {
310 getEnvironmentList();
313 template: 'views/modal/environmentDialog.html',
315 className: 'ngdialog-theme-default',
318 closeByDocument: false
322 function getEnvironmentList() {
323 $loading.start('key');
325 mainFactory.getEnvironmentList().get().$promise.then(function(response) {
326 $scope.environmentList = response.result.environments;
327 $loading.finish('key');
330 $loading.finish('key');
334 body: 'unknow error',
342 function gotoDetail(ifNew, uuid) {
344 $state.go('app.environmentDetail', { uuid: uuid, ifNew: ifNew });
348 function addEnvironment(name) {
349 mainFactory.addEnvName().post({
350 'action': 'create_environment',
354 }).$promise.then(function(response) {
355 if (response.status == 1) {
358 title: 'create name success',
359 body: 'you can go next step',
362 $scope.uuidEnv = response.result.uuid;
371 body: 'unknow error',
379 $scope.goBack = function goBack() {
380 $state.go('app.projectList');
382 $scope.displayContainerInfo = [];
384 function createContainer(selectContainer) {
386 $scope.showloading = true;
387 mainFactory.runAcontainer().post({
388 'action': selectContainer.value,
390 'environment_id': $scope.uuidEnv,
392 }).$promise.then(function(response) {
393 $scope.showloading = false;
394 if (response.status == 1) {
397 title: 'create container success',
398 body: 'you can go next step',
402 setTimeout(function() {
405 $scope.ifskipOrClose = 1;
410 body: response.result,
419 body: 'unknow error',
425 function getConDetail(id) {
426 mainFactory.containerDetail().get({
428 }).$promise.then(function(response) {
429 if (response.status == 1) {
430 // $scope.podData = response.result;
431 $scope.displayContainerInfo.push(response.result.container);
439 body: 'unknow error',
446 function chooseResult(name) {
447 $scope.selectContainer = name;
450 function getItemIdDetail() {
451 $scope.displayContainerInfo = [];
452 mainFactory.ItemDetail().get({
453 'envId': $scope.uuidEnv
454 }).$promise.then(function(response) {
455 if (response.status == 1) {
456 $scope.envName = response.result.environment.name;
457 $scope.containerId = response.result.environment.container_id;
458 if ($scope.containerId != null) {
460 var keysArray = Object.keys($scope.containerId);
461 for (var k in $scope.containerId) {
462 getConDetail($scope.containerId[k]);
468 $scope.podData = null;
476 body: 'unknow error',
482 $scope.uploadImage = function uploadImage() {
483 $scope.imageStatus = 0;
484 $scope.showImageStatus = 1;
485 $scope.showloading = true;
486 mainFactory.uploadImage().post({
487 'action': 'load_image',
489 'environment_id': $scope.uuid
492 }).$promise.then(function(response) {
493 $scope.showloading = false;
494 if (response.status == 1) {
497 title: 'create success',
498 body: 'you can go next step',
501 setTimeout(function() {
504 $scope.showNextPod = 1;
510 body: 'something wrong',
519 body: 'something wrong',
525 function getImageList() {
526 if ($scope.intervalImgae != undefined) {
527 $interval.cancel($scope.intervalImgae);
529 mainFactory.ImageList().get({}).$promise.then(function(response) {
530 if (response.status == 1) {
531 $scope.imageListData = response.result.images;
532 $scope.imageStatus = response.result.status;
534 if ($scope.imageStatus == 0) {
535 $scope.intervalImgae = $interval(function() {
538 } else if ($scope.intervalImgae != undefined) {
539 $interval.cancel($scope.intervalImgae);
545 title: 'get data failed',
546 body: 'please retry',
553 title: 'get data failed',
554 body: 'please retry',
560 function getImageListSimple() {
562 mainFactory.ImageList().get({}).$promise.then(function(response) {
563 if (response.status == 1) {
564 $scope.imageListData = response.result.images;
565 $scope.imageStatus = response.result.status;
570 title: 'get data failed',
571 body: 'please retry',
578 title: 'get data failed',
579 body: 'please retry',
585 $scope.openDeleteEnv = function openDeleteEnv(id, name) {
586 $scope.deleteName = name;
587 $scope.deleteId = id;
589 template: 'views/modal/deleteConfirm.html',
591 className: 'ngdialog-theme-default',
594 closeByDocument: false
599 $scope.deleteEnv = function deleteEnv() {
600 mainFactory.deleteEnv().delete({ 'env_id': $scope.deleteId }).$promise.then(function(response) {
601 if (response.status == 1) {
604 title: 'delete environment success',
605 body: 'you can go next step',
609 getEnvironmentList();
614 body: response.result,
623 body: 'unknow error',
634 function getItemIdDetailforOpenrc() {
636 mainFactory.ItemDetail().get({
637 'envId': $scope.uuidEnv
638 }).$promise.then(function(response) {
639 if (response.status == 1) {
640 $scope.baseElementInfo = response.result.environment;
643 if ($scope.ifNew != 'true') {
644 $scope.baseElementInfo = response.result.environment;
645 if ($scope.baseElementInfo.openrc_id != null) {
646 getOpenrcDetailForOpenrc($scope.baseElementInfo.openrc_id);
654 body: response.error_msg,
664 body: 'unknow error',
674 function getOpenrcDetailForOpenrc(openrcId) {
675 mainFactory.getEnvironmentDetail().get({
676 'openrc_id': openrcId
677 }).$promise.then(function(response) {
678 $scope.openrcInfo = response.result;
679 buildToEnvInfoOpenrc($scope.openrcInfo.openrc)
680 }, function(response) {
684 body: 'unknow error',
691 function buildToEnvInfoOpenrc(object) {
692 var tempKeyArray = Object.keys(object);
696 for (var i = 0; i < tempKeyArray.length; i++) {
697 var tempkey = tempKeyArray[i];
698 var tempValue = object[tempKeyArray[i]];
703 $scope.envInfo.push(temp);