All files / src/app/shared/cms/components/content-design-view-wrapper content-design-view-wrapper.component.ts

95.45% Statements 21/22
78.94% Branches 15/19
75% Functions 3/4
95.45% Lines 21/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 583x 3x   3x 3x 3x 3x               3x                       5x         5x 5x 5x       5x   5x 1x 1x   1x 1x   4x 1x 3x 1x                
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { Observable, map } from 'rxjs';
 
import { CMSFacade } from 'ish-core/facades/cms.facade';
import { ContentPageletEntryPointView, ContentPageletView } from 'ish-core/models/content-view/content-view.model';
import { DesignViewService } from 'ish-core/utils/design-view/design-view.service';
import { PreviewService } from 'ish-core/utils/preview/preview.service';
 
@Component({
  selector: 'ish-content-design-view-wrapper',
  templateUrl: './content-design-view-wrapper.component.html',
  styleUrls: ['./content-design-view-wrapper.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ContentDesignViewWrapperComponent implements OnInit {
  // pagelet parameter
  @Input() pageletId: string;
  // slot parameters
  @Input() slotId: string;
  @Input() pagelet: ContentPageletView;
  // include parameter
  @Input() include: ContentPageletEntryPointView;
 
  pagelet$: Observable<ContentPageletView>;
  type: 'pagelet' | 'slot' | 'include';
 
  isDesignViewMode = false; // temporary activation switch
 
  isPageletSelected$: Observable<boolean>;
 
  constructor(
    private cmsFacade: CMSFacade,
    private previewService: PreviewService,
    private designViewService: DesignViewService
  ) {}
 
  ngOnInit() {
    this.isDesignViewMode = this.previewService.isDesignViewMode;
 
    if (this.pageletId) {
      this.type = 'pagelet';
      this.pagelet$ = this.cmsFacade.pagelet$(this.pageletId);
 
      this.isPageletSelected$ = this.cmsFacade.designViewSelectedPageletId$.pipe(
        map(id => (this.isDesignViewMode ? this.pageletId === id : false))
      );
    } else if (this.slotId) {
      this.type = 'slot';
    } else if (this.include) {
      this.type = 'include';
    }
  }
 
  triggerAction(id: string, action: string) {
    this.designViewService.messageToHost({ type: 'dv-clientAction', payload: { id, action } });
  }
}