54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { Component, Input, OnInit } from '@angular/core';
|
|
import { FormGroup } from '@angular/forms';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
|
|
@Component({
|
|
selector: 'app-form-autocomplete',
|
|
templateUrl: './autocomplete-remote.component.html',
|
|
styleUrls: ['./autocomplete-remote.component.css']
|
|
})
|
|
export class AutocompleteRemoteComponent implements OnInit/* , ControlValueAccessor */ {
|
|
|
|
|
|
@Input() field: Field;
|
|
@Input() disabled = false;
|
|
@Input() form: FormGroup;
|
|
|
|
public autoCompleteConfiguration: AutoCompleteConfiguration;
|
|
public loading: boolean;
|
|
public datasetId;
|
|
public values: any[] = new Array();
|
|
public typeaheadMS = 1400;
|
|
|
|
constructor(private datasetProfileService: DatasetProfileService, route: ActivatedRoute) {
|
|
this.datasetId = route.snapshot.params['id'];
|
|
}
|
|
|
|
|
|
ngOnInit() {
|
|
const autocompleteRequestItem: RequestItem<AutocompleteLookupItem> = new RequestItem();
|
|
autocompleteRequestItem.criteria = new AutocompleteLookupItem();
|
|
autocompleteRequestItem.criteria.fieldID = this.field.id;
|
|
autocompleteRequestItem.criteria.profileID = this.datasetId;
|
|
this.autoCompleteConfiguration = new AutoCompleteConfiguration(this.datasetProfileService.queryAutocomplete.bind(this.datasetProfileService), autocompleteRequestItem);
|
|
|
|
}
|
|
|
|
displayWith(item: any) {
|
|
if (!item) { return null; }
|
|
if (typeof item === 'string') { item = this.transform(item); }
|
|
return item['label'];
|
|
}
|
|
|
|
assign(item: any) {
|
|
if (!item) { return null; }
|
|
return this.transform(item);
|
|
}
|
|
|
|
transform(item: any) {
|
|
if (typeof item === 'string') { return JSON.parse(item); } else { return JSON.stringify(item); }
|
|
}
|
|
}
|
|
|