diff options
Diffstat (limited to 'client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts')
-rw-r--r-- | client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts b/client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts new file mode 100644 index 000000000..13517b9f4 --- /dev/null +++ b/client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts | |||
@@ -0,0 +1,68 @@ | |||
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.loadSort() | ||
35 | } | ||
36 | |||
37 | protected loadData () { | ||
38 | return this.videoOwnershipService.getOwnershipChanges(this.pagination, this.sort) | ||
39 | .subscribe( | ||
40 | resultList => { | ||
41 | this.videoChangeOwnerships = resultList.data | ||
42 | this.totalRecords = resultList.total | ||
43 | }, | ||
44 | |||
45 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
46 | ) | ||
47 | } | ||
48 | |||
49 | createByString (account: Account) { | ||
50 | return Account.CREATE_BY_STRING(account.name, account.host) | ||
51 | } | ||
52 | |||
53 | openAcceptModal (videoChangeOwnership: VideoChangeOwnership) { | ||
54 | this.myAccountAcceptOwnershipComponent.show(videoChangeOwnership) | ||
55 | } | ||
56 | |||
57 | accepted () { | ||
58 | this.loadData() | ||
59 | } | ||
60 | |||
61 | refuse (videoChangeOwnership: VideoChangeOwnership) { | ||
62 | this.videoOwnershipService.refuseOwnership(videoChangeOwnership.id) | ||
63 | .subscribe( | ||
64 | () => this.loadData(), | ||
65 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
66 | ) | ||
67 | } | ||
68 | } | ||