mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-05-01 11:19:32 -05:00
59 lines
1.2 KiB
TypeScript
59 lines
1.2 KiB
TypeScript
import { Component, EventEmitter, forwardRef, Input, Output } from '@angular/core';
|
|
import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
import { AbstractInputComponent } from '../abstract-input';
|
|
|
|
@Component({
|
|
providers: [{
|
|
provide: NG_VALUE_ACCESSOR,
|
|
useExisting: forwardRef(() => SelectComponent),
|
|
multi: true
|
|
}],
|
|
selector: 'app-input-select',
|
|
templateUrl: './select.component.html',
|
|
styleUrls: ['./select.component.scss']
|
|
})
|
|
export class SelectComponent extends AbstractInputComponent<number> {
|
|
|
|
constructor() {
|
|
super()
|
|
this.addItemRef = this.addItem.bind(this)
|
|
}
|
|
|
|
@Input()
|
|
items: any[]
|
|
|
|
@Input()
|
|
textColor: any
|
|
|
|
@Input()
|
|
backgroundColor: any
|
|
|
|
@Input()
|
|
allowNull: boolean = false
|
|
|
|
@Input()
|
|
suggestions: number[]
|
|
|
|
@Output()
|
|
createNew = new EventEmitter<string>()
|
|
|
|
public addItemRef: (name) => void
|
|
|
|
get allowCreateNew(): boolean {
|
|
return this.createNew.observers.length > 0
|
|
}
|
|
|
|
getSuggestions() {
|
|
if (this.suggestions && this.items) {
|
|
return this.suggestions.filter(id => id != this.value).map(id => this.items.find(item => item.id == id))
|
|
} else {
|
|
return []
|
|
}
|
|
}
|
|
|
|
addItem(name: string) {
|
|
this.createNew.next(name)
|
|
}
|
|
|
|
}
|