Skip to content
Snippets Groups Projects
audio.ts 2.14 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Type } from '@angular/core';
    
      PlayerElement, PlayerElementBlueprint, UIElementType
    
    } from 'common/models/elements/element';
    
    import { ElementComponent } from 'common/directives/element-component.directive';
    import { AudioComponent } from 'common/components/media-elements/audio.component';
    
    rhenck's avatar
    rhenck committed
    import {
    
      PositionProperties, PropertyGroupGenerators
    
    rhenck's avatar
    rhenck committed
    } from 'common/models/elements/property-group-interfaces';
    import { environment } from 'common/environment';
    import { InstantiationEror } from 'common/util/errors';
    
    export class AudioElement extends PlayerElement implements AudioProperties {
    
      type: UIElementType = 'audio';
    
    rhenck's avatar
    rhenck committed
      src: string | null = null;
    
      position?: PositionProperties;
    
      styling: { backgroundColor: string };
    
      static title: string = 'Audio';
      static icon: string = 'volume_up';
    
    
    rhenck's avatar
    rhenck committed
      constructor(element?: AudioProperties) {
    
    rhenck's avatar
    rhenck committed
        if (element && isValid(element)) {
          this.src = element.src;
    
          if (element.position) this.position = { ...element.position };
    
          this.styling = { ...element.styling };
    
    rhenck's avatar
    rhenck committed
        } else {
          if (environment.strictInstantiation) {
            throw new InstantiationEror('Error at Audio instantiation', element);
          }
          if (element?.src !== undefined) this.src = element.src;
          this.dimensions = PropertyGroupGenerators.generateDimensionProps({
            width: 250,
            height: 90,
            ...element?.dimensions
          });
    
          this.position = PropertyGroupGenerators.generatePositionProps({
            marginBottom: { value: 15, unit: 'px' },
            ...element?.position
          });
    
          this.styling = {
            backgroundColor: '#f1f1f1',
            ...element?.styling
          };
    
    rhenck's avatar
    rhenck committed
        }
    
      getDuplicate(): AudioElement {
        return new AudioElement(this);
      }
    
    
      getElementComponent(): Type<ElementComponent> {
    
        return AudioComponent;
      }
    }
    
    
    export interface AudioProperties extends PlayerElementBlueprint {
      src: string | null;
    
      position?: PositionProperties;
    
      styling: { backgroundColor: string };
    
    rhenck's avatar
    rhenck committed
    
    function isValid(blueprint?: AudioProperties): boolean {
      if (!blueprint) return false;
      return blueprint.src !== undefined &&
    
        blueprint.styling?.backgroundColor !== undefined;
    
    rhenck's avatar
    rhenck committed
    }