ng2-tree-hackaday
Version:
angular2 component for visualizing data that can be naturally represented as a tree
27 lines (22 loc) • 963 B
text/typescript
import { Injectable, ElementRef } from '@angular/core';
import { Subject, Observable } from 'rxjs/Rx';
import { NodeMenuEvent, NodeMenuAction } from './menu.events';
()
export class NodeMenuService {
public nodeMenuEvents$: Subject<NodeMenuEvent> = new Subject<NodeMenuEvent>();
public fireMenuEvent(sender: HTMLElement, action: NodeMenuAction): void {
const nodeMenuEvent: NodeMenuEvent = { sender, action };
this.nodeMenuEvents$.next(nodeMenuEvent);
}
public hideMenuStream(treeElementRef: ElementRef): Observable<any> {
return this.nodeMenuEvents$
.filter((e: NodeMenuEvent) => treeElementRef.nativeElement !== e.sender)
.filter((e: NodeMenuEvent) => e.action === NodeMenuAction.Close);
}
public hideMenuForAllNodesExcept(treeElementRef: ElementRef): void {
this.nodeMenuEvents$.next({
sender: treeElementRef.nativeElement,
action: NodeMenuAction.Close
});
}
}