File

src/app/shared/widgets/list/list.service.ts

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(authHttp: HttpClient, _progressbarService: ProgressbarService, _localStorageService: LocalStorageService)
Parameters :
Name Type Optional
authHttp HttpClient no
_progressbarService ProgressbarService no
_localStorageService LocalStorageService no

Methods

getActions
getActions(inputurl: )
Parameters :
Name Optional
inputurl no
Returns : Observable<any>
Public getInputLink
getInputLink()
Returns : Observable<String>
getTemplatedFilteredResults
getTemplatedFilteredResults(inputurl: , showProgressBar: boolean)
Parameters :
Name Type Optional Default value
inputurl no
showProgressBar boolean no true
getTemplatedFilteredResultsIndex
getTemplatedFilteredResultsIndex(id: , inputurl: )
Parameters :
Name Optional
id no
inputurl no
Public setInputLink
setInputLink(data: )
Parameters :
Name Optional
data no
Returns : void

Properties

Private _data
_data: BehaviorSubject<any[]>
Type : BehaviorSubject<any[]>
Public _localStorageService
_localStorageService: LocalStorageService
Type : LocalStorageService
Public _progressbarService
_progressbarService: ProgressbarService
Type : ProgressbarService
Public authHttp
authHttp: HttpClient
Type : HttpClient
Public data
data: BehaviorSubject<any[]>
Type : BehaviorSubject<any[]>
Private inputLinkEvent
inputLinkEvent:
Default value : new Subject<String>()
Private inputLinkEventObservable
inputLinkEventObservable:
Default value : this.inputLinkEvent.asObservable()
Private localStorageEntry
localStorageEntry: LocalStorageEntry
Type : LocalStorageEntry
Public results
results: Result[]
Type : Result[]
Public total
total: number
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);
  }
}

results matching ""

    No results matching ""