summaryrefslogtreecommitdiffstats
path: root/testapi/opnfv_testapi/ui/components/pods/podsController.js
diff options
context:
space:
mode:
Diffstat (limited to 'testapi/opnfv_testapi/ui/components/pods/podsController.js')
-rw-r--r--testapi/opnfv_testapi/ui/components/pods/podsController.js111
1 files changed, 62 insertions, 49 deletions
diff --git a/testapi/opnfv_testapi/ui/components/pods/podsController.js b/testapi/opnfv_testapi/ui/components/pods/podsController.js
index c66873a..3b6ab97 100644
--- a/testapi/opnfv_testapi/ui/components/pods/podsController.js
+++ b/testapi/opnfv_testapi/ui/components/pods/podsController.js
@@ -21,7 +21,7 @@
PodsController.$inject = [
'$scope', '$http', '$filter', '$state', '$window', '$uibModal', 'testapiApiUrl','raiseAlert',
- 'confirmModal'
+ 'confirmModal', 'keepState', 'sortService', '$timeout'
];
/**
@@ -30,23 +30,41 @@
* through pods declared in TestAPI.
*/
function PodsController($scope, $http, $filter, $state, $window, $uibModal, testapiApiUrl,
- raiseAlert, confirmModal) {
+ raiseAlert, confirmModal, keepState, sortService, $timeout) {
var ctrl = this;
ctrl.url = testapiApiUrl + '/pods';
ctrl.checkBox = []
ctrl.checkBoxList = [];
+ ctrl.sorting = {};
ctrl.create = create;
ctrl.listPods = listPods;
ctrl.open = open;
ctrl.filter = 'name'
- ctrl.clearFilters = clearFilters;
ctrl.openDeleteModal = openDeleteModal
ctrl.openBatchDeleteModal = openBatchDeleteModal
ctrl.openCreateModal = openCreateModal
ctrl.podDelete = podDelete
ctrl.batchDelete = batchDelete;
ctrl.viewPod = viewPod
+ ctrl.sortBy = sortBy
+ 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 sortBy(field){
+ ctrl.data.pods = sortService.sortFunction(ctrl.data.pods, field , ctrl.sorting[field] )
+ ctrl.sorting[field]=!ctrl.sorting[field]
+ }
/**
* This is called when the date filter calendar is opened. It
@@ -61,13 +79,6 @@
ctrl[openVar] = true;
}
- /**
- * This function will clear all filters and update the results
- * listing.
- */
- function clearFilters() {
- ctrl.listPods();
- }
/**
* This will contact the TestAPI to create a new pod.
@@ -75,7 +86,6 @@
function create(pod) {
ctrl.showError = false;
ctrl.showSuccess = false;
- console.log(pod);
if(pod.name != ""){
var pods_url = ctrl.url;
var body = {
@@ -84,19 +94,21 @@
role: pod.role,
details: pod.details
};
- ctrl.podsRequest =
- $http.post(pods_url, body).success(function (data) {
- ctrl.showSuccess = true ;
+ ctrl.podsRequest = $http.post(pods_url, body)
+
+ ctrl.podsRequest.success(function (data) {
ctrl.success = "Create Success"
+ ctrl.toastSuccess()
ctrl.listPods();
}).catch(function (data) {
- ctrl.showError = true;
- ctrl.error = "Error creating the new pod from server: " + data.statusText;
+ ctrl.error = data.statusText;
+ ctrl.toastError()
});
+ return ctrl.podsRequest
}
else{
- ctrl.showError = true;
ctrl.error = 'Name is missing.'
+ ctrl.toastError()
}
}
@@ -105,21 +117,33 @@
*/
function listPods() {
ctrl.showError = false;
+ var reqURL = ctrl.url;
+ if(ctrl.filterText!=undefined){
+ reqURL = ctrl.url + "?name=" + ctrl.filterText
+ }
+ else if(keepState.filter.podFilter){
+ for (var filter in keepState.filter.podFilter){
+ reqURL = ctrl.url + '?' + filter + '=' + keepState.filter.podFilter[filter]
+ ctrl.filterText = keepState.filter.podFilter[filter]
+ }
+ }
ctrl.podsRequest =
- $http.get(ctrl.url).success(function (data) {
+ $http.get(reqURL).success(function (data) {
ctrl.data = data;
- // mapNametoRandom
- }).error(function (error) {
+ ctrl.sortBy("name")
+ if(ctrl.filterText != undefined){
+ keepState.filter.podFilter = {
+ 'name': ctrl.filterText
+ }
+ }
+ }).catch(function (data) {
ctrl.data = null;
- ctrl.showError = true;
- ctrl.error =
- 'Error retrieving pods from server: ' +
- angular.toJson(error);
+ ctrl.error = data.statusText;
+ ctrl.toastError()
});
}
function viewPod(name){
- console.log('hello');
$state.go('pod', {'name':name}, {reload: true});
}
/**
@@ -129,12 +153,12 @@
function podDelete(podName){
var pods_url = ctrl.url + "/" + podName
$http.delete(pods_url).success(function(){
- ctrl.showSuccess = true ;
ctrl.success = "Delete Success"
+ ctrl.toastSuccess()
ctrl.listPods();
}).catch(function (data) {
- ctrl.showError = true;
ctrl.error = data.statusText;
+ ctrl.toastError()
});
}
@@ -144,7 +168,6 @@
function batchDelete(){
var index;
var checkedBox = [];
- console.log(ctrl.checkBox)
for(index in ctrl.checkBox){
if(!ctrl.showError){
if(ctrl.checkBox[index]){
@@ -160,7 +183,13 @@
* message
*/
function openBatchDeleteModal() {
- confirmModal("Delete",ctrl.batchDelete);
+ var deleteObjects = []
+ for(var index in ctrl.checkBox){
+ if(ctrl.checkBox[index]){
+ deleteObjects.push(ctrl.data.pods[index].name)
+ }
+ }
+ confirmModal("Delete", 'pods', ctrl.batchDelete, deleteObjects);
}
/**
@@ -168,8 +197,7 @@
* message
*/
function openDeleteModal(name) {
- console.log(name)
- confirmModal("Delete", ctrl.podDelete, name);
+ confirmModal("Delete", 'pod', ctrl.podDelete, name);
}
/**
@@ -192,22 +220,6 @@
});
}
- // function openUpdateModal(podName){
- // $uibModal.open({
- // templateUrl: 'testapi-ui/components/pods/modals/createModal.html',
- // controller: 'PodModalCtrl as PodModalCtrl',
- // size: 'md',
- // resolve: {
- // data: function () {
- // return {
- // text: "Update",
- // successHandler: ctrl.update,
- // // pod: ctrl.
- // };
- // }
- // }
- // });
- // }
ctrl.listPods();
}
@@ -249,9 +261,10 @@
* inputs.
*/
function confirm() {
- $uibModalInstance.close();
if (angular.isDefined(ctrl.data.successHandler)) {
- ctrl.data.successHandler(ctrl.pod);
+ ctrl.data.successHandler(ctrl.pod).success( function(data){
+ $uibModalInstance.close();
+ })
}
}