]>
Commit | Line | Data |
---|---|---|
d7639f66 | 1 | import { Component, OnDestroy, OnInit } from '@angular/core' |
5d08a6a7 | 2 | import { ServerService } from '@app/core' |
4c8e4e04 C |
3 | import { NavigationStart, Router } from '@angular/router' |
4 | import { filter } from 'rxjs/operators' | |
5 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
d7639f66 | 6 | import { Subscription } from 'rxjs' |
4bb6886d C |
7 | |
8 | @Component({ | |
0626e7af | 9 | selector: 'my-my-account', |
4c8e4e04 C |
10 | templateUrl: './my-account.component.html', |
11 | styleUrls: [ './my-account.component.scss' ] | |
4bb6886d | 12 | }) |
d7639f66 | 13 | export class MyAccountComponent implements OnInit, OnDestroy { |
4c8e4e04 C |
14 | |
15 | libraryLabel = '' | |
5d08a6a7 | 16 | |
d7639f66 C |
17 | private routeSub: Subscription |
18 | ||
5d08a6a7 | 19 | constructor ( |
4c8e4e04 C |
20 | private serverService: ServerService, |
21 | private router: Router, | |
22 | private i18n: I18n | |
5d08a6a7 C |
23 | ) {} |
24 | ||
4c8e4e04 | 25 | ngOnInit () { |
4c8e4e04 C |
26 | this.updateLibraryLabel(this.router.url) |
27 | ||
d7639f66 | 28 | this.routeSub = this.router.events |
4c8e4e04 C |
29 | .pipe(filter(event => event instanceof NavigationStart)) |
30 | .subscribe((event: NavigationStart) => this.updateLibraryLabel(event.url)) | |
31 | } | |
32 | ||
d7639f66 C |
33 | ngOnDestroy () { |
34 | if (this.routeSub) this.routeSub.unsubscribe() | |
35 | } | |
36 | ||
5d08a6a7 | 37 | isVideoImportEnabled () { |
b0ee41df C |
38 | const importConfig = this.serverService.getConfig().import.videos |
39 | ||
40 | return importConfig.http.enabled || importConfig.torrent.enabled | |
5d08a6a7 | 41 | } |
4c8e4e04 C |
42 | |
43 | private updateLibraryLabel (url: string) { | |
44 | const [ path ] = url.split('?') | |
45 | ||
46 | if (path === '/my-account/video-channels') { | |
47 | this.libraryLabel = this.i18n('Channels') | |
48 | } else if (path === '/my-account/videos') { | |
49 | this.libraryLabel = this.i18n('Videos') | |
50 | } else if (path === '/my-account/subscriptions') { | |
51 | this.libraryLabel = this.i18n('Subscriptions') | |
52 | } else if (path === '/my-account/video-imports') { | |
53 | this.libraryLabel = this.i18n('Video imports') | |
54 | } else { | |
55 | this.libraryLabel = '' | |
56 | } | |
57 | } | |
5d08a6a7 | 58 | } |