File

src/app/shared/widgets/apps/my-shop-md/shop-category/shop-category.service.ts

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

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

Methods

Public cleanSubjects
cleanSubjects()
Returns : void
getCategories
getCategories(childUrl: string)
Parameters :
Name Type Optional
childUrl string no
Private getContext
getContext(identifier: )
Parameters :
Name Optional
identifier no
Public getCurrentDimensionUri
getCurrentDimensionUri(identifier: )
Parameters :
Name Optional
identifier no
Returns : string
Public getOrderedResults
getOrderedResults(identifier: string)
Parameters :
Name Type Optional
identifier string no
Returns : ReplaySubject<any>
getRootCategories
getRootCategories(url: )
Parameters :
Name Optional
url no
Public loadOrderedResults
loadOrderedResults(inputurl: )
Parameters :
Name Optional
inputurl no
Returns : any
Public setCurrentDimensionUri
setCurrentDimensionUri(identifier: , data: )
Parameters :
Name Optional
identifier no
data no
Returns : void
Public setOrderedResults
setOrderedResults(identifier: , data: )
Parameters :
Name Optional
identifier no
data no
Returns : void

Properties

Public _progressbarService
_progressbarService: ProgressbarService
Type : ProgressbarService
Private _selectedCategory
_selectedCategory: ShopCategory
Type : ShopCategory
Public authHttp
authHttp: HttpClient
Type : HttpClient
Private contexts
contexts: literal type
Type : literal type
Default value : {}
import { tap, map } from "rxjs/operators";
import { Injectable } from "@angular/core";
import { Observable, ReplaySubject } from "rxjs";
import { HttpClient } from "@angular/common/http";
import { ShopCategory } from "./shop-category";
import { ProgressbarService } from "../../../../components/progressbar/progressbar.service";
import { Link } from "../../../../components/hal/hal";

interface ShopCategoryContext {
  results: ReplaySubject<any>;
  dimensionUri?: string;
}

export interface ShopCategoryResource {
  _embedded: {
    categories: ShopCategory[];
  };
  _links?: {
    children: Link;
    [idx: string]: Link | Link[];
  };
}

@Injectable()
export class ShopCategoryService {
  private _selectedCategory: ShopCategory;

  private contexts: { [key: string]: ShopCategoryContext } = {};
  constructor(
    public authHttp: HttpClient,
    public _progressbarService: ProgressbarService
  ) {}

  public getOrderedResults(identifier: string): ReplaySubject<any> {
    return this.getContext(identifier).results;
  }

  private getContext(identifier): ShopCategoryContext {
    if (this.contexts[identifier]) {
      return this.contexts[identifier];
    }
    const context = {
      results: new ReplaySubject<any>(),
    };
    this.contexts[identifier] = context;
    return context;
  }

  // Clears the map of subjects. Should get called whenever an app using shop-categories is disposed
  public cleanSubjects() {
    this.contexts = {};
  }

  public setOrderedResults(identifier, data) {
    this.getContext(identifier).results.next(data);
  }

  public getCurrentDimensionUri(identifier): string {
    return this.getContext(identifier).dimensionUri;
  }

  public setCurrentDimensionUri(identifier, data) {
    this.getContext(identifier).dimensionUri = data;
  }

  public loadOrderedResults(inputurl) {
    this._progressbarService.addRequest();
    return this.authHttp.get(inputurl, {}).pipe(
      tap(
        (data) => this._progressbarService.requestFinished(),
        (err) => {
          this._progressbarService.requestFinished();
        }
      )
    );
  }

  getRootCategories(url): Observable<ShopCategoryResource> {
    this._progressbarService.addRequest();
    return this.authHttp.get(url).pipe(
      map((res) => <any>res),
      tap(
        (data) => this._progressbarService.requestFinished(),
        (err) => this._progressbarService.requestFinished()
      )
    );
  }
  getCategories(childUrl: string): Observable<ShopCategoryResource> {
    this._progressbarService.addRequest();
    return this.authHttp.get(childUrl).pipe(
      map((res) => <any>res),
      tap(
        (data) => this._progressbarService.requestFinished(),
        (err) => this._progressbarService.requestFinished()
      )
    );
  }
}

results matching ""

    No results matching ""