ng2-tree-hackaday
Version:
angular2 component for visualizing data that can be naturally represented as a tree
32 lines (24 loc) • 886 B
text/typescript
import { Injectable, ElementRef } from '@angular/core';
import { Subject } from 'rxjs/Rx';
import { CapturedNode } from './captured-node';
import { NodeDraggableEvent } from './draggable.events';
@Injectable()
export class NodeDraggableService {
public draggableNodeEvents$: Subject<NodeDraggableEvent> = new Subject<NodeDraggableEvent>();
private capturedNode: CapturedNode;
public fireNodeDragged(captured: CapturedNode, target: ElementRef): void {
if (!captured.tree || captured.tree.isStatic()) {
return;
}
this.draggableNodeEvents$.next(new NodeDraggableEvent(captured, target));
}
public captureNode(node: CapturedNode): void {
this.capturedNode = node;
}
public getCapturedNode(): CapturedNode {
return this.capturedNode;
}
public releaseCapturedNode(): void {
this.capturedNode = null;
}
}