diff options
Diffstat (limited to 'client/src/app/core')
-rw-r--r-- | client/src/app/core/core.module.ts | 5 | ||||
-rw-r--r-- | client/src/app/core/routing/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/core/routing/redirect.service.ts | 48 | ||||
-rw-r--r-- | client/src/app/core/server/server.service.ts | 1 |
4 files changed, 53 insertions, 2 deletions
diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts index 708831965..c2de2084e 100644 --- a/client/src/app/core/core.module.ts +++ b/client/src/app/core/core.module.ts | |||
@@ -13,7 +13,7 @@ import { ModalModule } from 'ngx-bootstrap/modal' | |||
13 | import { AuthService } from './auth' | 13 | import { AuthService } from './auth' |
14 | import { ConfirmComponent, ConfirmService } from './confirm' | 14 | import { ConfirmComponent, ConfirmService } from './confirm' |
15 | import { throwIfAlreadyLoaded } from './module-import-guard' | 15 | import { throwIfAlreadyLoaded } from './module-import-guard' |
16 | import { LoginGuard, UserRightGuard } from './routing' | 16 | import { LoginGuard, RedirectService, UserRightGuard } from './routing' |
17 | import { ServerService } from './server' | 17 | import { ServerService } from './server' |
18 | 18 | ||
19 | @NgModule({ | 19 | @NgModule({ |
@@ -48,7 +48,8 @@ import { ServerService } from './server' | |||
48 | ConfirmService, | 48 | ConfirmService, |
49 | ServerService, | 49 | ServerService, |
50 | LoginGuard, | 50 | LoginGuard, |
51 | UserRightGuard | 51 | UserRightGuard, |
52 | RedirectService | ||
52 | ] | 53 | ] |
53 | }) | 54 | }) |
54 | export class CoreModule { | 55 | export class CoreModule { |
diff --git a/client/src/app/core/routing/index.ts b/client/src/app/core/routing/index.ts index d1b982834..9f0b4eac5 100644 --- a/client/src/app/core/routing/index.ts +++ b/client/src/app/core/routing/index.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | export * from './login-guard.service' | 1 | export * from './login-guard.service' |
2 | export * from './user-right-guard.service' | 2 | export * from './user-right-guard.service' |
3 | export * from './preload-selected-modules-list' | 3 | export * from './preload-selected-modules-list' |
4 | export * from './redirect.service' | ||
diff --git a/client/src/app/core/routing/redirect.service.ts b/client/src/app/core/routing/redirect.service.ts new file mode 100644 index 000000000..a0125e0ae --- /dev/null +++ b/client/src/app/core/routing/redirect.service.ts | |||
@@ -0,0 +1,48 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { Router } from '@angular/router' | ||
3 | import { ServerService } from '../server' | ||
4 | |||
5 | @Injectable() | ||
6 | export class RedirectService { | ||
7 | // Default route could change according to the instance configuration | ||
8 | static INIT_DEFAULT_ROUTE = '/videos/trending' | ||
9 | static DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE | ||
10 | |||
11 | constructor ( | ||
12 | private router: Router, | ||
13 | private serverService: ServerService | ||
14 | ) { | ||
15 | // The config is first loaded from the cache so try to get the default route | ||
16 | const config = this.serverService.getConfig() | ||
17 | if (config && config.instance && config.instance.defaultClientRoute) { | ||
18 | RedirectService.DEFAULT_ROUTE = config.instance.defaultClientRoute | ||
19 | } | ||
20 | |||
21 | this.serverService.configLoaded | ||
22 | .subscribe(() => { | ||
23 | const defaultRouteConfig = this.serverService.getConfig().instance.defaultClientRoute | ||
24 | |||
25 | if (defaultRouteConfig) { | ||
26 | RedirectService.DEFAULT_ROUTE = defaultRouteConfig | ||
27 | } | ||
28 | }) | ||
29 | } | ||
30 | |||
31 | redirectToHomepage () { | ||
32 | console.log('Redirecting to %s...', RedirectService.DEFAULT_ROUTE) | ||
33 | |||
34 | this.router.navigate([ RedirectService.DEFAULT_ROUTE ]) | ||
35 | .catch(() => { | ||
36 | console.error( | ||
37 | 'Cannot navigate to %s, resetting default route to %s.', | ||
38 | RedirectService.DEFAULT_ROUTE, | ||
39 | RedirectService.INIT_DEFAULT_ROUTE | ||
40 | ) | ||
41 | |||
42 | RedirectService.DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE | ||
43 | return this.router.navigate([ RedirectService.DEFAULT_ROUTE ]) | ||
44 | }) | ||
45 | |||
46 | } | ||
47 | |||
48 | } | ||
diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts index 984738948..2135c3268 100644 --- a/client/src/app/core/server/server.service.ts +++ b/client/src/app/core/server/server.service.ts | |||
@@ -21,6 +21,7 @@ export class ServerService { | |||
21 | private config: ServerConfig = { | 21 | private config: ServerConfig = { |
22 | instance: { | 22 | instance: { |
23 | name: 'PeerTube', | 23 | name: 'PeerTube', |
24 | defaultClientRoute: '', | ||
24 | customizations: { | 25 | customizations: { |
25 | javascript: '', | 26 | javascript: '', |
26 | css: '' | 27 | css: '' |