Skip to content

Commit

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

Add user setting time date format
  • Loading branch information
a-h-abdelsalam authored Oct 16, 2024
2 parents d5c6502 + c7b3f4b commit f49afb2
Show file tree
Hide file tree
Showing 35 changed files with 719 additions and 446 deletions.
6 changes: 6 additions & 0 deletions public/locales/gsa-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,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 @@ -1548,6 +1549,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",
"Synchronization issue: {{error}}": "Synchronisationsproblem: {{error}}",
Expand Down Expand Up @@ -1739,6 +1741,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 @@ -1807,6 +1810,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 @@ -1869,6 +1873,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 f49afb2

Please sign in to comment.