diff options
Diffstat (limited to 'testapi/opnfv_testapi/ui/components/scenarios/scenariosController.js')
-rw-r--r-- | testapi/opnfv_testapi/ui/components/scenarios/scenariosController.js | 256 |
1 files changed, 80 insertions, 176 deletions
diff --git a/testapi/opnfv_testapi/ui/components/scenarios/scenariosController.js b/testapi/opnfv_testapi/ui/components/scenarios/scenariosController.js index 4243e21..0aa5bf0 100644 --- a/testapi/opnfv_testapi/ui/components/scenarios/scenariosController.js +++ b/testapi/opnfv_testapi/ui/components/scenarios/scenariosController.js @@ -21,7 +21,7 @@ ScenariosController.$inject = [ '$scope', '$http', '$filter', '$state', '$window', '$uibModal', 'testapiApiUrl', - 'raiseAlert', 'confirmModal' + 'raiseAlert', 'confirmModal', 'sortService', '$timeout' ]; /** @@ -30,7 +30,7 @@ * through projects declared in TestAPI. */ function ScenariosController($scope, $http, $filter, $state, $window, $uibModal, testapiApiUrl, - raiseAlert, confirmModal) { + raiseAlert, confirmModal, sortService, $timeout) { var ctrl = this; ctrl.url = testapiApiUrl + '/scenarios'; @@ -44,8 +44,21 @@ ctrl.deleteScenario = deleteScenario; ctrl.openBatchDeleteModal = openBatchDeleteModal; ctrl.deleteBatchScenario = deleteBatchScenario - + ctrl.sortBy = sortBy ctrl.checkBox = []; + ctrl.sortName = false + ctrl.toastError = toastError + ctrl.toastSuccess = toastSuccess + + function toastError() { + ctrl.showError = true + $timeout(function(){ ctrl.showError = false;}, 3000); + } + + function toastSuccess() { + ctrl.showSuccess = true + $timeout(function(){ ctrl.showSuccess = false;}, 3000); + } function openUpdateModal(name){ $uibModal.open({ @@ -65,32 +78,45 @@ } function openDeleteModal(name){ - confirmModal("Delete",ctrl.deleteScenario,name); + confirmModal("Delete", 'scenarios', ctrl.deleteScenario,name); + } + + function sortBy(){ + ctrl.data.scenarios = sortService.sortFunction(ctrl.data.scenarios, 'name' , ctrl.sortName) + ctrl.sortName=!ctrl.sortName } function deleteScenario(name){ var scenarioURL = ctrl.url+"/"+name; ctrl.scenarioRequest = $http.delete(scenarioURL).success(function (data){ - ctrl.showCreateSuccess = true; ctrl.success = "Scenario is successfully deleted."; ctrl.listScenarios(); + ctrl.toastSuccess(); }).catch(function (data) { - ctrl.showError = true; ctrl.error = data.statusText; + ctrl.toastError() }); } function openBatchDeleteModal(){ - confirmModal("Delete",ctrl.deleteBatchScenario); + var deleteObjects = [] + ctrl.checkBox.forEach(function(scenario, index){ + if(!ctrl.showError){ + if(scenario){ + deleteObjects.push(ctrl.data.scenarios[index].name); + } + } + }); + confirmModal("Delete", 'scenarios', ctrl.deleteBatchScenario, deleteObjects); } function deleteBatchScenario(){ var index; var checkedBox = []; - ctrl.checkBox.forEach(function(project, index){ + ctrl.checkBox.forEach(function(scenario, index){ if(!ctrl.showError){ - if(project){ + if(scenario){ deleteScenario(ctrl.data.scenarios[index].name); } } @@ -103,15 +129,21 @@ var body = { "name": newName } - ctrl.scenarioRequest = - $http.put(scenarioURL, body).success(function (data){ - ctrl.showCreateSuccess = true; + if(newName){ + ctrl.scenarioRequest = $http.put(scenarioURL, body) + ctrl.scenarioRequest.success(function (data){ ctrl.success = "Scenario is successfully Updated." - ctrl.listScenarios() + ctrl.listScenarios(); + ctrl.toastSuccess(); }).catch(function (data) { - ctrl.showError = true; ctrl.error = data.statusText; + ctrl.toastError(); }); + return ctrl.scenarioRequest + }else{ + ctrl.error = "Name is missing"; + ctrl.toastError(); + } } function viewScenario(name){ @@ -119,15 +151,17 @@ } function createScenario(scenario) { - console.log(scenario) - ctrl.scenarioRequest = - $http.post(ctrl.url, scenario).success(function (data){ - ctrl.showCreateSuccess = true; - ctrl.success = "Scenario is successfully created." + ctrl.scenarioRequest = $http.post(ctrl.url, scenario) + + ctrl.scenarioRequest.success(function (data){ + ctrl.success = "Scenario is successfully created."; + ctrl.toastSuccess(); }).catch(function (data) { - ctrl.showError = true; ctrl.error = data.statusText; + ctrl.toastError(); }); + + return ctrl.scenarioRequest; } function listScenarios() { @@ -135,10 +169,11 @@ ctrl.resultsRequest = $http.get(ctrl.url).success(function (data) { ctrl.data = data; + ctrl.sortBy() }).catch(function (data) { ctrl.data = null; - ctrl.showError = true; ctrl.error = data.statusText; + ctrl.toastError(); }); } @@ -169,8 +204,8 @@ * edit the project's details */ angular.module('testapiApp').controller('scenarioModalController', scenarioModalController); - scenarioModalController.$inject = ['$scope', '$uibModal', '$uibModalInstance', 'data']; - function scenarioModalController($scope, $uibModal, $uibModalInstance, data) { + scenarioModalController.$inject = ['$scope', '$uibModal', '$uibModalInstance', 'data', '$q']; + function scenarioModalController($scope, $uibModal, $uibModalInstance, data, $q) { var ctrl = this; ctrl.confirm = confirm; ctrl.cancel = cancel; @@ -187,8 +222,9 @@ * inputs. */ function confirm() { - ctrl.data.successHandler(ctrl.scenario); - $uibModalInstance.dismiss('cancel'); + ctrl.data.successHandler(ctrl.scenario).success(function(){ + $uibModalInstance.dismiss('cancel'); + }); } @@ -201,6 +237,9 @@ function handleModalData(installer){ ctrl.scenario.installers.push(installer) + var deferred = $q.defer(); + deferred.resolve(); + return deferred.promise; } function openInstallerModal(){ @@ -245,8 +284,9 @@ * inputs. */ function confirm() { - ctrl.data.successHandler(ctrl.installer); - $uibModalInstance.dismiss('cancel'); + ctrl.data.successHandler(ctrl.installer).success(function(){ + $uibModalInstance.dismiss('cancel'); + }); } @@ -262,7 +302,6 @@ } function openVersionModal(){ - console.log("Hello"); $uibModal.open({ templateUrl: 'testapi-ui/components/scenarios/modals/versionModal.html', controller: 'versionModalCtrl as versionModalCtrl', @@ -348,11 +387,7 @@ ctrl.confirm = confirm; ctrl.cancel = cancel; ctrl.data = angular.copy(data); - ctrl.openScoreModal = openScoreModal; - ctrl.openTrustIndicatorModal = openTrustIndicatorModal; ctrl.openCustomModal = openCustomModal; - ctrl.handleScore = handleScore; - ctrl.handleModalTrustIndicator = handleModalTrustIndicator; ctrl.handleModalCustom = handleModalCustom; ctrl.project = { "scores": [], @@ -379,48 +414,12 @@ $uibModalInstance.dismiss('cancel'); } - function handleModalTrustIndicator(trustIndicator){ - ctrl.project.trust_indicators.push(trustIndicator) - } - - function handleScore(score){ - ctrl.project.scores.push(score); - } - - function handleModalCustom(custom){ - ctrl.project.customs.push(custom); + function handleModalCustom(customs){ + for (var custom in customs){ + ctrl.project.customs.push(customs[custom]); + } } - function openScoreModal(){ - $uibModal.open({ - templateUrl: 'testapi-ui/components/scenarios/modals/scoreModal.html', - controller: 'scoreModalCtrl as scoreModalCtrl', - size: 'md', - resolve: { - data: function () { - return { - text: "Score", - successHandler: ctrl.handleScore, - }; - } - } - }); - } - function openTrustIndicatorModal(){ - $uibModal.open({ - templateUrl: 'testapi-ui/components/scenarios/modals/trustIndicatorModal.html', - controller: 'trustIndicatorModalCtrl as trustIndicatorModalCtrl', - size: 'md', - resolve: { - data: function () { - return { - text: "Trust Indicator", - successHandler: ctrl.handleModalTrustIndicator - }; - } - } - }); - } function openCustomModal(){ $uibModal.open({ templateUrl: 'testapi-ui/components/scenarios/modals/customModal.html', @@ -444,106 +443,6 @@ * the project information and for the edit modal where user can * edit the project's details */ - angular.module('testapiApp').controller('scoreModalCtrl', scoreModalCtrl); - scoreModalCtrl.$inject = ['$scope', '$uibModalInstance', 'data']; - function scoreModalCtrl($scope, $uibModalInstance, data) { - var ctrl = this; - ctrl.confirm = confirm; - ctrl.cancel = cancel; - ctrl.data = angular.copy(data); - ctrl.open = open; - - /** - * Initiate confirmation and call the success handler with the - * inputs. - */ - function confirm() { - ctrl.data.successHandler(ctrl.score); - $uibModalInstance.dismiss('cancel'); - } - - /** - * Close the confirm modal without initiating changes. - */ - function cancel() { - $uibModalInstance.dismiss('cancel'); - } - - function handleModalData(){ - - } - - /** - * This is called when the date filter calendar is opened. It - * does some event handling, and sets a scope variable so the UI - * knows which calendar was opened. - * @param {Object} $event - The Event object - * @param {String} openVar - Tells which calendar was opened - */ - function open($event, openVar) { - $event.preventDefault(); - $event.stopPropagation(); - ctrl[openVar] = true; - } - } - - /** - * TestAPI Project Modal Controller - * This controller is for the create modal where a user can create - * the project information and for the edit modal where user can - * edit the project's details - */ - angular.module('testapiApp').controller('trustIndicatorModalCtrl', trustIndicatorModalCtrl); - trustIndicatorModalCtrl.$inject = ['$scope', '$uibModalInstance', 'data']; - function trustIndicatorModalCtrl($scope, $uibModalInstance, data) { - var ctrl = this; - ctrl.confirm = confirm; - ctrl.cancel = cancel; - ctrl.data = angular.copy(data); - ctrl.open = open; - - - /** - * Initiate confirmation and call the success handler with the - * inputs. - */ - function confirm() { - ctrl.data.successHandler(ctrl.ti); - $uibModalInstance.dismiss('cancel'); - - } - - /** - * Close the confirm modal without initiating changes. - */ - function cancel() { - $uibModalInstance.dismiss('cancel'); - } - - function handleModalData(){ - - } - - /** - * This is called when the date filter calendar is opened. It - * does some event handling, and sets a scope variable so the UI - * knows which calendar was opened. - * @param {Object} $event - The Event object - * @param {String} openVar - Tells which calendar was opened - */ - function open($event, openVar) { - $event.preventDefault(); - $event.stopPropagation(); - ctrl[openVar] = true; - } - } - - /** - * TestAPI Project Modal Controller - * This controller is for the create modal where a user can create - * the project information and for the edit modal where user can - * edit the project's details - */ angular.module('testapiApp').controller('customModalCtrl', customModalCtrl); customModalCtrl.$inject = ['$scope', '$uibModalInstance', 'data']; function customModalCtrl($scope, $uibModalInstance, data) { @@ -552,6 +451,7 @@ ctrl.cancel = cancel; ctrl.data = angular.copy(data); ctrl.open = open; + ctrl.customs = [] /** @@ -559,7 +459,11 @@ * inputs. */ function confirm() { - ctrl.data.successHandler(ctrl.custom); + var custom = ctrl.custom; + if(custom!="" && custom!=undefined ){ + ctrl.customs = custom.split(/[ ,]+/).filter(Boolean); + } + ctrl.data.successHandler(ctrl.customs); $uibModalInstance.dismiss('cancel'); } @@ -594,9 +498,9 @@ * inputs. */ function confirm() { - ctrl.data.successHandler(ctrl.name,ctrl.data.name); - $uibModalInstance.dismiss('cancel'); - + ctrl.data.successHandler(ctrl.name,ctrl.data.name).success( function() { + $uibModalInstance.dismiss('cancel'); + }) } /** |