@WidgetComponent

nm-lighttable

File

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

Metadata

changeDetection ChangeDetectionStrategy.OnPush
providers WidgetframeService
selector nm-lighttable
styleUrls lighttable.component.scss
templateUrl ./lighttable.component.html

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(_widgetframeService: WidgetframeService, gallery: Gallery, lightbox: Lightbox, cdr: ChangeDetectorRef)
Parameters :
Name Type Optional
_widgetframeService WidgetframeService no
gallery Gallery no
lightbox Lightbox no
cdr ChangeDetectorRef no

Methods

Protected configureWidget
configureWidget(configuration: WidgetConfig)
Decorators : WidgetConfigure
Parameters :
Name Type Optional
configuration WidgetConfig no
Returns : void
Private mapAssets
mapAssets(data: )
Parameters :
Name Optional
data no
Returns : any
mapToTapEvent
mapToTapEvent(event: MouseEvent)
Parameters :
Name Type Optional
event MouseEvent no
Returns : { center: { x: any; y: any; }; }
openLightbox
openLightbox(index: number)
Parameters :
Name Type Optional
index number no
Returns : void
showDetails
showDetails(asset: )
Parameters :
Name Optional
asset no
Returns : string

Properties

Public _id
_id:
Default value : uuid()
Decorators : WidgetId
Public assets
assets: any[]
Type : any[]
Default value : []
Public configuration
configuration: WidgetConfig
Type : WidgetConfig
Decorators : WidgetConfiguration
itemTemplate
itemTemplate: TemplateRef<any>
Type : TemplateRef<any>
Decorators : ViewChild
Public productNo
productNo:
Default value : new Subject<any>()
Decorators : WidgetInput
import { filter, map, mergeMap, tap } from "rxjs/operators";
import {
  ChangeDetectionStrategy,
  ChangeDetectorRef,
  Component,
  TemplateRef,
  ViewChild,
} from "@angular/core";
import { WidgetConfig } from "../../widget.configuration";
import {
  WidgetComponent,
  WidgetConfiguration,
  WidgetConfigure,
  WidgetId,
  WidgetInput,
} from "../../widget.metadata";
import { Subject } from "rxjs";
import { WidgetframeService } from "../../widgetframe/widgetframe.service";
import * as uriTemplates_ from "uri-templates";
import { Lightbox } from "ng-gallery/lightbox";
import { uuid } from "../../configuration";
import { Gallery } from "ng-gallery";
import { GalleryComponent } from "../../gallery";

const uriTemplates = uriTemplates_;

declare var contextPath: string;

