aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-forms/select-channel.component.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-08-05 00:50:07 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-08-11 09:03:39 +0200
commit02c01341f4dae30ec6b81fcb644952393d73c4a8 (patch)
treeaca3f2b118bb123457fd38724be68fe877504c75 /client/src/app/shared/shared-forms/select-channel.component.ts
parent766d13b4470de02d3d7bec94188260b89a356399 (diff)
downloadPeerTube-02c01341f4dae30ec6b81fcb644952393d73c4a8.tar.gz
PeerTube-02c01341f4dae30ec6b81fcb644952393d73c4a8.tar.zst
PeerTube-02c01341f4dae30ec6b81fcb644952393d73c4a8.zip
add ng-select for templatable select options
- create select-tags component to replace ngx-chips - create select-options to factorize option selection in forms - create select-channel to simplify channel selection - refactor tags validation
Diffstat (limited to 'client/src/app/shared/shared-forms/select-channel.component.ts')
-rw-r--r--client/src/app/shared/shared-forms/select-channel.component.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-forms/select-channel.component.ts b/client/src/app/shared/shared-forms/select-channel.component.ts
new file mode 100644
index 000000000..de98c8c0a
--- /dev/null
+++ b/client/src/app/shared/shared-forms/select-channel.component.ts
@@ -0,0 +1,51 @@
1import { Component, Input, forwardRef, ViewChild } from '@angular/core'
2import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms'
3import { Actor } from '../shared-main'
4
5@Component({
6 selector: 'my-select-channel',
7 styleUrls: [ './select-shared.component.scss' ],
8 templateUrl: './select-channel.component.html',
9 providers: [
10 {
11 provide: NG_VALUE_ACCESSOR,
12 useExisting: forwardRef(() => SelectChannelComponent),
13 multi: true
14 }
15 ]
16})
17export class SelectChannelComponent implements ControlValueAccessor {
18 @Input() items: { id: number, label: string, support: string, avatarPath?: string }[] = []
19
20 selectedId: number
21
22 // ng-select options
23 bindLabel = 'label'
24 bindValue = 'id'
25 clearable = false
26 searchable = false
27
28 get channels () {
29 return this.items.map(c => Object.assign(c, {
30 avatarPath: c.avatarPath ? c.avatarPath : Actor.GET_DEFAULT_AVATAR_URL()
31 }))
32 }
33
34 propagateChange = (_: any) => { /* empty */ }
35
36 writeValue (id: number) {
37 this.selectedId = id
38 }
39
40 registerOnChange (fn: (_: any) => void) {
41 this.propagateChange = fn
42 }
43
44 registerOnTouched () {
45 // Unused
46 }
47
48 onModelChange () {
49 this.propagateChange(this.selectedId)
50 }
51}