@WidgetComponent

nm-attribute-list

File

src/app/shared/widgets/buy/attributelist/attributelist.component.ts

Description

Used in iPIM Buy. Surrounded by Widgetframe.

List of attributes. Displays attribute description and value. Uses productNo or assetTitle to fill url template from json property.

Implements

OnDestroy

Metadata

selector nm-attribute-list
styleUrls attributelist.component.scss
templateUrl ./attributelist.component.html

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(_widgetframeService: WidgetframeService, notificationService: CustomNotificationService)
Parameters :
Name Type Optional
_widgetframeService WidgetframeService no
notificationService CustomNotificationService no

Methods

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

Properties

Public _id
_id: string
Type : string
Decorators : WidgetId
Public assetTitle
assetTitle:
Default value : new Subject<any>()
Decorators : WidgetInput
Public attributes
attributes: any
Type : any
Public client
client:
Default value : new Subject<any>()
Decorators : WidgetInput
Public cols
cols: any[]
Type : any[]
Public combineWithClient
combineWithClient: boolean
Type : boolean
Default value : false
Public configuration
configuration: WidgetConfig<AttributeListConfiguration>
Type : WidgetConfig<AttributeListConfiguration>
Decorators : WidgetConfiguration
Public hideOnEmpty
hideOnEmpty: boolean
Type : boolean
Default value : true
Public infoText
infoText: string
Type : string
Public inputLink
inputLink: string
Type : string
Public locale
locale:
Default value : new Subject<any>()
Decorators : WidgetInput
Public productNo
productNo:
Default value : new Subject<any>()
Decorators : WidgetInput
Public reload
reload:
Default value : new Subject<any>()
Decorators : WidgetInput
Public resetChannel
resetChannel:
Default value : new Subject<any>()
Decorators : WidgetInput
Public title
title: string
Type : string
Public twoColumns
twoColumns: string
Type : string
Public uiLocale
uiLocale:
Default value : new Subject<any>()
Decorators : WidgetInput
Private unsubscribe
unsubscribe:
Default value : NgUnsubscribe.create()
Public wikiLink
wikiLink: string
Type : string
import {
  combineLatest as observableCombineLatest,
  Subject,
  Observable,
} from "rxjs";
import { getOrDefault } from "../../widget.configuration";
import { map, mergeMap, takeUntil, distinctUntilChanged } from "rxjs/operators";
import { Component, OnDestroy } from "@angular/core";
import { WidgetframeService } from "../../widgetframe/widgetframe.service";
import { WidgetConfig } from "../../widget.configuration";
import {
  WidgetComponent,
  WidgetId,
  WidgetConfiguration,
  WidgetConfigure,
  WidgetInput,
} from "../../widget.metadata";
import { NgUnsubscribe } from "../../../ng-unsubscribe";
import * as uriTemplates_ from "uri-templates";
import { CustomNotificationService } from "../../../components/notification/customnotification.service";
import { filter } from "rxjs/operators";
import { BaseConfiguration } from "../../widgetframe/widgetframe.component";

const uriTemplates = uriTemplates_;
export interface AttributeListConfiguration extends BaseConfiguration{
  /**
   * If set to true, the whole widget is hidden if the attributes list is empty.
   * @default(true)
   */
  hideOnEmpty: boolean;

  /**
   * If set to true, the attributes are displayed as two columns next to each other.
   * Otherwise, they're displayed as one column.
   * @default(false)
   */
  twoColumns: boolean;

  /**
   * Text to provide information about the widget and the business meaning of its usage.
   */
  infoText: string;

  /**
   * If set to true, the product number, client, locale and UI locale are added to the uri params when requesting the attributes data from the backend.
   * Otherwise, only the product number is taken into consideration.
   * @default(false)
   */
  combineWithClient: boolean;

  /**
   * If set to true, the whole attribute value should be displayed into nm-ellipsis component.
   * @default(false)
   */
  hasTextWidth: boolean;

  /**
   * Text to provide header for the widget.
   */
  header: string;

  /**
   * Text to provide title for the widget.
   */
  title: string;
}
/**
 * Used in iPIM Buy.
 * Surrounded by Widgetframe.
 *
 * List of attributes. Displays attribute description and value. Uses productNo or assetTitle to fill url template from json property.
 */
@WidgetComponent("nm-attribute-list")
@Component({
  selector: "nm-attribute-list",
  templateUrl: "./attributelist.component.html",
  styleUrls: ["./attributelist.component.scss"],
})
export class AttributeListWidgetComponent implements OnDestroy {
  public cols: any[];
  public attributes: any;
  public hideOnEmpty: boolean = true;
  public combineWithClient: boolean = false;
  public inputLink: string;

  @WidgetConfiguration()
  public configuration: WidgetConfig<AttributeListConfiguration>;

  // Input used to fill url template
  @WidgetInput()
  public productNo = new Subject<any>();

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

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

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

  @WidgetInput("reset")
  public resetChannel = new Subject<any>();

  // Input used to fill url template
  @WidgetInput()
  public assetTitle = new Subject<any>();

