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