@WidgetComponent

nm-edit-footer

File

src/app/shared/widgets/edit-footer/edit-footer.component.ts

Implements

OnDestroy

Metadata

selector nm-edit-footer
styleUrls edit-footer.component.scss
templateUrl ./edit-footer.component.html

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(_widgetframeService: WidgetframeService, renderer: Renderer2, _halService: HalService, _notificationService: CustomNotificationService, _progressbarService: ProgressbarService)
Parameters :
Name Type Optional
_widgetframeService WidgetframeService no
renderer Renderer2 no
_halService HalService no
_notificationService CustomNotificationService no
_progressbarService ProgressbarService no

Methods

Protected configureWidget
configureWidget(configuration: WidgetConfig)
Decorators : WidgetConfigure
Parameters :
Name Type Optional
configuration WidgetConfig no
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
onClick
onClick()
Returns : void

Properties

Public _progressbarService
_progressbarService: ProgressbarService
Type : ProgressbarService
Public action
action: Action
Type : Action
actionButton
actionButton: ElementRef
Type : ElementRef
Decorators : ViewChild
Public actionName
actionName: String
Type : String
Default value : ""
Public actionStream
actionStream:
Default value : new Subject<any>()
Decorators : WidgetInput
Public customIcon
customIcon:
Default value : false
Public icon
icon: string
Type : string
Public isDisabled
isDisabled: Boolean
Type : Boolean
Default value : false
Public payload
payload:
Default value : new Subject<any>()
Decorators : WidgetInput
Public reload
reload:
Default value : new Subject<any>()
Decorators : WidgetOutput
Public storeEvent
storeEvent:
Default value : new Subject<any>()
Decorators : WidgetInput
Private unsubscribe
unsubscribe:
Default value : NgUnsubscribe.create()
import { takeUntil, map, filter } from "rxjs/operators";
import {
  Component,
  OnDestroy,
  ViewChild,
  ElementRef,
  Renderer2,
} from "@angular/core";
import { Subject } from "rxjs";
import { WidgetframeService } from "../widgetframe/widgetframe.service";
import { WidgetConfig } from "../widget.configuration";
import {
  WidgetComponent,
  WidgetConfigure,
  WidgetInput,
  WidgetOutput,
} from "../widget.metadata";
import { NgUnsubscribe } from "../../ng-unsubscribe";
import { ProgressbarService } from "../../components/progressbar/progressbar.service";
import { HalService } from "../../components/hal/index";
import { CustomNotificationService } from "../../components/notification/customnotification.service";

import { Action } from "../../components/hal/index";

@WidgetComponent("nm-edit-footer")
@Component({
  selector: "nm-edit-footer",
  templateUrl: "./edit-footer.component.html",
  styleUrls: ["./edit-footer.component.scss"],
})
export class EditFooterWidgetComponent implements OnDestroy {
  @ViewChild("actionButton", { read: ElementRef, static: true })
  actionButton: ElementRef;

  @WidgetInput()
  public payload = new Subject<any>();

  @WidgetInput()
  public actionStream = new Subject<any>();

  @WidgetInput()
  public storeEvent = new Subject<any>();

  @WidgetOutput()
  public reload = new Subject<any>();

  public action: Action;

  public actionName: String = "";

  public isDisabled: Boolean = false;

  public icon: string;
  public customIcon = false;

  private unsubscribe = NgUnsubscribe.create();

  constructor(
    private _widgetframeService: WidgetframeService,
    private renderer: Renderer2,
    private _halService: HalService,
    private _notificationService: CustomNotificationService,
    public _progressbarService: ProgressbarService
  ) {}

  @WidgetConfigure()
  protected configureWidget(configuration: WidgetConfig) {
    this.actionName = configuration.configuration["action-name"];
    this.icon = configuration.configuration["icon"];

    if (configuration.configuration["customIcon"]) {
      this.customIcon = configuration.configuration["customIcon"];
    }
    this.isDisabled = true;
    this.storeEvent.subscribe((storeEvent) => {
      this.actionButton.nativeElement.click();
    });

    this.payload.subscribe((data) => {
      if (data != null) {
        this.isDisabled = false;
      } else {
        this.isDisabled = true;
      }
    });
    this.actionStream.subscribe((data) => {
      this.action = data;
    });

    this._halService
      .getActionEvents()
      .pipe(
        filter((event) => event.name === this.actionName),
        map((event) => (<any>event).response),
        takeUntil(this.unsubscribe)
      )
      .subscribe(
        (resp) => {
          if (resp.message !== undefined) {
            if (resp.level === "ERROR") {
              this._notificationService.create(
                resp.title,
                resp.message,
                resp.level
              );
              this._progressbarService.requestFinished();
              if (configuration.configuration["trigger-reload"]) {
                this.reload.next(new Date());
              }
            }
          }
          this.payload.next(null);
          this._notificationService.fromResponse(resp);
          this._progressbarService.requestFinished();
          if (configuration.configuration["trigger-reload"]) {
            this.reload.next(new Date());
          }
        },
        (err) => {
          this._notificationService.create(err.title, err.message, "error");
          this._progressbarService.requestFinished();
          if (configuration.configuration["trigger-reload"]) {
            this.reload.next(new Date());
          }
        }
      );
  }

  onClick() {
    if (!this.isDisabled) {
      this.isDisabled = true;
      this._progressbarService.addRequest();
    }
  }

  ngOnDestroy() {
    this.unsubscribe.destroy();
  }
}
<button
  #actionButton
  mat-raised-button
  type="button"
  color="primary"
  class="nm-footer-button"
  [disabled]="isDisabled"
  [nm-action]="action"
  [action-payload]="payload | async"
  (click)="onClick()"
  [action-name]="actionName"
>
  {{ "button.save" | translate }}
</button>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""