aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-forms/select/select-channel.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-08-11 16:07:53 +0200
committerChocobozzz <me@florianbigard.com>2020-08-11 16:18:42 +0200
commit52c4976fcf4ee255a3af68ff9778e4f5c4f84bd4 (patch)
tree887d2b6106548ad23cf016d82baf1977198027d9 /client/src/app/shared/shared-forms/select/select-channel.component.ts
parent3d25d5de33d8aa0ba00d7514522b25d22bf0e0a1 (diff)
downloadPeerTube-52c4976fcf4ee255a3af68ff9778e4f5c4f84bd4.tar.gz
PeerTube-52c4976fcf4ee255a3af68ff9778e4f5c4f84bd4.tar.zst
PeerTube-52c4976fcf4ee255a3af68ff9778e4f5c4f84bd4.zip
Use ng select for multiselect
Diffstat (limited to 'client/src/app/shared/shared-forms/select/select-channel.component.ts')
-rw-r--r--client/src/app/shared/shared-forms/select/select-channel.component.ts58
1 files changed, 58 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-forms/select/select-channel.component.ts b/client/src/app/shared/shared-forms/select/select-channel.component.ts
new file mode 100644
index 000000000..1b0db9b6f
--- /dev/null
+++ b/client/src/app/shared/shared-forms/select/select-channel.component.ts
@@ -0,0 +1,58 @@
1import { Component, forwardRef, Input } from '@angular/core'
2import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
3import { Actor } from '@app/shared/shared-main/account/actor.model'
4
5export type SelectChannelItem = {
6 id: number
7 label: string
8 support: string
9 avatarPath?: string
10}
11
12@Component({
13 selector: 'my-select-channel',
14 styleUrls: [ './select-shared.component.scss' ],
15 templateUrl: './select-channel.component.html',
16 providers: [
17 {
18 provide: NG_VALUE_ACCESSOR,
19 useExisting: forwardRef(() => SelectChannelComponent),
20 multi: true
21 }
22 ]
23})
24export class SelectChannelComponent implements ControlValueAccessor {
25 @Input() items: SelectChannelItem[] = []
26
27 selectedId: number
28
29 // ng-select options
30 bindLabel = 'label'
31 bindValue = 'id'
32 clearable = false
33 searchable = false
34
35 get channels () {
36 return this.items.map(c => Object.assign(c, {
37 avatarPath: c.avatarPath ? c.avatarPath : Actor.GET_DEFAULT_AVATAR_URL()
38 }))
39 }
40
41 propagateChange = (_: any) => { /* empty */ }
42
43 writeValue (id: number) {
44 this.selectedId = id
45 }
46
47 registerOnChange (fn: (_: any) => void) {
48 this.propagateChange = fn
49 }
50
51 registerOnTouched () {
52 // Unused
53 }
54
55 onModelChange () {
56 this.propagateChange(this.selectedId)
57 }
58}