diff options
author | 2018-05-14 15:15:04 +0800 | |
---|---|---|
committer | 2018-05-14 15:15:09 +0800 | |
commit | a3591f7fe0b20bd010b6daa5054a919aab6aa5fa (patch) | |
tree | 302ddf4af275a5b7e72cc1f2e327244f215243c0 /usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller | |
parent | ea506ea4aa4306bd594d747455291b18a030aa4e (diff) |
add service scaling function
Change-Id: If01f30e0a4105d27086f2ada555c94334c54e4ec
Issue-ID: USECASEUI-115
Signed-off-by: zhangab <zhanganbing@chinamobile.com>
Diffstat (limited to 'usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller')
-rw-r--r-- | usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/ServiceTemplateService.js | 84 | ||||
-rw-r--r-- | usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/lcmController.js | 492 |
2 files changed, 389 insertions, 187 deletions
diff --git a/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/ServiceTemplateService.js b/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/ServiceTemplateService.js index f78f7ce0..acb61f92 100644 --- a/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/ServiceTemplateService.js +++ b/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/ServiceTemplateService.js @@ -14,19 +14,21 @@ * limitations under the License. */ app.factory("ServiceTemplateService", function($http, $log) { - var url = '/api/usecaseui-server/v1/uui-lcm'; + var url = '/api/usecaseui-server/v1/uui-lcm'; var uuiHeaders = JSON.stringify({ 'Content-Type': 'application/json' // 'Authorization':'Basic dXNlY2FzZTp1c2VjYXNl' }); return { getAllCustomers: function (processFun) { + console.log("customers") return $http({ url: url+'/customers', method: 'GET', data: null, headers: uuiHeaders }).then(function(response){ + console.log(response) var customers = response.data; var result = customers.map(function (customer) { return { @@ -64,6 +66,7 @@ headers: uuiHeaders }).then(function(response){ var serviceInstances = response.data; + console.log(serviceInstances); var result = serviceInstances.map(function (serviceInstance) { return { serviceInstanceId: serviceInstance['service-instance-id'], @@ -72,7 +75,7 @@ }; }); processFun(result); - }); + }); }, getAllServiceTemplates: function (processFun) { @@ -93,10 +96,11 @@ }; }); processFun(result); - }); + }) }, getTemplateParameters: function (template, processFun) { + console.log(url+'/service-templates/' + template.id+'?toscaModelPath='+ template.toscaModelURL); return $http({ url: url+'/service-templates/' + template.id+'?toscaModelPath='+ template.toscaModelURL, method: 'GET', @@ -116,9 +120,10 @@ headers: uuiHeaders }).then(function(response){ var vimInfos = response.data; + console.log(vimInfos); var result = vimInfos.map(function (vim) { return { - name: vim['cloud-owner'] + '_' + vim['cloud-region-id'], + name: vim['cloud-owner'], //complex-name value: vim['cloud-owner'] + '_' + vim['cloud-region-id'] }; }); @@ -146,6 +151,7 @@ createService: function (customer, serviceType, service, template, successFun, failedFun) { var reqPara = []; + var newreqParas = {}; service.segments.forEach(function (segment) { var reqParas = {}; var vfLocations = []; @@ -166,17 +172,20 @@ reqParas[parameter.name] = parameter.value.value; } } else { - reqParas[parameter.name] = parameter.value; + newreqParas[parameter.name] = parameter.value; } }); var para = { resourceName: segment.nodeTemplateName, - resourceDefId: segment.invariantUUID, + resourceInvariantUuid: segment.invariantUUID,//resourceDefId resourceId: segment.uuid, - nsParameters: { + resourceCustomizationUuid: segment.customizationUuid, + parameters: { //nsParameters locationConstraints: vfLocations, - additionalParamForNs: reqParas + // additionalParamForNs: reqParas, + resources:[], + requestInputs:reqParas } }; reqPara.push(para); @@ -186,25 +195,34 @@ if( template.version !== undefined && template.version !== null && template.version !== '' ) { templateName = templateName + ":" + template.version; } + + service.parameters.forEach(function(item){ + newreqParas[item.name] = item.value; + }) + var requestBody = { service: { name: service.serviceName, description: service.serviceDescription, - serviceDefId: template.invariantUUID, - templateId: template.uuid, // uuid ?? + serviceInvariantUuid: template.invariantUUID, //serviceDefId + serviceUuid: template.uuid, // uuid ?? templateId + globalSubscriberId: customer.id, + serviceType: serviceType.value, parameters: { - globalSubscriberId: customer.id, - subscriberName: customer.name, - serviceType: serviceType.value, - templateName: templateName, - resources: reqPara + // globalSubscriberId: customer.id, + // subscriberName: customer.name, + // serviceType: serviceType.value, + // templateName: templateName, + locationConstraints:[], + resources: reqPara, + requestInputs:newreqParas } } }; - console.log('request body: '); - console.log(JSON.stringify(requestBody)); - + // console.log(requestBody); + // console.log(JSON.stringify(requestBody)); + return false; return $http({ url: url+'/services', method: 'POST', @@ -220,6 +238,36 @@ }); }, + getScaleServiceDialog:function(customer,serviceType,serviceInstanceId,successFun){ + return $http({ + url:url+'/getServiceInstanceById?customerId=' + customer + '&serviceType=' + serviceType + '&serviceId=' + serviceInstanceId, + method:'GET' + }).then(function(response){ + successFun(response); + }) + }, + + scaleService: function (requestBody, successFun, failedFun) { + + // console.log('request body: '); + // console.log(JSON.stringify(requestBody)); + + + return $http({ + url: url+'/services/scaleServices/'+requestBody.service.globalSubscriberId, + method: 'POST', + data: JSON.stringify(requestBody), + headers: uuiHeaders + }).then(function(response){ + // console.log('create response...'); + // console.log(response.data); + + var serviceId = response.data.service.serviceId; + var operationId = response.data.service.operationId; + successFun( operationId); + }); + }, + deleteService: function (serviceId, customer, serviceType, successFun) { var requestBody = { globalSubscriberId: customer.id, diff --git a/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/lcmController.js b/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/lcmController.js index 6b47353a..ffdb622d 100644 --- a/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/lcmController.js +++ b/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/lcmController.js @@ -17,16 +17,16 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' function ($scope, $uibModal, $log, $http, $timeout, $interval, ServiceTemplateService) { var ctrl = this; ctrl.alerts = []; - ctrl.closeAlert = function(index) { + ctrl.closeAlert = function (index) { ctrl.alerts.splice(index, 1); }; var openServiceProgressDialog = function (serviceId, operationId, title, successFun, failFun) { var serviceProgressInstance = $uibModal.open({ ariaLabelledBy: 'modal-title', ariaDescribedBy: 'modal-body', - templateUrl : 'app/uui/fusion/scripts/view-models/progress-dialog.html', - controller : 'ServiceProgressCtrl', - controllerAs : 'ctrl', + templateUrl: 'app/uui/fusion/scripts/view-models/progress-dialog.html', + controller: 'ServiceProgressCtrl', + controllerAs: 'ctrl', resolve: { serviceId: function () { return serviceId; @@ -52,9 +52,9 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' var modalInstance = $uibModal.open({ ariaLabelledBy: 'modal-title', ariaDescribedBy: 'modal-body', - templateUrl : 'app/uui/fusion/scripts/view-models/create-service-dialog.html', - controller : 'createServiceCtrl', - controllerAs : 'ctrl', + templateUrl: 'app/uui/fusion/scripts/view-models/create-service-dialog.html', + controller: 'createServiceCtrl', + controllerAs: 'ctrl', resolve: { customer: function () { return ctrl.customer; @@ -65,21 +65,27 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' } }); modalInstance.result.then( - function(result) { + function (result) { console.log('receive ok button clicked!'); console.log(result); var successFun = function (result) { - ctrl.alerts.push({type: 'success', msg: result}); + ctrl.alerts.push({ + type: 'success', + msg: result + }); ServiceTemplateService.getServiceInstances(ctrl.customer.id, ctrl.serviceType.value, function (instances) { ctrl.serviceInstances = instances; }); } var failFun = function (reason) { - ctrl.alerts.push({type: 'danger',msg: reason}); + ctrl.alerts.push({ + type: 'danger', + msg: reason + }); } openServiceProgressDialog(result.serviceId, result.operationId, 'Create Service', successFun, failFun); }, - function(reason) { + function (reason) { console.log('receive cancel button clicked!'); console.log(reason); $log.info('Modal dismissed at: ' + new Date()); @@ -90,7 +96,7 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' ctrl.init = function () { ctrl.canCreateService = "true"; ServiceTemplateService.getAllCustomers(function (customers) { - ctrl.customers = customers; + ctrl.customers = customers; }); ServiceTemplateService.getPackages(function (packages) { ctrl.packages = packages; @@ -98,7 +104,7 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' }; ctrl.customerChanged = function () { - if(ctrl.customer === undefined || ctrl.customer === null) { + if (ctrl.customer === undefined || ctrl.customer === null) { ctrl.serviceTypes = []; } else { ServiceTemplateService.getAllServiceTypes(ctrl.customer.id, function (serviceTypes) { @@ -110,7 +116,7 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' }; ctrl.serviceTypeChanged = function () { - if(ctrl.serviceType === undefined || ctrl.serviceType === null || ctrl.customer === undefined || ctrl.customer === null) { + if (ctrl.serviceType === undefined || ctrl.serviceType === null || ctrl.customer === undefined || ctrl.customer === null) { ctrl.canCreateService = "true"; return; } @@ -120,16 +126,72 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' }); }; + ctrl.scaleService = function (serviceInstance) { + + var modalInstance = $uibModal.open({ + ariaLabelledBy: 'modal-title', + ariaDescribedBy: 'modal-body', + templateUrl: 'app/uui/fusion/scripts/view-models/scale-service-dialog.html', + controller: 'scaleServiceCtrl', + controllerAs: 'ctrl', + resolve: { + customer: function () { + return ctrl.customer; + }, + serviceType: function () { + return ctrl.serviceType; + }, + serviceInstance: serviceInstance + } + }); + modalInstance.result.then( + function (result) { + console.log(result); + console.log(serviceInstance); + var successFun = function (result) { + ctrl.alerts.push({ + type: 'success', + msg: result + }); + ServiceTemplateService.getServiceInstances(ctrl.customer.id, ctrl.serviceType.value, function (instances) { + ctrl.serviceInstances = instances; + }); + } + var failFun = function (reason) { + console.log(reason) + ctrl.alerts.push({ + type: 'danger', + msg: reason + }); + } + openServiceProgressDialog(result.serviceId, result.operationId, 'Scale Service', successFun, failFun); + }, + function (reason) { + console.log('receive cancel button clicked!'); + console.log(reason); + $log.info('Modal dismissed at: ' + new Date()); + } + ); + + + }; + ctrl.deleteService = function (serviceInstance) { var successFun = function (serviceId, operationId) { var successFun = function (result) { - ctrl.alerts.push({type: 'success', msg: result}); + ctrl.alerts.push({ + type: 'success', + msg: result + }); ServiceTemplateService.getServiceInstances(ctrl.customer.id, ctrl.serviceType.value, function (instances) { ctrl.serviceInstances = instances; }); } var failFun = function (reason) { - ctrl.alerts.push({type: 'danger',msg: reason}); + ctrl.alerts.push({ + type: 'danger', + msg: reason + }); } openServiceProgressDialog(serviceId, operationId, 'Delete Service', successFun, failFun); } @@ -137,12 +199,18 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' }; ctrl.packageOnboard = function (onboardPackage) { - if(onboardPackage.type === 'NS') { + if (onboardPackage.type === 'NS') { var processFun = function (response) { - if('failed' === response.status) { - ctrl.alerts.push({type: 'danger',msg: 'Operation failed! ' + response.statusDescription}); + if ('failed' === response.status) { + ctrl.alerts.push({ + type: 'danger', + msg: 'Operation failed! ' + response.statusDescription + }); } else { - ctrl.alerts.push({type: 'success',msg: 'Operation is finished!'}); + ctrl.alerts.push({ + type: 'success', + msg: 'Operation is finished!' + }); } }; ServiceTemplateService.nsPackageOnboard(onboardPackage, processFun); @@ -151,9 +219,9 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' var onboardProgressInstance = $uibModal.open({ ariaLabelledBy: 'modal-title', ariaDescribedBy: 'modal-body', - templateUrl : 'app/uui/fusion/scripts/view-models/progress-dialog.html', - controller : 'VfOnboardProgressCtrl', - controllerAs : 'ctrl', + templateUrl: 'app/uui/fusion/scripts/view-models/progress-dialog.html', + controller: 'VfOnboardProgressCtrl', + controllerAs: 'ctrl', resolve: { jobId: function () { return jobId; @@ -173,10 +241,16 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' ); }; var successFun = function (result) { - ctrl.alerts.push({type: 'success',msg: 'Operation is finished!'}); + ctrl.alerts.push({ + type: 'success', + msg: 'Operation is finished!' + }); }; var failFun = function (reason) { - ctrl.alerts.push({type: 'danger',msg: 'Operation is failed! ' + reason}); + ctrl.alerts.push({ + type: 'danger', + msg: 'Operation is failed! ' + reason + }); }; var processFun = function (response) { openOnboardProgressDialog(response.jobId, 'VF Onboarding', successFun, failFun); @@ -186,58 +260,75 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' }; ctrl.packageDelete = function (deletePackage) { - if(deletePackage.type === 'NS') { - var processFun = function (response) { - if('failed' === response.status) { - ctrl.alerts.push({type: 'danger',msg: 'Operation failed! ' + response.statusDescription}); - } else { - ctrl.alerts.push({type: 'success',msg: 'Operation is finished!'}); - } - }; + if (deletePackage.type === 'NS') { + var processFun = function (response) { + if ('failed' === response.status) { + ctrl.alerts.push({ + type: 'danger', + msg: 'Operation failed! ' + response.statusDescription + }); + } else { + ctrl.alerts.push({ + type: 'success', + msg: 'Operation is finished!' + }); + } + }; ServiceTemplateService.nsPackageDelete(deletePackage, processFun); } else { - var openOnboardProgressDialog = function (jobId, title, successFun, failFun) { - var onboardProgressInstance = $uibModal.open({ - ariaLabelledBy: 'modal-title', - ariaDescribedBy: 'modal-body', - templateUrl : 'app/uui/fusion/scripts/view-models/progress-dialog.html', - controller : 'VfOnboardProgressCtrl', - controllerAs : 'ctrl', - resolve: { - jobId: function () { - return jobId; - }, - operationTitle: function () { - return title; - } - } - }); - onboardProgressInstance.result.then( - function (result) { - successFun(result); + var openOnboardProgressDialog = function (jobId, title, successFun, failFun) { + var onboardProgressInstance = $uibModal.open({ + ariaLabelledBy: 'modal-title', + ariaDescribedBy: 'modal-body', + templateUrl: 'app/uui/fusion/scripts/view-models/progress-dialog.html', + controller: 'VfOnboardProgressCtrl', + controllerAs: 'ctrl', + resolve: { + jobId: function () { + return jobId; }, - function (reason) { - failFun(reason); + operationTitle: function () { + return title; } - ); - }; - var successFun = function (result) { - ctrl.alerts.push({type: 'success',msg: 'Operation is finished!'}); - }; - var failFun = function (reason) { - ctrl.alerts.push({type: 'danger',msg: 'Operation is failed! ' + reason}); - }; - var processFun = function (response) { - openOnboardProgressDialog(response.jobId, 'Delete VF package', successFun, failFun); - }; + } + }); + onboardProgressInstance.result.then( + function (result) { + successFun(result); + }, + function (reason) { + failFun(reason); + } + ); + }; + var successFun = function (result) { + ctrl.alerts.push({ + type: 'success', + msg: 'Operation is finished!' + }); + }; + var failFun = function (reason) { + ctrl.alerts.push({ + type: 'danger', + msg: 'Operation is failed! ' + reason + }); + }; + var processFun = function (response) { + openOnboardProgressDialog(response.jobId, 'Delete VF package', successFun, failFun); + }; ServiceTemplateService.vfPackageDelete(deletePackage, processFun); } }; + + ctrl.jumpToUrl = function () { + var obj = $("#lm"); + angular.element(obj).scope().currentTab = "app/uui/fusion/scripts/view-models/device-topological.html"; + } + } - ] -) -.controller('createServiceCtrl',['$scope', '$uibModal','$uibModalInstance', 'ServiceTemplateService', 'customer', 'serviceType', - function($scope,$uibModal, $uibModalInstance, ServiceTemplateService, customer, serviceType) { + ]) + .controller('createServiceCtrl', ['$scope', '$uibModal', '$uibModalInstance', 'ServiceTemplateService', 'customer', 'serviceType', + function ($scope, $uibModal, $uibModalInstance, ServiceTemplateService, customer, serviceType) { var ctrl = this; ServiceTemplateService.getAllServiceTemplates(function (t) { @@ -268,12 +359,12 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' }; }); return { - nodeTemplateName: nestedTemplate.name, - invariantUUID: nestedTemplate.invariantUUID, - uuid: nestedTemplate.uuid, - type: nestedTemplate.type, - parameters: nestedParas - }; + nodeTemplateName: nestedTemplate.name, + invariantUUID: nestedTemplate.invariantUUID, + uuid: nestedTemplate.uuid, + type: nestedTemplate.type, + parameters: nestedParas + }; }); var service = { @@ -295,7 +386,7 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' ctrl.serviceTemplateChanged = function (template) { console.log('serviceTemplateChanged invoked... ' + template); - if(template === undefined || template === null) { + if (template === undefined || template === null) { ctrl.service = undefined; ctrl.realTemplate = undefined; } else { @@ -306,12 +397,12 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' } }; - ctrl.ok = function() { + ctrl.ok = function () { console.log('ok button clicked!'); console.log('service: '); - console.log(ctrl.service); console.log(customer); console.log(serviceType); + console.log(ctrl.service); console.log(ctrl.realTemplate); @@ -327,7 +418,7 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' ServiceTemplateService.createService(customer, serviceType, ctrl.service, ctrl.realTemplate, successFun, errorMessage); }; // cancel click - ctrl.cancel = function() { + ctrl.cancel = function () { $uibModalInstance.dismiss('cancel'); }; @@ -338,19 +429,80 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' ServiceTemplateService.getAllSdnControllers(function (sdnControllers) { ctrl.sdnControllers = sdnControllers; }); - }] -).controller('packageOnboardCtrl',['$scope', '$uibModalInstance', 'ServiceTemplateService','onboardPackage', - function($scope, $uibModalInstance, ServiceTemplateService, onboardPackage) { + } + ]) + .controller('scaleServiceCtrl', ['$scope', '$uibModal', '$uibModalInstance', 'ServiceTemplateService', 'customer', 'serviceType','serviceInstance', + function ($scope, $uibModal, $uibModalInstance, ServiceTemplateService, customer, serviceType, serviceInstance) { + var ctrl = this; + console.log(ctrl); + console.log(customer); + console.log(serviceType); + console.log(serviceInstance); + + ServiceTemplateService.getScaleServiceDialog(customer.name,serviceType.name,serviceInstance.serviceInstanceId,function(data){ + console.log(data.data); + ctrl.nsData = data.data; + // console.log(ctrl) + }) + ctrl.scaleTypes = ["SCALE_NS","SCALE_VNF"]; + ctrl.scaleType = ""; + ctrl.scalingDirections = ["SCALE_IN","SCALE_OUT"]; + ctrl.scalingDirection = ""; + ctrl.aspectId = null; + ctrl.numberOfStep = null; + + ctrl.ok = function () { + var requestBody = { + "service":{ + "serviceInstanceName": serviceInstance.serviceInstanceName, + "serviceType": serviceType, + "globalSubscriberId": serviceInstance.serviceInstanceId, + "resources": [ + { + "resourceInstanceId": "ns111", + "scaleType": ctrl.scaleType, + "scaleNsData": { + "scaleNsByStepsData": { + "aspectId": ctrl.aspectId, + "numberOfSteps": ctrl.numberOfStep, + "scalingDirection": ctrl.scalingDirection + } + } + } + ] + } + }; + var errorMessage = function () { + + }; + var successFun = function ( operationId) { + $uibModalInstance.close({ + operationId: operationId + }); + } + ServiceTemplateService.scaleService(requestBody, successFun, errorMessage); + + }; + // cancel click + ctrl.cancel = function () { + // $uibModalInstance.close("ok关闭效果"); + $uibModalInstance.dismiss('cancel'); + }; + + } + ]) + .controller('packageOnboardCtrl', ['$scope', '$uibModalInstance', 'ServiceTemplateService', 'onboardPackage', + function ($scope, $uibModalInstance, ServiceTemplateService, onboardPackage) { var ctrl = this; ServiceTemplateService.getAllVimInfo(function (vims) { ctrl.packageLocations = vims; }); - ctrl.ok = function() { + ctrl.ok = function () { var proVims = []; ctrl.packageLocations.forEach(function (location) { - if(location.productenv) { + if (location.productenv) { proVims.push(location.name); } }); @@ -361,94 +513,96 @@ app.controller('lcmCtrl', ['$scope', '$uibModal', '$log', '$http', '$timeout', ' $uibModalInstance.close('successfully'); }; // cancel click - ctrl.cancel = function() { + ctrl.cancel = function () { $uibModalInstance.dismiss('cancel'); }; - }] -).controller('ServiceProgressCtrl', ['$uibModalInstance', 'ServiceTemplateService', 'serviceId', 'operationId', 'operationTitle', '$q', '$interval', -function ($uibModalInstance, ServiceTemplateService, serviceId, operationId, operationTitle, $q, $interval) { - var ctrl = this; - ctrl.title = operationTitle; - ctrl.operation = ''; - ctrl.max = 100; - ctrl.dynamic = 0; - - var timerDeferred = $q.defer(); - var timerPromise = timerDeferred.promise; - - var progressFun = function (serviceProgress) { - if('finished' === serviceProgress.result || 'error' === serviceProgress.result) { - ctrl.dynamic = 100; - timerDeferred.resolve(); - if('finished' === serviceProgress.result) { - $uibModalInstance.close(operationTitle + ' finished!'); - } else if('error' === serviceProgress.result) { - $uibModalInstance.dismiss(operationTitle + ' failed! ' + serviceProgress.reason); - } - console.log('timer finished!'); - } else if('processing' === serviceProgress.result) { - ctrl.dynamic = serviceProgress.progress; - ctrl.operation = serviceProgress.operationContent; - console.log('timer processing ......'); } - }; - - var timer = $interval(function () { - ServiceTemplateService.queryServiceProgress(serviceId, operationId, progressFun); - }, 1000); - - timerPromise.then(function () { - $interval.cancel(timer); - console.log('timer cancel ---- '); - },function () { - $interval.cancel(timer); - }); -}] -).controller('VfOnboardProgressCtrl', ['$uibModalInstance', 'ServiceTemplateService', 'jobId', 'operationTitle', '$q', '$interval', -function ($uibModalInstance, ServiceTemplateService, jobId, operationTitle, $q, $interval) { - var ctrl = this; - ctrl.title = operationTitle; - ctrl.operation = ''; - ctrl.max = 100; - ctrl.dynamic = 0; - - var timerDeferred = $q.defer(); - var timerPromise = timerDeferred.promise; - - var responseId = '0'; - var progressFun = function (responseDescriptor) { - if('finished' === responseDescriptor.status || 'error' === responseDescriptor.status) { - ctrl.dynamic = 100; - timerDeferred.resolve(); - if('finished' === responseDescriptor.status) { - $uibModalInstance.close(''); - } else if('error' === responseDescriptor.status) { - $uibModalInstance.dismiss(responseDescriptor.statusDescription); - } - console.log('timer finished!'); - } else if('processing' === responseDescriptor.status) { - ctrl.dynamic = responseDescriptor.progress; - ctrl.operation = responseDescriptor.statusDescription; - console.log('timer processing ......'); - responseId = responseDescriptor.responseId; - if(responseId === undefined) { - console.log('Cannot get responseId...'); - $uibModalInstance.close(''); + ]) + .controller('ServiceProgressCtrl', ['$uibModalInstance', 'ServiceTemplateService', 'serviceId', 'operationId', 'operationTitle', '$q', '$interval', + function ($uibModalInstance, ServiceTemplateService, serviceId, operationId, operationTitle, $q, $interval) { + var ctrl = this; + ctrl.title = operationTitle; + ctrl.operation = ''; + ctrl.max = 100; + ctrl.dynamic = 0; + + var timerDeferred = $q.defer(); + var timerPromise = timerDeferred.promise; + + var progressFun = function (serviceProgress) { + if ('finished' === serviceProgress.result || 'error' === serviceProgress.result) { + ctrl.dynamic = 100; timerDeferred.resolve(); - } + if ('finished' === serviceProgress.result) { + $uibModalInstance.close(operationTitle + ' finished!'); + } else if ('error' === serviceProgress.result) { + $uibModalInstance.dismiss(operationTitle + ' failed! ' + serviceProgress.reason); + } + console.log('timer finished!'); + } else if ('processing' === serviceProgress.result) { + ctrl.dynamic = serviceProgress.progress; + ctrl.operation = serviceProgress.operationContent; + console.log('timer processing ......'); + } + }; + + var timer = $interval(function () { + ServiceTemplateService.queryServiceProgress(serviceId, operationId, progressFun); + }, 1000); + + timerPromise.then(function () { + $interval.cancel(timer); + console.log('timer cancel ---- '); + }, function () { + $interval.cancel(timer); + }); + } + ]) + .controller('VfOnboardProgressCtrl', ['$uibModalInstance', 'ServiceTemplateService', 'jobId', 'operationTitle', '$q', '$interval', + function ($uibModalInstance, ServiceTemplateService, jobId, operationTitle, $q, $interval) { + var ctrl = this; + ctrl.title = operationTitle; + ctrl.operation = ''; + ctrl.max = 100; + ctrl.dynamic = 0; + + var timerDeferred = $q.defer(); + var timerPromise = timerDeferred.promise; + + var responseId = '0'; + var progressFun = function (responseDescriptor) { + if ('finished' === responseDescriptor.status || 'error' === responseDescriptor.status) { + ctrl.dynamic = 100; + timerDeferred.resolve(); + if ('finished' === responseDescriptor.status) { + $uibModalInstance.close(''); + } else if ('error' === responseDescriptor.status) { + $uibModalInstance.dismiss(responseDescriptor.statusDescription); + } + console.log('timer finished!'); + } else if ('processing' === responseDescriptor.status) { + ctrl.dynamic = responseDescriptor.progress; + ctrl.operation = responseDescriptor.statusDescription; + console.log('timer processing ......'); + responseId = responseDescriptor.responseId; + if (responseId === undefined) { + console.log('Cannot get responseId...'); + $uibModalInstance.close(''); + timerDeferred.resolve(); + } + } + }; + + var timer = $interval(function () { + ServiceTemplateService.queryVfOnboardProgress(jobId, responseId, progressFun); + }, 1000); + + timerPromise.then(function () { + $interval.cancel(timer); + console.log('timer cancel ---- '); + }, function () { + $interval.cancel(timer); + }); } - }; - - var timer = $interval(function () { - ServiceTemplateService.queryVfOnboardProgress(jobId, responseId, progressFun); - }, 1000); - - timerPromise.then(function () { - $interval.cancel(timer); - console.log('timer cancel ---- '); - },function () { - $interval.cancel(timer); - }); -}] -); + ]);
\ No newline at end of file |