mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 16:42:56 +00:00
refactor: replace TSLint with ESLint
This commit is contained in:
committed by
Jovan Krunić
parent
67fb4a43c9
commit
d696215d08
@@ -27,5 +27,4 @@ export class DataDetailContentComponent {
|
||||
* TODO
|
||||
*/
|
||||
@Input() item: SCThings;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,68 @@
|
||||
<stapps-simple-card *ngIf="item.description" [title]="'Description'" [content]="item.description"></stapps-simple-card>
|
||||
<stapps-simple-card
|
||||
*ngIf="item.description"
|
||||
[title]="'Description'"
|
||||
[content]="item.description"
|
||||
></stapps-simple-card>
|
||||
<div [ngSwitch]="true">
|
||||
<stapps-article-detail-content [item]="item" [language]="language" *ngSwitchCase="item.type === 'article'"></stapps-article-detail-content>
|
||||
<stapps-catalog-detail-content [item]="item" [language]="language" *ngSwitchCase="item.type === 'catalog'"></stapps-catalog-detail-content>
|
||||
<stapps-date-series-detail-content [item]="item" [language]="language" *ngSwitchCase="item.type === 'date series'"></stapps-date-series-detail-content>
|
||||
<stapps-dish-detail-content [item]="item" [language]="language" *ngSwitchCase="item.type === 'dish'"></stapps-dish-detail-content>
|
||||
<stapps-event-detail-content [item]="item" [language]="language" *ngSwitchCase="item.type === 'academic event'"></stapps-event-detail-content>
|
||||
<stapps-event-detail-content [item]="item" [language]="language" *ngSwitchCase="item.type === 'sport course'"></stapps-event-detail-content>
|
||||
<stapps-favorite-detail-content [item]="item" [language]="language" *ngSwitchCase="item.type === 'favorite'"></stapps-favorite-detail-content>
|
||||
<stapps-message-detail-content [item]="item" [language]="language" *ngSwitchCase="item.type === 'message'"></stapps-message-detail-content>
|
||||
<stapps-person-detail-content [item]="item" [language]="language" *ngSwitchCase="item.type === 'person'"></stapps-person-detail-content>
|
||||
<stapps-place-detail-content [item]="item" [language]="language" *ngSwitchCase="item.type === 'building'"></stapps-place-detail-content>
|
||||
<stapps-place-detail-content [item]="item" [language]="language" *ngSwitchCase="item.type === 'floor'"></stapps-place-detail-content>
|
||||
<stapps-place-detail-content [item]="item" [language]="language" *ngSwitchCase="item.type === 'point of interest'"></stapps-place-detail-content>
|
||||
<stapps-place-detail-content [item]="item" [language]="language" *ngSwitchCase="item.type === 'room'"></stapps-place-detail-content>
|
||||
<stapps-semester-detail-content [item]="item" [language]="language" *ngSwitchCase="item.type === 'semester'"></stapps-semester-detail-content>
|
||||
<stapps-video-detail-content [item]="item" [language]="language" *ngSwitchCase="item.type === 'video'"></stapps-video-detail-content>
|
||||
<stapps-origin-detail [origin]="item.origin" ></stapps-origin-detail>
|
||||
<stapps-article-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="item.type === 'article'"
|
||||
></stapps-article-detail-content>
|
||||
<stapps-catalog-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="item.type === 'catalog'"
|
||||
></stapps-catalog-detail-content>
|
||||
<stapps-date-series-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="item.type === 'date series'"
|
||||
></stapps-date-series-detail-content>
|
||||
<stapps-dish-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="item.type === 'dish'"
|
||||
></stapps-dish-detail-content>
|
||||
<stapps-event-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="item.type === 'academic event'"
|
||||
></stapps-event-detail-content>
|
||||
<stapps-event-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="item.type === 'sport course'"
|
||||
></stapps-event-detail-content>
|
||||
<stapps-favorite-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="item.type === 'favorite'"
|
||||
></stapps-favorite-detail-content>
|
||||
<stapps-message-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="item.type === 'message'"
|
||||
></stapps-message-detail-content>
|
||||
<stapps-person-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="item.type === 'person'"
|
||||
></stapps-person-detail-content>
|
||||
<stapps-place-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="item.type === 'building'"
|
||||
></stapps-place-detail-content>
|
||||
<stapps-place-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="item.type === 'floor'"
|
||||
></stapps-place-detail-content>
|
||||
<stapps-place-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="item.type === 'point of interest'"
|
||||
></stapps-place-detail-content>
|
||||
<stapps-place-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="item.type === 'room'"
|
||||
></stapps-place-detail-content>
|
||||
<stapps-semester-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="item.type === 'semester'"
|
||||
></stapps-semester-detail-content>
|
||||
<stapps-video-detail-content
|
||||
[item]="item"
|
||||
*ngSwitchCase="item.type === 'video'"
|
||||
></stapps-video-detail-content>
|
||||
<stapps-origin-detail [origin]="item.origin"></stapps-origin-detail>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion,@typescript-eslint/no-explicit-any */
|
||||
/*
|
||||
* Copyright (C) 2018, 2019 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
@@ -16,7 +17,11 @@ import {CUSTOM_ELEMENTS_SCHEMA, DebugElement} from '@angular/core';
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {ActivatedRoute, RouterModule} from '@angular/router';
|
||||
import {IonRefresher, IonTitle} from '@ionic/angular';
|
||||
import {TranslateLoader, TranslateModule, TranslateService} from '@ngx-translate/core';
|
||||
import {
|
||||
TranslateLoader,
|
||||
TranslateModule,
|
||||
TranslateService,
|
||||
} from '@ngx-translate/core';
|
||||
import {sampleThingsMap} from '../../../_helpers/data/sample-things';
|
||||
import {DataRoutingModule} from '../data-routing.module';
|
||||
import {DataModule} from '../data.module';
|
||||
@@ -59,21 +64,26 @@ describe('DataDetailComponent', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [RouterModule.forRoot([]), DataRoutingModule, DataModule,
|
||||
TranslateModule.forRoot({
|
||||
loader: {provide: TranslateLoader, useClass: TranslateFakeLoader},
|
||||
})],
|
||||
imports: [
|
||||
RouterModule.forRoot([]),
|
||||
DataRoutingModule,
|
||||
DataModule,
|
||||
TranslateModule.forRoot({
|
||||
loader: {provide: TranslateLoader, useClass: TranslateFakeLoader},
|
||||
}),
|
||||
],
|
||||
providers: [{provide: ActivatedRoute, useValue: fakeActivatedRoute}],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
||||
})
|
||||
.compileComponents();
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(async () => {
|
||||
dataProvider = TestBed.get(DataProvider);
|
||||
translateService = TestBed.get(TranslateService);
|
||||
refresher = jasmine.createSpyObj('refresher', ['complete']);
|
||||
spyOn(dataProvider, 'get' as any).and.returnValue(Promise.resolve(sampleThing));
|
||||
spyOn(dataProvider, 'get' as any).and.returnValue(
|
||||
Promise.resolve(sampleThing),
|
||||
);
|
||||
spyOn(DataDetailComponent.prototype, 'getItem').and.callThrough();
|
||||
fixture = await TestBed.createComponent(DataDetailComponent);
|
||||
comp = fixture.componentInstance;
|
||||
@@ -83,28 +93,33 @@ describe('DataDetailComponent', () => {
|
||||
await dataProvider.deleteAll();
|
||||
});
|
||||
|
||||
it('should create component', () =>
|
||||
expect(comp).toBeDefined(),
|
||||
);
|
||||
it('should create component', () => expect(comp).toBeDefined());
|
||||
|
||||
it('should have appropriate title', async () => {
|
||||
const title: DebugElement | null = detailPage.query(By.directive(IonTitle));
|
||||
// eslint-disable-next-line unicorn/no-null
|
||||
expect(title).not.toBe(null);
|
||||
expect(title!.nativeElement.textContent).toBe('Foo');
|
||||
});
|
||||
|
||||
it('should get a data item', () => {
|
||||
comp.getItem(sampleThing.uid);
|
||||
expect(DataDetailComponent.prototype.getItem).toHaveBeenCalledWith(sampleThing.uid);
|
||||
expect(DataDetailComponent.prototype.getItem).toHaveBeenCalledWith(
|
||||
sampleThing.uid,
|
||||
);
|
||||
});
|
||||
|
||||
it('should get a data item when component is accessed', async () => {
|
||||
expect(DataDetailComponent.prototype.getItem).toHaveBeenCalledWith(sampleThing.uid);
|
||||
expect(DataDetailComponent.prototype.getItem).toHaveBeenCalledWith(
|
||||
sampleThing.uid,
|
||||
);
|
||||
});
|
||||
|
||||
it('should update the data item when refresh is called', async () => {
|
||||
await comp.refresh(refresher);
|
||||
expect(DataDetailComponent.prototype.getItem).toHaveBeenCalledWith(sampleThing.uid);
|
||||
expect(DataDetailComponent.prototype.getItem).toHaveBeenCalledWith(
|
||||
sampleThing.uid,
|
||||
);
|
||||
expect(refresher.complete).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,7 +17,12 @@ import {ActivatedRoute} from '@angular/router';
|
||||
import {Network} from '@ionic-native/network/ngx';
|
||||
import {IonRefresher} from '@ionic/angular';
|
||||
import {LangChangeEvent, TranslateService} from '@ngx-translate/core';
|
||||
import {SCLanguageCode, SCSaveableThing, SCThings, SCUuid} from '@openstapps/core';
|
||||
import {
|
||||
SCLanguageCode,
|
||||
SCSaveableThing,
|
||||
SCThings,
|
||||
SCUuid,
|
||||
} from '@openstapps/core';
|
||||
import {DataProvider, DataScope} from '../data.provider';
|
||||
|
||||
/**
|
||||
@@ -44,7 +49,9 @@ export class DataDetailComponent implements OnInit {
|
||||
/**
|
||||
* Type guard for SCSavableThing
|
||||
*/
|
||||
static isSCSavableThing(thing: SCThings | SCSaveableThing<SCThings>): thing is SCSaveableThing<SCThings> {
|
||||
static isSCSavableThing(
|
||||
thing: SCThings | SCSaveableThing<SCThings>,
|
||||
): thing is SCSaveableThing<SCThings> {
|
||||
return typeof (thing as SCSaveableThing<SCThings>).data !== 'undefined';
|
||||
}
|
||||
|
||||
@@ -55,10 +62,12 @@ export class DataDetailComponent implements OnInit {
|
||||
* @param network the network provider
|
||||
* @param translateService the translation service
|
||||
*/
|
||||
constructor(private readonly route: ActivatedRoute,
|
||||
private readonly dataProvider: DataProvider,
|
||||
private readonly network: Network,
|
||||
translateService: TranslateService) {
|
||||
constructor(
|
||||
private readonly route: ActivatedRoute,
|
||||
private readonly dataProvider: DataProvider,
|
||||
private readonly network: Network,
|
||||
translateService: TranslateService,
|
||||
) {
|
||||
this.language = translateService.currentLang as SCLanguageCode;
|
||||
translateService.onLangChange.subscribe((event: LangChangeEvent) => {
|
||||
this.language = event.lang as SCLanguageCode;
|
||||
@@ -74,7 +83,8 @@ export class DataDetailComponent implements OnInit {
|
||||
try {
|
||||
const item = await this.dataProvider.get(uid, DataScope.Remote);
|
||||
this.item = DataDetailComponent.isSCSavableThing(item) ? item.data : item;
|
||||
} catch (_) {
|
||||
} catch {
|
||||
// eslint-disable-next-line unicorn/no-null
|
||||
this.item = null;
|
||||
}
|
||||
}
|
||||
@@ -99,7 +109,9 @@ export class DataDetailComponent implements OnInit {
|
||||
* @param refresher Refresher component that triggers the update
|
||||
*/
|
||||
async refresh(refresher: IonRefresher) {
|
||||
await this.getItem(this.item?.uid ?? this.route.snapshot.paramMap.get('uid') ?? '');
|
||||
await this.getItem(
|
||||
this.item?.uid ?? this.route.snapshot.paramMap.get('uid') ?? '',
|
||||
);
|
||||
await refresher.complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
<ion-header>
|
||||
<ion-toolbar>
|
||||
<ion-buttons slot="start">
|
||||
<ion-back-button></ion-back-button>
|
||||
<ion-menu-button></ion-menu-button>
|
||||
</ion-buttons>
|
||||
<ion-title>{{'data.detail.TITLE' | translate}}</ion-title>
|
||||
<ion-buttons slot="start">
|
||||
<ion-back-button></ion-back-button>
|
||||
<ion-menu-button></ion-menu-button>
|
||||
</ion-buttons>
|
||||
<ion-title>{{ 'data.detail.TITLE' | translate }}</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
<ion-content class="ion-padding">
|
||||
<ion-refresher slot="fixed" (ionRefresh)="refresh($event.target)">
|
||||
<ion-refresher-content pullingIcon="chevron-down-outline" pullingText="{{'data.REFRESH_ACTION' | translate}}"
|
||||
refreshingText="{{'data.REFRESHING' | translate}}">
|
||||
<ion-refresher-content
|
||||
pullingIcon="chevron-down-outline"
|
||||
pullingText="{{ 'data.REFRESH_ACTION' | translate }}"
|
||||
refreshingText="{{ 'data.REFRESHING' | translate }}"
|
||||
>
|
||||
</ion-refresher-content>
|
||||
</ion-refresher>
|
||||
<div [ngSwitch]="true">
|
||||
<ng-container *ngSwitchCase='!item && isDisconnected()'>
|
||||
<div class='notFoundContainer'>
|
||||
<ion-icon name='no-connection'>
|
||||
</ion-icon>
|
||||
<ng-container *ngSwitchCase="!item && isDisconnected()">
|
||||
<div class="notFoundContainer">
|
||||
<ion-icon name="no-connection"> </ion-icon>
|
||||
<ion-label>
|
||||
{{ 'data.detail.COULD_NOT_CONNECT' | translate }}
|
||||
</ion-label>
|
||||
@@ -25,8 +27,7 @@
|
||||
</ng-container>
|
||||
<ng-container *ngSwitchCase="item === null">
|
||||
<div class="notFoundContainer">
|
||||
<ion-icon name="broken-link">
|
||||
</ion-icon>
|
||||
<ion-icon name="broken-link"> </ion-icon>
|
||||
<ion-label>
|
||||
{{ 'data.detail.NOT_FOUND' | translate }}
|
||||
</ion-label>
|
||||
@@ -39,14 +40,17 @@
|
||||
<ng-container *ngSwitchDefault>
|
||||
<ion-item class="ion-text-wrap" lines="inset">
|
||||
<ion-thumbnail slot="start" class="ion-margin-end">
|
||||
<ion-icon color="medium" [attr.name]="item.type | dataIcon"></ion-icon>
|
||||
<ion-icon
|
||||
color="medium"
|
||||
[attr.name]="item.type | dataIcon"
|
||||
></ion-icon>
|
||||
</ion-thumbnail>
|
||||
<ion-grid *ngSwitchDefault>
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user