]>
Commit | Line | Data |
---|---|---|
21e493d4 | 1 | import { Component, forwardRef, Input, OnChanges } from '@angular/core' |
9abd170d | 2 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms' |
c418d483 | 3 | import { VideoChannel } from '@app/shared/shared-main' |
21e493d4 | 4 | import { SelectChannelItem } from '../../../../types/select-options-item.model' |
9abd170d | 5 | |
02c01341 RK |
6 | @Component({ |
7 | selector: 'my-select-channel', | |
8 | styleUrls: [ './select-shared.component.scss' ], | |
9 | templateUrl: './select-channel.component.html', | |
10 | providers: [ | |
11 | { | |
12 | provide: NG_VALUE_ACCESSOR, | |
13 | useExisting: forwardRef(() => SelectChannelComponent), | |
14 | multi: true | |
15 | } | |
16 | ] | |
17 | }) | |
21e493d4 | 18 | export class SelectChannelComponent implements ControlValueAccessor, OnChanges { |
9abd170d | 19 | @Input() items: SelectChannelItem[] = [] |
02c01341 | 20 | |
21e493d4 | 21 | channels: SelectChannelItem[] = [] |
02c01341 RK |
22 | selectedId: number |
23 | ||
24 | // ng-select options | |
25 | bindLabel = 'label' | |
26 | bindValue = 'id' | |
27 | clearable = false | |
28 | searchable = false | |
29 | ||
21e493d4 C |
30 | ngOnChanges () { |
31 | this.channels = this.items.map(c => { | |
32 | const avatarPath = c.avatarPath | |
33 | ? c.avatarPath | |
34 | : VideoChannel.GET_DEFAULT_AVATAR_URL() | |
35 | ||
36 | return Object.assign({}, c, { avatarPath }) | |
37 | }) | |
02c01341 RK |
38 | } |
39 | ||
40 | propagateChange = (_: any) => { /* empty */ } | |
41 | ||
42 | writeValue (id: number) { | |
43 | this.selectedId = id | |
44 | } | |
45 | ||
46 | registerOnChange (fn: (_: any) => void) { | |
47 | this.propagateChange = fn | |
48 | } | |
49 | ||
50 | registerOnTouched () { | |
51 | // Unused | |
52 | } | |
53 | ||
54 | onModelChange () { | |
55 | this.propagateChange(this.selectedId) | |
56 | } | |
57 | } |