aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/routing
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/core/routing')
-rw-r--r--client/src/app/core/routing/index.ts1
-rw-r--r--client/src/app/core/routing/redirect.service.ts26
-rw-r--r--client/src/app/core/routing/trending-guard.service.ts14
3 files changed, 39 insertions, 2 deletions
diff --git a/client/src/app/core/routing/index.ts b/client/src/app/core/routing/index.ts
index 239c27caf..b3985d870 100644
--- a/client/src/app/core/routing/index.ts
+++ b/client/src/app/core/routing/index.ts
@@ -8,3 +8,4 @@ export * from './redirect.service'
8export * from './server-config-resolver.service' 8export * from './server-config-resolver.service'
9export * from './unlogged-guard.service' 9export * from './unlogged-guard.service'
10export * from './user-right-guard.service' 10export * from './user-right-guard.service'
11export * from './trending-guard.service'
diff --git a/client/src/app/core/routing/redirect.service.ts b/client/src/app/core/routing/redirect.service.ts
index 3218040bf..76e28e461 100644
--- a/client/src/app/core/routing/redirect.service.ts
+++ b/client/src/app/core/routing/redirect.service.ts
@@ -7,11 +7,14 @@ export class RedirectService {
7 // Default route could change according to the instance configuration 7 // Default route could change according to the instance configuration
8 static INIT_DEFAULT_ROUTE = '/videos/trending' 8 static INIT_DEFAULT_ROUTE = '/videos/trending'
9 static DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE 9 static DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE
10 static INIT_DEFAULT_TRENDING_ROUTE = '/videos/most-viewed'
11 static DEFAULT_TRENDING_ROUTE = RedirectService.INIT_DEFAULT_TRENDING_ROUTE
10 12
11 private previousUrl: string 13 private previousUrl: string
12 private currentUrl: string 14 private currentUrl: string
13 15
14 private redirectingToHomepage = false 16 private redirectingToHomepage = false
17 private redirectingToTrending = false
15 18
16 constructor ( 19 constructor (
17 private router: Router, 20 private router: Router,
@@ -19,18 +22,28 @@ export class RedirectService {
19 ) { 22 ) {
20 // The config is first loaded from the cache so try to get the default route 23 // The config is first loaded from the cache so try to get the default route
21 const tmpConfig = this.serverService.getTmpConfig() 24 const tmpConfig = this.serverService.getTmpConfig()
22 if (tmpConfig && tmpConfig.instance && tmpConfig.instance.defaultClientRoute) { 25 if (tmpConfig && tmpConfig.instance) {
23 RedirectService.DEFAULT_ROUTE = tmpConfig.instance.defaultClientRoute 26 if (tmpConfig.instance.defaultClientRoute) {
27 RedirectService.DEFAULT_ROUTE = tmpConfig.instance.defaultClientRoute
28 }
29 if (tmpConfig.instance.defaultTrendingRoute) {
30 RedirectService.DEFAULT_TRENDING_ROUTE = tmpConfig.instance.defaultTrendingRoute
31 }
24 } 32 }
25 33
26 // Load default route 34 // Load default route
27 this.serverService.getConfig() 35 this.serverService.getConfig()
28 .subscribe(config => { 36 .subscribe(config => {
29 const defaultRouteConfig = config.instance.defaultClientRoute 37 const defaultRouteConfig = config.instance.defaultClientRoute
38 const defaultTrendingConfig = config.instance.defaultTrendingRoute
30 39
31 if (defaultRouteConfig) { 40 if (defaultRouteConfig) {
32 RedirectService.DEFAULT_ROUTE = defaultRouteConfig 41 RedirectService.DEFAULT_ROUTE = defaultRouteConfig
33 } 42 }
43
44 if (defaultTrendingConfig) {
45 RedirectService.DEFAULT_TRENDING_ROUTE = defaultTrendingConfig
46 }
34 }) 47 })
35 48
36 // Track previous url 49 // Track previous url
@@ -57,6 +70,15 @@ export class RedirectService {
57 return this.redirectToHomepage() 70 return this.redirectToHomepage()
58 } 71 }
59 72
73 redirectToTrending () {
74 if (this.redirectingToTrending) return
75
76 this.redirectingToTrending = true
77
78 this.router.navigate([ RedirectService.DEFAULT_TRENDING_ROUTE ])
79 .then(() => this.redirectingToTrending = false)
80 }
81
60 redirectToHomepage (skipLocationChange = false) { 82 redirectToHomepage (skipLocationChange = false) {
61 if (this.redirectingToHomepage) return 83 if (this.redirectingToHomepage) return
62 84
diff --git a/client/src/app/core/routing/trending-guard.service.ts b/client/src/app/core/routing/trending-guard.service.ts
new file mode 100644
index 000000000..7db7fe994
--- /dev/null
+++ b/client/src/app/core/routing/trending-guard.service.ts
@@ -0,0 +1,14 @@
1import { Injectable } from '@angular/core'
2import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router'
3import { RedirectService } from './redirect.service'
4
5@Injectable()
6export class TrendingGuard implements CanActivate {
7
8 constructor (private redirectService: RedirectService) {}
9
10 canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
11 this.redirectService.redirectToTrending()
12 return false
13 }
14}