@WidgetComponent

nm-simple-item-list

File

src/app/shared/widgets/imarket/simple-item-list/simple-item-list.component.widget.ts

Implements

OnInit OnDestroy CellWidget AfterViewInit

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector nm-simple-item-list
templateUrl ./simple-item-list.component.widget.html

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(_widgetframeService: WidgetframeService, _responseService: IMarketResponseService, currentLocaleService: CurrentLocaleService, cd: ChangeDetectorRef)
Parameters :
Name Type Optional
_widgetframeService WidgetframeService no
_responseService IMarketResponseService no
currentLocaleService CurrentLocaleService no
cd ChangeDetectorRef no

Methods

Protected configureWidget
configureWidget(configuration: WidgetConfig)
Decorators : WidgetConfigure
Parameters :
Name Type Optional
configuration WidgetConfig no
Returns : void
ngAfterViewInit
ngAfterViewInit()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
onButtonClick
onButtonClick(event: )
Parameters :
Name Optional
event no
Returns : void
onTogglerClick
onTogglerClick(event: )
Parameters :
Name Optional
event no
Returns : void
updateData
updateData(data: )
Parameters :
Name Optional
data no
Returns : void

Properties

Public buttonClicked
buttonClicked: Subject<string>
Type : Subject<string>
Default value : new Subject<string>()
Decorators : WidgetOutput

Data sent drectly from controller

Public configuration
configuration: WidgetConfig<SimpleListConfiguration>
Type : WidgetConfig<SimpleListConfiguration>
Decorators : WidgetConfiguration
Public data
data: Subject<any>
Type : Subject<any>
Default value : new Subject<any>()
Decorators : WidgetInput

Data sent drectly from controller

Public dataRecieved
dataRecieved: Subject<any>
Type : Subject<any>
Default value : new Subject<any>()
Private dataType
dataType: string
Type : string
Public header
header: string
Type : string
Public infoText
infoText: string
Type : string
Public infoTitle
infoTitle: string
Type : string
Public listItemClasses
listItemClasses: string
Type : string
Private notificationKey
notificationKey: string
Type : string
Public row
row: any
Type : any
Public title
title: string
Type : string
Public togglerClicked
togglerClicked: Subject<string>
Type : Subject<string>
Default value : new Subject<string>()
Decorators : WidgetOutput

Data sent drectly from controller

Private unsubscribe
unsubscribe:
Default value : NgUnsubscribe.create()
Public uri
uri: Subject<string>
Type : Subject<string>
Default value : new Subject<string>()
Decorators : WidgetInput

Uri used to fetch data

Public value
value: any
Type : any
Public widgetId
widgetId: string
Type : string
Decorators : WidgetId
Public wikiLink
wikiLink: string
Type : string
Public withBorder
withBorder: boolean
Type : boolean
Default value : true
Public withHeader
withHeader: string
Type : string
import {
  Component,
  OnInit,
  OnDestroy,
  AfterViewInit,
  ChangeDetectorRef,
  ChangeDetectionStrategy,
} from "@angular/core";
import { WidgetConfig, getOrDefault } from "../../widget.configuration";
import {
  WidgetComponent,
  WidgetId,
  WidgetConfiguration,
  WidgetConfigure,
  WidgetInput,
  WidgetOutput,
} from "../../widget.metadata";
import { BaseConfiguration } from "../../widgetframe/widgetframe.component";
import { WidgetframeService } from "../../widgetframe/widgetframe.service";
import { IMarketResponseService } from "../../../components/imarket/services/iMarketresponse.service";
import { NgUnsubscribe } from "../../../ng-unsubscribe";
import { Subject, EMPTY, of as observableOf } from "rxjs";
import {
  takeUntil,
  mergeMap,
  catchError,
  switchMap,
  distinctUntilChanged,
} from "rxjs/operators";
import { CurrentLocaleService } from "../../../components/i18n/currentLocale.service";
import { CellWidget } from "../../../components/list-cell";

export interface SimpleListConfiguration extends BaseConfiguration {
  /**
   * Data type of expected data
   */
  dataType: string;
  /**
   * Width of list
   */
  width: string;
  /**
   * Min-Width of list
   */
  minWidth: string;
  /**
   * Base path used to split currrent url  to get correct context path for redirection @default(null)
   */
  baseRedirectionPage: string;
  /**
   * Format used to show numbers within "NUMBER" switchcase in list @default(1.2-2)
   */
  numberFormat: string;
  /**
   * Classes to be added to whole list
   */
  listItemClasses?: string;

