diff --git a/ui-ngx/src/app/shared/components/time/timezone-select.component.ts b/ui-ngx/src/app/shared/components/time/timezone-select.component.ts index a65fc28481..f96c80b4c1 100644 --- a/ui-ngx/src/app/shared/components/time/timezone-select.component.ts +++ b/ui-ngx/src/app/shared/components/time/timezone-select.component.ts @@ -63,6 +63,15 @@ export class TimezoneSelectComponent implements ControlValueAccessor, OnInit, Af this.requiredValue = coerceBooleanProperty(value); } + private userTimezoneByDefaultValue: boolean; + get userTimezoneByDefault(): boolean { + return this.userTimezoneByDefaultValue; + } + @Input() + set userTimezoneByDefault(value: boolean) { + this.userTimezoneByDefaultValue = coerceBooleanProperty(value); + } + @Input() disabled: boolean; @@ -129,28 +138,23 @@ export class TimezoneSelectComponent implements ControlValueAccessor, OnInit, Af writeValue(value: string | null): void { this.searchText = ''; - if (value !== null) { - getTimezoneInfo(value, this.defaultTimezoneId).subscribe( - (foundTimezone) => { - if (foundTimezone !== null) { - this.selectTimezoneFormGroup.get('timezone').patchValue(foundTimezone, {emitEvent: false}); - if (foundTimezone.id !== value) { - setTimeout(() => { - this.updateView(foundTimezone.id); - }, 0); - } else { - this.modelValue = value; - } + getTimezoneInfo(value, this.defaultTimezoneId, this.userTimezoneByDefaultValue).subscribe( + (foundTimezone) => { + if (foundTimezone !== null) { + this.selectTimezoneFormGroup.get('timezone').patchValue(foundTimezone, {emitEvent: false}); + if (foundTimezone.id !== value) { + setTimeout(() => { + this.updateView(foundTimezone.id); + }, 0); } else { - this.modelValue = null; - this.selectTimezoneFormGroup.get('timezone').patchValue('', {emitEvent: false}); + this.modelValue = value; } + } else { + this.modelValue = null; + this.selectTimezoneFormGroup.get('timezone').patchValue('', {emitEvent: false}); } - ); - } else { - this.modelValue = null; - this.selectTimezoneFormGroup.get('timezone').patchValue('', {emitEvent: false}); - } + } + ); this.dirty = true; } @@ -165,8 +169,8 @@ export class TimezoneSelectComponent implements ControlValueAccessor, OnInit, Af if (this.ignoreClosePanel) { this.ignoreClosePanel = false; } else { - if (!this.modelValue && this.defaultTimezoneId) { - getTimezoneInfo(this.defaultTimezoneId).subscribe( + if (!this.modelValue && (this.defaultTimezoneId || this.userTimezoneByDefaultValue)) { + getTimezoneInfo(this.defaultTimezoneId, this.defaultTimezoneId, this.userTimezoneByDefaultValue).subscribe( (defaultTimezoneInfo) => { if (defaultTimezoneInfo !== null) { this.ngZone.run(() => { diff --git a/ui-ngx/src/app/shared/models/time/time.models.ts b/ui-ngx/src/app/shared/models/time/time.models.ts index 19d2a12e26..314a6f2e69 100644 --- a/ui-ngx/src/app/shared/models/time/time.models.ts +++ b/ui-ngx/src/app/shared/models/time/time.models.ts @@ -19,7 +19,7 @@ import { deepClone, isDefined, isUndefined } from '@app/core/utils'; import * as moment_ from 'moment'; import { Observable } from 'rxjs/internal/Observable'; import { from, of } from 'rxjs'; -import { map, tap } from 'rxjs/operators'; +import { map, mergeMap, tap } from 'rxjs/operators'; const moment = moment_; @@ -518,14 +518,22 @@ export function getTimezones(): Observable { } } -export function getTimezoneInfo(timezoneId: string, defaultTimezoneId?: string): Observable { +export function getTimezoneInfo(timezoneId: string, defaultTimezoneId?: string, userTimezoneByDefault?: boolean): Observable { return getTimezones().pipe( - map((timezoneList) => { + mergeMap((timezoneList) => { let foundTimezone = timezoneList.find(timezoneInfo => timezoneInfo.id === timezoneId); - if (!foundTimezone && defaultTimezoneId) { - foundTimezone = timezoneList.find(timezoneInfo => timezoneInfo.id === defaultTimezoneId); + if (!foundTimezone) { + if (userTimezoneByDefault) { + return getDefaultTimezone().pipe( + map((userTimezone) => { + return timezoneList.find(timezoneInfo => timezoneInfo.id === userTimezone); + }) + ); + } else if (defaultTimezoneId) { + foundTimezone = timezoneList.find(timezoneInfo => timezoneInfo.id === defaultTimezoneId); + } } - return foundTimezone; + return of(foundTimezone); }) ); }