/
advanced-search-params.service.ts
53 lines (43 loc) · 1.35 KB
/
advanced-search-params.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
/*
* represents the parameters of an advanced search.
*/
export class AdvancedSearchParams {
/**
*
* @param generateGravsearch a function that generates a Gravsearch query.
*
* The function takes the offset
* as a parameter and returns a Gravsearch query string.
* Returns false if not set correctly (init state).
*/
constructor(public generateGravsearch: (offset: number) => string | boolean) {
}
}
@Injectable({
providedIn: 'root'
})
export class AdvancedSearchParamsService {
private _currentSearchParams;
constructor() {
// init with a dummy function that returns false
// if the application is reloaded, this will be returned
this._currentSearchParams = new BehaviorSubject<AdvancedSearchParams>(new AdvancedSearchParams((offset: number) => false));
}
/**
* updates the parameters of an advanced search.
*
* @param searchParams new advanced search params.
*/
changeSearchParamsMsg(searchParams: AdvancedSearchParams): void {
this._currentSearchParams.next(searchParams);
}
/**
* gets the search params of an advanced search.
*
*/
getSearchParams(): AdvancedSearchParams {
return this._currentSearchParams.getValue();
}
}