@WidgetComponent

nm-add-relations-popup

File

src/app/shared/widgets/apps/my-cross-sell/add-relations-popup/add-relations-popup.component.ts

Implements

OnInit

Metadata

selector nm-add-relations-popup
templateUrl ./add-relations-popup.component.html

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(data: any, dialogRef: MatDialogRef, listService: ListService, _progressbarService: ProgressbarService)
Parameters :
Name Type Optional
data any no
dialogRef MatDialogRef<AddRelationsPopupComponent> no
listService ListService no
_progressbarService ProgressbarService no

Methods

closeDialog
closeDialog()
Returns : void
Private mapResult
mapResult(data: ResultResource)
Parameters :
Name Type Optional
data ResultResource no
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

Public actionsToAdd
actionsToAdd: string
Type : string
Public cols
cols: Subject<any[]>
Type : Subject<any[]>
Default value : new BehaviorSubject([])
Public configuration
configuration: any
Type : any
Private currentLink
currentLink: string
Type : string
Public data
data: any
Type : any
Decorators : Inject
Private dataType
dataType: string
Type : string
Public dialogRef
dialogRef: MatDialogRef<AddRelationsPopupComponent>
Type : MatDialogRef<AddRelationsPopupComponent>
Private filter
filter: string[]
Type : string[]
Public identifier
identifier: string
Type : string
Default value : ""
Public inputChannel
inputChannel: Subject<any>
Type : Subject<any>
Default value : new Subject<any>()
Public limit
limit: number
Type : number
Default value : 10
Private offset
offset: number
Type : number
Private onChange
onChange: Subject<any>
Type : Subject<any>
Default value : new Subject<any>()
Public profile
profile: string
Type : string
Public results
results: Subject<Result[]>
Type : Subject<Result[]>
Default value : new BehaviorSubject([])
Public selectedRows
selectedRows: Result[]
Type : Result[]
Default value : []
Private sort
sort: string
Type : string
Public template
template: any
Type : any
Public title
title: string
Type : string
Public total
total: BehaviorSubject<number>
Type : BehaviorSubject<number>
Default value : new BehaviorSubject(0)
Private unsubscribe
unsubscribe:
Default value : NgUnsubscribe.create()
import {
  takeUntil,
  switchMap,
  filter,
  map,
  debounceTime,
} from "rxjs/operators";
import { Component, OnInit, Inject } from "@angular/core";
import { MatDialogRef } from "@angular/material/dialog";
import { WidgetComponent } from "../../../widget.metadata";
import { EditAttributeService } from "../../../../components/edit-attribute/edit-attribute.service";
import { MAT_DIALOG_DATA } from "@angular/material/dialog";
import { Subject, BehaviorSubject } from "rxjs";
import { ListService } from "../../../list/list.service";
import { ProgressbarService } from "../../../../components/progressbar/progressbar.service";
import { Result, ResultResource } from "../../../interfaces/list.interfaces";
import { NgUnsubscribe } from "../../../../ng-unsubscribe";
import * as uriTemplates_ from "uri-templates";
const uriTemplates = uriTemplates_;

@WidgetComponent("nm-add-relations-popup")
@Component({
  selector: "nm-add-relations-popup",
  templateUrl: "./add-relations-popup.component.html",
})
export class AddRelationsPopupComponent implements OnInit {
  public total: BehaviorSubject<number> = new BehaviorSubject(0);
  public cols: Subject<any[]> = new BehaviorSubject([]);

  public selectedRows: Result[] = [];
  public template: any;
  public profile: string;
  public actionsToAdd: string;
  public identifier: string = "";
  public configuration: any;
  public title: string;
  public inputChannel: Subject<any> = new Subject<any>();
  public results: Subject<Result[]> = new BehaviorSubject([]);
  private currentLink: string;
  private onChange: Subject<any> = new Subject<any>();

  private offset: number;
  public limit: number = 10;
  private sort: string;
  private filter: string[];

  private unsubscribe = NgUnsubscribe.create();
  private dataType: string;

  constructor(
    @Inject(MAT_DIALOG_DATA) public data: any,
    public dialogRef: MatDialogRef<AddRelationsPopupComponent>,
    private listService: ListService,
    private _progressbarService: ProgressbarService
  ) {}

  ngOnInit() {
    this.configuration = this.data["configuration"]["configuration"];
    this.profile = this.configuration["popup-configuration"]["default-profile"];

    this.cols.next(
      this.configuration["popup-configuration"]["profiles"][
        this.configuration["popup-configuration"]["default-profile"]
      ]
    );
    this.dataType = this.configuration["popup-configuration"]["dataType"];
    this.title = this.configuration["popup-configuration"]["title"];
    this.actionsToAdd = this.configuration["popup-configuration"]["actions"];
    this.identifier = this.configuration["popup-configuration"]["identifier"];

    this.inputChannel
      .asObservable()

      .subscribe((link) => {
        if (link === null) {
          this.total.next(null);
          this.results.next([]);
        } else {
          this.total.next(null);
          this.currentLink = link;
          this.offset = 0;
          this.onChange.next(new Date());
        }
      });

    this.onChange
      .pipe(
        debounceTime(500),
        map((trigger) => {
          let input = this.currentLink;
          let offset = this.offset || 0;
          let limit = this.limit || 10;
          let sort = this.sort || "";
          let filter = this.filter || [];

          if (!input) {
            return null;
          }

          let uriParams = Object.assign(
            {},
            { offset: offset },
            { limit: limit },
            { sort: sort },
            { filter: filter }
          );

          if (trigger === "reset") {
            return {};
          }

          if (trigger !== undefined) {
            uriParams.cache = (<Date>trigger).getTime();
            input += "{&cache}";
          }

          uriParams.template = input;
          return uriParams;
        }),
        filter((uriParams) => !!uriParams),
        map((uriParams) => {
          if (Object.keys(uriParams).length == 0) {
            return "";
          }
          this.template = uriTemplates((<any>uriParams).template);
          return this.template.fill(uriParams);
        }),
        switchMap((uri) => {
          if (uri === "") {
            return new Subject();
          }
          return this.listService.getTemplatedFilteredResults(uri);
        }),
        takeUntil(this.unsubscribe)
      )

      .subscribe(
        (data) => {
          this.mapResult(data);
          this._progressbarService.requestFinished();
        },
        (err) => {
          this._progressbarService.requestFinished();
        }
      );
    this.inputChannel.next(this.data["uri"]);
  }

