import { map, distinctUntilChanged, debounceTime, tap } from "rxjs/operators";
import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { Observable, Subject } from "rxjs";
import { Resource, Link, MultiSelectAction } from "../../../components/hal/hal";
import { Result, ResultResource } from "../../interfaces/list.interfaces";
import { ProgressbarService } from "../../../components/progressbar/progressbar.service";
declare var $;
export interface mpValuesResource {
total?: number;
count?: number;
_embedded?: {
values: availableValues[];
};
_links?: {
custom: Link;
};
}
export interface availableValues {
key: string;
value?: string;
}
@Injectable()
export class IMarketListService {
public results: Result[];
private inputLinkEvent = new Subject<String>();
private inputLinkEventObservable = this.inputLinkEvent.asObservable();
constructor(
public authHttp: HttpClient,
public _progressbarService: ProgressbarService
) {}
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();
}
return res;
},
(err) => {
if (showProgressBar) {
this._progressbarService.requestFinished();
}
}
),
map((res) => {
return <ResultResource>res;
})
);
}
getTemplatedFilteredResultsIndex(id, inputurl): Observable<ResultResource> {
return this.authHttp.get(inputurl, {}).pipe(
debounceTime(400),
distinctUntilChanged(),
map((res) => {
let results = <ResultResource>res;
results["id"] = id;
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);
}
getAttributeValues(inputurl): Observable<any> {
return this.authHttp.get(inputurl, {}).pipe(
debounceTime(400),
distinctUntilChanged(),
map((res) => <any>res)
);
}
}