  [key: string]: any;
}
@WidgetComponent("nm-simple-item-list")
@Component({
  selector: "nm-simple-item-list",
  templateUrl: "./simple-item-list.component.widget.html",
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SimpleItemListWidgetComponent
  implements OnInit, OnDestroy, CellWidget, AfterViewInit {
  /**
   * Uri used to fetch data
   */
  @WidgetInput("uri")
  public uri: Subject<string> = new Subject<string>();

  /**
   * Data sent drectly from controller
   */
  @WidgetInput("data")
  public data: Subject<any> = new Subject<any>();

  /**
   * Data sent drectly from controller
   */
  @WidgetOutput("buttonClicked")
  public buttonClicked: Subject<string> = new Subject<string>();

  /**
   * Data sent drectly from controller
  */
  @WidgetOutput("togglerClicked")
  public togglerClicked: Subject<string> = new Subject<string>();
  
  @WidgetConfiguration()
  public configuration: WidgetConfig<SimpleListConfiguration>;

  @WidgetId()
  public widgetId: string;

  private unsubscribe = NgUnsubscribe.create();

  public row: any;
  public value: any;

  public header: string;
  public infoTitle: string;
  public infoText: string;
  public wikiLink: string;
  public withBorder: boolean = true;
  public withHeader: string;
  public title: string;
  private dataType: string;
  private notificationKey: string;
  public dataRecieved: Subject<any> = new Subject<any>();
  public listItemClasses: string;

  constructor(
    private _widgetframeService: WidgetframeService,
    private _responseService: IMarketResponseService,
    private currentLocaleService: CurrentLocaleService,
    private cd: ChangeDetectorRef
  ) {}

  @WidgetConfigure()
  protected configureWidget(configuration: WidgetConfig) {
    this.dataType = configuration.configuration.dataType;
    this.notificationKey = getOrDefault(
      configuration.configuration.notificationKey,
      "imarket.api-call"
    );
    this.header = getOrDefault(
      this.configuration.configuration.header,
      "primary"
    );
    this.withHeader = getOrDefault(
      this.configuration.configuration.withHeader,
      false
    );
    this.title = this.configuration.configuration.title;
    this.infoTitle = configuration.configuration.infoTitle;
    this.infoText = configuration.configuration.infoText;
    this.wikiLink = this.configuration.configuration.wikiLink;
    this.withBorder = getOrDefault(
      this.configuration.configuration.withBorder,
      true
    );
    this.listItemClasses = this.configuration.configuration.listItemClasses;

    if (this.configuration.id) {
      this.widgetId = this.configuration.id;
    }
  }

  ngOnInit() {
    this.uri
      .asObservable()
      .pipe(
        switchMap((uri) => {
          return observableOf(uri).pipe(
            mergeMap((href) => this._widgetframeService.getData(href)),
            catchError((error) => {
              this._responseService.showNotification(
                this.notificationKey,
                "error"
              );
              return EMPTY;
            })
          );
        }),
        takeUntil(this.unsubscribe)
      )
      .subscribe((data) => {
        if (
          this._responseService.handleResponse(data, this.notificationKey, {
            notify: false,
          })
        ) {
          this.updateData(data);
        }
      });

    this.currentLocaleService
      .getCurrentLocale()
      .pipe(distinctUntilChanged())
      .subscribe((locale) => {
        const link = this.configuration.configuration.uri;
        if (link) {
          this._widgetframeService
            .getData(link)
            .pipe(takeUntil(this.unsubscribe))
            .subscribe(
              (data) => {
                this.updateData(data);
              },
              (err) => {
                this._responseService.showNotification(
                  this.notificationKey,
                  "error"
                );
                return EMPTY;
              }
            );
        }
    });

    this.data
      .asObservable()
      .pipe(takeUntil(this.unsubscribe))
      .subscribe((data) => this.updateData(data));
  }

  ngAfterViewInit() {
    if (this.row) {
      this.updateData(this.value);
    }
  }

  updateData(data) {
    if (!data) {
      this.dataRecieved.next(null);
    } else if (this.dataType && data[this.dataType]) {
      this.dataRecieved.next(data[this.dataType]);
    } else {
      this.dataRecieved.next(data);
    }
    this.cd.detectChanges();
  }

  onButtonClick(event) {
    this.buttonClicked.next(event);
  }

  onTogglerClick(event) {
    this.togglerClicked.next(event);
  }

  ngOnDestroy() {
    this.unsubscribe.destroy();
  }
}
<nm-widgetframe
  [header]="header"
  [configuration]="configuration"
  [infoTitle]="infoTitle"
  [widgetId]="widgetId"
  [infoText]="infoText"
  [infoWidth]="'550px'"
  [infoPlacement]="'bottom'"
  [wikiLink]="wikiLink"
  [toolbarInvisible]="!withHeader"
  [withBorder]="withBorder"
>
  <div slot="title" class="nm-widgetframe__title">
    <span>{{title |translate}} </span>
  </div>
  <div slot="content" class="nm-widgetframe__content">
    <nm-simple-item-list-component
      [data]="dataRecieved | async"
      (buttonClicked)="onButtonClick($event)"
      (togglerClicked)="onTogglerClick($event)"
      [configuration]="configuration"
      [listItemClasses]="listItemClasses"
    >
    </nm-simple-item-list-component>
  </div>
</nm-widgetframe>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""