]>
Commit | Line | Data |
---|---|---|
0626e7af C |
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' | |
0626e7af C |
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' | |
0bf1f265 | 12 | import { tap } from 'rxjs/operators' |
0626e7af C |
13 | |
14 | @Component({ | |
15 | selector: 'my-account-videos', | |
16 | templateUrl: '../../shared/video/abstract-video-list.html', | |
17 | styleUrls: [ | |
18 | '../../shared/video/abstract-video-list.scss', | |
19 | './account-videos.component.scss' | |
20 | ] | |
21 | }) | |
22 | export class AccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy { | |
23 | titlePage = 'Published videos' | |
24 | marginContent = false // Disable margin | |
25 | currentRoute = '/account/videos' | |
26 | loadOnInit = false | |
27 | ||
28 | private account: Account | |
29 | ||
30 | constructor ( | |
31 | protected router: Router, | |
32 | protected route: ActivatedRoute, | |
33 | protected authService: AuthService, | |
34 | protected notificationsService: NotificationsService, | |
35 | protected confirmService: ConfirmService, | |
36 | protected location: Location, | |
37 | private accountService: AccountService, | |
38 | private videoService: VideoService | |
39 | ) { | |
40 | super() | |
41 | } | |
42 | ||
43 | ngOnInit () { | |
44 | super.ngOnInit() | |
45 | ||
46 | // Parent get the account for us | |
47 | this.accountService.accountLoaded | |
48 | .subscribe(account => { | |
49 | this.account = account | |
50 | this.currentRoute = '/account/' + this.account.id + '/videos' | |
51 | ||
52 | this.loadMoreVideos(this.pagination.currentPage) | |
53 | this.generateSyndicationList() | |
54 | }) | |
55 | } | |
56 | ||
57 | ngOnDestroy () { | |
58 | super.ngOnDestroy() | |
59 | } | |
60 | ||
61 | getVideosObservable (page: number) { | |
62 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
63 | ||
0bf1f265 C |
64 | return this.videoService |
65 | .getAccountVideos(this.account, newPagination, this.sort) | |
66 | .pipe(tap(({ totalVideos }) => this.titlePage = `Published ${totalVideos} videos`)) | |
0626e7af C |
67 | } |
68 | ||
69 | generateSyndicationList () { | |
70 | this.syndicationItems = this.videoService.getAccountFeedUrls(this.account.id) | |
71 | } | |
72 | } |