UNPKG

5.54 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tree_events_1 = require("./tree.events");
4var Subject_1 = require("rxjs/Subject");
5var core_1 = require("@angular/core");
6var node_draggable_service_1 = require("./draggable/node-draggable.service");
7var fn_utils_1 = require("./utils/fn.utils");
8var TreeService = (function () {
9 function TreeService(nodeDraggableService) {
10 this.nodeDraggableService = nodeDraggableService;
11 this.nodeMoved$ = new Subject_1.Subject();
12 this.nodeRemoved$ = new Subject_1.Subject();
13 this.nodeRenamed$ = new Subject_1.Subject();
14 this.nodeCreated$ = new Subject_1.Subject();
15 this.nodeSelected$ = new Subject_1.Subject();
16 this.nodeUnselected$ = new Subject_1.Subject();
17 this.nodeExpanded$ = new Subject_1.Subject();
18 this.nodeCollapsed$ = new Subject_1.Subject();
19 this.menuItemSelected$ = new Subject_1.Subject();
20 this.loadNextLevel$ = new Subject_1.Subject();
21 this.nodeChecked$ = new Subject_1.Subject();
22 this.nodeUnchecked$ = new Subject_1.Subject();
23 this.nodeIndetermined$ = new Subject_1.Subject();
24 this.controllers = new Map();
25 this.nodeRemoved$.subscribe(function (e) { return e.node.removeItselfFromParent(); });
26 }
27 TreeService.prototype.unselectStream = function (tree) {
28 return this.nodeSelected$.filter(function (e) { return tree !== e.node; });
29 };
30 TreeService.prototype.fireNodeRemoved = function (tree) {
31 this.nodeRemoved$.next(new tree_events_1.NodeRemovedEvent(tree, tree.positionInParent));
32 };
33 TreeService.prototype.fireNodeCreated = function (tree) {
34 this.nodeCreated$.next(new tree_events_1.NodeCreatedEvent(tree));
35 };
36 TreeService.prototype.fireNodeSelected = function (tree) {
37 this.nodeSelected$.next(new tree_events_1.NodeSelectedEvent(tree));
38 };
39 TreeService.prototype.fireNodeUnselected = function (tree) {
40 this.nodeUnselected$.next(new tree_events_1.NodeUnselectedEvent(tree));
41 };
42 TreeService.prototype.fireNodeRenamed = function (oldValue, tree) {
43 this.nodeRenamed$.next(new tree_events_1.NodeRenamedEvent(tree, oldValue, tree.value));
44 };
45 TreeService.prototype.fireNodeMoved = function (tree, parent) {
46 this.nodeMoved$.next(new tree_events_1.NodeMovedEvent(tree, parent));
47 };
48 TreeService.prototype.fireMenuItemSelected = function (tree, selectedItem) {
49 this.menuItemSelected$.next(new tree_events_1.MenuItemSelectedEvent(tree, selectedItem));
50 };
51 TreeService.prototype.fireNodeSwitchFoldingType = function (tree) {
52 if (tree.isNodeExpanded()) {
53 this.fireNodeExpanded(tree);
54 if (this.shouldFireLoadNextLevel(tree)) {
55 this.fireLoadNextLevel(tree);
56 }
57 }
58 else if (tree.isNodeCollapsed()) {
59 this.fireNodeCollapsed(tree);
60 }
61 };
62 TreeService.prototype.fireNodeExpanded = function (tree) {
63 this.nodeExpanded$.next(new tree_events_1.NodeExpandedEvent(tree));
64 };
65 TreeService.prototype.fireNodeCollapsed = function (tree) {
66 this.nodeCollapsed$.next(new tree_events_1.NodeCollapsedEvent(tree));
67 };
68 TreeService.prototype.fireLoadNextLevel = function (tree) {
69 this.loadNextLevel$.next(new tree_events_1.LoadNextLevelEvent(tree));
70 };
71 TreeService.prototype.fireNodeChecked = function (tree) {
72 this.nodeChecked$.next(new tree_events_1.NodeCheckedEvent(tree));
73 };
74 TreeService.prototype.fireNodeUnchecked = function (tree) {
75 this.nodeUnchecked$.next(new tree_events_1.NodeUncheckedEvent(tree));
76 };
77 TreeService.prototype.draggedStream = function (tree, element) {
78 return this.nodeDraggableService.draggableNodeEvents$
79 .filter(function (e) { return e.target === element; })
80 .filter(function (e) { return !e.captured.tree.hasChild(tree); });
81 };
82 TreeService.prototype.setController = function (id, controller) {
83 this.controllers.set(id, controller);
84 };
85 TreeService.prototype.deleteController = function (id) {
86 if (this.controllers.has(id)) {
87 this.controllers.delete(id);
88 }
89 };
90 TreeService.prototype.getController = function (id) {
91 if (this.controllers.has(id)) {
92 return this.controllers.get(id);
93 }
94 return null;
95 };
96 TreeService.prototype.hasController = function (id) {
97 return this.controllers.has(id);
98 };
99 TreeService.prototype.shouldFireLoadNextLevel = function (tree) {
100 var shouldLoadNextLevel = tree.node.emitLoadNextLevel &&
101 !tree.node.loadChildren &&
102 !tree.childrenAreBeingLoaded() &&
103 fn_utils_1.isEmpty(tree.children);
104 if (shouldLoadNextLevel) {
105 tree.loadingChildrenRequested();
106 }
107 return shouldLoadNextLevel;
108 };
109 TreeService.prototype.fireNodeIndetermined = function (tree) {
110 this.nodeIndetermined$.next(new tree_events_1.NodeIndeterminedEvent(tree));
111 };
112 TreeService.decorators = [
113 { type: core_1.Injectable },
114 ];
115 /** @nocollapse */
116 TreeService.ctorParameters = function () { return [
117 { type: node_draggable_service_1.NodeDraggableService, decorators: [{ type: core_1.Inject, args: [node_draggable_service_1.NodeDraggableService,] },] },
118 ]; };
119 return TreeService;
120}());
121exports.TreeService = TreeService;
122//# sourceMappingURL=tree.service.js.map
\No newline at end of file