From e5f0b9dd2d8caff4f91009b7b7578c30d17fcbd1 Mon Sep 17 00:00:00 2001 From: Nabil Adouani Date: Thu, 4 Mar 2021 12:07:51 +0100 Subject: [PATCH] #1813 Enahance organisation list page --- .../admin/organisation/OrgListCtrl.js | 98 +++++++++++++++++-- .../partials/admin/organisation/list.html | 65 ++++++++++-- .../admin/organisation/list/toolbar.html | 11 +++ 3 files changed, 158 insertions(+), 16 deletions(-) diff --git a/frontend/app/scripts/controllers/admin/organisation/OrgListCtrl.js b/frontend/app/scripts/controllers/admin/organisation/OrgListCtrl.js index c068b4d491..2bcc22a6e2 100644 --- a/frontend/app/scripts/controllers/admin/organisation/OrgListCtrl.js +++ b/frontend/app/scripts/controllers/admin/organisation/OrgListCtrl.js @@ -2,21 +2,54 @@ 'use strict'; angular.module('theHiveControllers').controller('OrgListCtrl', - function($scope, $q, $uibModal, OrganisationSrv, NotificationSrv, appConfig) { + function($scope, $q, $uibModal, PaginatedQuerySrv, OrganisationSrv, NotificationSrv, FilteringSrv, appConfig) { var self = this; self.appConfig = appConfig; - self.load = function() { - OrganisationSrv.list() - .then(function(response) { - self.list = response.data; - }) - .catch(function(err) { - NotificationSrv.error('Error', 'Failed to list organisations', err.status); + this.$onInit = function() { + self.filtering = new FilteringSrv('organisation', 'organisation.list', { + version: 'v1', + defaults: { + showFilters: true, + showStats: false, + pageSize: 15, + sort: ['-_updatedAt'] + }, + defaultFilter: [] + }); + self.filtering.initContext('list') + .then(function() { + self.load(); + + $scope.$watch('$vm.list.pageSize', function (newValue) { + self.filtering.setPageSize(newValue); + }); }); }; + this.load = function() { + + this.list = new PaginatedQuerySrv({ + name: 'organisations', + root: undefined, + objectType: 'organisation', + version: 'v1', + scope: $scope, + sort: self.filtering.context.sort, + loadAll: false, + pageSize: self.filtering.context.pageSize, + filter: this.filtering.buildQuery(), + operations: [ + {'_name': 'listOrganisation'} + ], + //extraData: ['observableStats', 'taskStats', 'isOwner', 'shareCount', 'permissions', 'actionRequired'], + onUpdate: function() { + // self.resetSelection(); + } + }); + }; + self.showNewOrg = function(mode, org) { var modal = $uibModal.open({ controller: 'OrgModalCtrl', @@ -106,6 +139,53 @@ }); }; - self.load(); + this.toggleFilters = function () { + this.filtering.toggleFilters(); + }; + + this.filter = function () { + self.filtering.filter().then(this.applyFilters); + }; + + this.clearFilters = function () { + this.filtering.clearFilters() + .then(self.search); + }; + + this.removeFilter = function (index) { + self.filtering.removeFilter(index) + .then(self.search); + }; + + this.search = function () { + self.load(); + self.filtering.storeContext(); + }; + this.addFilterValue = function (field, value) { + this.filtering.addFilterValue(field, value); + this.search(); + }; + + this.sortBy = function(sort) { + this.list.sort = sort; + this.list.update(); + this.filtering.setSort(sort); + }; + + this.sortByField = function(field) { + var context = this.filtering.context; + var currentSort = Array.isArray(context.sort) ? context.sort[0] : context.sort; + var sort = null; + + if(currentSort.substr(1) !== field) { + sort = ['+' + field]; + } else { + sort = [(currentSort === '+' + field) ? '-'+field : '+'+field]; + } + + self.list.sort = sort; + self.list.update(); + self.filtering.setSort(sort); + }; }); })(); diff --git a/frontend/app/views/partials/admin/organisation/list.html b/frontend/app/views/partials/admin/organisation/list.html index 15c94bebe5..f4e3665039 100644 --- a/frontend/app/views/partials/admin/organisation/list.html +++ b/frontend/app/views/partials/admin/organisation/list.html @@ -2,25 +2,67 @@
-

List of organisations

+

List of organisations ({{$vm.list.values.length || 0}} of {{$vm.list.total}})

+
+ + +
+
+ +
+
+
+ + - - - + + + - + + -
NameCreated ByCreated At + + Name + + + + + + + Created By + + + + + + Dates + + + C. + + + + + + U. + + + + +
{{::org.name}} @@ -39,9 +81,16 @@

List of organisations

- + + + + {{org.createdAt | shortDate}} @@ -59,6 +108,8 @@

List of organisations

+ +
diff --git a/frontend/app/views/partials/admin/organisation/list/toolbar.html b/frontend/app/views/partials/admin/organisation/list/toolbar.html index 0a51cd7f65..c5a259003c 100644 --- a/frontend/app/views/partials/admin/organisation/list/toolbar.html +++ b/frontend/app/views/partials/admin/organisation/list/toolbar.html @@ -1,12 +1,23 @@