From 6b8a9d436c75d595bb66f0c47dbdfc8ad69094ec Mon Sep 17 00:00:00 2001 From: Nabil Adouani Date: Thu, 29 Oct 2020 14:42:49 +0100 Subject: [PATCH] #1579 Refactor the UiSettings service and add new ui options related to alert similar cases section --- frontend/app/scripts/app.js | 12 --- .../alert/AlertSimilarCaseListCmp.js | 24 +++++- .../organisation/OrgConfigListCmp.js | 7 +- .../controllers/alert/AlertEventCtrl.js | 2 +- .../case/CaseTemplatesDialogCtrl.js | 2 +- .../app/scripts/services/api/UiSettingsSrv.js | 78 +++++++++---------- .../alert/similar-case-list.component.html | 2 +- .../app/views/components/org/config.list.html | 22 +++++- thehive/conf/reference.conf | 2 + 9 files changed, 87 insertions(+), 64 deletions(-) diff --git a/frontend/app/scripts/app.js b/frontend/app/scripts/app.js index 39e83c6a71..019121422f 100644 --- a/frontend/app/scripts/app.js +++ b/frontend/app/scripts/app.js @@ -313,18 +313,6 @@ angular.module('thehive', [ permissions: ['manageObservableTemplate'] } }) - // .state('app.administration.ui-settings', { - // url: '/ui-settings', - // templateUrl: 'views/partials/admin/ui-settings.html', - // controller: 'AdminUiSettingsCtrl', - // controllerAs: '$vm', - // title: 'UI settings', - // resolve: { - // uiConfig: function(UiSettingsSrv) { - // return UiSettingsSrv.all(); - // } - // } - // }) .state('app.case', { abstract: true, url: 'case/{caseId}', diff --git a/frontend/app/scripts/components/alert/AlertSimilarCaseListCmp.js b/frontend/app/scripts/components/alert/AlertSimilarCaseListCmp.js index 850bad9b42..8f076e9659 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) { + controller: function($scope, FilteringSrv, PaginatedQuerySrv, CaseResolutionStatus, UiSettingsSrv) { var self = this; self.CaseResolutionStatus = CaseResolutionStatus; @@ -30,6 +30,11 @@ currentPage: 1 }; + self.state = { + disallowMerge: UiSettingsSrv.disallowMergeAlertInResolvedSimilarCases() === true, + defaultAlertSimilarCaseFilter: UiSettingsSrv.defaultAlertSimilarCaseFilter() + }; + self.$onInit = function() { this.filtering = new FilteringSrv('case', 'alert.dialog.similar-cases', { version: 'v1', @@ -42,8 +47,23 @@ defaultFilter: [] }); - self.filtering.initContext(this.alertId) + 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); + } + self.load(); $scope.$watch('$cmp.list.pageSize', function (newValue) { diff --git a/frontend/app/scripts/components/organisation/OrgConfigListCmp.js b/frontend/app/scripts/components/organisation/OrgConfigListCmp.js index f3592d07e5..143bc820ac 100644 --- a/frontend/app/scripts/components/organisation/OrgConfigListCmp.js +++ b/frontend/app/scripts/components/organisation/OrgConfigListCmp.js @@ -7,9 +7,7 @@ var self = this; self.isDirtySetting = function(key, newValue) { - var currentValue = (self.currentSettings[key] || {}).value; - - return newValue !== currentValue; + return newValue !== self.currentSettings[key]; }; self.save = function(/*form*/) { @@ -36,6 +34,7 @@ }; self.loadSettings = function(configurations) { + var notifyRoot = false; var promise; @@ -52,7 +51,7 @@ self.configs = {}; self.settingsKeys.forEach(function(key) { - self.configs[key] = (configs[key] || {}).value; + self.configs[key] = configs[key]; }); if(notifyRoot) { diff --git a/frontend/app/scripts/controllers/alert/AlertEventCtrl.js b/frontend/app/scripts/controllers/alert/AlertEventCtrl.js index 0db05c183c..c36e492711 100644 --- a/frontend/app/scripts/controllers/alert/AlertEventCtrl.js +++ b/frontend/app/scripts/controllers/alert/AlertEventCtrl.js @@ -21,7 +21,7 @@ similarCases: 0 }; - self.hideEmptyCaseButton = UiSettingsSrv.uiHideEmptyCaseButton(); + self.hideEmptyCaseButton = UiSettingsSrv.hideEmptyCaseButton(); self.updateObservableCount = function(count) { self.counts.observables = count; diff --git a/frontend/app/scripts/controllers/case/CaseTemplatesDialogCtrl.js b/frontend/app/scripts/controllers/case/CaseTemplatesDialogCtrl.js index 1412dd640b..67fa8689d8 100644 --- a/frontend/app/scripts/controllers/case/CaseTemplatesDialogCtrl.js +++ b/frontend/app/scripts/controllers/case/CaseTemplatesDialogCtrl.js @@ -7,7 +7,7 @@ this.state = { filter: '', selected: null, - hideEmptyCaseButton: UiSettingsSrv.uiHideEmptyCaseButton() + hideEmptyCaseButton: UiSettingsSrv.hideEmptyCaseButton() }; this.selectTemplate = function(template) { diff --git a/frontend/app/scripts/services/api/UiSettingsSrv.js b/frontend/app/scripts/services/api/UiSettingsSrv.js index 77821aa051..4ffaabd92b 100644 --- a/frontend/app/scripts/services/api/UiSettingsSrv.js +++ b/frontend/app/scripts/services/api/UiSettingsSrv.js @@ -1,64 +1,58 @@ (function() { 'use strict'; - angular.module('theHiveServices').factory('UiSettingsSrv', function($http, $q) { - - var settings = null; + angular.module('theHiveServices').service('UiSettingsSrv', function($http, $q) { var baseUrl = './api/config/organisation/'; + var self = this; - var keys = [ - 'ui.hideEmptyCaseButton' - ]; + this.settings = null; - var factory = { - keys: keys, - clearCache: function() { - settings = null; - }, + this.keys = [ + 'hideEmptyCaseButton', + 'disallowMergeAlertInResolvedSimilarCases', + 'defaultAlertSimilarCaseFilter' + ]; - get: function(name) { - return settings[name]; - }, + this.clearCache = function() { + self.settings = null; + }; - save: function(name, value) { - return $http.put(baseUrl + name, {value: value}); - }, + this.get = function(name) { + return self.settings[name]; + }; - all: function(force) { - var deferred = $q.defer(); + this.save = function(name, value) { + return $http.put(baseUrl + 'ui.' + name, {value: value}); + }; - if(settings === null || force) { + this.all = function(force) { + var deferred = $q.defer(); - settings = {}; + if(self.settings === null || force) { - $q.all(_.map(keys, function(key) { - return $http.get(baseUrl + key); - })).then(function(responses) { - _.each(responses, function(response) { - var data = response.data; + self.settings = {}; - settings[data.path] = data; - settings[data.path].id = data.path; - }); + $http.get('./api/config/organisation?path=ui') + .then(function(response) { + var data = response.data; - deferred.resolve(settings); - }).catch(function(responses) { - deferred.reject(responses); + self.settings = data; + deferred.resolve(data); + }) + .catch(function(response) { + deferred.reject(response); }); - } else { - deferred.resolve(settings); - } - - return deferred.promise; + } else { + deferred.resolve(self.settings); } + + return deferred.promise; }; - keys.forEach(function(key) { + this.keys.forEach(function(key) { var camelcased = s.camelize(key.replace(/\./gi, '_')); - factory[camelcased] = function() { - return (settings[key] || {}).value; + self[camelcased] = function() { + return (self.settings || {})[key]; }; }); - - return factory; }); })(); diff --git a/frontend/app/views/components/alert/similar-case-list.component.html b/frontend/app/views/components/alert/similar-case-list.component.html index 86a17ffd0e..be1bb10afb 100644 --- a/frontend/app/views/components/alert/similar-case-list.component.html +++ b/frontend/app/views/components/alert/similar-case-list.component.html @@ -163,7 +163,7 @@
- +
diff --git a/frontend/app/views/components/org/config.list.html b/frontend/app/views/components/org/config.list.html index 585bb686ab..b083028c9d 100644 --- a/frontend/app/views/components/org/config.list.html +++ b/frontend/app/views/components/org/config.list.html @@ -6,12 +6,32 @@
+
+ +
+
+ +
+
+
+ +
+ +
+ +
+
+
diff --git a/thehive/conf/reference.conf b/thehive/conf/reference.conf index 02b10595b0..1bce841547 100644 --- a/thehive/conf/reference.conf +++ b/thehive/conf/reference.conf @@ -165,4 +165,6 @@ integrityCheck { organisation.defaults { ui.hideEmptyCaseButton: false + ui.disallowMergeAlertInResolvedSimilarCases: false + ui.defaultAlertSimilarCaseFilter: "open-cases" }