Skip to content

Commit

Permalink
Merge pull request #4154 from greenbone/Add-user-custom-setting-time-…
Browse files Browse the repository at this point in the history
…date-format

Add user custom setting time date format to main
  • Loading branch information
a-h-abdelsalam authored Oct 17, 2024
2 parents f36deb4 + 5c332df commit 29113a4
Show file tree
Hide file tree
Showing 34 changed files with 746 additions and 176 deletions.
6 changes: 6 additions & 0 deletions public/locales/gsa-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@
"Dashboards": "Dashboards",
"Dashboards limit reached": "Dashboardgrenze erreicht",
"Date": "Datum",
"Date Format": "Datumsformat",
"Day": "Tag",
"Debug": "Debug",
"Decrease the minimum QoD in the filter settings to 30 percent to see those results.": "Die Minimum-QdE im Filter auf 30 Prozent verringern, um diese Ergebnisse zu sehen.",
Expand Down Expand Up @@ -1538,6 +1539,7 @@
"Super (Has super access)": "Super (hat Super-Zugriff)",
"Support for LDAP is not available.": "Unterstützung für LDAP ist nicht verfügbar.",
"Support for RADIUS is not available.": "Unterstützung für RADIUS ist nicht verfügbar.",
"System Default": "Systemstandard",
"System Logger": "System-Logger",
"System Reports": "Systemberichte",
"TCP": "TCP",
Expand Down Expand Up @@ -1727,6 +1729,7 @@
"Tickets by Creation Time (Total: {{count}})": "Tickets nach Erstellungszeit (Gesamt: {{count}})",
"Tickets by Status (Total: {{count}})": "Tickets nach Status (Gesamt: {{count}})",
"Time": "Zeit",
"Time Format": "Zeitformat",
"Timeout": "Timeout",
"Timezone": "Zeitzone",
"TippingPoint SMS": "TippingPoint SMS",
Expand Down Expand Up @@ -1795,6 +1798,7 @@
"Uploading": "Hochladen",
"Urgency": "Dringlichkeit",
"Use LDAPS only": "Ausschließlich LDAPS verwenden",
"Use System Default for Time and Date Format": "Systemstandard für Zeit- und Datumsformat verwenden",
"Use workaround for default certificate": "Problemumgehung für Standard-Zertifikat verwenden",
"User": "Benutzer",
"User ID": "Benutzer-ID",
Expand Down Expand Up @@ -1857,6 +1861,8 @@
"Wednesday": "Mittwoch",
"Week": "Woche",
"Weekly": "Wöchentlich",
"Weekday, Month, Day, Year": "Wochentag, Monat, Tag, Jahr",
"Weekday, Day, Month, Year": "Wochentag, Tag, Monat, Jahr",
"When changing status to \"closed\", a \"Note for Closed\" is required.": "Wenn der Status zu \"Geschlossen\" geändert wird, ist eine \"Notiz für Geschlossen\" erforderlich.",
"When changing status to \"fixed\", a \"Note for Fixed\" is required.": "Wenn der Status zu \"Behoben\" geändert wird, ist eine \"Notiz für Behoben\" erforderlich.",
"When changing status to \"open\", a \"Note for Open\" is required.": "Wenn der Status zu \"Offen\" geändert wird, ist eine \"Notiz für Offen\" erforderlich.",
Expand Down
8 changes: 8 additions & 0 deletions src/gmp/commands/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export const DEFAULT_FILTER_SETTINGS = {
vulnerability: '17c9d269-95e7-4bfa-b1b2-bc106a2175c7',
};

const PARAM_KEYS = {
DATE: 'date_format',
TIME: 'time_format',
};

const saveDefaultFilterSettingId = entityType =>
`settings_filter:${DEFAULT_FILTER_SETTINGS[entityType]}`;

