Skip to content
Snippets Groups Projects
drag-operation.ts 1.64 KiB
Newer Older
  • Learn to ignore specific revisions
  • rhenck's avatar
    rhenck committed
    import { DragNDropValueObject } from 'common/models/elements/label-interfaces';
    import { DropListComponent } from 'common/components/input-elements/drop-list/drop-list.component';
    
    import { DropLogic } from 'common/components/input-elements/drop-list/drop-logic';
    
    rhenck's avatar
    rhenck committed
    
    export class DragOperation {
      sourceElement: HTMLElement;
      draggedItem: DragNDropValueObject;
      sourceComponent: DropListComponent;
      sourceIndex: number;
      targetComponent: DropListComponent | undefined;
      dragType: 'mouse' | 'touch';
      sortingPlaceholderIndex: number | undefined;
      isForeignPlaceholderActive: boolean = false;
      placeholderElement: HTMLElement | undefined;
      eligibleTargetListsIDs: string[]; // helper list for better performance
    
      constructor(sourceElement: HTMLElement, sourceListComponent: DropListComponent, sourceIndex: number,
                  item: DragNDropValueObject, dragType: 'mouse' | 'touch',
                  allDropLists: { [id: string]: DropListComponent }) {
        this.sourceElement = sourceElement;
        this.draggedItem = item;
        this.sourceComponent = sourceListComponent;
        this.sourceIndex = sourceIndex;
        this.dragType = dragType;
        if (this.sourceComponent.elementModel.isSortList) this.sortingPlaceholderIndex = sourceIndex;
        this.targetComponent = sourceListComponent;
    
        this.eligibleTargetListsIDs = Object.values(allDropLists)
    
          .filter(dropList => (DropLogic.isDropAllowed( // TODO performance!
    
    rhenck's avatar
    rhenck committed
            this.draggedItem,
    
            sourceListComponent.elementModel.id,
            allDropLists[dropList.elementModel.id].elementModel.id,
            DropLogic.createDropListMocks(allDropLists))
    
    rhenck's avatar
    rhenck committed
          ))
          .map(droplist => droplist.elementModel.id);
      }
    }