mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-10 16:46:50 +01:00
add observables to search results
This commit is contained in:
parent
ceaade29a6
commit
57ad485913
1 changed files with 9 additions and 2 deletions
|
|
@ -1,9 +1,11 @@
|
||||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
import { PaperlessDocument } from 'src/app/data/paperless-document';
|
import { PaperlessDocument } from 'src/app/data/paperless-document';
|
||||||
import { SearchResult } from 'src/app/data/search-result';
|
import { SearchResult } from 'src/app/data/search-result';
|
||||||
import { environment } from 'src/environments/environment';
|
import { environment } from 'src/environments/environment';
|
||||||
|
import { DocumentService } from './document.service';
|
||||||
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
|
|
@ -11,14 +13,19 @@ import { environment } from 'src/environments/environment';
|
||||||
})
|
})
|
||||||
export class SearchService {
|
export class SearchService {
|
||||||
|
|
||||||
constructor(private http: HttpClient) { }
|
constructor(private http: HttpClient, private documentService: DocumentService) { }
|
||||||
|
|
||||||
search(query: string, page?: number): Observable<SearchResult> {
|
search(query: string, page?: number): Observable<SearchResult> {
|
||||||
let httpParams = new HttpParams().set('query', query)
|
let httpParams = new HttpParams().set('query', query)
|
||||||
if (page) {
|
if (page) {
|
||||||
httpParams = httpParams.set('page', page.toString())
|
httpParams = httpParams.set('page', page.toString())
|
||||||
}
|
}
|
||||||
return this.http.get<SearchResult>(`${environment.apiBaseUrl}search/`, {params: httpParams})
|
return this.http.get<SearchResult>(`${environment.apiBaseUrl}search/`, {params: httpParams}).pipe(
|
||||||
|
map(result => {
|
||||||
|
result.results.forEach(hit => this.documentService.addObservablesToDocument(hit.document))
|
||||||
|
return result
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
autocomplete(term: string): Observable<string[]> {
|
autocomplete(term: string): Observable<string[]> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue