3 angular.module('yardStickGui2App')
4 .controller('ImageController', ['$scope', '$state', '$stateParams', 'mainFactory', 'Upload', 'toaster', '$location', '$interval', 'ngDialog',
5 function($scope, $state, $stateParams, mainFactory, Upload, toaster, $location, $interval, ngDialog) {
11 $scope.showloading = false;
12 $scope.ifshowStatus = 0;
14 $scope.yardstickImage = [
16 'name': 'yardstick-image',
23 'name': 'Ubuntu-16.04',
30 'name': 'cirros-0.3.5',
37 $scope.customImage = [];
40 $scope.uuid = $stateParams.uuid;
41 $scope.showloading = false;
43 $scope.environmentInfo = null;
45 getYardstickImageList();
46 getCustomImageList(function(image, image_id){});
49 function getYardstickImageList(){
50 mainFactory.ImageList().get({}).$promise.then(function(response){
51 if(response.status == 1){
52 angular.forEach($scope.yardstickImage, function(ele, index){
53 if(typeof(response.result.images[ele.name]) != 'undefined'){
54 $scope.yardstickImage[index] = response.result.images[ele.name];
58 mainFactory.errorHandler1(response);
60 }, function(response){
61 mainFactory.errorHandler2(response);
65 function getCustomImageList(func){
66 mainFactory.ItemDetail().get({
67 'envId': $stateParams.uuid
68 }).$promise.then(function(response) {
69 if(response.status == 1){
70 $scope.environmentInfo = response.result.environment;
71 $scope.customImage = [];
72 angular.forEach(response.result.environment.image_id, function(ele){
73 mainFactory.getImage().get({'imageId': ele}).$promise.then(function(responseData){
74 if(responseData.status == 1){
75 $scope.customImage.push(responseData.result.image);
76 func(responseData.result.image, ele);
78 mainFactory.errorHandler1(responseData);
80 }, function(errorData){
81 mainFactory.errorHandler2(errorData);
85 mainFactory.errorHandler1(response);
87 }, function(response){
88 mainFactory.errorHandler2(response);
92 $scope.loadYardstickImage = function(image_name){
94 var updateImageTask = $interval(updateYardstickImage, 10000);
96 function updateYardstickImage(){
97 mainFactory.ImageList().get({}).$promise.then(function(responseData){
98 if(responseData.status == 1){
99 if(typeof(responseData.result.images[image_name]) != 'undefined' && responseData.result.images[image_name].status == 'ACTIVE'){
100 angular.forEach($scope.yardstickImage, function(ele, index){
101 if(ele.name == image_name){
102 $scope.yardstickImage[index] = responseData.result.images[ele.name];
105 $interval.cancel(updateImageTask);
108 mainFactory.errorHandler1(responseData);
110 },function(errorData){
111 mainFactory.errorHandler2(errorData);
115 mainFactory.uploadImage().post({'action': 'load_image', 'args': {'name': image_name}}).$promise.then(function(response){
116 },function(response){
117 mainFactory.errorHandler2(response);
121 $scope.deleteYardstickImage = function(image_name){
123 var updateImageTask = $interval(updateYardstickImage, 10000);
125 function updateYardstickImage(){
126 mainFactory.ImageList().get({}).$promise.then(function(response){
127 if(response.status == 1){
128 if(typeof(response.result.images[image_name]) == 'undefined'){
129 angular.forEach($scope.yardstickImage, function(ele, index){
130 if(ele.name == image_name){
131 $scope.yardstickImage[index].size = 'N/A';
132 $scope.yardstickImage[index].status = 'N/A';
133 $scope.yardstickImage[index].time = 'N/A';
136 $interval.cancel(updateImageTask);
139 mainFactory.errorHandler1(response);
141 },function(response){
142 mainFactory.errorHandler2(response);
146 mainFactory.uploadImage().post({'action': 'delete_image', 'args': {'name': image_name}}).$promise.then(function(response){
147 },function(response){
148 mainFactory.errorHandler2(response);
152 $scope.uploadCustomImageByUrl = function(url){
153 mainFactory.uploadImageByUrl().post({
154 'action': 'upload_image_by_url',
156 'environment_id': $stateParams.uuid,
159 }).$promise.then(function(response){
160 if(response.status == 1){
161 var updateImageTask = $interval(getCustomImageList, 30000, 10, true, function(image, image_id){
162 if(image_id == response.result.uuid && image.status == 'ACTIVE'){
163 $interval.cancel(updateImageTask);
168 mainFactory.errorHandler1(response);
170 }, function(response){
171 mainFactory.errorHandler2(response);
175 $scope.uploadCustomImage = function($file, $invalidFiles) {
176 $scope.showloading = true;
178 $scope.displayImageFile = $file;
180 url: Base_URL + '/api/v2/yardstick/images',
181 data: { file: $file, 'environment_id': $scope.uuid, 'action': 'upload_image' }
182 }).then(function(response) {
184 $scope.showloading = false;
185 if (response.data.status == 1) {
189 title: 'upload success',
190 body: 'you can go next step',
194 var updateImageTask = $interval(getCustomImageList, 10000, 10, true, function(image, image_id){
195 if(image_id == response.data.result.uuid && image.status == 'ACTIVE'){
196 $interval.cancel(updateImageTask);
200 mainFactory.errorHandler1(response);
203 }, function(response) {
204 $scope.uploadfile = null;
205 mainFactory.errorHandler2(response);
209 $scope.deleteCustomImage = function(image_id){
210 mainFactory.deleteImage().delete({'imageId': image_id}).$promise.then(function(response){
211 if(response.status == 1){
212 $interval(getCustomImageList, 10000, 5, true, function(image, image_id){
215 mainFactory.errorHandler2(response);
217 }, function(response){
218 mainFactory.errorHandler2(response);
222 $scope.openImageDialog = function(){
225 preCloseCallback: function(value) {
227 template: 'views/modal/imageDialog.html',
229 className: 'ngdialog-theme-default',
232 closeByDocument: false
236 $scope.goBack = function goBack() {
237 $state.go('app.projectList');
240 $scope.goNext = function goNext() {
241 $scope.path = $location.path();
242 $scope.uuid = $scope.path.split('/').pop();
243 $state.go('app.podUpload', { uuid: $scope.uuid });