diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-23 14:10:17 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-23 16:00:49 +0200 |
commit | 67ed6552b831df66713bac9e672738796128d33f (patch) | |
tree | 59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/shared/shared-moderation/account-blocklist.component.ts | |
parent | 0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff) | |
download | PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip |
Reorganize client shared modules
Diffstat (limited to 'client/src/app/shared/shared-moderation/account-blocklist.component.ts')
-rw-r--r-- | client/src/app/shared/shared-moderation/account-blocklist.component.ts | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-moderation/account-blocklist.component.ts b/client/src/app/shared/shared-moderation/account-blocklist.component.ts new file mode 100644 index 000000000..38e0d0424 --- /dev/null +++ b/client/src/app/shared/shared-moderation/account-blocklist.component.ts | |||
@@ -0,0 +1,78 @@ | |||
1 | import { SortMeta } from 'primeng/api' | ||
2 | import { OnInit } from '@angular/core' | ||
3 | import { Notifier, RestPagination, RestTable } from '@app/core' | ||
4 | import { Actor } from '@app/shared/shared-main' | ||
5 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
6 | import { AccountBlock } from './account-block.model' | ||
7 | import { BlocklistComponentType, BlocklistService } from './blocklist.service' | ||
8 | |||
9 | export class GenericAccountBlocklistComponent extends RestTable implements OnInit { | ||
10 | // @ts-ignore: "Abstract methods can only appear within an abstract class" | ||
11 | abstract mode: BlocklistComponentType | ||
12 | |||
13 | blockedAccounts: AccountBlock[] = [] | ||
14 | totalRecords = 0 | ||
15 | sort: SortMeta = { field: 'createdAt', order: -1 } | ||
16 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | ||
17 | |||
18 | constructor ( | ||
19 | private notifier: Notifier, | ||
20 | private blocklistService: BlocklistService, | ||
21 | private i18n: I18n | ||
22 | ) { | ||
23 | super() | ||
24 | } | ||
25 | |||
26 | // @ts-ignore: "Abstract methods can only appear within an abstract class" | ||
27 | abstract getIdentifier (): string | ||
28 | |||
29 | ngOnInit () { | ||
30 | this.initialize() | ||
31 | } | ||
32 | |||
33 | switchToDefaultAvatar ($event: Event) { | ||
34 | ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL() | ||
35 | } | ||
36 | |||
37 | unblockAccount (accountBlock: AccountBlock) { | ||
38 | const blockedAccount = accountBlock.blockedAccount | ||
39 | const operation = this.mode === BlocklistComponentType.Account | ||
40 | ? this.blocklistService.unblockAccountByUser(blockedAccount) | ||
41 | : this.blocklistService.unblockAccountByInstance(blockedAccount) | ||
42 | |||
43 | operation.subscribe( | ||
44 | () => { | ||
45 | this.notifier.success( | ||
46 | this.mode === BlocklistComponentType.Account | ||
47 | ? this.i18n('Account {{nameWithHost}} unmuted.', { nameWithHost: blockedAccount.nameWithHost }) | ||
48 | : this.i18n('Account {{nameWithHost}} unmuted by your instance.', { nameWithHost: blockedAccount.nameWithHost }) | ||
49 | ) | ||
50 | |||
51 | this.loadData() | ||
52 | } | ||
53 | ) | ||
54 | } | ||
55 | |||
56 | protected loadData () { | ||
57 | const operation = this.mode === BlocklistComponentType.Account | ||
58 | ? this.blocklistService.getUserAccountBlocklist({ | ||
59 | pagination: this.pagination, | ||
60 | sort: this.sort, | ||
61 | search: this.search | ||
62 | }) | ||
63 | : this.blocklistService.getInstanceAccountBlocklist({ | ||
64 | pagination: this.pagination, | ||
65 | sort: this.sort, | ||
66 | search: this.search | ||
67 | }) | ||
68 | |||
69 | return operation.subscribe( | ||
70 | resultList => { | ||
71 | this.blockedAccounts = resultList.data | ||
72 | this.totalRecords = resultList.total | ||
73 | }, | ||
74 | |||
75 | err => this.notifier.error(err.message) | ||
76 | ) | ||
77 | } | ||
78 | } | ||