-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathnode-menu.service.ts
More file actions
26 lines (22 loc) · 936 Bytes
/
node-menu.service.ts
File metadata and controls
26 lines (22 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { ElementRef, Injectable } from '@angular/core';
import { Subject , Observable } from 'rxjs';
import { NodeMenuAction, NodeMenuEvent } from './menu.events';
@Injectable()
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
});
}
}