summaryrefslogtreecommitdiffstats
path: root/gui/app/scripts/controllers/main.js
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2017-08-11 09:26:22 +0000
committerchenjiankun <chenjiankun1@huawei.com>2017-08-24 03:29:25 +0000
commitefb4f088f14aee394599bea21973f82f1867c4fe (patch)
tree7dee3588a21ac0b3aa6d130a77d6d6a8f30a01d7 /gui/app/scripts/controllers/main.js
parent4a5bc16d841221e8ac7853b3044e50af0c8143d2 (diff)
Add function to upload image from local/url in GUI
JIRA: YARDSTICK-782 As user, we need to upload image from local/url. If upload image from local, user need to choose local image, then we will load it to openstack. If upload image from url, we will download it and load it to openstack. Change-Id: Ia9a42fda15a1dfc91476643635343a2f77a94a6b Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'gui/app/scripts/controllers/main.js')
-rw-r--r--gui/app/scripts/controllers/main.js169
1 files changed, 79 insertions, 90 deletions
diff --git a/gui/app/scripts/controllers/main.js b/gui/app/scripts/controllers/main.js
index ab76bf0f2..ceec83fa9 100644
--- a/gui/app/scripts/controllers/main.js
+++ b/gui/app/scripts/controllers/main.js
@@ -15,7 +15,7 @@ angular.module('yardStickGui2App')
$scope.showImage = null;
$scope.showContainer = null;
$scope.showNextOpenRc = null;
- $scope.showNextPod = null;
+ $scope.showNextPod = 1;
$scope.displayContainerInfo = [];
$scope.containerList = [{ value: 'create_influxdb', name: "InfluxDB" }, { value: 'create_grafana', name: "Grafana" }]
@@ -51,7 +51,6 @@ angular.module('yardStickGui2App')
$scope.chooseResult = chooseResult;
getEnvironmentList();
- // getImageList();
}
@@ -85,7 +84,7 @@ angular.module('yardStickGui2App')
}
$scope.goToImage = function goToImage() {
- getImageListSimple();
+ getImageList();
$scope.showImage = 1;
}
$scope.goToPod = function goToPod() {
@@ -290,7 +289,7 @@ angular.module('yardStickGui2App')
$scope.showImage = null;
$scope.showContainer = null;
$scope.showNextOpenRc = null;
- $scope.showNextPod = null;
+ $scope.showNextPod = 1;
$scope.displayContainerInfo = [];
$scope.displayPodFile = null;
@@ -308,7 +307,6 @@ angular.module('yardStickGui2App')
ngDialog.open({
preCloseCallback: function(value) {
getEnvironmentList();
- // getImageList();
},
template: 'views/modal/environmentDialog.html',
scope: $scope,
@@ -479,106 +477,97 @@ angular.module('yardStickGui2App')
})
}
- $scope.uploadImage = function uploadImage() {
- $scope.imageStatus = 0;
- $scope.showImageStatus = 1;
- $scope.showloading = true;
- mainFactory.uploadImage().post({
- 'action': 'load_image',
- 'args': {
- 'environment_id': $scope.uuid
+ $scope.yardstickImage = {
+ 'yardstick-image': {
+ 'name': 'yardstick-image',
+ 'description': '',
+ 'status': 'N/A'
+ },
+ 'Ubuntu-16.04': {
+ 'name': 'Ubuntu-16.04',
+ 'description': '',
+ 'status': 'N/A'
+ },
+ 'cirros-0.3.5': {
+ 'name': 'cirros-0.3.5',
+ 'description': '',
+ 'status': 'N/A'
+ }
+ };
- }
- }).$promise.then(function(response) {
- $scope.showloading = false;
- if (response.status == 1) {
- toaster.pop({
- type: 'success',
- title: 'create success',
- body: 'you can go next step',
- timeout: 3000
- });
- setTimeout(function() {
- getImageList();
- }, 10000);
- $scope.showNextPod = 1;
+ $scope.selectImageList = [];
- } else {
- toaster.pop({
- type: 'error',
- title: 'failed',
- body: 'something wrong',
- timeout: 3000
- });
+ $scope.selectImage = function(name){
+ $scope.selectImageList.push(name);
+ }
- }
- }, function(error) {
- toaster.pop({
- type: 'error',
- title: 'failed',
- body: 'something wrong',
- timeout: 3000
- });
- })
+ $scope.unselectImage = function(name){
+ var index = $scope.selectImageList.indexOf(name);
+ $scope.selectImageList.splice(index, 1);
}
- 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;
+ $scope.uploadImage = function() {
+ $scope.imageStatus = 0;
+ $scope.showImageStatus = 1;
+ $scope.showloading = true;
- if ($scope.imageStatus == 0) {
- $scope.intervalImgae = $interval(function() {
- getImageList();
- }, 5000);
- } else if ($scope.intervalImgae != undefined) {
- $interval.cancel($scope.intervalImgae);
+ var updateImageTask = $interval(function(){
+ mainFactory.ImageList().get({}).$promise.then(function(response){
+ if(response.status == 1){
+ var isOk = true;
+ angular.forEach($scope.selectImageList, function(ele){
+ if(typeof(response.result.images[ele]) != 'undefined' && response.result.images[ele].status == 'ACTIVE'){
+ $scope.yardstickImage[ele] = response.result.images[ele];
+ }else{
+ isOk = false;
+ }
+ });
+ if(isOk){
+ $interval.cancel(updateImageTask);
+ $scope.imageStatus = 1;
+ }
+ }else{
+ mainFactory.errorHandler1(response);
}
-
- } 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
+ }, function(response){
+ mainFactory.errorHandler2(response);
});
- })
+ }, 10000);
+
+ angular.forEach($scope.selectImageList, function(ele){
+ mainFactory.uploadImage().post({
+ 'action': 'load_image',
+ 'args': {
+ 'name': ele
+ }
+ }).$promise.then(function(response) {
+ if(response.status == 1){
+ $scope.showloading = false;
+ $scope.showNextPod = 1;
+ }else{
+ mainFactory.errorHandler1(response);
+ }
+ }, function(response) {
+ mainFactory.errorHandler2(response);
+ })
+ });
}
- function getImageListSimple() {
+ function getImageList() {
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
+ angular.forEach($scope.yardstickImage, function(value, key){
+ if(typeof(response.result.images[key]) != 'undefined'){
+ $scope.yardstickImage[key] = response.result.images[key];
+ }
});
+ $scope.imageStatus = response.result.status;
+ }else{
+ mainFactory.errorHandler1(response);
}
- }, function(error) {
- toaster.pop({
- type: 'error',
- title: 'get data failed',
- body: 'please retry',
- timeout: 3000
- });
+ }, function(response) {
+ mainFactory.errorHandler2(response);
})
}