]>
Commit | Line | Data |
---|---|---|
67ed6552 C |
1 | import { Subscription } from 'rxjs' |
2 | import { first, tap } from 'rxjs/operators' | |
0626e7af C |
3 | import { Component, OnDestroy, OnInit } from '@angular/core' |
4 | import { ActivatedRoute, Router } from '@angular/router' | |
67ed6552 C |
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' | |
0aa52e17 | 9 | import { VideoFilter } from '@shared/models' |
0626e7af C |
10 | |
11 | @Component({ | |
12 | selector: 'my-account-videos', | |
67ed6552 | 13 | templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html', |
0626e7af | 14 | styleUrls: [ |
ae2dd046 | 15 | '../../shared/shared-video-miniature/abstract-video-list.scss' |
0626e7af C |
16 | ] |
17 | }) | |
18 | export class AccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy { | |
b1d40cff | 19 | titlePage: string |
0626e7af C |
20 | loadOnInit = false |
21 | ||
0aa52e17 C |
22 | filter: VideoFilter = null |
23 | ||
0626e7af | 24 | private account: Account |
734a5ceb | 25 | private accountSub: Subscription |
0626e7af C |
26 | |
27 | constructor ( | |
28 | protected router: Router, | |
489290b8 | 29 | protected serverService: ServerService, |
0626e7af C |
30 | protected route: ActivatedRoute, |
31 | protected authService: AuthService, | |
d3217560 | 32 | protected userService: UserService, |
f8b2c1b4 | 33 | protected notifier: Notifier, |
0626e7af | 34 | protected confirmService: ConfirmService, |
bbe0f064 | 35 | protected screenService: ScreenService, |
d3217560 | 36 | protected storageService: LocalStorageService, |
0626e7af C |
37 | private accountService: AccountService, |
38 | private videoService: VideoService | |
39 | ) { | |
40 | super() | |
41 | } | |
42 | ||
43 | ngOnInit () { | |
44 | super.ngOnInit() | |
45 | ||
0aa52e17 C |
46 | this.enableAllFilterIfPossible() |
47 | ||
0626e7af | 48 | // Parent get the account for us |
734a5ceb | 49 | this.accountSub = this.accountService.accountLoaded |
722bca90 C |
50 | .pipe(first()) |
51 | .subscribe(account => { | |
52 | this.account = account | |
0626e7af | 53 | |
722bca90 C |
54 | this.reloadVideos() |
55 | this.generateSyndicationList() | |
56 | }) | |
0626e7af C |
57 | } |
58 | ||
59 | ngOnDestroy () { | |
734a5ceb C |
60 | if (this.accountSub) this.accountSub.unsubscribe() |
61 | ||
0626e7af C |
62 | super.ngOnDestroy() |
63 | } | |
64 | ||
65 | getVideosObservable (page: number) { | |
66 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
0aa52e17 C |
67 | const options = { |
68 | account: this.account, | |
69 | videoPagination: newPagination, | |
70 | sort: this.sort, | |
71 | nsfwPolicy: this.nsfwPolicy, | |
72 | videoFilter: this.filter | |
73 | } | |
0626e7af | 74 | |
0bf1f265 | 75 | return this.videoService |
0aa52e17 | 76 | .getAccountVideos(options) |
b1d40cff | 77 | .pipe( |
93cae479 | 78 | tap(({ total }) => { |
66357162 | 79 | this.titlePage = $localize`Published ${total} videos` |
b1d40cff C |
80 | }) |
81 | ) | |
0626e7af C |
82 | } |
83 | ||
0aa52e17 C |
84 | toggleModerationDisplay () { |
85 | this.filter = this.buildLocalFilter(this.filter, null) | |
86 | ||
87 | this.reloadVideos() | |
88 | } | |
89 | ||
0626e7af C |
90 | generateSyndicationList () { |
91 | this.syndicationItems = this.videoService.getAccountFeedUrls(this.account.id) | |
92 | } | |
93 | } |