]>
Commit | Line | Data |
---|---|---|
f6cf8e8d | 1 | import { forkJoin, Observable } from 'rxjs' |
67ed6552 | 2 | import { map, switchMap } from 'rxjs/operators' |
b42f9c40 | 3 | import { Injectable } from '@angular/core' |
2989628b | 4 | import { Resolve } from '@angular/router' |
f6cf8e8d | 5 | import { ServerService } from '@app/core' |
789ba349 C |
6 | import { CustomMarkupService } from '@app/shared/shared-custom-markup' |
7 | import { AboutHTML, InstanceService } from '@app/shared/shared-instance' | |
f6cf8e8d | 8 | import { About, ServerStats } from '@shared/models/server' |
b42f9c40 | 9 | |
789ba349 | 10 | export type ResolverData = { |
f6cf8e8d | 11 | serverStats: ServerStats |
789ba349 C |
12 | about: About |
13 | languages: string[] | |
14 | categories: string[] | |
15 | aboutHTML: AboutHTML | |
16 | descriptionElement: HTMLDivElement | |
17 | } | |
b42f9c40 C |
18 | |
19 | @Injectable() | |
20 | export class AboutInstanceResolver implements Resolve<any> { | |
67ed6552 | 21 | |
12c8a463 | 22 | constructor ( |
789ba349 | 23 | private instanceService: InstanceService, |
f6cf8e8d C |
24 | private customMarkupService: CustomMarkupService, |
25 | private serverService: ServerService | |
12c8a463 | 26 | ) {} |
b42f9c40 | 27 | |
f6cf8e8d C |
28 | resolve (): Observable<ResolverData> { |
29 | return forkJoin([ | |
30 | this.buildInstanceAboutObservable(), | |
31 | this.buildInstanceStatsObservable() | |
32 | ]).pipe( | |
33 | map(([ | |
34 | [ about, languages, categories, aboutHTML, { rootElement } ], | |
35 | serverStats | |
36 | ]) => { | |
37 | return { | |
38 | serverStats, | |
39 | about, | |
40 | languages, | |
41 | categories, | |
42 | aboutHTML, | |
43 | descriptionElement: rootElement | |
44 | } | |
45 | }) | |
46 | ) | |
47 | } | |
48 | ||
49 | private buildInstanceAboutObservable () { | |
b42f9c40 | 50 | return this.instanceService.getAbout() |
f6cf8e8d C |
51 | .pipe( |
52 | switchMap(about => { | |
53 | return forkJoin([ | |
54 | Promise.resolve(about), | |
55 | this.instanceService.buildTranslatedLanguages(about), | |
56 | this.instanceService.buildTranslatedCategories(about), | |
57 | this.instanceService.buildHtml(about), | |
58 | this.customMarkupService.buildElement(about.instance.description) | |
59 | ]) | |
60 | }) | |
61 | ) | |
62 | } | |
63 | ||
64 | private buildInstanceStatsObservable () { | |
65 | return this.serverService.getServerStats() | |
b42f9c40 C |
66 | } |
67 | } |