src/app/shared/widgets/apps/my-shop-md/shop-category/shop-category.service.ts
Widget inputs |
Widget outputs |
Properties |
|
Methods |
|
constructor(authHttp: HttpClient, _progressbarService: ProgressbarService)
|
|||||||||
Parameters :
|
Public cleanSubjects |
cleanSubjects()
|
Returns :
void
|
getCategories | ||||||
getCategories(childUrl: string)
|
||||||
Parameters :
Returns :
Observable<ShopCategoryResource>
|
Private getContext | ||||
getContext(identifier: )
|
||||
Parameters :
Returns :
ShopCategoryContext
|
Public getCurrentDimensionUri | ||||
getCurrentDimensionUri(identifier: )
|
||||
Parameters :
Returns :
string
|
Public getOrderedResults | ||||||
getOrderedResults(identifier: string)
|
||||||
Parameters :
Returns :
ReplaySubject<any>
|
getRootCategories | ||||
getRootCategories(url: )
|
||||
Parameters :
Returns :
Observable<ShopCategoryResource>
|
Public loadOrderedResults | ||||
loadOrderedResults(inputurl: )
|
||||
Parameters :
Returns :
any
|
Public setCurrentDimensionUri | ||||||
setCurrentDimensionUri(identifier: , data: )
|
||||||
Parameters :
Returns :
void
|
Public setOrderedResults | ||||||
setOrderedResults(identifier: , data: )
|
||||||
Parameters :
Returns :
void
|
Public _progressbarService |
_progressbarService:
|
Type : ProgressbarService
|
Private _selectedCategory |
_selectedCategory:
|
Type : ShopCategory
|
Public authHttp |
authHttp:
|
Type : HttpClient
|
Private contexts |
contexts:
|
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()
)
);
}
}