@WidgetComponent

nm-linkexport

File

src/app/shared/widgets/analytics/linkexport/linkexport.component.ts

Description

Used in iPIM Analytics.

Uses message input channel to recive a productNo and transfers it to backend

Implements

OnDestroy

Metadata

selector nm-linkexport
template
<div></div>

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(_widgetframeService: WidgetframeService, _halService: HalService, _notificationService: NotificationsService, _appdataStore: AppdataStore, router: Router, translateService: TranslateService)
Parameters :
Name Type Optional
_widgetframeService WidgetframeService no
_halService HalService no
_notificationService NotificationsService no
_appdataStore AppdataStore no
router Router no
translateService TranslateService no

Methods

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

Properties

Private _id
_id: string
Type : string
Decorators : WidgetId
Public action
action:
Public actionName
actionName:
Private configuration
configuration: WidgetConfig
Type : WidgetConfig
Decorators : WidgetConfiguration
Public formGroup
formGroup: FormGroup
Type : FormGroup
Public href
href: Subject<String>
Type : Subject<String>
Default value : new ReplaySubject<String>(1)
Private inputChannel
inputChannel: Subject<any>
Type : Subject<any>
Default value : new Subject<any>()
Decorators : WidgetInput
Private subscription
subscription: Subscription
Type : Subscription
import { Component, OnInit, OnDestroy } from "@angular/core";
import { Subject, Subscription, ReplaySubject } from "rxjs";
import { AppdataStore } from "../../../components/appdata/appdata.store";
import { HalService } from "../../../components/hal/hal.service";
import { FormGroup } from "@angular/forms";
import { Router } from "@angular/router";
import { TranslateService } from "@ngx-translate/core";
import { WidgetframeService } from "../../widgetframe/widgetframe.service";
import { WidgetConfig } from "../../widget.configuration";
import {
  WidgetComponent,
  WidgetId,
  WidgetConfiguration,
  WidgetConfigure,
  WidgetInput,
  WidgetOutput,
} from "../../widget.metadata";
import { NotificationsService } from "../../../components/notifications/services/notifications.service";

declare var require: any;

/**
 * Used in iPIM Analytics.
 *
 * Uses message input channel to recive a productNo and transfers it to backend
 */
@WidgetComponent("nm-linkexport")
@Component({
  selector: "nm-linkexport",
  template: ` <div></div> `,
})
export class LinkExportComponent implements OnDestroy {
  @WidgetConfiguration()
  private configuration: WidgetConfig;

  // The message input from the kibana iframe
  @WidgetInput("messages-output")
  private inputChannel: Subject<any> = new Subject<any>();

  @WidgetId()
  private _id: string;

  public href: Subject<String> = new ReplaySubject<String>(1);
  public formGroup: FormGroup;
  public action;
  public actionName;

  private subscription: Subscription;

  constructor(
    private _widgetframeService: WidgetframeService,
    private _halService: HalService,
    private _notificationService: NotificationsService,
    private _appdataStore: AppdataStore,
    private router: Router,
    private translateService: TranslateService
  ) {
    this.formGroup = new FormGroup({});
  }

  @WidgetConfigure()
  protected configureWidget(configuration: WidgetConfig) {
    this.actionName = this.configuration.configuration["actionName"];
    this.subscription = this.inputChannel.asObservable().subscribe((resp) => {
      if (this.configuration.configuration["actionHref"]) {
        this._widgetframeService
          .getData(this.configuration.configuration["actionHref"])
          .subscribe((data) => {
            if (this.actionName === resp.data.action) {
              this.action = data._actions[this.actionName];
              var uriTemplates = require("uri-templates");
              this.action.href = uriTemplates(this.action.href).fill({
                product: resp.data.data,
              });
              this._halService
                .execute(this.actionName, this.action)
                .subscribe((resp) => {
                  if (resp.response.message !== undefined) {
                    this._notificationService.success(
                      resp.response.title,
                      resp.response.message
                    );
                  } else {
                    this._notificationService.success(
                      this.translateService.instant("message.success.title"),
                      this.translateService.instant("message.success.body")
                    );
                  }
                });
            }
          });
      }
    });
  }

  ngOnDestroy() {
    if (this.subscription) {
      this.subscription.unsubscribe();
    }
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""