3 angular.module('yardStickGui2App')
4 .controller('DetailController', ['$scope', '$state', '$stateParams', 'mainFactory', 'Upload', 'toaster', '$location', 'ngDialog',
5 function($scope, $state, $stateParams, mainFactory, Upload, toaster, $location, ngDialog) {
11 $scope.showEnvironment = false;
15 $scope.showEnvironments = showEnvironments;
16 // $scope.openrcID = $stateParams.uuid;
17 $scope.deleteEnvItem = deleteEnvItem;
18 $scope.addInfo = addInfo;
19 $scope.submitOpenRcFile = submitOpenRcFile;
20 $scope.uploadFiles = uploadFiles;
21 $scope.addEnvironment = addEnvironment;
23 $scope.uuid = $stateParams.uuid;
24 $scope.openrcID = $stateParams.opercId;
25 $scope.imageID = $stateParams.imageId;
26 $scope.podID = $stateParams.podId;
27 $scope.containerId = $stateParams.containerId;
28 $scope.ifNew = $stateParams.ifNew;
36 function showEnvironments() {
37 $scope.showEnvironment = true;
41 function deleteEnvItem(index) {
42 $scope.envInfo.splice(index, 1);
52 $scope.envInfo.push(temp);
56 function submitOpenRcFile() {
57 $scope.showloading = true;
60 postData['action'] = 'update_openrc';
62 postData['args'] = {};
63 postData['args']['openrc'] = $scope.postEnvInfo;
64 postData['args']['environment_id'] = $scope.uuid;
67 mainFactory.postEnvironmentVariable().post(postData).$promise.then(function(response) {
68 $scope.showloading = false;
70 if (response.status == 1) {
72 $scope.openrcInfo = response.result;
75 title: 'create success',
76 body: 'you can go next step',
79 $scope.showEnvrionment = true;
85 body: response.error_msg,
101 function rebuildEnvInfo() {
102 $scope.postEnvInfo = {};
103 for (var i = 0; i < $scope.envInfo.length; i++) {
104 $scope.postEnvInfo[$scope.envInfo[i].name] = $scope.envInfo[i].value;
110 function buildToEnvInfo(object) {
112 var tempKeyArray = Object.keys(object);
114 for (var i = 0; i < tempKeyArray.length; i++) {
115 var tempkey = tempKeyArray[i];
116 var tempValue = object[tempKeyArray[i]];
121 $scope.envInfo.push(temp);
125 console.log($scope.envInfo);
126 console.log($scope.openrcInfo);
129 function uploadFiles($file, $invalidFiles) {
130 $scope.openrcInfo = {};
131 $scope.loadingOPENrc = true;
133 $scope.displayOpenrcFile = $file;
134 timeConstruct($scope.displayOpenrcFile.lastModified);
136 url: Base_URL + '/api/v2/yardstick/openrcs',
137 data: { file: $file, 'environment_id': $scope.uuid, 'action': 'upload_openrc' }
138 }).then(function(response) {
140 $scope.loadingOPENrc = false;
141 if (response.data.status == 1) {
144 title: 'upload success',
145 body: 'you can go next step',
148 $scope.openrcInfo = response.data.result;
155 body: response.error_msg,
161 $scope.uploadfile = null;
165 body: 'unknow error',
171 function timeConstruct(array) {
172 var date = new Date(1398250549490);
173 var Y = date.getFullYear() + '-';
174 var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
175 var D = date.getDate() + ' ';
176 var h = date.getHours() + ':';
177 var m = date.getMinutes() + ':';
178 var s = date.getSeconds();
179 $scope.filelastModified = Y + M + D + h + m + s;
183 function addEnvironment() {
184 mainFactory.addEnvName().post({
185 'action': 'create_environment',
187 'name': $scope.baseElementInfo.name
189 }).$promise.then(function(response) {
190 if (response.status == 1) {
193 title: 'create name success',
194 body: 'you can go next step',
197 $scope.uuid = response.result.uuid;
198 var path = $location.path();
199 path = path + $scope.uuid;
208 body: 'unknow error',
214 function getItemIdDetail() {
216 mainFactory.ItemDetail().get({
218 }).$promise.then(function(response) {
219 if (response.status == 1) {
220 $scope.baseElementInfo = response.result.environment;
223 if ($scope.ifNew != 'true') {
224 $scope.baseElementInfo = response.result.environment;
225 if ($scope.baseElementInfo.openrc_id != null) {
226 getOpenrcDetail($scope.baseElementInfo.openrc_id);
234 body: response.error_msg,
243 body: 'unknow error',
250 function getOpenrcDetail(openrcId) {
251 mainFactory.getEnvironmentDetail().get({
252 'openrc_id': openrcId
253 }).$promise.then(function(response) {
254 $scope.openrcInfo = response.result;
255 buildToEnvInfo($scope.openrcInfo.openrc)
256 }, function(response) {
263 function getImageDetail() {
264 mainFactory.ImageDetail().get({
265 'image_id': $scope.baseElementInfo.image_id
266 }).$promise.then(function(response) {
267 if (response.status == 1) {
268 $scope.imageDetail = response.result.image;
274 body: 'unknow error',
281 function getPodDetail() {
282 mainFactory.podDeatil().get({
283 'podId': $scope.baseElementInfo.pod_id
284 }).$promise.then(function(response) {
285 if (response.status == 1) {
286 $scope.podDetail = response.result.pod;
292 body: 'unknow error',
298 function getPodDetail(containerId) {
299 mainFactory.containerDetail().get({
300 'containerId': containerId
301 }).$promise.then(function(response) {
302 if (response.status == 1) {
303 $scope.podDetail = response.result.pod;
308 body: response.error_msg,
316 body: 'unknow error',
321 $scope.goBack = function goBack() {
322 window.history.back();
325 $scope.goNext = function goNext() {
326 $scope.path = $location.path();
327 $scope.uuid = $scope.path.split('/').pop();
328 $state.go('app.uploadImage', { uuid: $scope.uuid });
331 $scope.openDeleteEnv = function openDeleteEnv(id, name) {
332 $scope.deleteName = name;
333 $scope.deleteId = id;
335 template: 'views/modal/deleteConfirm.html',
337 className: 'ngdialog-theme-default',
340 closeByDocument: false
345 $scope.deleteOpenRc = function deleteOpenRc() {
346 mainFactory.deleteOpenrc().delete({ 'openrc': $scope.baseElementInfo.openrc_id }).$promise.then(function(response) {
347 if (response.status == 1) {
350 title: 'delete openrc success',
351 body: 'you can go next step',
356 $scope.openrcInfo = null;
358 $scope.displayOpenrcFile = null;
363 body: response.result,
372 body: 'unknow error',