allow limiting video-comments rss feeds to an account or video channel
[oweals/peertube.git] / client / src / app / +my-account / my-account-ownership / my-account-ownership.component.ts
1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit, ViewChild } from '@angular/core'
3 import { Notifier, RestPagination, RestTable } from '@app/core'
4 import { Account, VideoOwnershipService } from '@app/shared/shared-main'
5 import { VideoChangeOwnership } from '@shared/models'
6 import { MyAccountAcceptOwnershipComponent } from './my-account-accept-ownership/my-account-accept-ownership.component'
7
8 @Component({
9   selector: 'my-account-ownership',
10   templateUrl: './my-account-ownership.component.html'
11 })
12 export class MyAccountOwnershipComponent extends RestTable implements OnInit {
13   videoChangeOwnerships: VideoChangeOwnership[] = []
14   totalRecords = 0
15   sort: SortMeta = { field: 'createdAt', order: -1 }
16   pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
17
18   @ViewChild('myAccountAcceptOwnershipComponent', { static: true }) myAccountAcceptOwnershipComponent: MyAccountAcceptOwnershipComponent
19
20   constructor (
21     private notifier: Notifier,
22     private videoOwnershipService: VideoOwnershipService
23   ) {
24     super()
25   }
26
27   ngOnInit () {
28     this.initialize()
29   }
30
31   getIdentifier () {
32     return 'MyAccountOwnershipComponent'
33   }
34
35   createByString (account: Account) {
36     return Account.CREATE_BY_STRING(account.name, account.host)
37   }
38
39   openAcceptModal (videoChangeOwnership: VideoChangeOwnership) {
40     this.myAccountAcceptOwnershipComponent.show(videoChangeOwnership)
41   }
42
43   accepted () {
44     this.loadData()
45   }
46
47   refuse (videoChangeOwnership: VideoChangeOwnership) {
48     this.videoOwnershipService.refuseOwnership(videoChangeOwnership.id)
49       .subscribe(
50         () => this.loadData(),
51         err => this.notifier.error(err.message)
52       )
53   }
54
55   protected loadData () {
56     return this.videoOwnershipService.getOwnershipChanges(this.pagination, this.sort)
57       .subscribe(
58         resultList => {
59           this.videoChangeOwnerships = resultList.data
60           this.totalRecords = resultList.total
61         },
62
63         err => this.notifier.error(err.message)
64       )
65   }
66 }