nm-action-button
src/app/shared/widgets/buttons/actionbutton/actionbutton.component.ts
Used in iPIM Buy. No Widgetframe.
Triggers cart action
selector | nm-action-button |
styleUrls | actionbutton.component.scss |
templateUrl | ./actionbutton.component.html |
Widget inputs |
Widget outputs |
Properties |
|
Methods |
|
constructor(_widgetframeService: WidgetframeService, _appdataStore: AppdataStore, halService: HalService, notificationService: NotificationsService, translateService: TranslateService)
|
||||||||||||||||||
Parameters :
|
Protected configureWidget | ||||||
configureWidget(configuration: WidgetConfig)
|
||||||
Decorators : WidgetConfigure
|
||||||
Parameters :
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
Public action |
action:
|
Type : any
|
Public actionName |
actionName:
|
Type : string
|
Public configuration |
configuration:
|
Type : WidgetConfig
|
Decorators : WidgetConfiguration
|
Public isResetButtonNeeded |
isResetButtonNeeded:
|
Private reloadChannel |
reloadChannel:
|
Type : Subject<any>
|
Default value : new Subject<any>()
|
Decorators : WidgetOutput
|
Private unsubscribe |
unsubscribe:
|
Default value : NgUnsubscribe.create()
|
import { takeUntil, map, filter, mergeMap } from "rxjs/operators";
import { Component, OnDestroy } from "@angular/core";
import { Subject } from "rxjs";
import { WidgetframeService } from "../../widgetframe/widgetframe.service";
import { WidgetConfig } from "../../widget.configuration";
import {
WidgetComponent,
WidgetConfiguration,
WidgetConfigure,
WidgetOutput,
} from "../../widget.metadata";
import { AppdataStore } from "../../../components/appdata/appdata.store";
import { HalService } from "../../../components/hal/hal.service";
import { TranslateService } from "@ngx-translate/core";
import { NgUnsubscribe } from "../../../ng-unsubscribe";
import { NotificationsService } from "../../../components/notifications/services/notifications.service";
/**
* Used in iPIM Buy.
* No Widgetframe.
*
* Triggers cart action
*/
@WidgetComponent("nm-action-button")
@Component({
selector: "nm-action-button",
templateUrl: "./actionbutton.component.html",
styleUrls: ["./actionbutton.component.scss"],
})
export class ActionButtonWidgetComponent implements OnDestroy {
private unsubscribe = NgUnsubscribe.create();
@WidgetConfiguration()
public configuration: WidgetConfig;
// triggers a reload after hal action success
@WidgetOutput("reload")
private reloadChannel: Subject<any> = new Subject<any>();
public action: any;
public actionName: string;
public isResetButtonNeeded;
constructor(
private _widgetframeService: WidgetframeService,
private _appdataStore: AppdataStore,
private halService: HalService,
private notificationService: NotificationsService,
private translateService: TranslateService
) {}
@WidgetConfigure()
protected configureWidget(configuration: WidgetConfig) {
this.actionName = configuration.configuration["action"];
this._appdataStore
.getAppdata()
.pipe(
map((data) => data["buy"]._links["cart"].href),
mergeMap((cartHref) => this._widgetframeService.getData(cartHref)),
takeUntil(this.unsubscribe)
)
.subscribe((data) => {
this.action = data._actions[this.actionName];
});
this.halService
.getActionEvents()
.pipe(
filter((event) => event.name === this.actionName),
map((event) => (<any>event).response),
takeUntil(this.unsubscribe)
)
.subscribe((resp) => {
if (resp.message !== undefined) {
this.notificationService.success(resp.title, resp.message);
} else {
this.notificationService.success(
this.translateService.instant("message.success.title"),
this.translateService.instant("message.success.body")
);
}
if (configuration.configuration["triggerReload"]) {
this.reloadChannel.next(new Date());
}
});
}
ngOnDestroy() {
this.unsubscribe.destroy();
}
}
<button
mat-mini-fab
color="primary"
[nm-action]="action"
[action-name]="actionName"
popover="{{ configuration.configuration['infoText'] | translate }}"
class="mat-icon-button nm-button__reset"
[class.nm-fadein]="isResetButtonNeeded"
>
<div
class="material-icons nm-svg-icon"
[ngStyle]="{ fill: 'rgb(255,153,0)' }"
>
<!--TODO: Why a minus does not work?! <mat-icon>{{configuration.configuration["action"]}}</mat-icon> -->
<mat-icon>close</mat-icon>
</div>
</button>