@WidgetComponent

nm-product-search-reset

File

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

Metadata

selector nm-product-search-reset
styleUrls productsearchreset.component.scss
templateUrl ./productsearchreset.component.html

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(_widgetframeService: WidgetframeService, localstorageService: LocalStorageService)
Parameters :
Name Type Optional
_widgetframeService WidgetframeService no
localstorageService LocalStorageService no

Methods

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

Properties

Private _id
_id: string
Type : string
Decorators : WidgetId
Private configuration
configuration: WidgetConfig
Type : WidgetConfig
Decorators : WidgetConfiguration
Private hide
hide: Subject<any>
Type : Subject<any>
Default value : new Subject<any>()
Decorators : WidgetInput
Private hideButton
hideButton: Subject<any>
Type : Subject<any>
Default value : new Subject<any>()
Decorators : WidgetInput
Private inputChannel
inputChannel: Subject<any>
Type : Subject<any>
Default value : new Subject<any>()
Decorators : WidgetInput
Private inputSubscription
inputSubscription: Subscription
Type : Subscription
Public isHidden
isHidden: boolean
Type : boolean
Public isResetButtonNeeded
isResetButtonNeeded: boolean
Type : boolean
Public isRoundStyle
isRoundStyle: boolean
Type : boolean
Default value : true
Private localstorageEntries
localstorageEntries: LocalStorageEntry[]
Type : LocalStorageEntry[]
Public placeholder
placeholder: string
Type : string
Private reset
reset: Subject<any>
Type : Subject<any>
Decorators : WidgetOutput
Public style
style: boolean
Type : boolean
import { filter } from "rxjs/operators";
import { Component } from "@angular/core";
import { Subject, Subscription } from "rxjs";
import { WidgetframeService } from "../../widgetframe/widgetframe.service";
import { getOrDefault, WidgetConfig } from "../../widget.configuration";
import {
  WidgetComponent,
  WidgetConfiguration,
  WidgetConfigure,
  WidgetId,
  WidgetInput,
  WidgetOutput,
} from "../../widget.metadata";
import {
  LocalStorageEntry,
  LocalStorageService,
} from "../../../components/local-storage/local-storage.service";
import {
  DeletionMode,
  Scope,
} from "../../../components/local-storage/local-storage-constants";

@WidgetComponent("nm-product-search-reset")
@Component({
  selector: "nm-product-search-reset",
  templateUrl: "./productsearchreset.component.html",
  styleUrls: ["./productsearchreset.component.scss"],
})
export class ProductSearchResetWidgetComponent {
  @WidgetConfiguration()
  private configuration: WidgetConfig;

  @WidgetOutput("reset")
  private reset: Subject<any>;

  @WidgetInput("uri")
  private inputChannel: Subject<any> = new Subject<any>();

  @WidgetInput("hideButton")
  private hideButton: Subject<any> = new Subject<any>();

  @WidgetInput("hide")
  private hide: Subject<any> = new Subject<any>();

  @WidgetId()
  private _id: string;

  public style: boolean;

  private localstorageEntries: LocalStorageEntry[];
  private inputSubscription: Subscription;
  public isResetButtonNeeded: boolean;
  public isRoundStyle: boolean = true;
  public placeholder: string;
  public isHidden: boolean;

  constructor(
    private _widgetframeService: WidgetframeService,
    private localstorageService: LocalStorageService
  ) {
    this.inputSubscription = this.inputChannel
      .asObservable()
      .pipe(filter((link) => link))
      .subscribe((link) => {
        let isResetButtonNeeded = false;
        if (this.localstorageEntries) {
          this.localstorageEntries.forEach((entry) => {
            if (entry.value) {
              isResetButtonNeeded = true;
            }
          });
        }
        if (isResetButtonNeeded) {
          this.isResetButtonNeeded = isResetButtonNeeded;
          return;
        }
        // TODO: Find Better critera for showing the button!!
        if (
          (<any>link).indexOf("category") !== -1 ||
          localStorage.getItem(
            "productcomparison-portal-product-comparison-nm-product-listInput"
          ) ||
          localStorage.getItem("imarket-order-search-nm-order-searchInput")
        ) {
          this.isResetButtonNeeded = true;
        } else {
          this.isResetButtonNeeded = false;
        }
      });
  }

  resetSearch() {
    this.reset.next(Date.now);
    this.isResetButtonNeeded = false;
  }

  @WidgetConfigure()
  protected configureWidget(configuration: WidgetConfig) {
    if (configuration.configuration["isRoundStyle"] != undefined) {
      this.isRoundStyle = configuration.configuration["isRoundStyle"];
    }
    this.placeholder = getOrDefault(
      configuration.configuration["placeholder"],
      ""
    );
    if (this.configuration.configuration["localstorage-config"]) {
      let localStorageConfigs = this.configuration.configuration[
        "localstorage-config"
      ];
      this.localstorageEntries = [];
      localStorageConfigs.forEach((config) => {
        const scope: Scope = config.scope
          ? Scope[<string>config.scope]
          : Scope.GLOBAL;
        const localstorageEntry = this.localstorageService.getLocalStorageEntry(
          config.key,
          scope,
          DeletionMode.NEVER
        );
        this.localstorageEntries.push(localstorageEntry);
      });
    }
    this.style = this.configuration.configuration["customStyle"];

    this.hideButton.asObservable().subscribe((hide) => {
      this.isResetButtonNeeded = false;
    });

    this.hide.asObservable().subscribe((hide) => {
      this.isHidden = hide;
    });
  }
}
<button
  *ngIf="style == true && isResetButtonNeeded && isRoundStyle"
  mat-mini-fab
  color="primary"
  pTooltip="{{ 'infotext.newsearch' | translate }}"
  placement="bottom"
  container="body"
  triggers="mouseenter:mouseleave"
  class="mat-icon-button mat-elevation-z0 nm-button__reset"
  [class.nm-fadein]="isResetButtonNeeded"
  (click)="resetSearch()"
>
  <div
    class="material-icons nm-svg-icon"
    [ngStyle]="{ fill: 'rgb(255,153,0)' }"
  >
    <mat-icon>clear</mat-icon>
  </div>
</button>

<button
  *ngIf="style == false && isResetButtonNeeded && isRoundStyle"
  mat-mini-fab
  color="primary"
  pTooltip="{{ 'infotext.newsearch' | translate }}"
  class="mat-icon-button nm-button__reset mat-elevation-z0"
  [class.nm-fadein]="isResetButtonNeeded"
  (click)="resetSearch()"
>
  <div
    class="material-icons nm-svg-icon"
    [ngStyle]="{ fill: 'rgb(255,153,0)' }"
  >
    <mat-icon>clear</mat-icon>
  </div>
</button>

<button *ngIf="!isRoundStyle && !isHidden" mat-button (click)="resetSearch()">
  {{ placeholder | translate }}
</button>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""