]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts
Factorize rest-table and fix/simplify SQL
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-ownership / my-account-ownership.component.ts
CommitLineData
74d63469 1import { Component, OnInit, ViewChild } from '@angular/core'
f8b2c1b4 2import { Notifier } from '@app/core'
74d63469 3import { RestPagination, RestTable } from '@app/shared'
f77eb73b 4import { SortMeta } from 'primeng/api'
74d63469
GR
5import { VideoChangeOwnership } from '../../../../../shared'
6import { VideoOwnershipService } from '@app/shared/video-ownership'
7import { Account } from '@app/shared/account/account.model'
f8b2c1b4 8import { MyAccountAcceptOwnershipComponent } from './my-account-accept-ownership/my-account-accept-ownership.component'
74d63469
GR
9
10@Component({
11 selector: 'my-account-ownership',
12 templateUrl: './my-account-ownership.component.html'
13})
14export class MyAccountOwnershipComponent extends RestTable implements OnInit {
15 videoChangeOwnerships: VideoChangeOwnership[] = []
16 totalRecords = 0
74d63469
GR
17 sort: SortMeta = { field: 'createdAt', order: -1 }
18 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
19
f36da21e 20 @ViewChild('myAccountAcceptOwnershipComponent', { static: true }) myAccountAcceptOwnershipComponent: MyAccountAcceptOwnershipComponent
74d63469
GR
21
22 constructor (
f8b2c1b4
C
23 private notifier: Notifier,
24 private videoOwnershipService: VideoOwnershipService
74d63469
GR
25 ) {
26 super()
27 }
28
29 ngOnInit () {
24b9417c 30 this.initialize()
74d63469
GR
31 }
32
8e11a1b3
C
33 getIdentifier () {
34 return 'MyAccountOwnershipComponent'
35 }
36
74d63469
GR
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(),
f8b2c1b4 53 err => this.notifier.error(err.message)
74d63469
GR
54 )
55 }
dffd5d12
B
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
f8b2c1b4 65 err => this.notifier.error(err.message)
dffd5d12
B
66 )
67 }
74d63469 68}