]>
Commit | Line | Data |
---|---|---|
1 | import { Subscription } from 'rxjs' | |
2 | import { first, tap } from 'rxjs/operators' | |
3 | import { Component, ComponentFactoryResolver, OnDestroy, OnInit } from '@angular/core' | |
4 | import { ActivatedRoute, Router } from '@angular/router' | |
5 | import { AuthService, ConfirmService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core' | |
6 | import { immutableAssign } from '@app/helpers' | |
7 | import { Account, AccountService, VideoService } from '@app/shared/shared-main' | |
8 | import { AbstractVideoList } from '@app/shared/shared-video-miniature' | |
9 | import { VideoFilter } from '@shared/models' | |
10 | ||
11 | @Component({ | |
12 | selector: 'my-account-search', | |
13 | templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html', | |
14 | styleUrls: [ '../../shared/shared-video-miniature/abstract-video-list.scss' ] | |
15 | }) | |
16 | export class AccountSearchComponent extends AbstractVideoList implements OnInit, OnDestroy { | |
17 | titlePage: string | |
18 | loadOnInit = false | |
19 | ||
20 | search = '' | |
21 | filter: VideoFilter = null | |
22 | ||
23 | private account: Account | |
24 | private accountSub: Subscription | |
25 | ||
26 | constructor ( | |
27 | protected router: Router, | |
28 | protected serverService: ServerService, | |
29 | protected route: ActivatedRoute, | |
30 | protected authService: AuthService, | |
31 | protected userService: UserService, | |
32 | protected notifier: Notifier, | |
33 | protected confirmService: ConfirmService, | |
34 | protected screenService: ScreenService, | |
35 | protected storageService: LocalStorageService, | |
36 | protected cfr: ComponentFactoryResolver, | |
37 | private accountService: AccountService, | |
38 | private videoService: VideoService | |
39 | ) { | |
40 | super() | |
41 | } | |
42 | ||
43 | ngOnInit () { | |
44 | super.ngOnInit() | |
45 | ||
46 | this.enableAllFilterIfPossible() | |
47 | ||
48 | // Parent get the account for us | |
49 | this.accountSub = this.accountService.accountLoaded | |
50 | .pipe(first()) | |
51 | .subscribe(account => { | |
52 | this.account = account | |
53 | ||
54 | this.reloadVideos() | |
55 | this.generateSyndicationList() | |
56 | }) | |
57 | } | |
58 | ||
59 | ngOnDestroy () { | |
60 | if (this.accountSub) this.accountSub.unsubscribe() | |
61 | ||
62 | super.ngOnDestroy() | |
63 | } | |
64 | ||
65 | updateSearch (value: string) { | |
66 | if (value === '') this.router.navigate(['../videos'], { relativeTo: this.route }) | |
67 | this.search = value | |
68 | ||
69 | this.reloadVideos() | |
70 | } | |
71 | ||
72 | getVideosObservable (page: number) { | |
73 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
74 | const options = { | |
75 | account: this.account, | |
76 | videoPagination: newPagination, | |
77 | sort: this.sort, | |
78 | nsfwPolicy: this.nsfwPolicy, | |
79 | videoFilter: this.filter, | |
80 | search: this.search | |
81 | } | |
82 | ||
83 | return this.videoService | |
84 | .getAccountVideos(options) | |
85 | .pipe( | |
86 | tap(({ total }) => { | |
87 | this.titlePage = this.search | |
88 | ? $localize`Published ${total} videos matching "${this.search}"` | |
89 | : $localize`Published ${total} videos` | |
90 | }) | |
91 | ) | |
92 | } | |
93 | ||
94 | toggleModerationDisplay () { | |
95 | this.filter = this.buildLocalFilter(this.filter, null) | |
96 | ||
97 | this.reloadVideos() | |
98 | } | |
99 | ||
100 | generateSyndicationList () { | |
101 | /* method disabled */ | |
102 | throw new Error('Method not implemented.') | |
103 | } | |
104 | } |