From 6badf58ccee238acb1d636eebb01785671fe4553 Mon Sep 17 00:00:00 2001 From: Nabil Adouani Date: Wed, 4 Nov 2020 18:31:13 +0100 Subject: [PATCH] #1579 Add support to the new ui settings that defines the default filter of the alert similar cases section --- .../alert/AlertSimilarCaseListCmp.js | 36 ++++-- .../organisation/OrgConfigListCmp.js | 6 +- .../app/scripts/services/api/AlertingSrv.js | 120 +++++++++++++++++- .../components/alert/similarity/toolbar.html | 4 + .../app/views/components/org/config.list.html | 6 +- 5 files changed, 154 insertions(+), 18 deletions(-) diff --git a/frontend/app/scripts/components/alert/AlertSimilarCaseListCmp.js b/frontend/app/scripts/components/alert/AlertSimilarCaseListCmp.js index 8f076e9659..c557b16bca 100644 --- a/frontend/app/scripts/components/alert/AlertSimilarCaseListCmp.js +++ b/frontend/app/scripts/components/alert/AlertSimilarCaseListCmp.js @@ -3,7 +3,7 @@ angular.module('theHiveComponents') .component('alertSimilarCaseList', { - controller: function($scope, FilteringSrv, PaginatedQuerySrv, CaseResolutionStatus, UiSettingsSrv) { + controller: function($scope, AlertingSrv, FilteringSrv, PaginatedQuerySrv, CaseResolutionStatus, UiSettingsSrv) { var self = this; self.CaseResolutionStatus = CaseResolutionStatus; @@ -49,19 +49,12 @@ self.filtering.initContext('alert.dialog.similar-cases') .then(function() { - var defaultFilter = { - field: 'status', - type: 'enumeration', - value: { - list: [{ - text: 'Open', - label: 'Open' - }] - } - }; - - if(_.isEmpty(self.filtering.context.filters)) { - self.filtering.addFilter(defaultFilter); + var defaultFilter = AlertingSrv.getSimilarityFilter(self.state.defaultAlertSimilarCaseFilter); + + if(_.isEmpty(self.filtering.context.filters) && defaultFilter && defaultFilter.length > 0) { + _.each(defaultFilter, function(item) { + self.filtering.addFilter(item); + }); } self.load(); @@ -173,6 +166,21 @@ }); }; + this.applyDefaultFilter = function() { + self.filtering.clearFilters() + .then(function(){ + var defaultFilter = AlertingSrv.getSimilarityFilter(self.state.defaultAlertSimilarCaseFilter); + + if(defaultFilter && defaultFilter.length > 0) { + _.each(defaultFilter, function(item) { + self.filtering.addFilter(item); + }); + + self.search(); + } + }); + }; + this.filterSimilarities = function(data) { return data; }; diff --git a/frontend/app/scripts/components/organisation/OrgConfigListCmp.js b/frontend/app/scripts/components/organisation/OrgConfigListCmp.js index 143bc820ac..f96da1fade 100644 --- a/frontend/app/scripts/components/organisation/OrgConfigListCmp.js +++ b/frontend/app/scripts/components/organisation/OrgConfigListCmp.js @@ -3,9 +3,11 @@ angular.module('theHiveComponents') .component('orgConfigList', { - controller: function($scope, $q, NotificationSrv, UiSettingsSrv) { + controller: function($scope, $q, NotificationSrv, AlertingSrv, UiSettingsSrv) { var self = this; + self.alertSimilarityFilters = []; + self.isDirtySetting = function(key, newValue) { return newValue !== self.currentSettings[key]; }; @@ -62,6 +64,8 @@ self.$onInit = function() { self.loadSettings(this.uiConfig); + + self.alertSimilarityFilters = AlertingSrv.getSimilarityFilters(); }; }, controllerAs: '$ctrl', diff --git a/frontend/app/scripts/services/api/AlertingSrv.js b/frontend/app/scripts/services/api/AlertingSrv.js index f661565cc1..954644aec3 100644 --- a/frontend/app/scripts/services/api/AlertingSrv.js +++ b/frontend/app/scripts/services/api/AlertingSrv.js @@ -5,8 +5,126 @@ var baseUrl = './api/alert'; - var factory = { + var similarityFilters = { + 'open-cases': { + label: 'Open Cases', + filters: [{ + field: 'status', + type: 'enumeration', + value: { + list: [{ + text: 'Open', + label: 'Open' + }] + } + }] + }, + 'open-cases-last-7days': { + label: 'Open Cases in the last 7 days', + filters: [{ + field: 'status', + type: 'enumeration', + value: { + list: [{ + text: 'Open', + label: 'Open' + }] + } + }, { + field: '_createdAt', + type: 'date', + value: { + operator: 'last7days', + from: null, + to: null + } + }] + }, + 'open-cases-last-30days': { + label: 'Open Cases in the last 30 days', + filters: [{ + field: 'status', + type: 'enumeration', + value: { + list: [{ + text: 'Open', + label: 'Open' + }] + } + }, { + field: '_createdAt', + type: 'date', + value: { + operator: 'last30days', + from: null, + to: null + } + }] + }, + 'open-cases-last-3months': { + label: 'Open Cases in the last 3 months', + filters: [{ + field: 'status', + type: 'enumeration', + value: { + list: [{ + text: 'Open', + label: 'Open' + }] + } + }, { + field: '_createdAt', + type: 'date', + value: { + operator: 'last3months', + from: null, + to: null + } + }] + }, + 'open-cases-last-year': { + label: 'Open Cases in the last year', + filters: [{ + field: 'status', + type: 'enumeration', + value: { + list: [{ + text: 'Open', + label: 'Open' + }] + } + }, { + field: '_createdAt', + type: 'date', + value: { + operator: 'lastyear', + from: null, + to: null + } + }] + }, + 'resolved-cases': { + label: 'Resolved cases', + filters: [{ + field: 'status', + type: 'enumeration', + value: { + list: [{ + text: 'Resolved', + label: 'Resolved' + }] + } + }] + } + }; + var factory = { + getSimilarityFilters: function() { + return similarityFilters; + }, + getSimilarityFilter: function(name) { + return (similarityFilters[name] || {}).filters; + }, list: function(config, callback) { return new PaginatedQuerySrv({ name: 'alerts', diff --git a/frontend/app/views/components/alert/similarity/toolbar.html b/frontend/app/views/components/alert/similarity/toolbar.html index 6f10e21bbb..de0bc3b8d1 100644 --- a/frontend/app/views/components/alert/similarity/toolbar.html +++ b/frontend/app/views/components/alert/similarity/toolbar.html @@ -9,6 +9,10 @@