]>
Commit | Line | Data |
---|---|---|
1 | import { Component, Input, forwardRef, ViewChild } from '@angular/core' | |
2 | import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms' | |
3 | import { 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 | }) | |
17 | export 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 | } |