initial version of the query autocompletion

Missing features at this point:
1. No suggestions when the input gets the focus.
2. Suggestions are not shown after selecting a suggestion.
This commit is contained in:
2019-10-13 10:35:38 +02:00
parent 47d8387fec
commit a3099d4981
9 changed files with 132 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
import { Injectable, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
@@ -11,7 +11,7 @@ export class PlotService {
plotTypes: Array<PlotType>;
tagFields: Array<TagField>;
constructor(private http: HttpClient) {
this.plotTypes = new Array<PlotType>();
this.plotTypes.push(new PlotType(
@@ -55,6 +55,16 @@ export class PlotService {
});
return this.tagFields;
}
autocomplete(query: string, caretIndex: number): Observable<AutocompleteResult>
{
const options = {
params: new HttpParams()
.set('caretIndex', ""+caretIndex)
.set('query', query)
};
return this.http.get<AutocompleteResult>('//'+window.location.hostname+':8080/autocomplete', options);
}
}
@@ -111,3 +121,17 @@ export enum DataType {
Other
}
export class Suggestion {
value: string;
newQuery: string;
newCaretPosition: number;
}
export class AutocompleteResult{
proposals: Array<Suggestion>;
}