aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/routing/redirect.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/core/routing/redirect.service.ts')
-rw-r--r--client/src/app/core/routing/redirect.service.ts26
1 files changed, 24 insertions, 2 deletions
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