Expand Down Expand Up @@ -251,9 +256,12 @@ export class UserCommand extends EntityCommand {

saveSettings(data) {
log.debug('Saving settings', data);

return this.httpPost({
cmd: 'save_my_settings',
text: data.timezone,
[PARAM_KEYS.DATE]: data.userInterfaceDateFormat,
[PARAM_KEYS.TIME]: data.userInterfaceTimeFormat,
old_password: data.oldPassword,
password: data.newPassword,
lang: data.userInterfaceLanguage,
Expand Down
158 changes: 143 additions & 15 deletions src/gmp/locale/__tests__/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import {describe, test, expect} from '@gsa/testing';
import {describe, test, expect, beforeEach} from '@gsa/testing';

import date, {setLocale as locale} from '../../models/date';

Expand Down Expand Up @@ -55,15 +55,30 @@ describe('shortDate tests', () => {
expect(shortDate(d)).toEqual('01/01/2018');
});

test('should format string', () => {
setLocale('en');
expect(shortDate('2018-01-01')).toEqual('01/01/2018');
test('should format date locale', () => {
setLocale('de');
expect(
shortDate(date('2018-11-24T15:30:00Z'), 'UTC', 'system_default'),
).toEqual('24.11.2018');
});

test('should format JS date', () => {
const d = new Date('2018-01-01');
setLocale('en');
expect(shortDate(d)).toEqual('01/01/2018');
describe('shortDate tests', () => {
beforeEach(() => {
setLocale('en');
});

test.each([
['2018-01-01', undefined, undefined, '01/01/2018'],
[new Date('2018-01-01'), undefined, undefined, '01/01/2018'],
[new Date('2018-11-24'), undefined, 'wmdy', '11/24/2018'],
[new Date('2018-11-24'), undefined, 'wdmy', '24/11/2018'],
[new Date('2018-11-24'), undefined, 'system_default', '11/24/2018'],
])(
'should format date %p with tz %p and userInterfaceDateFormat %p to %p',
(input, tz, userInterfaceDateFormat, expected) => {
expect(shortDate(input, tz, userInterfaceDateFormat)).toEqual(expected);
},
);
});
});

Expand All @@ -83,15 +98,61 @@ describe('longDate tests', () => {
expect(longDate(d)).toEqual('Mon, Jan 1, 2018 12:00 AM');
});

test('should format string', () => {
setLocale('en');
expect(longDate('2018-01-01')).toEqual('Mon, Jan 1, 2018 12:00 AM');
test('should format date locale', () => {
setLocale('de');
expect(
longDate(
date('2018-11-24T15:30:00Z'),
'UTC',
'system_default',
'system_default',
),
).toEqual('Sa., 24. Nov. 2018 15:30');
});

test('should format JS date', () => {
const d = new Date('2018-01-01T00:00:00');
setLocale('en');
expect(longDate(d)).toEqual('Mon, Jan 1, 2018 12:00 AM');
describe('longDate tests', () => {
beforeEach(() => {
setLocale('en');
});

test.each([
[
'2018-11-24',
undefined,
undefined,
undefined,
'Sat, Nov 24, 2018 12:00 AM',
],
[
new Date('2018-11-23T00:00:00'),
undefined,
undefined,
undefined,
'Fri, Nov 23, 2018 12:00 AM',
],
['2018-11-24T15:30:00Z', 'UTC', 12, 'wdmy', 'Sat, 24 Nov 2018 3:30 PM'],
['2018-11-24T15:30:00Z', 'UTC', 24, 'wmdy', 'Sat, Nov 24, 2018 15:30'],
[
'2018-11-24T15:30:00Z',
'UTC',
'system_default',
'system_default',
'Sat, Nov 24, 2018 3:30 PM',
],
])(
'should format date %p with tz %p, userInterfaceTimeFormat %p, and userInterfaceDateFormat %p to %p',
(
input,
tz,
userInterfaceTimeFormat,
userInterfaceDateFormat,
expected,
) => {
expect(
longDate(input, tz, userInterfaceTimeFormat, userInterfaceDateFormat),
).toEqual(expected);
},
);
});
});

Expand All @@ -110,6 +171,73 @@ describe('dateTimeWithTimeZone tests', () => {
const d = date('2018-01-01T00:00:00+01:00').tz('CET');
expect(dateTimeWithTimeZone(d)).toEqual('Mon, Jan 1, 2018 12:00 AM CET');
});

test('should format date locale', () => {
setLocale('de');
expect(
dateTimeWithTimeZone(
date('2018-11-24T15:30:00Z'),
'UTC',
'system_default',
'system_default',
),
).toEqual('Sa., 24. Nov. 2018 15:30 UTC');
});

describe('dateTimeWithTimeZone tests', () => {
beforeEach(() => {
setLocale('en');
});

test.each([
[
new Date('2018-11-23T00:00:00'),
undefined,
undefined,
undefined,
'Fri, Nov 23, 2018 12:00 AM ',
],
[
'2018-11-24T15:30:00Z',
'UTC',
12,
'wdmy',
'Sat, 24 Nov 2018 3:30 PM UTC',
],
[
'2018-11-24T15:30:00Z',
'UTC',
24,
'wmdy',
'Sat, Nov 24, 2018 15:30 UTC',
],
[
'2018-11-24T15:30:00Z',
'UTC',
'system_default',
'system_default',
'Sat, Nov 24, 2018 3:30 PM UTC',
],
])(
'should format date %p with tz %p, userInterfaceTimeFormat %p, and userInterfaceDateFormat %p to %p',
(
input,
tz,
userInterfaceTimeFormat,
userInterfaceDateFormat,
expected,
) => {
expect(
dateTimeWithTimeZone(
input,
tz,
userInterfaceTimeFormat,
userInterfaceDateFormat,
),
).toEqual(expected);
},
);
});
});

// vim: set ts=2 sw=2 tw=80:
Loading

0 comments on commit 29113a4

Please sign in to comment.