2017-11-27 14:40:16 +01:00
|
|
|
import { Field } from '../../../models/Field';
|
2017-12-06 12:39:49 +01:00
|
|
|
import { Component, OnInit, Input, Output, EventEmitter, forwardRef, ViewEncapsulation } from '@angular/core';
|
2017-11-27 14:40:16 +01:00
|
|
|
import { ControlValueAccessor, FormControl, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms';
|
2018-05-14 08:44:35 +02:00
|
|
|
import { DatasetProfileService } from '../../../services/dataset-profile.service';
|
2018-03-08 11:54:56 +01:00
|
|
|
import { ActivatedRoute } from '@angular/router';
|
2018-05-14 08:44:35 +02:00
|
|
|
import { AutoCompleteConfiguration } from '../../../shared/components/autocomplete/AutoCompleteConfiguration';
|
|
|
|
import { RequestItem } from '../../../models/criteria/RequestItem';
|
|
|
|
import { BaseCriteria } from '../../../models/criteria/BaseCriteria';
|
2018-06-27 12:29:21 +02:00
|
|
|
import { AutocompleteLookupItem } from '../../../models/auto-complete/AutocompleteLookupItem';
|
2017-11-27 14:40:16 +01:00
|
|
|
declare var $: any;
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'df-autocomplete',
|
|
|
|
templateUrl: './autocomplete-remote.component.html',
|
2017-12-06 12:39:49 +01:00
|
|
|
styleUrls: ['./autocomplete-remote.component.css'],
|
2018-03-08 11:54:56 +01:00
|
|
|
encapsulation: ViewEncapsulation.None,
|
2017-11-27 14:40:16 +01:00
|
|
|
})
|
|
|
|
export class AutocompleteRemoteComponent implements OnInit/* , ControlValueAccessor */ {
|
|
|
|
|
|
|
|
|
|
|
|
@Input() field: Field;
|
2018-03-28 15:24:47 +02:00
|
|
|
@Input() disabled = false
|
2017-11-27 14:40:16 +01:00
|
|
|
@Input() form: FormGroup;
|
|
|
|
|
2018-07-11 15:47:36 +02:00
|
|
|
public autoCompleteConfiguration: AutoCompleteConfiguration;
|
|
|
|
public loading: boolean;
|
|
|
|
public datasetId;
|
|
|
|
public values: any[] = new Array();
|
|
|
|
public typeaheadMS: number = 1400;
|
2017-12-06 12:39:49 +01:00
|
|
|
|
2018-03-08 11:54:56 +01:00
|
|
|
constructor(private datasetProfileService: DatasetProfileService, route: ActivatedRoute) {
|
|
|
|
this.datasetId = route.snapshot.params['id'];
|
2017-11-27 14:40:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
2018-05-14 08:44:35 +02:00
|
|
|
let 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);
|
2017-11-27 14:40:16 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-14 08:44:35 +02:00
|
|
|
displayWith(item: any) {
|
|
|
|
if (!item) return null;
|
|
|
|
if (typeof item === 'string') item = this.transform(item);
|
|
|
|
return item["label"];
|
2017-11-27 14:40:16 +01:00
|
|
|
}
|
|
|
|
|
2018-05-14 08:44:35 +02:00
|
|
|
assign(item: any) {
|
|
|
|
if (!item) return null;
|
|
|
|
return this.transform(item);
|
2017-11-27 14:40:16 +01:00
|
|
|
}
|
|
|
|
|
2018-05-14 08:44:35 +02:00
|
|
|
transform(item: any) {
|
|
|
|
if (typeof item === 'string') return JSON.parse(item)
|
|
|
|
else return JSON.stringify(item);
|
2017-11-27 14:40:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|