diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 8e774f33..4c021a6f 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,4 +1,4 @@ -import { HttpClientModule } from "@angular/common/http"; +import { HTTP_INTERCEPTORS, HttpClientModule } from "@angular/common/http"; import { APP_INITIALIZER, NgModule } from "@angular/core"; import { MatButtonModule } from "@angular/material/button"; import { MatCardModule } from "@angular/material/card"; @@ -48,6 +48,7 @@ import { ShowGridComponent } from "./components/show-grid/show-grid.component"; import { MatBadgeModule } from "@angular/material/badge"; import { StartupService } from "./services/startup.service"; import { LongPressDirective } from "./misc/long-press.directive"; +import { DatetimeInterceptorService } from "./services/datetime-interceptor.service"; @NgModule({ @@ -115,6 +116,11 @@ import { LongPressDirective } from "./misc/long-press.directive"; useFactory: (startup: StartupService) => () => startup.load(), deps: [StartupService], multi: true + }, + { + provide: HTTP_INTERCEPTORS, + useClass: DatetimeInterceptorService, + multi: true } ] }) diff --git a/src/app/components/items-grid/items-grid.component.ts b/src/app/components/items-grid/items-grid.component.ts index 2ff45889..9c92b05f 100644 --- a/src/app/components/items-grid/items-grid.component.ts +++ b/src/app/components/items-grid/items-grid.component.ts @@ -226,25 +226,22 @@ export class ItemsGridComponent implements OnInit replaceUrl: true, queryParams: {sortBy: this.route.snapshot.queryParams.sortBy} }); - return; } - if (this.filters.studio != null && this.getFilterCount() === 1) + else if (this.filters.studio != null && this.getFilterCount() === 1) { this.router.navigate(["studio", this.filters.studio.slug], { replaceUrl: true, queryParams: {sortBy: this.route.snapshot.queryParams.sortBy} }); - return; } - if (this.filters.people.length === 1 && this.getFilterCount() === 1) + else if (this.filters.people.length === 1 && this.getFilterCount() === 1) { this.router.navigate(["people", this.filters.people[0].slug], { replaceUrl: true, queryParams: {sortBy: this.route.snapshot.queryParams.sortBy} }); - return; } - if (this.getFilterCount() === 0 || this.router.url !== "/browse") + else if (this.getFilterCount() === 0 || this.router.url !== "/browse") { const params: {[key: string]: string} = {[category]: param}; if (this.router.url.startsWith("/studio") && category !== "studio") @@ -259,15 +256,17 @@ export class ItemsGridComponent implements OnInit replaceUrl: true, queryParamsHandling: "merge" }); - return; } } - this.router.navigate([], { - relativeTo: this.route, - queryParams: {[category]: param}, - replaceUrl: true, - queryParamsHandling: "merge" - }); + else + { + this.router.navigate([], { + relativeTo: this.route, + queryParams: {[category]: param}, + replaceUrl: true, + queryParamsHandling: "merge" + }); + } } nameGetter(obj: Studio): string diff --git a/src/app/misc/items-utils.ts b/src/app/misc/items-utils.ts index 5488b175..395acbd7 100644 --- a/src/app/misc/items-utils.ts +++ b/src/app/misc/items-utils.ts @@ -24,10 +24,10 @@ export class ItemsUtils if ("type" in item && item.type && typeof item.type === "string") return item.type; - if (!("startYear" in item)) + if (!("startAir" in item)) return ""; - if (item.endYear && item.startYear !== item.endYear) - return `${item.startYear} - ${item.endYear}`; - return item.startYear?.toString(); + if (item.endAir && item.startAir !== item.endAir) + return `${item.startAir.getFullYear()} - ${item.endAir.getFullYear()}`; + return item.startAir?.getFullYear().toString(); } } diff --git a/src/app/models/resources/collection.ts b/src/app/models/resources/collection.ts index 3ea69cd9..58712eeb 100644 --- a/src/app/models/resources/collection.ts +++ b/src/app/models/resources/collection.ts @@ -6,7 +6,7 @@ export interface Collection extends IResource name: string; poster: string; overview: string; - startYear: number; - endYear: number; + startAir: Date; + endAir: Date; shows: Show[]; } diff --git a/src/app/models/resources/library-item.ts b/src/app/models/resources/library-item.ts index f7e48319..de114be9 100644 --- a/src/app/models/resources/library-item.ts +++ b/src/app/models/resources/library-item.ts @@ -13,8 +13,8 @@ export interface LibraryItem extends IResource overview: string; status: string; trailerUrl: string; - startYear: number; - endYear: number; + startAir: Date; + endAir: Date; poster: string; type: ItemType; } diff --git a/src/app/models/resources/show.ts b/src/app/models/resources/show.ts index 10b9b358..3fc775b4 100644 --- a/src/app/models/resources/show.ts +++ b/src/app/models/resources/show.ts @@ -17,8 +17,8 @@ export interface Show extends IResource seasons: Season[]; trailerUrl: string; isMovie: boolean; - startYear: number; - endYear: number; + startAir: Date; + endAir: Date; poster: string; logo: string; backdrop: string; @@ -37,8 +37,8 @@ export interface ShowRole extends IResource status: string; trailerUrl: string; isMovie: boolean; - startYear: number; - endYear: number; + startAir: Date; + endAir: Date; poster: string; logo: string; backdrop: string; diff --git a/src/app/services/datetime-interceptor.service.ts b/src/app/services/datetime-interceptor.service.ts new file mode 100644 index 00000000..907f1ac7 --- /dev/null +++ b/src/app/services/datetime-interceptor.service.ts @@ -0,0 +1,40 @@ +import { Injectable } from "@angular/core"; +import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from "@angular/common/http"; +import { Observable } from "rxjs"; +import { map } from "rxjs/operators"; + +@Injectable() +export class DatetimeInterceptorService implements HttpInterceptor +{ + intercept(request: HttpRequest, next: HttpHandler): Observable> + { + return next.handle(request) + .pipe(map((event: HttpEvent) => + { + if (event instanceof HttpResponse) + return event.clone({body: this.convertDates(event.body)}); + return event; + })); + } + + + private convertDates(object: T): T | Date + { + if (typeof(object) === "string" && /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z?$/.exec(object)) + { + return new Date(object); + } + + if (object instanceof Array) + { + for (const i in object) + object[i] = this.convertDates(object[i]); + } + else if (object instanceof Object) + { + for (const key of Object.keys(object)) + object[key] = this.convertDates(object[key]); + } + return object; + } +}