aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-forms/select-options.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-options.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-options.component.ts')
-rw-r--r--client/src/app/shared/shared-forms/select-options.component.ts47
1 files changed, 47 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-forms/select-options.component.ts b/client/src/app/shared/shared-forms/select-options.component.ts
new file mode 100644
index 000000000..09f7df53b
--- /dev/null
+++ b/client/src/app/shared/shared-forms/select-options.component.ts
@@ -0,0 +1,47 @@
1import { Component, Input, forwardRef } from '@angular/core'
2import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms'
3
4export type SelectOptionsItem = { id: number | string, label: string, description?: string }
5
6@Component({
7 selector: 'my-select-options',
8 styleUrls: [ './select-shared.component.scss' ],
9 templateUrl: './select-options.component.html',
10 providers: [
11 {
12 provide: NG_VALUE_ACCESSOR,
13 useExisting: forwardRef(() => SelectOptionsComponent),
14 multi: true
15 }
16 ]
17})
18export class SelectOptionsComponent implements ControlValueAccessor {
19 @Input() items: SelectOptionsItem[] = []
20 @Input() clearable = false
21 @Input() searchable = false
22 @Input() bindValue = 'id'
23 @Input() groupBy: string
24
25 selectedId: number | string
26
27 // ng-select options
28 bindLabel = 'label'
29
30 propagateChange = (_: any) => { /* empty */ }
31
32 writeValue (id: number | string) {
33 this.selectedId = id
34 }
35
36 registerOnChange (fn: (_: any) => void) {
37 this.propagateChange = fn
38 }
39
40 registerOnTouched () {
41 // Unused
42 }
43
44 onModelChange () {
45 this.propagateChange(this.selectedId)
46 }
47}