diff options
author | Chocobozzz <me@florianbigard.com> | 2018-03-01 13:57:29 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-03-01 13:57:29 +0100 |
commit | 901637bb87f5eb0518fb7ca69d98b53ed918339e (patch) | |
tree | a8e8943fef7a109ba269d33029174cbdf4dde6d2 /client | |
parent | a73c582e5b6f5c52427b38aaf55b3afbead24053 (diff) | |
download | PeerTube-901637bb87f5eb0518fb7ca69d98b53ed918339e.tar.gz PeerTube-901637bb87f5eb0518fb7ca69d98b53ed918339e.tar.zst PeerTube-901637bb87f5eb0518fb7ca69d98b53ed918339e.zip |
Add ability to change the homepage
Diffstat (limited to 'client')
9 files changed, 86 insertions, 17 deletions
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html index 18ba7ba06..c7ddaaf01 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html | |||
@@ -37,6 +37,16 @@ | |||
37 | </div> | 37 | </div> |
38 | </div> | 38 | </div> |
39 | 39 | ||
40 | <div class="form-group"> | ||
41 | <label for="instanceDefaultClientRoute">Default client route</label> | ||
42 | <div class="peertube-select-container"> | ||
43 | <select id="instanceDefaultClientRoute" formControlName="instanceDefaultClientRoute"> | ||
44 | <option value="/videos/trending">Videos Trending</option> | ||
45 | <option value="/videos/recently-added">Videos Recently Added</option> | ||
46 | </select> | ||
47 | </div> | ||
48 | </div> | ||
49 | |||
40 | <div class="inner-form-title">Cache</div> | 50 | <div class="inner-form-title">Cache</div> |
41 | 51 | ||
42 | <div class="form-group"> | 52 | <div class="form-group"> |
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts index cf93b4060..c38bc326a 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts | |||
@@ -46,6 +46,7 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { | |||
46 | instanceName: '', | 46 | instanceName: '', |
47 | instanceDescription: '', | 47 | instanceDescription: '', |
48 | instanceTerms: '', | 48 | instanceTerms: '', |
49 | instanceDefaultClientRoute: '', | ||
49 | cachePreviewsSize: '', | 50 | cachePreviewsSize: '', |
50 | signupLimit: '', | 51 | signupLimit: '', |
51 | adminEmail: '', | 52 | adminEmail: '', |
@@ -85,6 +86,7 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { | |||
85 | instanceName: [ '', INSTANCE_NAME.VALIDATORS ], | 86 | instanceName: [ '', INSTANCE_NAME.VALIDATORS ], |
86 | instanceDescription: [ '' ], | 87 | instanceDescription: [ '' ], |
87 | instanceTerms: [ '' ], | 88 | instanceTerms: [ '' ], |
89 | instanceDefaultClientRoute: [ '' ], | ||
88 | cachePreviewsSize: [ '', CACHE_PREVIEWS_SIZE.VALIDATORS ], | 90 | cachePreviewsSize: [ '', CACHE_PREVIEWS_SIZE.VALIDATORS ], |
89 | signupEnabled: [ ], | 91 | signupEnabled: [ ], |
90 | signupLimit: [ '', SIGNUP_LIMIT.VALIDATORS ], | 92 | signupLimit: [ '', SIGNUP_LIMIT.VALIDATORS ], |
@@ -153,11 +155,12 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { | |||
153 | if (confirmRes === false) return | 155 | if (confirmRes === false) return |
154 | } | 156 | } |
155 | 157 | ||
156 | const data = { | 158 | const data: CustomConfig = { |
157 | instance: { | 159 | instance: { |
158 | name: this.form.value['instanceName'], | 160 | name: this.form.value['instanceName'], |
159 | description: this.form.value['instanceDescription'], | 161 | description: this.form.value['instanceDescription'], |
160 | terms: this.form.value['instanceTerms'], | 162 | terms: this.form.value['instanceTerms'], |
163 | defaultClientRoute: this.form.value['instanceDefaultClientRoute'], | ||
161 | customizations: { | 164 | customizations: { |
162 | javascript: this.form.value['customizationJavascript'], | 165 | javascript: this.form.value['customizationJavascript'], |
163 | css: this.form.value['customizationCSS'] | 166 | css: this.form.value['customizationCSS'] |
@@ -213,6 +216,7 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { | |||
213 | instanceName: this.customConfig.instance.name, | 216 | instanceName: this.customConfig.instance.name, |
214 | instanceDescription: this.customConfig.instance.description, | 217 | instanceDescription: this.customConfig.instance.description, |
215 | instanceTerms: this.customConfig.instance.terms, | 218 | instanceTerms: this.customConfig.instance.terms, |
219 | instanceDefaultClientRoute: this.customConfig.instance.defaultClientRoute, | ||
216 | cachePreviewsSize: this.customConfig.cache.previews.size, | 220 | cachePreviewsSize: this.customConfig.cache.previews.size, |
217 | signupEnabled: this.customConfig.signup.enabled, | 221 | signupEnabled: this.customConfig.signup.enabled, |
218 | signupLimit: this.customConfig.signup.limit, | 222 | signupLimit: this.customConfig.signup.limit, |
diff --git a/client/src/app/app-routing.module.ts b/client/src/app/app-routing.module.ts index f31b51e23..c8a6b3924 100644 --- a/client/src/app/app-routing.module.ts +++ b/client/src/app/app-routing.module.ts | |||
@@ -1,15 +1,11 @@ | |||
1 | import { NgModule } from '@angular/core' | 1 | import { NgModule } from '@angular/core' |
2 | import { Routes, RouterModule } from '@angular/router' | 2 | import { Routes, RouterModule } from '@angular/router' |
3 | import { RedirectService } from '@app/core/routing/redirect.service' | ||
3 | 4 | ||
4 | import { PreloadSelectedModulesList } from './core' | 5 | import { PreloadSelectedModulesList } from './core' |
5 | 6 | ||
6 | const routes: Routes = [ | 7 | const routes: Routes = [ |
7 | { | 8 | { |
8 | path: '', | ||
9 | redirectTo: '/videos/trending', | ||
10 | pathMatch: 'full' | ||
11 | }, | ||
12 | { | ||
13 | path: 'admin', | 9 | path: 'admin', |
14 | loadChildren: './+admin/admin.module#AdminModule' | 10 | loadChildren: './+admin/admin.module#AdminModule' |
15 | } | 11 | } |
@@ -22,7 +18,9 @@ const routes: Routes = [ | |||
22 | preloadingStrategy: PreloadSelectedModulesList | 18 | preloadingStrategy: PreloadSelectedModulesList |
23 | }) | 19 | }) |
24 | ], | 20 | ], |
25 | providers: [ PreloadSelectedModulesList ], | 21 | providers: [ |
22 | PreloadSelectedModulesList | ||
23 | ], | ||
26 | exports: [ RouterModule ] | 24 | exports: [ RouterModule ] |
27 | }) | 25 | }) |
28 | export class AppRoutingModule {} | 26 | export class AppRoutingModule {} |
diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index 25936146c..346e966e5 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | 1 | import { Component, OnInit } from '@angular/core' |
2 | import { DomSanitizer, SafeHtml } from '@angular/platform-browser' | 2 | import { DomSanitizer, SafeHtml } from '@angular/platform-browser' |
3 | import { GuardsCheckStart, Router } from '@angular/router' | 3 | import { GuardsCheckStart, Router } from '@angular/router' |
4 | import { AuthService, ServerService } from '@app/core' | 4 | import { AuthService, RedirectService, ServerService } from '@app/core' |
5 | import { isInSmallView } from '@app/shared/misc/utils' | 5 | import { isInSmallView } from '@app/shared/misc/utils' |
6 | 6 | ||
7 | @Component({ | 7 | @Component({ |
@@ -31,7 +31,8 @@ export class AppComponent implements OnInit { | |||
31 | private router: Router, | 31 | private router: Router, |
32 | private authService: AuthService, | 32 | private authService: AuthService, |
33 | private serverService: ServerService, | 33 | private serverService: ServerService, |
34 | private domSanitizer: DomSanitizer | 34 | private domSanitizer: DomSanitizer, |
35 | private redirectService: RedirectService | ||
35 | ) {} | 36 | ) {} |
36 | 37 | ||
37 | get serverVersion () { | 38 | get serverVersion () { |
@@ -43,6 +44,10 @@ export class AppComponent implements OnInit { | |||
43 | } | 44 | } |
44 | 45 | ||
45 | ngOnInit () { | 46 | ngOnInit () { |
47 | if (this.router.url === '/') { | ||
48 | this.redirectService.redirectToHomepage() | ||
49 | } | ||
50 | |||
46 | this.authService.loadClientCredentials() | 51 | this.authService.loadClientCredentials() |
47 | 52 | ||
48 | if (this.authService.isLoggedIn()) { | 53 | if (this.authService.isLoggedIn()) { |
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: '' |
diff --git a/client/src/app/videos/+video-watch/video-watch.component.ts b/client/src/app/videos/+video-watch/video-watch.component.ts index 585ab2e00..66ef0399a 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core' | 1 | import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | 2 | import { ActivatedRoute, Router } from '@angular/router' |
3 | import { RedirectService } from '@app/core/routing/redirect.service' | ||
3 | import { VideoSupportComponent } from '@app/videos/+video-watch/modal/video-support.component' | 4 | import { VideoSupportComponent } from '@app/videos/+video-watch/modal/video-support.component' |
4 | import { MetaService } from '@ngx-meta/core' | 5 | import { MetaService } from '@ngx-meta/core' |
5 | import { NotificationsService } from 'angular2-notifications' | 6 | import { NotificationsService } from 'angular2-notifications' |
6 | import { Observable } from 'rxjs/Observable' | ||
7 | import { Subscription } from 'rxjs/Subscription' | 7 | import { Subscription } from 'rxjs/Subscription' |
8 | import * as videojs from 'video.js' | 8 | import * as videojs from 'video.js' |
9 | import 'videojs-hotkeys' | 9 | import 'videojs-hotkeys' |
@@ -64,7 +64,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
64 | private authService: AuthService, | 64 | private authService: AuthService, |
65 | private notificationsService: NotificationsService, | 65 | private notificationsService: NotificationsService, |
66 | private markdownService: MarkdownService, | 66 | private markdownService: MarkdownService, |
67 | private zone: NgZone | 67 | private zone: NgZone, |
68 | private redirectService: RedirectService | ||
68 | ) {} | 69 | ) {} |
69 | 70 | ||
70 | get user () { | 71 | get user () { |
@@ -142,7 +143,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
142 | .subscribe( | 143 | .subscribe( |
143 | status => { | 144 | status => { |
144 | this.notificationsService.success('Success', `Video ${this.video.name} had been blacklisted.`) | 145 | this.notificationsService.success('Success', `Video ${this.video.name} had been blacklisted.`) |
145 | this.router.navigate(['/videos/list']) | 146 | this.redirectService.redirectToHomepage() |
146 | }, | 147 | }, |
147 | 148 | ||
148 | error => this.notificationsService.error('Error', error.message) | 149 | error => this.notificationsService.error('Error', error.message) |
@@ -247,7 +248,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
247 | this.notificationsService.success('Success', `Video ${this.video.name} deleted.`) | 248 | this.notificationsService.success('Success', `Video ${this.video.name} deleted.`) |
248 | 249 | ||
249 | // Go back to the video-list. | 250 | // Go back to the video-list. |
250 | this.router.navigate([ '/videos/list' ]) | 251 | this.redirectService.redirectToHomepage() |
251 | }, | 252 | }, |
252 | 253 | ||
253 | error => this.notificationsService.error('Error', error.message) | 254 | error => this.notificationsService.error('Error', error.message) |
@@ -313,7 +314,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
313 | 'This video contains mature or explicit content. Are you sure you want to watch it?', | 314 | 'This video contains mature or explicit content. Are you sure you want to watch it?', |
314 | 'Mature or explicit content' | 315 | 'Mature or explicit content' |
315 | ) | 316 | ) |
316 | if (res === false) return this.router.navigate([ '/videos/list' ]) | 317 | if (res === false) return this.redirectService.redirectToHomepage() |
317 | } | 318 | } |
318 | 319 | ||
319 | if (!this.hasAlreadyAcceptedPrivacyConcern()) { | 320 | if (!this.hasAlreadyAcceptedPrivacyConcern()) { |
@@ -323,7 +324,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
323 | 'Privacy concern', | 324 | 'Privacy concern', |
324 | 'I accept!' | 325 | 'I accept!' |
325 | ) | 326 | ) |
326 | if (res === false) return this.router.navigate([ '/videos/list' ]) | 327 | if (res === false) return this.redirectService.redirectToHomepage() |
327 | } | 328 | } |
328 | 329 | ||
329 | this.acceptedPrivacyConcern() | 330 | this.acceptedPrivacyConcern() |