src/app/shared/widgets/list/list.service.ts
Widget inputs |
Widget outputs |
Properties |
|
Methods |
constructor(authHttp: HttpClient, _progressbarService: ProgressbarService, _localStorageService: LocalStorageService)
|
||||||||||||
Parameters :
|
getActions | ||||
getActions(inputurl: )
|
||||
Parameters :
Returns :
Observable<any>
|
Public getInputLink |
getInputLink()
|
Returns :
Observable<String>
|
getTemplatedFilteredResults | ||||||||||||
getTemplatedFilteredResults(inputurl: , showProgressBar: boolean)
|
||||||||||||
Parameters :
Returns :
Observable<ResultResource>
|
getTemplatedFilteredResultsIndex | ||||||
getTemplatedFilteredResultsIndex(id: , inputurl: )
|
||||||
Parameters :
Returns :
Observable<ResultResource>
|
Public setInputLink | ||||
setInputLink(data: )
|
||||
Parameters :
Returns :
void
|
Private _data |
_data:
|
Type : BehaviorSubject<any[]>
|
Public _localStorageService |
_localStorageService:
|
Type : LocalStorageService
|
Public _progressbarService |
_progressbarService:
|
Type : ProgressbarService
|
Public authHttp |
authHttp:
|
Type : HttpClient
|
Public data |
data:
|
Type : BehaviorSubject<any[]>
|
Private inputLinkEvent |
inputLinkEvent:
|
Default value : new Subject<String>()
|
Private inputLinkEventObservable |
inputLinkEventObservable:
|
Default value : this.inputLinkEvent.asObservable()
|
Private localStorageEntry |
localStorageEntry:
|
Type : LocalStorageEntry
|
Public results |
results:
|
Type : Result[]
|
Public total |
total:
|
Type : number
|
import { debounceTime, distinctUntilChanged, map, tap } from "rxjs/operators";
import { Injectable } from "@angular/core";
import { BehaviorSubject, Observable, Subject } from "rxjs";
import { HttpClient, HttpErrorResponse } from "@angular/common/http";
import { Result, ResultResource } from "../interfaces/list.interfaces";
import { ProgressbarService } from "../../components/progressbar/progressbar.service";
import * as uriTemplates_ from "uri-templates";
import {
LocalStorageService,
LocalStorageEntry,
} from "../../components/local-storage/local-storage.service";
import {
Scope,
DeletionMode,
} from "../../components/local-storage/local-storage-constants";
const uriTemplates = uriTemplates_;
declare var $;
@Injectable()
export class ListService {
public results: Result[];
private inputLinkEvent = new Subject<String>();
private inputLinkEventObservable = this.inputLinkEvent.asObservable();
public data: BehaviorSubject<any[]>;
private _data: BehaviorSubject<any[]>;
public total: number;
private localStorageEntry: LocalStorageEntry;
constructor(
public authHttp: HttpClient,
public _progressbarService: ProgressbarService,
public _localStorageService: LocalStorageService
) {
this._data = new BehaviorSubject([]);
this.data = this._data;
}
getTemplatedFilteredResults(
inputurl,
showProgressBar: boolean = true
): Observable<ResultResource> {
if (showProgressBar) {
this._progressbarService.addRequest();
}
return this.authHttp.get(inputurl, {}).pipe(
debounceTime(400),
distinctUntilChanged(),
tap(
(res) => {
if (showProgressBar) {
this._progressbarService.requestFinished();
}
let autoSearchEntry = this._localStorageService.getLocalStorageEntry(
"autoSearch",
Scope.GLOBAL,
DeletionMode.LOGIN
);
if (autoSearchEntry) {
autoSearchEntry.clear();
}
if (res["level"] && res["level"] === "ERROR") {
let error = {};
error["title"] = res["title"];
error["content"] = res["message"];
error["level"] = res["level"];
throw new HttpErrorResponse({ error: error, status: 200 });
}
return res;
},
(err) => {
if (showProgressBar) {
this._progressbarService.requestFinished();
}
}
),
map((res) => {
return <ResultResource>res;
})
);
}
getTemplatedFilteredResultsIndex(id, inputurl): Observable<ResultResource> {
this._progressbarService.addRequest();
return this.authHttp.get(inputurl, {}).pipe(
debounceTime(400),
distinctUntilChanged(),
map((res) => {
let results = <ResultResource>res;
results["id"] = id;
this._progressbarService.requestFinished();
return results;
})
);
}
getActions(inputurl): Observable<any> {
return this.authHttp.get(inputurl, {}).pipe(
debounceTime(400),
distinctUntilChanged(),
map((res) => <ResultResource>res)
);
}
public getInputLink(): Observable<String> {
return this.inputLinkEventObservable;
}
public setInputLink(data) {
this.inputLinkEvent.next(data);
}
}