aboutsummaryrefslogtreecommitdiffstats
path: root/gui/app/scripts/controllers/image.controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'gui/app/scripts/controllers/image.controller.js')
-rw-r--r--gui/app/scripts/controllers/image.controller.js303
1 files changed, 192 insertions, 111 deletions
diff --git a/gui/app/scripts/controllers/image.controller.js b/gui/app/scripts/controllers/image.controller.js
index 53acff405..d7a7edfa9 100644
--- a/gui/app/scripts/controllers/image.controller.js
+++ b/gui/app/scripts/controllers/image.controller.js
@@ -1,155 +1,240 @@
'use strict';
angular.module('yardStickGui2App')
- .controller('ImageController', ['$scope', '$state', '$stateParams', 'mainFactory', 'Upload', 'toaster', '$location', '$interval',
- function($scope, $state, $stateParams, mainFactory, Upload, toaster, $location, $interval) {
+ .controller('ImageController', ['$scope', '$state', '$stateParams', 'mainFactory', 'Upload', 'toaster', '$location', '$interval', 'ngDialog',
+ function($scope, $state, $stateParams, mainFactory, Upload, toaster, $location, $interval, ngDialog) {
init();
- $scope.showloading = false;
- $scope.ifshowStatus = 0;
function init() {
+ $scope.showloading = false;
+ $scope.ifshowStatus = 0;
+
+ $scope.yardstickImage = [
+ {
+ 'name': 'yardstick-image',
+ 'description': '',
+ 'size': 'N/A',
+ 'status': 'N/A',
+ 'time': 'N/A'
+ },
+ {
+ 'name': 'Ubuntu-16.04',
+ 'description': '',
+ 'size': 'N/A',
+ 'status': 'N/A',
+ 'time': 'N/A'
+ },
+ {
+ 'name': 'cirros-0.3.5',
+ 'description': '',
+ 'size': 'N/A',
+ 'status': 'N/A',
+ 'time': 'N/A'
+ }
+ ];
+ $scope.customImage = [];
$scope.uuid = $stateParams.uuid;
- $scope.uploadImage = uploadImage;
- getItemIdDetail();
- getImageListSimple();
+ $scope.showloading = false;
+ $scope.url = null;
+ $scope.environmentInfo = null;
+
+ getYardstickImageList();
+ getCustomImageList(function(image, image_id){});
}
- function getItemIdDetail() {
+ function getYardstickImageList(){
+ mainFactory.ImageList().get({}).$promise.then(function(response){
+ if(response.status == 1){
+ angular.forEach($scope.yardstickImage, function(ele, index){
+ if(typeof(response.result.images[ele.name]) != 'undefined'){
+ $scope.yardstickImage[index] = response.result.images[ele.name];
+ }
+ });
+ }else{
+ mainFactory.errorHandler1(response);
+ }
+ }, function(response){
+ mainFactory.errorHandler2(response);
+ });
+ }
+
+ function getCustomImageList(func){
mainFactory.ItemDetail().get({
'envId': $stateParams.uuid
}).$promise.then(function(response) {
- if (response.status == 1) {
- $scope.baseElementInfo = response.result.environment;
-
-
- } else {
- toaster.pop({
- type: 'error',
- title: 'fail',
- body: response.error_msg,
- timeout: 3000
+ if(response.status == 1){
+ $scope.environmentInfo = response.result.environment;
+ $scope.customImage = [];
+ angular.forEach(response.result.environment.image_id, function(ele){
+ mainFactory.getImage().get({'imageId': ele}).$promise.then(function(responseData){
+ if(responseData.status == 1){
+ $scope.customImage.push(responseData.result.image);
+ func(responseData.result.image, ele);
+ }else{
+ mainFactory.errorHandler1(responseData);
+ }
+ }, function(errorData){
+ mainFactory.errorHandler2(errorData);
+ });
});
+ }else{
+ mainFactory.errorHandler1(response);
}
- }, function(error) {
- toaster.pop({
- type: 'error',
- title: 'fail',
- body: 'unknow error',
- timeout: 3000
- });
- })
+ }, function(response){
+ mainFactory.errorHandler2(response);
+ });
}
- function getImageListSimple() {
-
- mainFactory.ImageList().get({}).$promise.then(function(response) {
- if (response.status == 1) {
- $scope.imageListData = response.result.images;
- // $scope.imageStatus = response.result.status;
-
- } else {
- toaster.pop({
- type: 'error',
- title: 'get data failed',
- body: 'please retry',
- timeout: 3000
- });
- }
- }, function(error) {
- toaster.pop({
- type: 'error',
- title: 'get data failed',
- body: 'please retry',
- timeout: 3000
+ $scope.loadYardstickImage = function(image_name){
+
+ var updateImageTask = $interval(updateYardstickImage, 10000);
+
+ function updateYardstickImage(){
+ mainFactory.ImageList().get({}).$promise.then(function(responseData){
+ if(responseData.status == 1){
+ if(typeof(responseData.result.images[image_name]) != 'undefined' && responseData.result.images[image_name].status == 'ACTIVE'){
+ angular.forEach($scope.yardstickImage, function(ele, index){
+ if(ele.name == image_name){
+ $scope.yardstickImage[index] = responseData.result.images[ele.name];
+ }
+ });
+ $interval.cancel(updateImageTask);
+ }
+ }else{
+ mainFactory.errorHandler1(responseData);
+ }
+ },function(errorData){
+ mainFactory.errorHandler2(errorData);
});
- })
- }
+ }
+ mainFactory.uploadImage().post({'action': 'load_image', 'args': {'name': image_name}}).$promise.then(function(response){
+ },function(response){
+ mainFactory.errorHandler2(response);
+ });
+ }
- function getImageList() {
- if ($scope.intervalImgae != undefined) {
- $interval.cancel($scope.intervalImgae);
- }
- mainFactory.ImageList().get({}).$promise.then(function(response) {
- if (response.status == 1) {
- $scope.imageListData = response.result.images;
- $scope.imageStatus = response.result.status;
-
- if ($scope.imageStatus == 0) {
- $scope.intervalImgae = $interval(function() {
- getImageList();
- }, 5000);
- } else if ($scope.intervalImgae != undefined) {
- $interval.cancel($scope.intervalImgae);
+ $scope.deleteYardstickImage = function(image_name){
+
+ var updateImageTask = $interval(updateYardstickImage, 10000);
+
+ function updateYardstickImage(){
+ mainFactory.ImageList().get({}).$promise.then(function(response){
+ if(response.status == 1){
+ if(typeof(response.result.images[image_name]) == 'undefined'){
+ angular.forEach($scope.yardstickImage, function(ele, index){
+ if(ele.name == image_name){
+ $scope.yardstickImage[index].size = 'N/A';
+ $scope.yardstickImage[index].status = 'N/A';
+ $scope.yardstickImage[index].time = 'N/A';
+ }
+ });
+ $interval.cancel(updateImageTask);
+ }
+ }else{
+ mainFactory.errorHandler1(response);
}
+ },function(response){
+ mainFactory.errorHandler2(response);
+ });
+ }
- } else {
- toaster.pop({
- type: 'error',
- title: 'get data failed',
- body: 'please retry',
- timeout: 3000
+ mainFactory.uploadImage().post({'action': 'delete_image', 'args': {'name': image_name}}).$promise.then(function(response){
+ },function(response){
+ mainFactory.errorHandler2(response);
+ });
+ }
+
+ $scope.uploadCustomImageByUrl = function(url){
+ mainFactory.uploadImageByUrl().post({
+ 'action': 'upload_image_by_url',
+ 'args': {
+ 'environment_id': $stateParams.uuid,
+ 'url': url
+ }
+ }).$promise.then(function(response){
+ if(response.status == 1){
+ var updateImageTask = $interval(getCustomImageList, 30000, 10, true, function(image, image_id){
+ if(image_id == response.result.uuid && image.status == 'ACTIVE'){
+ $interval.cancel(updateImageTask);
+ }
});
+ ngDialog.close();
+ }else{
+ mainFactory.errorHandler1(response);
}
- }, function(error) {
- toaster.pop({
- type: 'error',
- title: 'get data failed',
- body: 'please retry',
- timeout: 3000
- });
- })
+ }, function(response){
+ mainFactory.errorHandler2(response);
+ });
}
- function uploadImage() {
- $scope.imageStatus = 0;
- $interval.cancel($scope.intervalImgae);
- $scope.ifshowStatus = 1;
+ $scope.uploadCustomImage = function($file, $invalidFiles) {
$scope.showloading = true;
- mainFactory.uploadImage().post({
- 'action': 'load_image',
- 'args': {
- 'environment_id': $scope.uuid
- }
- }).$promise.then(function(response) {
+ $scope.displayImageFile = $file;
+ Upload.upload({
+ url: Base_URL + '/api/v2/yardstick/images',
+ data: { file: $file, 'environment_id': $scope.uuid, 'action': 'upload_image' }
+ }).then(function(response) {
+
$scope.showloading = false;
- if (response.status == 1) {
+ if (response.data.status == 1) {
+
toaster.pop({
type: 'success',
- title: 'create success',
+ title: 'upload success',
body: 'you can go next step',
timeout: 3000
});
- setTimeout(function() {
- getImageList();
- }, 10000);
- } else {
- toaster.pop({
- type: 'error',
- title: 'failed',
- body: 'something wrong',
- timeout: 3000
+ var updateImageTask = $interval(getCustomImageList, 10000, 10, true, function(image, image_id){
+ if(image_id == response.data.result.uuid && image.status == 'ACTIVE'){
+ $interval.cancel(updateImageTask);
+ }
});
+ }else{
+ mainFactory.errorHandler1(response);
+ }
+ }, function(response) {
+ $scope.uploadfile = null;
+ mainFactory.errorHandler2(response);
+ })
+ }
+
+ $scope.deleteCustomImage = function(image_id){
+ mainFactory.deleteImage().delete({'imageId': image_id}).$promise.then(function(response){
+ if(response.status == 1){
+ $interval(getCustomImageList, 10000, 5, true, function(image, image_id){
+ });
+ }else{
+ mainFactory.errorHandler2(response);
}
- }, function(error) {
- toaster.pop({
- type: 'error',
- title: 'failed',
- body: 'something wrong',
- timeout: 3000
- });
+ }, function(response){
+ mainFactory.errorHandler2(response);
+ });
+ }
+
+ $scope.openImageDialog = function(){
+ $scope.url = null;
+ ngDialog.open({
+ preCloseCallback: function(value) {
+ },
+ template: 'views/modal/imageDialog.html',
+ scope: $scope,
+ className: 'ngdialog-theme-default',
+ width: 950,
+ showClose: true,
+ closeByDocument: false
})
}
$scope.goBack = function goBack() {
- $state.go('app2.projectList');
+ $state.go('app.projectList');
}
$scope.goNext = function goNext() {
@@ -158,9 +243,5 @@ angular.module('yardStickGui2App')
$state.go('app.podUpload', { uuid: $scope.uuid });
}
-
-
-
-
}
]);