]>
Commit | Line | Data |
---|---|---|
1 | import { Component, OnDestroy, OnInit } from '@angular/core' | |
2 | import { ActivatedRoute, Router } from '@angular/router' | |
3 | import { Location } from '@angular/common' | |
4 | import { immutableAssign } from '@app/shared/misc/utils' | |
5 | import { NotificationsService } from 'angular2-notifications' | |
6 | import { AuthService } from '../../core/auth' | |
7 | import { ConfirmService } from '../../core/confirm' | |
8 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' | |
9 | import { VideoService } from '../../shared/video/video.service' | |
10 | import { Account } from '@app/shared/account/account.model' | |
11 | import { AccountService } from '@app/shared/account/account.service' | |
12 | import { tap } from 'rxjs/operators' | |
13 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
14 | import { Subscription } from 'rxjs' | |
15 | ||
16 | @Component({ | |
17 | selector: 'my-account-videos', | |
18 | templateUrl: '../../shared/video/abstract-video-list.html', | |
19 | styleUrls: [ | |
20 | '../../shared/video/abstract-video-list.scss', | |
21 | './account-videos.component.scss' | |
22 | ] | |
23 | }) | |
24 | export class AccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy { | |
25 | titlePage: string | |
26 | marginContent = false // Disable margin | |
27 | currentRoute = '/account/videos' | |
28 | loadOnInit = false | |
29 | ||
30 | private account: Account | |
31 | private accountSub: Subscription | |
32 | ||
33 | constructor ( | |
34 | protected router: Router, | |
35 | protected route: ActivatedRoute, | |
36 | protected authService: AuthService, | |
37 | protected notificationsService: NotificationsService, | |
38 | protected confirmService: ConfirmService, | |
39 | protected location: Location, | |
40 | protected i18n: I18n, | |
41 | private accountService: AccountService, | |
42 | private videoService: VideoService | |
43 | ) { | |
44 | super() | |
45 | ||
46 | this.titlePage = this.i18n('Published videos') | |
47 | } | |
48 | ||
49 | ngOnInit () { | |
50 | super.ngOnInit() | |
51 | ||
52 | // Parent get the account for us | |
53 | this.accountSub = this.accountService.accountLoaded | |
54 | .subscribe(account => { | |
55 | this.account = account | |
56 | this.currentRoute = '/account/' + this.account.nameWithHost + '/videos' | |
57 | ||
58 | this.reloadVideos() | |
59 | this.generateSyndicationList() | |
60 | }) | |
61 | } | |
62 | ||
63 | ngOnDestroy () { | |
64 | if (this.accountSub) this.accountSub.unsubscribe() | |
65 | ||
66 | super.ngOnDestroy() | |
67 | } | |
68 | ||
69 | getVideosObservable (page: number) { | |
70 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
71 | ||
72 | return this.videoService | |
73 | .getAccountVideos(this.account, newPagination, this.sort) | |
74 | .pipe( | |
75 | tap(({ totalVideos }) => { | |
76 | this.titlePage = this.i18n('Published {{totalVideos}} videos', { totalVideos }) | |
77 | }) | |
78 | ) | |
79 | } | |
80 | ||
81 | generateSyndicationList () { | |
82 | this.syndicationItems = this.videoService.getAccountFeedUrls(this.account.id) | |
83 | } | |
84 | } |