File

feature-libs/storefinder/components/store-finder-search-result/store-finder-search-result.component.ts

Implements

OnInit OnDestroy

Metadata

selector cx-store-finder-search-result
templateUrl ./store-finder-search-result.component.html

Index

Properties
Methods

Constructor

constructor(storeFinderService: StoreFinderService, route: ActivatedRoute, config: StoreFinderConfig)
Parameters :
Name Type Optional
storeFinderService StoreFinderService No
route ActivatedRoute No
config StoreFinderConfig No

Methods

Private initialize
initialize(params: Params)
Parameters :
Name Type Optional
params Params No
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
Private parseParameters
parseParameters(queryParams: literal type)
Parameters :
Name Type Optional
queryParams literal type No
viewPage
viewPage(pageNumber: number)
Parameters :
Name Type Optional
pageNumber number No
Returns : void

Properties

countryCode
Type : string
Default value : null
geolocation
Type : GeoPoint
isLoading$
Type : Observable<any>
locations
Type : any
locations$
Type : Observable<any>
radius
Type : number
searchConfig
Type : SearchConfig
Default value : { currentPage: 0, }
searchQuery
Type : StoreFinderSearchQuery
subscription
Type : Subscription
useMyLocation
Type : boolean
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { GeoPoint, SearchConfig } from '@spartacus/core';
import { Observable, Subscription } from 'rxjs';
import {
  StoreFinderSearchQuery,
  StoreFinderService,
  StoreFinderConfig,
} from '@spartacus/storefinder/core';

@Component({
  selector: 'cx-store-finder-search-result',
  templateUrl: './store-finder-search-result.component.html',
})
export class StoreFinderSearchResultComponent implements OnInit, OnDestroy {
  locations: any;
  subscription: Subscription;
  useMyLocation: boolean;
  countryCode: string = null;
  searchConfig: SearchConfig = {
    currentPage: 0,
  };
  radius: number;
  searchQuery: StoreFinderSearchQuery;
  geolocation: GeoPoint;
  locations$: Observable<any>;
  isLoading$: Observable<any>;

  constructor(
    private storeFinderService: StoreFinderService,
    private route: ActivatedRoute,
    protected config: StoreFinderConfig
  ) {}

  ngOnInit() {
    this.subscription = this.route.queryParams.subscribe((params) =>
      this.initialize(params)
    );
  }

  ngOnDestroy() {
    if (this.subscription) {
      this.subscription.unsubscribe();
    }
  }

  viewPage(pageNumber: number) {
    this.searchConfig = { ...this.searchConfig, currentPage: pageNumber };
    this.storeFinderService.findStoresAction(
      this.searchQuery.queryText,
      this.searchConfig,
      this.geolocation,
      this.countryCode,
      this.useMyLocation,
      this.radius
    );
  }

  private initialize(params: Params) {
    this.searchQuery = this.parseParameters(params);
    this.useMyLocation = params && params.useMyLocation ? true : false;
    this.searchConfig = { ...this.searchConfig, currentPage: 0 };
    this.radius = this.config.googleMaps.radius;
    this.storeFinderService.findStoresAction(
      this.searchQuery.queryText,
      this.searchConfig,
      this.geolocation,
      this.countryCode,
      this.useMyLocation,
      this.radius
    );

    this.isLoading$ = this.storeFinderService.getStoresLoading();
    this.locations$ = this.storeFinderService.getFindStoresEntities();
  }

  private parseParameters(queryParams: {
    [key: string]: any;
  }): StoreFinderSearchQuery {
    let searchQuery: StoreFinderSearchQuery;

    if (queryParams.query) {
      searchQuery = { queryText: queryParams.query };
    } else {
      searchQuery = { queryText: '' };
    }

    searchQuery.useMyLocation =
      queryParams.useMyLocation != null &&
      queryParams.useMyLocation.toUpperCase() === 'TRUE';

    return searchQuery;
  }
}
<div
  *ngIf="
    !(isLoading$ | async) && (locations$ | async) as locations;
    else loading
  "
>
  <div *ngIf="locations?.stores.length">
    <div class="cx-pagination">
      <cx-pagination
        [pagination]="locations.pagination"
        (viewPageEvent)="viewPage($event)"
      ></cx-pagination>
    </div>
  </div>
  <cx-store-finder-list
    *ngIf="locations?.stores.length"
    [locations]="locations"
    [useMylocation]="useMyLocation"
  ></cx-store-finder-list>
  <div class="container" *ngIf="!locations?.stores.length">
    <div class="row">
      <span class="cx-no-stores" role="alert">
        {{ 'storeFinder.noStoresMessage' | cxTranslate }}
      </span>
    </div>
  </div>
</div>
<ng-template #loading>
  <div class="cx-spinner">
    <cx-spinner></cx-spinner>
  </div>
</ng-template>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""