Skip to content

Commit

Permalink
#1583 Add a UI setting that allows defining the default date format
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Feb 24, 2021
1 parent 2c4bcee commit 066625c
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 27 deletions.
14 changes: 13 additions & 1 deletion frontend/app/scripts/components/organisation/OrgConfigListCmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

angular.module('theHiveComponents')
.component('orgConfigList', {
controller: function($scope, $q, NotificationSrv, AlertingSrv, UiSettingsSrv) {
controller: function($scope, $q, $interval, NotificationSrv, AlertingSrv, UiSettingsSrv) {
var self = this;

self.alertSimilarityFilters = [];
Expand Down Expand Up @@ -66,7 +66,19 @@
self.loadSettings(this.uiConfig);

self.alertSimilarityFilters = AlertingSrv.getSimilarityFilters();


self.timer = $interval(function() {
self.date = new moment();
}, 1000);

};

self.$onDestroy = function() {
if(self.timer) {
$interval.cancel(self.timer);
}
}
},
controllerAs: '$ctrl',
templateUrl: 'views/components/org/config.list.html',
Expand Down
6 changes: 4 additions & 2 deletions frontend/app/scripts/filters/custom-field-value.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
(function() {
'use strict';
angular.module('theHiveFilters').filter('customFieldValue', function() {
angular.module('theHiveFilters').filter('customFieldValue', function(UiSettingsSrv) {
return function(customField) {
if(!customField) {
return '';
}

var format = UiSettingsSrv.defaultDateFormat()

switch(customField.type) {
case 'date':
return moment(customField.value).format('MM/DD/YY H:mm');
return moment(customField.value).format(format);
default:
return customField.value;
}
Expand Down
8 changes: 5 additions & 3 deletions frontend/app/scripts/filters/filter-value.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
(function() {
'use strict';

angular.module('theHiveFilters').filter('filterValue', function(UtilsSrv) {
angular.module('theHiveFilters').filter('filterValue', function(UtilsSrv, UiSettingsSrv) {
return function(value) {
var dateFormat = UiSettingsSrv.defaultDateFormat();

if (angular.isArray(value)) {
return _.map(value, function(item) {
return item.label || item.text;
Expand Down Expand Up @@ -33,11 +35,11 @@
}

if(start !== null) {
result.push('From: ' + moment(start).hour(0).minutes(0).seconds(0).format('MM/DD/YY HH:mm'));
result.push('From: ' + moment(start).hour(0).minutes(0).seconds(0).format(dateFormat));
}

if(end !== null) {
result.push('To: ' + moment(end).hour(23).minutes(59).seconds(59).format('MM/DD/YY HH:mm'));
result.push('To: ' + moment(end).hour(23).minutes(59).seconds(59).format(dateFormat));
}

return result.join(', ');
Expand Down
5 changes: 3 additions & 2 deletions frontend/app/scripts/filters/shortDate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
(function() {
'use strict';
angular.module('theHiveFilters').filter('shortDate', function() {
angular.module('theHiveFilters').filter('shortDate', function(UiSettingsSrv) {
return function(str) {
var format = 'MM/DD/YY H:mm';
var format = UiSettingsSrv.defaultDateFormat() || 'MM/DD/YY H:mm';

if (angular.isString(str) && str.length > 0) {
return moment(str, ['YYYYMMDDTHHmmZZ', 'DD-MM-YYYY HH:mm']).format(format);
} else if (angular.isNumber(str)) {
Expand Down
3 changes: 2 additions & 1 deletion frontend/app/scripts/services/api/UiSettingsSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
this.keys = [
'hideEmptyCaseButton',
'disallowMergeAlertInResolvedSimilarCases',
'defaultAlertSimilarCaseFilter'
'defaultAlertSimilarCaseFilter',
'defaultDateFormat'
];

this.clearCache = function() {
Expand Down
32 changes: 26 additions & 6 deletions frontend/app/views/components/org/config.list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<div class="col-md-12">
<form name="settingsForm" class="mt-xs form-horizontal" ng-submit="$ctrl.save(settingsForm)" novalidate>
<div class="form-group">
<label class="col-md-3 control-label">Hide <em>Empty Case</em> button</label>
<div class="col-md-9">
<label class="col-lg-3 col-md-4 control-label">Hide <em>Empty Case</em> button</label>
<div class="col-lg-9 col-md-8">
<div class="checkbox">
<label>
<input name="hideEmptyCaseButton" type="checkbox" ng-model="$ctrl.configs['hideEmptyCaseButton']"> Check this to disallow creating empty cases
Expand All @@ -13,8 +13,8 @@
</div>

<div class="form-group">
<label class="col-md-3 control-label">Merge alerts into closed cases</label>
<div class="col-md-9">
<label class="col-lg-3 col-md-4 control-label">Merge alerts into closed cases</label>
<div class="col-lg-9 col-md-6">
<div class="checkbox">
<label>
<input name="disallowMergeAlertInResolvedSimilarCases" type="checkbox"
Expand All @@ -25,15 +25,35 @@
</div>

<div class="form-group">
<label class="col-md-3 control-label">Select the default filter of alert case similarity panel</label>
<div class="col-md-3">
<label class="col-lg-3 col-md-4 control-label">Select the default filter of alert case similarity panel</label>
<div class="col-lg-6 col-md-8">
<select class="form-control" name="defaultAlertSimilarCaseFilter"
ng-options="k as o.label for (k, o) in $ctrl.alertSimilarityFilters"
ng-model="$ctrl.configs['defaultAlertSimilarCaseFilter']">
</select>
</div>
</div>

<div class="form-group">
<label class="col-lg-3 col-md-4 control-label">Define the default date format used to display dates</label>
<div class="col-lg-6 col-md-8">
<input class="form-control" type="text" name="defaultDateFormat" ng-model="$ctrl.configs['defaultDateFormat']">
<span>Result: <code>{{$ctrl.date | amDateFormat:$ctrl.configs['defaultDateFormat']}}</code></span>

<div class="mt-xxs">
<label>More examples:</label>
<ul class="list-unstyled">
<li><em class="text-bold">YYYY-MM-DD HH:mm</em> results in <code>{{$ctrl.date | amDateFormat:'YYYY-MM-DD HH:mm'}}</code></li>
<li><em class="text-bold">DD/MM/YYYY HH:mm</em> results in <code>{{$ctrl.date | amDateFormat:'DD/MM/YYYY HH:mm'}}</code></li>
<li><em class="text-bold">DD.MM.YY HH:mm:ss</em> results in <code>{{$ctrl.date | amDateFormat:'DD.MM.YY HH:mm:ss'}}</code></li>
<li><em class="text-bold">MM-DD-YYYY HH:mm:ss</em> results in <code>{{$ctrl.date | amDateFormat:'MM-DD-YYYY HH:mm:ss'}}</code></li>
</ul>
</div>
</div>
</div>

<!-- defaultDateFormat -->

<div class="mt-s">
<button class="btn btn-primary pull-right" ng-disabled="settingsForm.$invalid" type="submit">Save</button>
</div>
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/views/directives/flow/action.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
<div class="flow-item-updates wrap">
<span ng-repeat="(k, v) in base.details" ng-switch="k">
<div ng-switch-when="startDate">
{{k}}: <em>{{v | showDate}}</em>
{{k}}: <em>{{v | shortDate}}</em>
</div>
<div ng-switch-when="endDate">
{{k}}: <em>{{v | showDate}}</em>
{{k}}: <em>{{v | shortDate}}</em>
</div>
<div ng-switch-default>
{{k}}: <em>{{v | limitTo: 250}}</em>
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/views/directives/flow/case.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
</span>
</div>
<div ng-switch-when="startDate">
{{k}}: <em>{{v | showDate}}</em>
{{k}}: <em>{{v | shortDate}}</em>
</div>
<div ng-switch-when="endDate">
{{k}}: <em>{{v | showDate}}</em>
{{k}}: <em>{{v | shortDate}}</em>
</div>
<div ng-switch-when="tlp">
{{k}}: <tlp format="'static'" value="v"></tlp>
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/views/directives/flow/observable-job.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
<div class="flow-item-updates wrap">
<span ng-repeat="(k, v) in base.details" ng-switch="k">
<div ng-switch-when="startDate">
{{k}}: <em>{{v | showDate}}</em>
{{k}}: <em>{{v | shortDate}}</em>
</div>
<div ng-switch-when="endDate">
{{k}}: <em>{{v | showDate}}</em>
{{k}}: <em>{{v | shortDate}}</em>
</div>
<div ng-switch-default>
{{k}}: <em>{{v | limitTo: 250}}</em>
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/views/directives/flow/procedure.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>
<div class="flow-item-updates" ng-switch-when="Creation">
<div>
occureDate: <span><em>{{base.details.occurDate | showDate}}</em></span>
occureDate: <span><em>{{base.details.occurDate | shortDate}}</em></span>
</div>
<div>
description: <span><em>{{(base.details.procedure || '-')| limitTo: 250}}</em></span>
Expand All @@ -15,7 +15,7 @@
<span ng-repeat="(k, v) in base.details" ng-switch="k">
<div ng-switch-when="occurDate">
{{k}}:
<em>{{v | showDate}}</em>
<em>{{v | shortDate}}</em>
</div>
<div ng-switch-default>
{{k}}:
Expand Down
6 changes: 3 additions & 3 deletions frontend/app/views/directives/flow/task.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
<div class="flow-item-updates" ng-switch-default>
<span ng-repeat="(k, v) in base.details" ng-switch="k">
<div ng-switch-when="owner">
{{k}}:
{{k}}:
<em><user-info value="v" field="name"></user-info></em>
</div>
<div ng-switch-when="startDate">
{{k}}:
<em>{{v | showDate}}</em>
<em>{{v | shortDate}}</em>
</div>
<div ng-switch-when="endDate">
{{k}}:
<em>{{v | showDate}}</em>
<em>{{v | shortDate}}</em>
</div>
<div ng-switch-default>
{{k}}:
Expand Down
3 changes: 2 additions & 1 deletion thehive/conf/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,6 @@ integrityCheck {
organisation.defaults {
ui.hideEmptyCaseButton: false
ui.disallowMergeAlertInResolvedSimilarCases: false
ui.defaultAlertSimilarCaseFilter: "open-cases"
ui.defaultAlertSimilarCaseFilter: "open-cases",
ui.defaultDateFormat: "MM/DD/YY HH:mm"
}

0 comments on commit 066625c

Please sign in to comment.