diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-01-10 14:01:13 +0100 |
---|---|---|
committer | Rigel Kent <sendmemail@rigelk.eu> | 2020-01-10 14:01:23 +0100 |
commit | 000eb0e40d74e914f6691305511c44e89cd8bf07 (patch) | |
tree | 8745c9f15041fc04b3f02dd087ecce330d3b9428 /client/src/app/header/header.component.ts | |
parent | ab4d4db44a4f943056b856cbdc7b8d157cabf9af (diff) | |
download | PeerTube-000eb0e40d74e914f6691305511c44e89cd8bf07.tar.gz PeerTube-000eb0e40d74e914f6691305511c44e89cd8bf07.tar.zst PeerTube-000eb0e40d74e914f6691305511c44e89cd8bf07.zip |
Add informational message at login for visitors coming from upload button
resolves #1880
Diffstat (limited to 'client/src/app/header/header.component.ts')
-rw-r--r-- | client/src/app/header/header.component.ts | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/client/src/app/header/header.component.ts b/client/src/app/header/header.component.ts index c6e942e0e..192d6945b 100644 --- a/client/src/app/header/header.component.ts +++ b/client/src/app/header/header.component.ts | |||
@@ -2,8 +2,9 @@ import { filter, first, map, tap } from 'rxjs/operators' | |||
2 | import { Component, OnInit } from '@angular/core' | 2 | import { Component, OnInit } from '@angular/core' |
3 | import { ActivatedRoute, NavigationEnd, Params, Router } from '@angular/router' | 3 | import { ActivatedRoute, NavigationEnd, Params, Router } from '@angular/router' |
4 | import { getParameterByName } from '../shared/misc/utils' | 4 | import { getParameterByName } from '../shared/misc/utils' |
5 | import { AuthService } from '@app/core' | 5 | import { AuthService, ServerService, Notifier } from '@app/core' |
6 | import { of } from 'rxjs' | 6 | import { of } from 'rxjs' |
7 | import { ServerConfig } from '@shared/models' | ||
7 | 8 | ||
8 | @Component({ | 9 | @Component({ |
9 | selector: 'my-header', | 10 | selector: 'my-header', |
@@ -14,10 +15,15 @@ import { of } from 'rxjs' | |||
14 | export class HeaderComponent implements OnInit { | 15 | export class HeaderComponent implements OnInit { |
15 | searchValue = '' | 16 | searchValue = '' |
16 | 17 | ||
18 | private serverConfig: ServerConfig | ||
19 | |||
17 | constructor ( | 20 | constructor ( |
18 | private router: Router, | 21 | private router: Router, |
19 | private route: ActivatedRoute, | 22 | private route: ActivatedRoute, |
20 | private auth: AuthService | 23 | private auth: AuthService, |
24 | private serverService: ServerService, | ||
25 | private authService: AuthService, | ||
26 | private notifier: Notifier | ||
21 | ) {} | 27 | ) {} |
22 | 28 | ||
23 | ngOnInit () { | 29 | ngOnInit () { |
@@ -27,6 +33,13 @@ export class HeaderComponent implements OnInit { | |||
27 | map(() => getParameterByName('search', window.location.href)) | 33 | map(() => getParameterByName('search', window.location.href)) |
28 | ) | 34 | ) |
29 | .subscribe(searchQuery => this.searchValue = searchQuery || '') | 35 | .subscribe(searchQuery => this.searchValue = searchQuery || '') |
36 | |||
37 | this.serverConfig = this.serverService.getTmpConfig() | ||
38 | this.serverService.getConfig().subscribe( | ||
39 | config => this.serverConfig = config, | ||
40 | |||
41 | err => this.notifier.error(err.message) | ||
42 | ) | ||
30 | } | 43 | } |
31 | 44 | ||
32 | doSearch () { | 45 | doSearch () { |
@@ -45,6 +58,25 @@ export class HeaderComponent implements OnInit { | |||
45 | o.subscribe(() => this.router.navigate([ '/search' ], { queryParams })) | 58 | o.subscribe(() => this.router.navigate([ '/search' ], { queryParams })) |
46 | } | 59 | } |
47 | 60 | ||
61 | isUserLoggedIn () { | ||
62 | return this.authService.isLoggedIn() | ||
63 | } | ||
64 | |||
65 | isRegistrationAllowed () { | ||
66 | return this.serverConfig.signup.allowed && | ||
67 | this.serverConfig.signup.allowedForCurrentIP | ||
68 | } | ||
69 | |||
70 | goToUpload () { | ||
71 | if (this.isUserLoggedIn()) { | ||
72 | this.router.navigate([ '/videos/upload' ]) | ||
73 | } else if (this.isRegistrationAllowed()) { | ||
74 | this.router.navigate([ '/signup' ]) | ||
75 | } else { | ||
76 | this.router.navigate([ '/login', { fromUpload: true } ]) | ||
77 | } | ||
78 | } | ||
79 | |||
48 | private loadUserLanguagesIfNeeded (queryParams: any) { | 80 | private loadUserLanguagesIfNeeded (queryParams: any) { |
49 | if (queryParams && queryParams.languageOneOf) return of(queryParams) | 81 | if (queryParams && queryParams.languageOneOf) return of(queryParams) |
50 | 82 | ||