File

src/converter/teaser/fs-teaser-overlay-factory.ts

Description

This class is a factory to create teaser overlay links.

Index

Methods

Constructor

constructor(semanticPathService: SemanticPathService, productService: ProductService)
Parameters :
Name Type Optional
semanticPathService SemanticPathService No
productService ProductService No

Methods

Public createOverlay
createOverlay(templateUid: string, area: ImageLinkTemplate | TextLinkTemplate | SearchLinkLinkTemplate | CategoryLinkTemplate | ProductLinkTemplate | ContentLinkTemplate, positionAndDimension)
Parameters :
Name Type Optional
templateUid string No
area ImageLinkTemplate | TextLinkTemplate | SearchLinkLinkTemplate | CategoryLinkTemplate | ProductLinkTemplate | ContentLinkTemplate No
positionAndDimension No
Returns : OverlayText | OverlayImage | OverlayLink | undefined
import { FsTeaserTextOverlay } from './fs-teaser-text-overlay';
import { FsTeaserSearchLinkOverlay } from './fs-teaser-search-link-overlay';
import { Injectable } from '@angular/core';

import {
  TextLinkTemplate,
  ImageLinkTemplate,
  OverlayDimension,
  OverlayPosition,
  SearchLinkLinkTemplate,
  FsTeaserOverlayFactoryInterface,
  OverlayText,
  OverlayImage,
  OverlayLink,
  CategoryLinkTemplate,
  ProductLinkTemplate,
  ContentLinkTemplate,
} from './fs-teaser.model';
import { FsTeaserImageOverlay } from './fs-teaser-image-overlay';
import { ProductService, SemanticPathService } from '@spartacus/core';
import { FsTeaserCategoryLinkOverlay } from './fs-teaser-category-link-overlay';
import { FsTeaserProductLinkOverlay } from './fs-teaser-product-link-overlay';
import { FsTeaserContentLinkOverlay } from './fs-teaser-content-link-overlay';

/**
 * This class is a factory to create teaser overlay links.
 *
 * @export
 * @class FsTeaserOverlayFactory
 */
@Injectable({ providedIn: 'root' })
export class FsTeaserOverlayFactory {
  constructor(private semanticPathService: SemanticPathService, private productService: ProductService) {}

  public createOverlay(
    templateUid: string,
    area: ImageLinkTemplate | TextLinkTemplate | SearchLinkLinkTemplate | CategoryLinkTemplate | ProductLinkTemplate | ContentLinkTemplate,
    positionAndDimension: OverlayPosition & OverlayDimension
  ): OverlayText | OverlayImage | OverlayLink | undefined {
    let overlay: FsTeaserOverlayFactoryInterface<any>;
    switch (templateUid) {
      case 'text':
        overlay = new FsTeaserTextOverlay(area as TextLinkTemplate, positionAndDimension);
        break;

      case 'image':
        overlay = new FsTeaserImageOverlay(area as ImageLinkTemplate, positionAndDimension);
        break;

      case 'search_link':
        overlay = new FsTeaserSearchLinkOverlay(area as SearchLinkLinkTemplate, positionAndDimension, this.semanticPathService);
        break;

      case 'category_link':
        overlay = new FsTeaserCategoryLinkOverlay(area as CategoryLinkTemplate, positionAndDimension, this.semanticPathService);
        break;

      case 'product_link':
        overlay = new FsTeaserProductLinkOverlay(area as ProductLinkTemplate, positionAndDimension, this.productService);
        break;

      case 'content_link':
        overlay = new FsTeaserContentLinkOverlay(area as ContentLinkTemplate, positionAndDimension, this.semanticPathService);
        break;

      default:
        console.warn(
          `No overlay implementation was found for the template '${templateUid}'! Please extend the FsTeaserOverlayFactory and add an implementation for this template uid`
        );
    }
    if (overlay != null) {
      return overlay.create();
    }
  }
}

results matching ""

    No results matching ""