mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-06 21:42:49 +00:00
refactor: apply new eslint rules
This commit is contained in:
@@ -66,7 +66,6 @@ export class AppComponent {
|
||||
* TODO
|
||||
*/
|
||||
async initializeApp() {
|
||||
// tslint:disable-next-line: no-floating-promises
|
||||
this.platform.ready().then(async () => {
|
||||
// Okay, so the platform is ready and our plugins are available.
|
||||
// Here you can do any higher level native things you might need.
|
||||
|
||||
@@ -12,7 +12,12 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {CommonModule, LocationStrategy, PathLocationStrategy, registerLocaleData} from '@angular/common';
|
||||
import {
|
||||
CommonModule,
|
||||
LocationStrategy,
|
||||
PathLocationStrategy,
|
||||
registerLocaleData,
|
||||
} from '@angular/common';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import localeDe from '@angular/common/locales/de';
|
||||
import {APP_INITIALIZER, NgModule, Provider} from '@angular/core';
|
||||
|
||||
@@ -1,19 +1,64 @@
|
||||
<div [ngSwitch]="item.type">
|
||||
<stapps-article-detail-content [item]="item" *ngSwitchCase="'article'"></stapps-article-detail-content>
|
||||
<stapps-catalog-detail-content [item]="item" *ngSwitchCase="'catalog'"></stapps-catalog-detail-content>
|
||||
<stapps-date-series-detail-content [item]="item" *ngSwitchCase="'date series'"></stapps-date-series-detail-content>
|
||||
<stapps-dish-detail-content [item]="item" *ngSwitchCase="'dish'"></stapps-dish-detail-content>
|
||||
<stapps-event-detail-content [item]="item" *ngSwitchCase="'academic event'"></stapps-event-detail-content>
|
||||
<stapps-event-detail-content [item]="item" *ngSwitchCase="'sport course'"></stapps-event-detail-content>
|
||||
<stapps-favorite-detail-content [item]="item" *ngSwitchCase="'favorite'"></stapps-favorite-detail-content>
|
||||
<stapps-message-detail-content [item]="item" *ngSwitchCase="'message'"></stapps-message-detail-content>
|
||||
<stapps-person-detail-content [item]="item" *ngSwitchCase="'person'"></stapps-person-detail-content>
|
||||
<stapps-place-detail-content [item]="item" *ngSwitchCase="'building'"></stapps-place-detail-content>
|
||||
<stapps-place-detail-content [item]="item" *ngSwitchCase="'floor'"></stapps-place-detail-content>
|
||||
<stapps-place-detail-content [item]="item" *ngSwitchCase="'point of interest'"></stapps-place-detail-content>
|
||||
<stapps-place-detail-content [item]="item" *ngSwitchCase="'room'"></stapps-place-detail-content>
|
||||
<stapps-semester-detail-content [item]="item" *ngSwitchCase="'semester'"></stapps-semester-detail-content>
|
||||
<stapps-video-detail-content [item]="item" *ngSwitchCase="'video'"></stapps-video-detail-content>
|
||||
<stapps-article-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="'article'"
|
||||
></stapps-article-detail-content>
|
||||
<stapps-catalog-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="'catalog'"
|
||||
></stapps-catalog-detail-content>
|
||||
<stapps-date-series-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="'date series'"
|
||||
></stapps-date-series-detail-content>
|
||||
<stapps-dish-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="'dish'"
|
||||
></stapps-dish-detail-content>
|
||||
<stapps-event-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="'academic event'"
|
||||
></stapps-event-detail-content>
|
||||
<stapps-event-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="'sport course'"
|
||||
></stapps-event-detail-content>
|
||||
<stapps-favorite-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="'favorite'"
|
||||
></stapps-favorite-detail-content>
|
||||
<stapps-message-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="'message'"
|
||||
></stapps-message-detail-content>
|
||||
<stapps-person-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="'person'"
|
||||
></stapps-person-detail-content>
|
||||
<stapps-place-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="'building'"
|
||||
></stapps-place-detail-content>
|
||||
<stapps-place-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="'floor'"
|
||||
></stapps-place-detail-content>
|
||||
<stapps-place-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="'point of interest'"
|
||||
></stapps-place-detail-content>
|
||||
<stapps-place-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="'room'"
|
||||
></stapps-place-detail-content>
|
||||
<stapps-semester-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="'semester'"
|
||||
></stapps-semester-detail-content>
|
||||
<stapps-video-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="'video'"
|
||||
></stapps-video-detail-content>
|
||||
<ng-container *ngSwitchDefault>
|
||||
<ion-item class="ion-text-wrap" lines="inset">
|
||||
<ion-thumbnail slot="start" class="ion-margin-end">
|
||||
@@ -23,14 +68,18 @@
|
||||
<ion-row>
|
||||
<ion-col>
|
||||
<div class="ion-text-wrap">
|
||||
<h2 class="name">{{item.name}}</h2>
|
||||
<ion-note>{{item.type}}</ion-note>
|
||||
<h2 class="name">{{ item.name }}</h2>
|
||||
<ion-note>{{ item.type }}</ion-note>
|
||||
</div>
|
||||
</ion-col>
|
||||
</ion-row>
|
||||
</ion-grid>
|
||||
</ion-item>
|
||||
<stapps-simple-card *ngIf="item.description" [title]="'description' | propertyNameTranslate: item | titlecase" [content]="'description' | thingTranslate: item"></stapps-simple-card>
|
||||
<stapps-simple-card
|
||||
*ngIf="item.description"
|
||||
[title]="'description' | propertyNameTranslate: item | titlecase"
|
||||
[content]="'description' | thingTranslate: item"
|
||||
></stapps-simple-card>
|
||||
</ng-container>
|
||||
</div>
|
||||
<stapps-origin-detail [origin]="item.origin" ></stapps-origin-detail>
|
||||
<stapps-origin-detail [origin]="item.origin"></stapps-origin-detail>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<div *ngIf="origin.type === 'user'">
|
||||
<p>{{origin.created | dateFormat}}</p>
|
||||
<p>{{ origin.created | dateFormat }}</p>
|
||||
</div>
|
||||
|
||||
<div *ngIf="origin.type === 'remote'">
|
||||
<p>{{origin.indexed | dateFormat}}</p>
|
||||
<p>{{ origin.indexed | dateFormat }}</p>
|
||||
</div>
|
||||
|
||||
@@ -42,9 +42,7 @@ export class PlaceDetailContentComponent {
|
||||
*
|
||||
* @param item TODO
|
||||
*/
|
||||
// tslint:disable-next-line:completed-docs prefer-function-over-method
|
||||
hasCategories(item: SCThings): item is SCThings & {categories: string[]} {
|
||||
// tslint:disable-next-line:completed-docs
|
||||
return typeof (item as {categories: string[]}).categories !== 'undefined';
|
||||
}
|
||||
|
||||
|
||||
@@ -2,26 +2,28 @@
|
||||
<ion-row>
|
||||
<ion-col>
|
||||
<div class="ion-text-wrap">
|
||||
<ion-label>{{'name' | thingTranslate: item}}</ion-label>
|
||||
<ion-label>{{ 'name' | thingTranslate: item }}</ion-label>
|
||||
<ng-container *ngIf="item.type !== 'floor'">
|
||||
<p>
|
||||
<ion-note *ngIf="item.openingHours">
|
||||
{{item.openingHours | openingHours}}
|
||||
{{ item.openingHours | openingHours }}
|
||||
</ion-note>
|
||||
</p>
|
||||
<p>
|
||||
<ion-note *ngIf="item.categories && item.type !== 'building'; else onlyType">
|
||||
{{'categories' | thingTranslate: item | join:', ' | titlecase }}
|
||||
<ion-note
|
||||
*ngIf="item.categories && item.type !== 'building'; else onlyType"
|
||||
>
|
||||
{{ 'categories' | thingTranslate: item | join: ', ' | titlecase }}
|
||||
</ion-note>
|
||||
</p>
|
||||
<ng-template #onlyType>
|
||||
<ion-note>
|
||||
{{'type' | thingTranslate: item}}
|
||||
{{ 'type' | thingTranslate: item }}
|
||||
</ion-note>
|
||||
</ng-template>
|
||||
</ng-container>
|
||||
<p *ngIf="item.description">
|
||||
{{'description' | thingTranslate: item}}
|
||||
{{ 'description' | thingTranslate: item }}
|
||||
</p>
|
||||
<ion-note>
|
||||
<ul>
|
||||
@@ -36,7 +38,8 @@
|
||||
</ion-col>
|
||||
<div *ngIf="item.type !== 'building'">
|
||||
<ion-col width-20 text-right *ngIf="item.inPlace">
|
||||
<ion-icon name="location"></ion-icon>{{'name' | thingTranslate: item.inPlace}}
|
||||
<ion-icon name="location"></ion-icon
|
||||
>{{ 'name' | thingTranslate: item.inPlace }}
|
||||
</ion-col>
|
||||
</div>
|
||||
</ion-row>
|
||||
|
||||
@@ -57,8 +57,7 @@ export class PlaceMensaDetailComponent implements AfterViewInit {
|
||||
startingDay: Moment;
|
||||
|
||||
constructor(private readonly mensaService: PlaceMensaService) {
|
||||
this.startingDay = moment()
|
||||
.startOf('day');
|
||||
this.startingDay = moment().startOf('day');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +65,7 @@ export class PlaceMensaDetailComponent implements AfterViewInit {
|
||||
*/
|
||||
ngAfterViewInit() {
|
||||
this.dishes = this.mensaService.getAllDishes(this.item, this.displayRange);
|
||||
this.dishes.then((result) => {
|
||||
this.dishes.then(result => {
|
||||
for (const [key, value] of Object.entries(result)) {
|
||||
if (value.length === 0) {
|
||||
delete result[key];
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
<ng-container>
|
||||
<div *ngIf="dishes | async as dishes; else loading">
|
||||
<ion-segment [(ngModel)]="selectedDay" mode="md">
|
||||
<ion-segment-button *ngFor="let day of dishes | keyvalue" [value]="day.key">
|
||||
<ion-label class="ion-hide-sm-down">{{day.key | dateFormat:'weekday:long,month:numeric,day:numeric'}}</ion-label>
|
||||
<ion-label class="ion-hide-sm-up">{{day.key | dateFormat:'weekday:short,month:numeric,day:numeric' }}</ion-label>
|
||||
<ion-segment-button
|
||||
*ngFor="let day of dishes | keyvalue"
|
||||
[value]="day.key"
|
||||
>
|
||||
<ion-label class="ion-hide-sm-down">{{
|
||||
day.key | dateFormat: 'weekday:long,month:numeric,day:numeric'
|
||||
}}</ion-label>
|
||||
<ion-label class="ion-hide-sm-up">{{
|
||||
day.key | dateFormat: 'weekday:short,month:numeric,day:numeric'
|
||||
}}</ion-label>
|
||||
</ion-segment-button>
|
||||
</ion-segment>
|
||||
<div [ngSwitch]="selectedDay">
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
<h2 class="name">{{ 'name' | thingTranslate: item }}</h2>
|
||||
<p>
|
||||
<ion-icon name="calendar"></ion-icon>
|
||||
<span>{{item.startDate | dateFormat}} - {{item.endDate | dateFormat}}</span>
|
||||
<span
|
||||
>{{ item.startDate | dateFormat }} -
|
||||
{{ item.endDate | dateFormat }}</span
|
||||
>
|
||||
</p>
|
||||
<ion-note>{{ 'type' | thingTranslate: item }}</ion-note>
|
||||
</div>
|
||||
|
||||
@@ -46,9 +46,7 @@ export class MapProvider {
|
||||
static getPointMarker(point: Point) {
|
||||
return marker(geoJSON(point).getBounds().getCenter(), {
|
||||
icon: icon({
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
iconAnchor: [13, 41],
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
iconSize: [25, 41],
|
||||
iconUrl: '../assets/marker-icon.png',
|
||||
shadowUrl: '../assets/marker-shadow.png',
|
||||
|
||||
@@ -1,25 +1,41 @@
|
||||
<ion-card>
|
||||
<span *ngIf="item.url; else imageNoUrl">
|
||||
<a href="{{item.url}}">
|
||||
<ion-thumbnail><ion-img src="{{item.image}}" (ionError)="$event.target.nextSibling.style.display='block'" alt=""></ion-img>
|
||||
<ion-icon name="newspaper-outline"></ion-icon>
|
||||
</ion-thumbnail>
|
||||
</a>
|
||||
</span>
|
||||
<span *ngIf="item.url; else imageNoUrl">
|
||||
<a href="{{ item.url }}">
|
||||
<ion-thumbnail
|
||||
><ion-img
|
||||
src="{{ item.image }}"
|
||||
(ionError)="$event.target.nextSibling.style.display = 'block'"
|
||||
alt=""
|
||||
></ion-img>
|
||||
<ion-icon name="newspaper-outline"></ion-icon>
|
||||
</ion-thumbnail>
|
||||
</a>
|
||||
</span>
|
||||
<ng-template #imageNoUrl>
|
||||
<ion-thumbnail>
|
||||
<ion-img src="{{item.image}}" (ionError)="$event.target.nextSibling.style.display='block'" alt=""></ion-img>
|
||||
<ion-img
|
||||
src="{{ item.image }}"
|
||||
(ionError)="$event.target.nextSibling.style.display = 'block'"
|
||||
alt=""
|
||||
></ion-img>
|
||||
<ion-icon name="newspaper-outline"></ion-icon>
|
||||
</ion-thumbnail>
|
||||
</ng-template>
|
||||
<ion-card-header>
|
||||
<ion-card-subtitle *ngIf="item.datePublished">{{item.datePublished | amCalendar | sentencecase}}</ion-card-subtitle>
|
||||
<ion-card-subtitle *ngIf="item.datePublished">{{
|
||||
item.datePublished | amCalendar | sentencecase
|
||||
}}</ion-card-subtitle>
|
||||
<ion-card-title>
|
||||
<span *ngIf="item.url; else titleNoUrl"><a href="{{item.url}}"><span class="text">{{item.name}}</span><span class="icon"><ion-icon name="open-outline"></ion-icon></span></a></span>
|
||||
<ng-template #titleNoUrl>{{item.name}}</ng-template>
|
||||
<span *ngIf="item.url; else titleNoUrl"
|
||||
><a href="{{ item.url }}"
|
||||
><span class="text">{{ item.name }}</span
|
||||
><span class="icon"
|
||||
><ion-icon name="open-outline"></ion-icon></span></a
|
||||
></span>
|
||||
<ng-template #titleNoUrl>{{ item.name }}</ng-template>
|
||||
</ion-card-title>
|
||||
</ion-card-header>
|
||||
<ion-card-content>
|
||||
{{item.messageBody}}
|
||||
{{ item.messageBody }}
|
||||
</ion-card-content>
|
||||
</ion-card>
|
||||
|
||||
@@ -19,11 +19,9 @@ import moment from 'moment';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {logger} from '../_helpers/ts-logger';
|
||||
|
||||
// tslint:disable-next-line: no-var-requires
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module
|
||||
const openingHoursFn = require('opening_hours');
|
||||
|
||||
// tslint:disable: completed-docs
|
||||
|
||||
@Injectable()
|
||||
@Pipe({
|
||||
name: 'join',
|
||||
@@ -58,13 +56,13 @@ export class SentenceCasePipe implements PipeTransform {
|
||||
value = '';
|
||||
|
||||
transform(aString: string | unknown): string {
|
||||
|
||||
if (typeof aString !== 'string'){
|
||||
throw new SyntaxError(`Wrong parameter in StringSplitPipe. Expected a valid String, received: ${aString}`);
|
||||
if (typeof aString !== 'string') {
|
||||
throw new SyntaxError(
|
||||
`Wrong parameter in StringSplitPipe. Expected a valid String, received: ${aString}`,
|
||||
);
|
||||
}
|
||||
|
||||
this.value = aString.substr(0,1)
|
||||
.toUpperCase() + aString.substr(1);
|
||||
this.value = aString.slice(0, 1).toUpperCase() + aString.slice(1);
|
||||
|
||||
return this.value;
|
||||
}
|
||||
@@ -102,7 +100,9 @@ export class StringSplitPipe implements PipeTransform {
|
||||
})
|
||||
export class OpeningHoursPipe implements PipeTransform {
|
||||
locale: string;
|
||||
|
||||
onLangChange?: Subscription;
|
||||
|
||||
value = '';
|
||||
|
||||
constructor(private readonly translate: TranslateService) {
|
||||
@@ -115,29 +115,30 @@ export class OpeningHoursPipe implements PipeTransform {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
transform(aString: string | unknown): string {
|
||||
this.updateValue(aString);
|
||||
this._dispose();
|
||||
if (this.onLangChange?.closed === true) {
|
||||
this.onLangChange = this.translate.onLangChange.subscribe((event: LangChangeEvent) => {
|
||||
this.locale = event.lang;
|
||||
this.updateValue(aString);
|
||||
});
|
||||
this.onLangChange = this.translate.onLangChange.subscribe(
|
||||
(event: LangChangeEvent) => {
|
||||
this.locale = event.lang;
|
||||
this.updateValue(aString);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return this.value;
|
||||
}
|
||||
|
||||
updateValue(aString: string | unknown) {
|
||||
if (typeof aString !== 'string'){
|
||||
if (typeof aString !== 'string') {
|
||||
logger.warn(`openingHours pipe unable to parse input: ${aString}`);
|
||||
|
||||
return;
|
||||
}
|
||||
const openingHours = new openingHoursFn(aString);
|
||||
|
||||
if ((openingHours.getWarnings() as string[]).length > 0){
|
||||
if ((openingHours.getWarnings() as string[]).length > 0) {
|
||||
logger.warn((openingHours.getWarnings() as string[]).join('. '));
|
||||
|
||||
return;
|
||||
@@ -146,27 +147,24 @@ export class OpeningHoursPipe implements PipeTransform {
|
||||
const isOpen: boolean = openingHours.getState();
|
||||
const nextChange: Date = openingHours.getNextChange();
|
||||
|
||||
let prefixKey = isOpen ?
|
||||
'common.openingHours.open_until' :
|
||||
'common.openingHours.closed_until';
|
||||
let prefixKey = isOpen
|
||||
? 'common.openingHours.open_until'
|
||||
: 'common.openingHours.closed_until';
|
||||
|
||||
let formattedCalender = moment(nextChange)
|
||||
.calendar();
|
||||
let formattedCalender = moment(nextChange).calendar();
|
||||
|
||||
if (moment(nextChange)
|
||||
.isBefore(moment()
|
||||
.add(1, 'hours'))) {
|
||||
prefixKey= isOpen ?
|
||||
'common.openingHours.closing_soon' :
|
||||
'common.openingHours.opening_soon';
|
||||
formattedCalender = formattedCalender.substr(0,1)
|
||||
.toUpperCase() + formattedCalender.substr(1);
|
||||
if (moment(nextChange).isBefore(moment().add(1, 'hours'))) {
|
||||
prefixKey = isOpen
|
||||
? 'common.openingHours.closing_soon'
|
||||
: 'common.openingHours.opening_soon';
|
||||
formattedCalender =
|
||||
formattedCalender.slice(0, 1).toUpperCase() +
|
||||
formattedCalender.slice(1);
|
||||
}
|
||||
this.value = `${this.translate.instant(prefixKey)} ${formattedCalender}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Injectable()
|
||||
@Pipe({
|
||||
name: 'numberLocalized',
|
||||
@@ -174,7 +172,9 @@ export class OpeningHoursPipe implements PipeTransform {
|
||||
})
|
||||
export class NumberLocalizedPipe implements PipeTransform, OnDestroy {
|
||||
locale: string;
|
||||
|
||||
onLangChange?: Subscription;
|
||||
|
||||
value: string;
|
||||
|
||||
constructor(private readonly translate: TranslateService) {
|
||||
@@ -200,10 +200,12 @@ export class NumberLocalizedPipe implements PipeTransform, OnDestroy {
|
||||
this.updateValue(value, formatOptions);
|
||||
this._dispose();
|
||||
if (this.onLangChange?.closed === true) {
|
||||
this.onLangChange = this.translate.onLangChange.subscribe((event: LangChangeEvent) => {
|
||||
this.locale = event.lang;
|
||||
this.updateValue(value, formatOptions);
|
||||
});
|
||||
this.onLangChange = this.translate.onLangChange.subscribe(
|
||||
(event: LangChangeEvent) => {
|
||||
this.locale = event.lang;
|
||||
this.updateValue(value, formatOptions);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return this.value;
|
||||
@@ -215,10 +217,19 @@ export class NumberLocalizedPipe implements PipeTransform, OnDestroy {
|
||||
|
||||
return;
|
||||
}
|
||||
const options = formatOptions?.split(',')
|
||||
.map((element) => element.split(':'))
|
||||
.reduce((acc, [key, val]) => ({...acc, [key.trim()]: val.trim()}),{}) as Intl.NumberFormatOptions;
|
||||
const float = typeof value === 'string' ? Number.parseFloat(value) : value as number;
|
||||
const options = formatOptions
|
||||
?.split(',')
|
||||
.map(element => element.split(':'))
|
||||
// eslint-disable-next-line unicorn/no-array-reduce
|
||||
.reduce(
|
||||
(accumulator, [key, value_]) => ({
|
||||
...accumulator,
|
||||
[key.trim()]: value_.trim(),
|
||||
}),
|
||||
{},
|
||||
) as Intl.NumberFormatOptions;
|
||||
const float =
|
||||
typeof value === 'string' ? Number.parseFloat(value) : (value as number);
|
||||
this.value = new Intl.NumberFormat(this.locale, options).format(float);
|
||||
}
|
||||
}
|
||||
@@ -230,7 +241,9 @@ export class NumberLocalizedPipe implements PipeTransform, OnDestroy {
|
||||
})
|
||||
export class DateLocalizedFormatPipe implements PipeTransform, OnDestroy {
|
||||
locale: string;
|
||||
|
||||
onLangChange?: Subscription;
|
||||
|
||||
value: string;
|
||||
|
||||
constructor(private readonly translate: TranslateService) {
|
||||
@@ -257,32 +270,48 @@ export class DateLocalizedFormatPipe implements PipeTransform, OnDestroy {
|
||||
this.updateValue(value, formatOptions);
|
||||
this._dispose();
|
||||
if (this.onLangChange?.closed === true) {
|
||||
this.onLangChange = this.translate.onLangChange.subscribe((event: LangChangeEvent) => {
|
||||
this.locale = event.lang;
|
||||
this.updateValue(value, formatOptions);
|
||||
});
|
||||
this.onLangChange = this.translate.onLangChange.subscribe(
|
||||
(event: LangChangeEvent) => {
|
||||
this.locale = event.lang;
|
||||
this.updateValue(value, formatOptions);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return this.value;
|
||||
}
|
||||
|
||||
updateValue(value: string | Date | unknown, formatOptions?: string): void {
|
||||
if (typeof value !== 'string' && Object.prototype.toString.call(value) !== '[object Date]') {
|
||||
if (
|
||||
typeof value !== 'string' &&
|
||||
Object.prototype.toString.call(value) !== '[object Date]'
|
||||
) {
|
||||
logger.warn(`dateFormat pipe unable to parse input: ${value}`);
|
||||
|
||||
return;
|
||||
}
|
||||
const options = formatOptions?.split(',')
|
||||
.map((element) => element.split(':'))
|
||||
.reduce((acc, [key, val]) => ({...acc, [key.trim()]: val.trim()}),{}) as Intl.DateTimeFormatOptions;
|
||||
const date = typeof value === 'string' ? Date.parse(value) : value as Date;
|
||||
this.value = new Intl.DateTimeFormat(this.locale, options ?? {
|
||||
day: 'numeric',
|
||||
month: 'numeric',
|
||||
year: 'numeric',
|
||||
hour: 'numeric',
|
||||
minute: 'numeric',
|
||||
})
|
||||
.format(date);
|
||||
const options = formatOptions
|
||||
?.split(',')
|
||||
.map(element => element.split(':'))
|
||||
// eslint-disable-next-line unicorn/no-array-reduce
|
||||
.reduce(
|
||||
(accumulator, [key, value_]) => ({
|
||||
...accumulator,
|
||||
[key.trim()]: value_.trim(),
|
||||
}),
|
||||
{},
|
||||
) as Intl.DateTimeFormatOptions;
|
||||
const date =
|
||||
typeof value === 'string' ? Date.parse(value) : (value as Date);
|
||||
this.value = new Intl.DateTimeFormat(
|
||||
this.locale,
|
||||
options ?? {
|
||||
day: 'numeric',
|
||||
month: 'numeric',
|
||||
year: 'numeric',
|
||||
hour: 'numeric',
|
||||
minute: 'numeric',
|
||||
},
|
||||
).format(date);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,22 @@
|
||||
*/
|
||||
|
||||
import {ModuleWithProviders, NgModule, Provider} from '@angular/core';
|
||||
import {ArrayJoinPipe, DateLocalizedFormatPipe, NumberLocalizedPipe, SentenceCasePipe, StringSplitPipe, OpeningHoursPipe} from './common-string-pipes';
|
||||
import {ThingTranslateDefaultParser, ThingTranslateParser} from './thing-translate.parser';
|
||||
import {ThingPropertyNameTranslatePipe, ThingTranslatePipe} from './thing-translate.pipe';
|
||||
import {
|
||||
ArrayJoinPipe,
|
||||
DateLocalizedFormatPipe,
|
||||
NumberLocalizedPipe,
|
||||
SentenceCasePipe,
|
||||
StringSplitPipe,
|
||||
OpeningHoursPipe,
|
||||
} from './common-string-pipes';
|
||||
import {
|
||||
ThingTranslateDefaultParser,
|
||||
ThingTranslateParser,
|
||||
} from './thing-translate.parser';
|
||||
import {
|
||||
ThingPropertyNameTranslatePipe,
|
||||
ThingTranslatePipe,
|
||||
} from './thing-translate.pipe';
|
||||
import {ThingTranslateService} from './thing-translate.service';
|
||||
|
||||
export interface ThingTranslateModuleConfig {
|
||||
|
||||
@@ -19,8 +19,6 @@ import {isThing, SCThings, SCThingType} from '@openstapps/core';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {ThingTranslateService} from './thing-translate.service';
|
||||
|
||||
// tslint:disable: member-ordering prefer-function-over-method completed-docs
|
||||
|
||||
@Injectable()
|
||||
@Pipe({
|
||||
name: 'thingTranslate',
|
||||
|
||||
@@ -23,5 +23,4 @@ if (environment.production) {
|
||||
|
||||
platformBrowserDynamic()
|
||||
.bootstrapModule(AppModule)
|
||||
// tslint:disable-next-line:no-console
|
||||
.catch(async error => console.error(error));
|
||||
|
||||
Reference in New Issue
Block a user