  // Forces a reload of the data url
  @WidgetInput()
  public reload = new Subject<any>();

  @WidgetId()
  public _id: string;

  public infoText: string;
  public wikiLink: string;
  public title: string;
  public twoColumns: string;
  private unsubscribe = NgUnsubscribe.create();

  constructor(
    private _widgetframeService: WidgetframeService,
    private notificationService: CustomNotificationService
  ) {
    this.cols = [
      { field: "description", header: "tab.head.att.name" },
      { field: "value", header: "" },
    ];
  }

  @WidgetConfigure()
  protected configureWidget(
    configuration: WidgetConfig<AttributeListConfiguration>
  ) {
    this.hideOnEmpty = getOrDefault(
      this.configuration.configuration.hideOnEmpty,
      true
    );

    this.twoColumns = getOrDefault(
      this.configuration.configuration.twoColumns,
      false
    );

    this.combineWithClient = getOrDefault(
      this.configuration.configuration.combineWithClient,
      false
    );

    this.infoText = this.configuration.configuration.infoText;

    let href = configuration._links["attributes"]["href"];
    let template = uriTemplates(href);

    if (configuration.configuration.combineWithClient) {
      observableCombineLatest(
        this.productNo.asObservable().pipe(filter((productNo) => !!productNo)),
        this.client.asObservable().pipe(distinctUntilChanged()),
        this.locale.asObservable().pipe(distinctUntilChanged()),
        this.uiLocale.asObservable().pipe(distinctUntilChanged()),
        this.reload.asObservable(),
        function (productNo, client, locale, uiLocale, reloadEvent) {
          let uriParams: any = {};
          uriParams.locale = locale ? locale : "";
          uriParams.productNo = productNo ? productNo : "";
          uriParams.client = client ? client : "";
          uriParams.uilocale = uiLocale ? uiLocale : "";

          if (productNo) {
            return template.fill(uriParams);
          }
        }
      )
        .pipe(
          mergeMap((href) => this._widgetframeService.getData(href)),
          takeUntil(this.unsubscribe)
        )
        .subscribe((data) => {
          if (data) {
            if (data.error !== undefined) {
              this.notificationService.fromResponse(data);
              this.attributes = [];
            } else {
              this.attributes = data.values;
            }
          }
        });
    } else {
      observableCombineLatest(
        this.productNo.asObservable().pipe(distinctUntilChanged()),
        this.reload.asObservable(),
        (productNo, reloadEvent) => productNo
      )
        .pipe(
          map((number) => template.fill({ product: number })),
          mergeMap((href) => this._widgetframeService.getData(href)),
          takeUntil(this.unsubscribe)
        )
        .subscribe((data) => (this.attributes = data["values"]));

      observableCombineLatest(
        this.assetTitle.asObservable().pipe(distinctUntilChanged()),
        this.reload.asObservable(),
        (assetTitle, reloadEvent) => assetTitle
      )
        .pipe(
          map((title) => template.fill({ asset: title })),
          mergeMap((href) => this._widgetframeService.getData(href)),
          takeUntil(this.unsubscribe)
        )
        .subscribe((data) => (this.attributes = data["values"]));
    }

    this.resetChannel
      .asObservable()
      .pipe(takeUntil(this.unsubscribe))
      .subscribe((reset) => {
        this.attributes = [];
      });
  }

  ngOnDestroy() {
    this.unsubscribe.destroy();
  }
}
<nm-widgetframe
  [header]="configuration.configuration['header']"
  widgetId="{{ _id }}"
  [visible]="attributes?.length > 0 || !hideOnEmpty"
>
  <div slot="title" class="nm-widgetframe__title">
    {{ configuration.configuration["title"] | translate }}
    <nm-help-icon
      *ngIf="configuration.configuration['infoText']"
      style="position: absolute; display: inline; right: 50px; z-index: 666"
      [info-text]="configuration.configuration['infoText'] | translate"
      [info-title]="configuration.configuration['title'] | translate"
      [info-placement]="'bottom'"
      [wiki-link]="configuration.configuration['wikiLink']"
    ></nm-help-icon>
  </div>
  <div slot="content" class="nm-widgetframe__content">
    <div
      class="nm-attribute-list"
      [ngClass]="configuration.configuration.twoColumns ? '--twoColumns' : ''"
    >
      <ng-container *ngFor="let attribute of attributes">
        <div class="nm-attribute-list-elements">
          <div class="nm-attribute-list-description">
            {{ attribute.description }}
          </div>
          <div
            [ngClass]="attribute.inherited ? 'inherited-value' : ''"
            class="nm-attribute-list-value"
          >
            <div *ngIf="configuration.configuration['hasTextWidth']">
              <nm-ellipsis [content]="attribute.value"></nm-ellipsis>
            </div>
            <div *ngIf="!configuration.configuration['hasTextWidth']">
              {{ attribute.value }}
            </div>
          </div>
        </div>
      </ng-container>
    </div>
  </div>
</nm-widgetframe>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""