|
|
@@ -1,9 +1,9 @@
|
|
|
-import { ChangeDetectorRef, OnDestroy, Optional, Pipe, PipeTransform } from '@angular/core';
|
|
|
-import { Subscription } from 'rxjs';
|
|
|
+import { ChangeDetectorRef, Optional, Pipe, PipeTransform } from '@angular/core';
|
|
|
|
|
|
-import { LanguageCode } from '../../common/generated-types';
|
|
|
import { DataService } from '../../data/providers/data.service';
|
|
|
|
|
|
+import { LocaleBasePipe } from './locale-base.pipe';
|
|
|
+
|
|
|
/**
|
|
|
* @description
|
|
|
* A replacement of the Angular DatePipe which makes use of the Intl API
|
|
|
@@ -13,31 +13,10 @@ import { DataService } from '../../data/providers/data.service';
|
|
|
name: 'localeDate',
|
|
|
pure: false,
|
|
|
})
|
|
|
-export class LocaleDatePipe implements PipeTransform, OnDestroy {
|
|
|
- private locale: string;
|
|
|
- private readonly subscription: Subscription;
|
|
|
-
|
|
|
- constructor(
|
|
|
- @Optional() private dataService?: DataService,
|
|
|
- @Optional() changeDetectorRef?: ChangeDetectorRef,
|
|
|
- ) {
|
|
|
- if (this.dataService && changeDetectorRef) {
|
|
|
- this.subscription = this.dataService.client
|
|
|
- .uiState()
|
|
|
- .mapStream(data => data.uiState.language)
|
|
|
- .subscribe(languageCode => {
|
|
|
- this.locale = languageCode.replace(/_/g, '-');
|
|
|
- changeDetectorRef.markForCheck();
|
|
|
- });
|
|
|
- }
|
|
|
+export class LocaleDatePipe extends LocaleBasePipe implements PipeTransform {
|
|
|
+ constructor(@Optional() dataService?: DataService, @Optional() changeDetectorRef?: ChangeDetectorRef) {
|
|
|
+ super(dataService, changeDetectorRef);
|
|
|
}
|
|
|
-
|
|
|
- ngOnDestroy() {
|
|
|
- if (this.subscription) {
|
|
|
- this.subscription.unsubscribe();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
transform(value: unknown, ...args: unknown[]): unknown {
|
|
|
const [format, locale] = args;
|
|
|
if (this.locale || typeof locale === 'string') {
|