diff options
Diffstat (limited to 'client/src/app/core/routing')
-rw-r--r-- | client/src/app/core/routing/index.ts | 2 | ||||
-rw-r--r-- | client/src/app/core/routing/meta-guard.service.ts | 23 | ||||
-rw-r--r-- | client/src/app/core/routing/meta.service.ts | 40 |
3 files changed, 65 insertions, 0 deletions
diff --git a/client/src/app/core/routing/index.ts b/client/src/app/core/routing/index.ts index 239c27caf..4314ea475 100644 --- a/client/src/app/core/routing/index.ts +++ b/client/src/app/core/routing/index.ts | |||
@@ -3,6 +3,8 @@ export * from './custom-reuse-strategy' | |||
3 | export * from './disable-for-reuse-hook' | 3 | export * from './disable-for-reuse-hook' |
4 | export * from './login-guard.service' | 4 | export * from './login-guard.service' |
5 | export * from './menu-guard.service' | 5 | export * from './menu-guard.service' |
6 | export * from './meta-guard.service' | ||
7 | export * from './meta.service' | ||
6 | export * from './preload-selected-modules-list' | 8 | export * from './preload-selected-modules-list' |
7 | export * from './redirect.service' | 9 | export * from './redirect.service' |
8 | export * from './server-config-resolver.service' | 10 | export * from './server-config-resolver.service' |
diff --git a/client/src/app/core/routing/meta-guard.service.ts b/client/src/app/core/routing/meta-guard.service.ts new file mode 100644 index 000000000..bedb3450e --- /dev/null +++ b/client/src/app/core/routing/meta-guard.service.ts | |||
@@ -0,0 +1,23 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, RouterStateSnapshot } from '@angular/router' | ||
3 | import { MetaService } from './meta.service' | ||
4 | |||
5 | @Injectable() | ||
6 | export class MetaGuard implements CanActivate, CanActivateChild { | ||
7 | |||
8 | constructor (private meta: MetaService) { } | ||
9 | |||
10 | canActivate (route: ActivatedRouteSnapshot): boolean { | ||
11 | const metaSettings = route.data?.meta | ||
12 | |||
13 | if (metaSettings) { | ||
14 | this.meta.update(metaSettings) | ||
15 | } | ||
16 | |||
17 | return true | ||
18 | } | ||
19 | |||
20 | canActivateChild (route: ActivatedRouteSnapshot): boolean { | ||
21 | return this.canActivate(route) | ||
22 | } | ||
23 | } | ||
diff --git a/client/src/app/core/routing/meta.service.ts b/client/src/app/core/routing/meta.service.ts new file mode 100644 index 000000000..a5ac778dc --- /dev/null +++ b/client/src/app/core/routing/meta.service.ts | |||
@@ -0,0 +1,40 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { Meta, Title } from '@angular/platform-browser' | ||
3 | import { HTMLServerConfig } from '@shared/models/server' | ||
4 | import { ServerService } from '../server' | ||
5 | |||
6 | export interface MetaSettings { | ||
7 | title?: string | ||
8 | } | ||
9 | |||
10 | @Injectable() | ||
11 | export class MetaService { | ||
12 | private config: HTMLServerConfig | ||
13 | |||
14 | constructor ( | ||
15 | private titleService: Title, | ||
16 | private meta: Meta, | ||
17 | private server: ServerService | ||
18 | ) { | ||
19 | this.config = this.server.getTmpConfig() | ||
20 | this.server.getConfig() | ||
21 | .subscribe(config => this.config = config) | ||
22 | } | ||
23 | |||
24 | setTitle (subTitle?: string) { | ||
25 | let title = '' | ||
26 | if (subTitle) title += `${subTitle} - ` | ||
27 | |||
28 | title += this.config.instance.name | ||
29 | |||
30 | this.titleService.setTitle(title) | ||
31 | } | ||
32 | |||
33 | setTag (name: string, value: string) { | ||
34 | this.meta.addTag({ name, content: value }) | ||
35 | } | ||
36 | |||
37 | update (meta: MetaSettings) { | ||
38 | this.setTitle(meta.title) | ||
39 | } | ||
40 | } | ||