]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-forms/select/select-channel.component.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-forms / select / select-channel.component.ts
CommitLineData
21e493d4 1import { Component, forwardRef, Input, OnChanges } from '@angular/core'
9abd170d 2import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
c418d483 3import { VideoChannel } from '@app/shared/shared-main'
21e493d4 4import { 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 18export 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
d0800f76 34 : VideoChannel.GET_DEFAULT_AVATAR_URL(20)
21e493d4
C
35
36 return Object.assign({}, c, { avatarPath })
37 })
02c01341
RK
38 }
39
40 propagateChange = (_: any) => { /* empty */ }
41
2198bb5a
C
42 writeValue (id: number | string) {
43 this.selectedId = typeof id === 'string'
44 ? parseInt(id, 10)
45 : id
02c01341
RK
46 }
47
48 registerOnChange (fn: (_: any) => void) {
49 this.propagateChange = fn
50 }
51
52 registerOnTouched () {
53 // Unused
54 }
55
56 onModelChange () {
57 this.propagateChange(this.selectedId)
58 }
59}