@WidgetComponent("nm-lighttable")
@Component({
  selector: "nm-lighttable",
  templateUrl: "./lighttable.component.html",
  styleUrls: ["./lighttable.component.scss"],
  providers: [WidgetframeService],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class LightTableWidgetComponent {
  @ViewChild("itemTemplate", { static: true }) itemTemplate: TemplateRef<any>;

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

  @WidgetId()
  public _id = uuid();

  @WidgetConfiguration()
  public configuration: WidgetConfig;

  public assets: any[] = [];

  constructor(
    private _widgetframeService: WidgetframeService,
    private gallery: Gallery,
    private lightbox: Lightbox,
    private cdr: ChangeDetectorRef
  ) {}

  @WidgetConfigure()
  protected configureWidget(configuration: WidgetConfig) {
    const lightboxRef = this.gallery.ref(this._id);
    lightboxRef.setConfig({
      itemTemplate: this.itemTemplate,
    });

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

    this.productNo
      .asObservable()
      .pipe(
        map((number) => template.fill({ product: number })),
        mergeMap((href) => this._widgetframeService.getData(href)),
        tap(() => (this.assets = [])),
        filter((data) => data && data["_embedded"])
      )
      .subscribe(
        (response) => {
          const relations: any[] = response?._embedded?.["asset-relations"];
          if (relations == null) {
            return;
          }

          const mappedAssets = [];
          for (let relation of relations) {
            const relationAssets = relation?._embedded?.assets;
            if (relationAssets == null) {
              continue;
            }

            mappedAssets.push(
              ...relationAssets.map((data) => this.mapAssets(data))
            );
          }

          lightboxRef.load(GalleryComponent.toLightboxItems(mappedAssets));
          this.assets = mappedAssets;
          this.cdr.markForCheck();
        },
        (error) => {
          console.error(error);
        }
      );
  }

  openLightbox(index: number) {
    this.lightbox.open(index, this._id);
  }

  private mapAssets(data) {
    if (data.type === "image") {
      let image: any = data;
      if (image._links != undefined) {
        let src: any = {};
        if (image._links.thumbnail != undefined) {
          src.small = image._links.thumbnail.href;
        } else {
          src.small = image._links.default.href;
        }
        if (image._links.full != undefined) {
          src.medium = image._links.full.href;
          src.large = image._links.full.href;
        } else {
          src.medium = image._links.default.href;
          src.large = image._links.default.href;
        }

        image.src = src;
      }
    }

    if (data.type === "document") {
      data.placeholderimg = contextPath + "/assets/placeholder_pdf_281x202.jpg";
    }

    if (data.type === "video") {
      data.placeholderimg =
        contextPath + "/assets/placeholder_movie_281x202.jpg";
    }

    return data;
  }

  mapToTapEvent(event: MouseEvent) {
    return { center: { x: event.clientX, y: event.clientY } };
  }

  showDetails(asset) {
    return "/asset-search/asset/" + asset.title;
  }
}
<nm-widgetframe
  [header]="configuration.configuration['header']"
  widgetId="{{ _id }}"
>
  <div slot="title" class="nm-widgetframe__title">
    {{ configuration.configuration.title | translate }}
  </div>
  <div slot="content" class="nm-widgetframe__content">
    <div class="nm-gridlist">
      <div class="nm-gridlist-box" *ngFor="let asset of assets; let i = index">
        <div class="nm-gridlist-boxInner" *ngIf="asset['type'] === 'image'">
          <div class="nm-gridlist-actionBox" style="z-index: 11111">
            <div>
              <nm-action-icon
                *ngFor="let act of asset._actions | iterable"
                [action]="act.value"
                [name]="act.key"
              >
              </nm-action-icon>
            </div>
          </div>

          <div
            [style.backgroundImage]="'url(' + asset.src.medium + ')'"
            class="nm-lighttable_image"
            (click)="openLightbox(i)"
          ></div>

          <a [routerLink]="showDetails(asset)">
            <div class="nm-gridlist-titleBox">
              <span> {{ asset.title }}</span>
            </div>
          </a>
        </div>

        <div class="nm-gridlist-boxInner" *ngIf="asset['type'] !== 'image'">
          <div class="nm-gridlist-actionBox" style="z-index: 11111">
            <div>
              <nm-action-icon
                *ngFor="let act of asset._actions | iterable"
                [action]="act.value"
                [name]="act.key"
              >
              </nm-action-icon>
            </div>
          </div>
          <a [href]="asset._links.default.href" target="_blank">
            <img [src]="asset.placeholderimg" />
          </a>
          <a [routerLink]="showDetails(asset)">
            <div class="nm-gridlist-titleBox">
              <span> {{ asset.title }}</span>
            </div>
          </a>
        </div>
      </div>
    </div>
  </div>
</nm-widgetframe>

<ng-template
  #itemTemplate
  let-index="index"
  let-type="type"
  let-data="data"
  let-currIndex="currIndex"
>
  <ng-container *ngIf="type === 'imageViewer' && index === currIndex">
    <ngx-imageviewer
      [src]="data.src"
      [width]="800"
      [height]="600"
      #imageViewer
      (click)="imageViewer.onTap(mapToTapEvent($event))"
    >
    </ngx-imageviewer>
  </ng-container>
</ng-template>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""