diff options
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.ts | 25 |
1 files changed, 12 insertions, 13 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 index 1d91d59bc..40a7c53bb 100644 --- a/client/src/app/shared/shared-forms/select/select-channel.component.ts +++ b/client/src/app/shared/shared-forms/select/select-channel.component.ts | |||
@@ -1,13 +1,7 @@ | |||
1 | import { Component, forwardRef, Input } from '@angular/core' | 1 | import { Component, forwardRef, Input, OnChanges } from '@angular/core' |
2 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms' | 2 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms' |
3 | import { VideoChannel } from '@app/shared/shared-main' | 3 | import { VideoChannel } from '@app/shared/shared-main' |
4 | 4 | import { SelectChannelItem } from '../../../../types/select-options-item.model' | |
5 | export type SelectChannelItem = { | ||
6 | id: number | ||
7 | label: string | ||
8 | support: string | ||
9 | avatarPath?: string | ||
10 | } | ||
11 | 5 | ||
12 | @Component({ | 6 | @Component({ |
13 | selector: 'my-select-channel', | 7 | selector: 'my-select-channel', |
@@ -21,9 +15,10 @@ export type SelectChannelItem = { | |||
21 | } | 15 | } |
22 | ] | 16 | ] |
23 | }) | 17 | }) |
24 | export class SelectChannelComponent implements ControlValueAccessor { | 18 | export class SelectChannelComponent implements ControlValueAccessor, OnChanges { |
25 | @Input() items: SelectChannelItem[] = [] | 19 | @Input() items: SelectChannelItem[] = [] |
26 | 20 | ||
21 | channels: SelectChannelItem[] = [] | ||
27 | selectedId: number | 22 | selectedId: number |
28 | 23 | ||
29 | // ng-select options | 24 | // ng-select options |
@@ -32,10 +27,14 @@ export class SelectChannelComponent implements ControlValueAccessor { | |||
32 | clearable = false | 27 | clearable = false |
33 | searchable = false | 28 | searchable = false |
34 | 29 | ||
35 | get channels () { | 30 | ngOnChanges () { |
36 | return this.items.map(c => Object.assign(c, { | 31 | this.channels = this.items.map(c => { |
37 | avatarPath: c.avatarPath ? c.avatarPath : VideoChannel.GET_DEFAULT_AVATAR_URL() | 32 | const avatarPath = c.avatarPath |
38 | })) | 33 | ? c.avatarPath |
34 | : VideoChannel.GET_DEFAULT_AVATAR_URL() | ||
35 | |||
36 | return Object.assign({}, c, { avatarPath }) | ||
37 | }) | ||
39 | } | 38 | } |
40 | 39 | ||
41 | propagateChange = (_: any) => { /* empty */ } | 40 | propagateChange = (_: any) => { /* empty */ } |