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