Skip to content
Snippets Groups Projects
page.ts 1.33 KiB
Newer Older
import { Section } from 'common/models/section';
rhenck's avatar
rhenck committed
import { IDManager } from 'common/util/id-manager';
import { UIElement } from 'common/models/elements/element';

export class Page {
  [index: string]: any;
  sections: Section[] = [];
  hasMaxWidth: boolean = false;
  maxWidth: number = 900;
  margin: number = 30;
  backgroundColor: string = '#ffffff';
  alwaysVisible: boolean = false;
  alwaysVisiblePagePosition: 'left' | 'right' | 'top' | 'bottom' = 'left';
  alwaysVisibleAspectRatio: number = 50;

rhenck's avatar
rhenck committed
  constructor(page?: Partial<Page>, idManager?: IDManager) {
rhenck's avatar
rhenck committed
    if (page?.hasMaxWidth) this.hasMaxWidth = page.hasMaxWidth;
    if (page?.maxWidth) this.maxWidth = page.maxWidth;
    if (page?.margin !== undefined) this.margin = page.margin;
rhenck's avatar
rhenck committed
    if (page?.backgroundColor) this.backgroundColor = page.backgroundColor;
    if (page?.alwaysVisible) this.alwaysVisible = page.alwaysVisible;
    if (page?.alwaysVisiblePagePosition) this.alwaysVisiblePagePosition = page.alwaysVisiblePagePosition;
    if (page?.alwaysVisibleAspectRatio) this.alwaysVisibleAspectRatio = page.alwaysVisibleAspectRatio;
rhenck's avatar
rhenck committed
    this.sections = page?.sections?.map(section => new Section(section, idManager)) || [new Section()];

  getAllElements(elementType?: string): UIElement[] {
    return this.sections.map(section => section.getAllElements(elementType)).flat();
  }