nm-product-info-view
src/app/shared/widgets/apps/my-text-edit/product-info-view/product-info-view.component.ts
selector | nm-product-info-view |
styleUrls | product-info-view.component.scss |
templateUrl | ./product-info-view.component.html |
Widget inputs |
Widget outputs |
Properties |
|
Methods |
|
constructor(_widgetframeService: WidgetframeService)
|
||||||
Parameters :
|
Protected configureWidget | ||||||
configureWidget(configuration: WidgetConfig)
|
||||||
Decorators : WidgetConfigure
|
||||||
Parameters :
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
resetWidget |
resetWidget()
|
Returns :
any
|
Public _id |
_id:
|
Decorators : WidgetId
|
Public assetHref |
assetHref:
|
Default value : new ReplaySubject<any>(1)
|
Public cols |
cols:
|
Type : any[]
|
Public configuration |
configuration:
|
Type : WidgetConfig
|
Decorators : WidgetConfiguration
|
Public header |
header:
|
Type : any
|
Public linkDE |
linkDE:
|
Type : string
|
Default value : "http://www.c-and-a.com/de/de/shop/product/"
|
Public linkEU |
linkEU:
|
Type : string
|
Default value : "http://www.c-and-a.com/eu/en/shop/product/"
|
Public product |
product:
|
Type : any
|
Public productNo |
productNo:
|
Default value : new Subject<any>()
|
Decorators : WidgetInput
|
Public productNoForProduct |
productNoForProduct:
|
Default value : new Subject<any>()
|
Decorators : WidgetInput
|
Public reload |
reload:
|
Default value : new BehaviorSubject<any>(1)
|
Decorators : WidgetInput
|
Public resetWidgets |
resetWidgets:
|
Default value : new ReplaySubject<any>()
|
Decorators : WidgetOutput
|
Public selectedUiLocale |
selectedUiLocale:
|
Default value : new Subject<any>()
|
Decorators : WidgetInput
|
Public title |
title:
|
Type : string
|
import {
empty as observableEmpty,
of as observableOf,
combineLatest as observableCombineLatest,
Subject,
ReplaySubject,
BehaviorSubject,
Observable,
} from "rxjs";
import {
distinctUntilChanged,
mergeMap,
map,
switchMap,
catchError,
} from "rxjs/operators";
import { Component } from "@angular/core";
import { WidgetframeService } from "../../../widgetframe/widgetframe.service";
import { WidgetConfig } from "../../../widget.configuration";
import {
WidgetComponent,
WidgetId,
WidgetConfiguration,
WidgetConfigure,
WidgetInput,
WidgetOutput,
} from "../../../widget.metadata";
import * as uriTemplates_ from "uri-templates";
const uriTemplates = uriTemplates_;
declare var $: any;
@WidgetComponent("nm-product-info-view")
@Component({
selector: "nm-product-info-view",
templateUrl: "./product-info-view.component.html",
styleUrls: ["./product-info-view.component.scss"],
})
export class ProductInfoViewWidgetComponent {
public cols: any[];
public header: any;
public product: any;
// public manufacturerImage: any = "";
public assetHref = new ReplaySubject<any>(1);
public title: string;
public linkDE: string = "http://www.c-and-a.com/de/de/shop/product/";
public linkEU: string = "http://www.c-and-a.com/eu/en/shop/product/";
@WidgetId()
public _id;
@WidgetInput()
public productNo = new Subject<any>();
@WidgetOutput()
public resetWidgets = new ReplaySubject<any>();
@WidgetInput()
public productNoForProduct = new Subject<any>();
@WidgetInput()
public selectedUiLocale = new Subject<any>();
@WidgetInput()
public reload = new BehaviorSubject<any>(1);
@WidgetConfiguration()
public configuration: WidgetConfig;
constructor(private _widgetframeService: WidgetframeService) {
this.header = null;
this.product = [];
}
@WidgetConfigure()
protected configureWidget(configuration: WidgetConfig) {
this.title = this.configuration.configuration["title"];
this.linkEU = this.configuration.configuration["shop-link-eu"];
this.linkDE = this.configuration.configuration["shop-link-de"];
// this.productNoForProduct.subscribe(data => { console.log("PRODUCT NO IN product info", data) });
// this.resetWidgets.subscribe(data => { console.log("reset in info", data) });
let headerHref = configuration._links["showcase-header"]["href"];
let headerTemplate = uriTemplates(headerHref);
observableCombineLatest(
this.productNoForProduct.asObservable().pipe(distinctUntilChanged()),
this.selectedUiLocale.asObservable(),
this.reload.asObservable(),
(productNoForProduct, selectedUiLocale) => {
this.linkEU =
this.configuration.configuration["shop-link-eu"] +
productNoForProduct;
this.linkDE =
this.configuration.configuration["shop-link-de"] +
productNoForProduct;
let uriParams = {};
uriParams["product"] = productNoForProduct;
uriParams["data-locale"] = selectedUiLocale;
uriParams["context"] = configuration.configuration["context"];
uriParams["locale"] = selectedUiLocale;
return uriParams;
}
)
.pipe(
map((uriParams) => headerTemplate.fill(uriParams)),
switchMap((uri) => {
return observableOf(uri).pipe(
mergeMap((uri) => {
return this._widgetframeService.getData(uri);
}),
catchError((err) => {
this.header = null;
return observableEmpty();
})
);
})
)
.subscribe(
(data) => {
this.header = [];
this.header = data;
// JQuery helper to position nm-categorypath at the bottom without knowing the height.
window.setTimeout(() =>
$(".nm-featurelist").css(
"padding-bottom",
$(".nm-categorypath").height()
)
);
},
(error) => {
console.log(error);
this.header = null;
}
);
let productHref = configuration._links["product"]["href"];
let productTemplate = uriTemplates(productHref);
observableCombineLatest(
this.productNoForProduct.asObservable().pipe(distinctUntilChanged()),
this.reload.asObservable(),
(productNoForProduct, reloadEvent) => productNoForProduct
)
.pipe(
map((number) => productTemplate.fill({ product: number })),
mergeMap((href) => this._widgetframeService.getData(href))
)
.subscribe(
(data) => (this.product = data),
(error) => {
console.log(error);
var err = JSON.parse(error.text());
}
);
this.productNoForProduct.asObservable().subscribe((number) => {
console.log("productNoForProduct", number);
let assetHref = this.configuration._links["assets"]["href"];
let assetTemplate = uriTemplates(assetHref);
this.assetHref.next(assetTemplate.fill({ product: number }));
});
}
resetWidget() {
this.header = null;
this.resetWidgets.next(new Date());
return null;
}
ngOnInit() {}
}
<nm-widgetframe
[header]="configuration.configuration['header']"
widgetId="{{ _id }}"
>
<div slot="title" class="nm-widgetframe__title">{{ title | translate }}</div>
<div slot="content" class="nm-widgetframe__content" style="min-height: 62px">
<nm-gallery
[href]="assetHref"
[width]="'300px'"
[height]="'200px'"
*ngIf="header !== null"
>
</nm-gallery>
<div class="info" *ngIf="header !== null">
<!-- <img *ngIf="manufacturerImage.length > 0 " class="nm-manufacturerImage" src="{{manufacturerImage}}"> -->
<h3>{{ header.description }}</h3>
<span>{{ header.manufacturer }} </span>
<div *ngIf="header?.productStateColors" class="traffic_light_container">
<div
*ngFor="let color of header?.productStateColors; let i = index"
pTooltip="{{
'app.ipim-mytextedit.infotext.product.state.' + (i + 1).toString()
| translate
}}"
class="traffic_light traffic_light_grid single"
>
<span class="active" [ngClass]="color"></span>
</div>
</div>
<div class="nm-bottom">
<h4>{{ "categories" | translate }}:</h4>
<div class="nm-categorypath" *ngIf="header?.salesCategories">
<ul>
<li *ngFor="let category of header?.salesCategories">
<div *ngFor="let node of category; let last = last">
{{ node }}
<div class="divider" *ngIf="!last">/ </div>
</div>
</li>
</ul>
</div>
</div>
<div class="nm-head-links" *ngIf="header !== null">
<a
href="{{ linkDE }}"
target="_blank"
mat-raised-button
type="button"
color="primary"
pTooltip="{{
'app.ipim-mytextedit.shop.link.de.tooltip' | translate
}}"
>{{ "app.ipim-mytextedit.shop.link.de" | translate }}</a
>
<a
href="{{ linkEU }}"
target="_blank"
mat-raised-button
type="button"
color="primary"
pTooltip="{{
'app.ipim-mytextedit.shop.link.eu.tooltip' | translate
}}"
>{{ "app.ipim-mytextedit.shop.link.eu" | translate }}</a
>
</div>
</div>
</div>
</nm-widgetframe>