  private mapResult(data: ResultResource) {
    if (data._embedded[this.dataType].length > 0) {
      for (var result of data._embedded[this.dataType]) {
        for (var attribute of result.attributes.default) {
          result[attribute.identifier] = attribute.value;
        }
      }
      this.results.next(data._embedded[this.dataType]);
    } else {
      this.results.next([]);
    }
    this.total.next(data.total);
  }
  closeDialog() {
    this.dialogRef.close();
  }

  ngOnDestroy(): void {
    this.unsubscribe.destroy();
  }
}
<nm-dialog
  [dialogRef]="dialogRef"
  class="nm-dialog"
  style="max-width: 650px; width: 650px; min-width: 650px"
>
  <ng-container slot="title">
    {{ title | translate }}
  </ng-container>
  <ng-container slot="content">
    <p-dataTable
      [(selection)]="selectedRows"
      [value]="results | async"
      emptyMessage="{{ 'table.emptytext.product' | translate }}"
      [paginator]="false"
      [rows]="limit"
      [pageLinks]="3"
      [lazy]="false"
      [totalRecords]="total | async"
      [rowsPerPageOptions]="[5, 10, 25, 50, 100]"
      selectionMode="multiple"
      #dt
    >
      <p-column
        *ngFor="let col of cols | async"
        [sortable]="col.sortable"
        [filter]="col.filter"
        [field]="col.field"
        [filterMatchMode]="col.filterMatchMode"
        [header]="col.header | translate"
        [styleClass]="col.style"
      >
        <ng-template pTemplate="filter" let-col *ngIf="col.filter">
          <mat-form-field>
            <input
              pinputtext
              matInput
              placeholder="{{ col.header }}"
              [value]="dt.filters[col.field] ? dt.filters[col.field].value : ''"
              type="text"
              class="ui-column-filter"
              *ngIf="col.filter == true"
              (click)="dt.onFilterInputClick($event)"
              (input)="
                dt.onFilterKeyup(
                  $event.target.value,
                  col.field,
                  col.filterMatchMode
                )
              "
            />
          </mat-form-field>
        </ng-template>

        <ng-template pTemplate="filter" let-col *ngIf="!col.filter">
          <span class="nm-column-title">{{ col.header }}</span>
        </ng-template>

        <ng-template let-col let-results="rowData" pTemplate="body">
          <div (id)="(results[col.field])" style="width: 100%">
            <div [ngSwitch]="col.field">
              <div *ngSwitchCase="'main-asset'">
                <nm-image
                  [container]="results"
                  asset="main-asset"
                  size="thumbnail"
                  width="auto"
                  height="auto"
                  max-width="48px"
                  max-height="48px"
                ></nm-image>
              </div>
              <div *ngSwitchCase="'identifier'" style="padding-left: 5px">
                <nm-ellipsis [content]="results[col.field]"></nm-ellipsis>
              </div>
              <div *ngSwitchCase="'links'" class="nm-actions">
                <span *ngFor="let act of results._actions | iterable">
                  <nm-action-icon
                    *ngIf="act.key != 'download'"
                    [action]="act.value"
                    [name]="act.key"
                  >
                  </nm-action-icon>
                </span>
              </div>

              <div *ngSwitchCase="'ShortDescription'">
                <nm-ellipsis
                  [content]="results[col.field]"
                  width="100px"
                ></nm-ellipsis>
              </div>

              <div *ngSwitchDefault>
                <nm-ellipsis
                  [content]="results[col.field]"
                  width="75px"
                ></nm-ellipsis>
              </div>
            </div>
          </div>
        </ng-template>
      </p-column>
      <footer>
        <div class="ui-helper-clearfix" style="width: 100%"></div>
      </footer>
    </p-dataTable>
    <br />
    <br />
    <div
      class="upload-button-container"
      style="margin: 0px 11px; bottom: 20px; position: relative"
    >
      <button
        mat-raised-button
        type="button"
        class="btn-black"
        (click)="dialogRef.close(null)"
        style="float: right"
      >
        {{ "button.cancel" | translate }}
      </button>
      <button
        [disabled]="!(selectedRows.length > 0)"
        mat-raised-button
        type="button"
        class="btn-orange"
        (click)="dialogRef.close(selectedRows)"
        style="float: right"
      >
        {{ "button.accept" | translate }}
      </button>
    </div> </ng-container
  >>
</nm-dialog>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""