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) {
111 var tempKeyArray = Object.keys(object);
113 for (var i = 0; i < tempKeyArray.length; i++) {
114 var tempkey = tempKeyArray[i];
115 var tempValue = object[tempKeyArray[i]];
120 $scope.envInfo.push(temp);
124 function uploadFiles($file, $invalidFiles) {
125 $scope.openrcInfo = {};
126 $scope.loadingOPENrc = true;
128 $scope.displayOpenrcFile = $file;
129 timeConstruct($scope.displayOpenrcFile.lastModified);
131 url: Base_URL + '/api/v2/yardstick/openrcs',
132 data: { file: $file, 'environment_id': $scope.uuid, 'action': 'upload_openrc' }
133 }).then(function(response) {
135 $scope.loadingOPENrc = false;
136 if (response.data.status == 1) {
139 title: 'upload success',
140 body: 'you can go next step',
143 $scope.openrcInfo = response.data.result;
150 body: response.error_msg,
156 $scope.uploadfile = null;
160 body: 'unknow error',
166 function timeConstruct(array) {
167 var date = new Date(1398250549490);
168 var Y = date.getFullYear() + '-';
169 var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
170 var D = date.getDate() + ' ';
171 var h = date.getHours() + ':';
172 var m = date.getMinutes() + ':';
173 var s = date.getSeconds();
174 $scope.filelastModified = Y + M + D + h + m + s;
178 function addEnvironment() {
179 mainFactory.addEnvName().post({
180 'action': 'create_environment',
182 'name': $scope.baseElementInfo.name
184 }).$promise.then(function(response) {
185 if (response.status == 1) {
188 title: 'create name success',
189 body: 'you can go next step',
192 $scope.uuid = response.result.uuid;
193 var path = $location.path();
194 path = path + $scope.uuid;
203 body: 'unknow error',
209 function getItemIdDetail() {
211 mainFactory.ItemDetail().get({
213 }).$promise.then(function(response) {
214 if (response.status == 1) {
215 $scope.baseElementInfo = response.result.environment;
218 if ($scope.ifNew != 'true') {
219 $scope.baseElementInfo = response.result.environment;
220 if ($scope.baseElementInfo.openrc_id != null) {
221 getOpenrcDetail($scope.baseElementInfo.openrc_id);
229 body: response.error_msg,
238 body: 'unknow error',
245 function getOpenrcDetail(openrcId) {
246 mainFactory.getEnvironmentDetail().get({
247 'openrc_id': openrcId
248 }).$promise.then(function(response) {
249 $scope.openrcInfo = response.result;
250 buildToEnvInfo($scope.openrcInfo.openrc)
251 }, function(response) {
258 function getImageDetail() {
259 mainFactory.ImageDetail().get({
260 'image_id': $scope.baseElementInfo.image_id
261 }).$promise.then(function(response) {
262 if (response.status == 1) {
263 $scope.imageDetail = response.result.image;
269 body: 'unknow error',
276 function getPodDetail() {
277 mainFactory.podDeatil().get({
278 'podId': $scope.baseElementInfo.pod_id
279 }).$promise.then(function(response) {
280 if (response.status == 1) {
281 $scope.podDetail = response.result.pod;
287 body: 'unknow error',
293 function getPodDetail(containerId) {
294 mainFactory.containerDetail().get({
295 'containerId': containerId
296 }).$promise.then(function(response) {
297 if (response.status == 1) {
298 $scope.podDetail = response.result.pod;
303 body: response.error_msg,
311 body: 'unknow error',
316 $scope.goBack = function goBack() {
317 window.history.back();
320 $scope.goNext = function goNext() {
321 $scope.path = $location.path();
322 $scope.uuid = $scope.path.split('/').pop();
323 $state.go('app.uploadImage', { uuid: $scope.uuid });
326 $scope.openDeleteEnv = function openDeleteEnv(id, name) {
327 $scope.deleteName = name;
328 $scope.deleteId = id;
330 template: 'views/modal/deleteConfirm.html',
332 className: 'ngdialog-theme-default',
335 closeByDocument: false
340 $scope.deleteOpenRc = function deleteOpenRc() {
341 mainFactory.deleteOpenrc().delete({ 'openrc': $scope.baseElementInfo.openrc_id }).$promise.then(function(response) {
342 if (response.status == 1) {
345 title: 'delete openrc success',
346 body: 'you can go next step',
351 $scope.openrcInfo = null;
353 $scope.displayOpenrcFile = null;
358 body: response.result,
367 body: 'unknow error',