UNPKG

10.9 kBJavaScriptView Raw
1/**
2 * ag-grid - Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components
3 * @version v18.1.2
4 * @link http://www.ag-grid.com/
5 * @license MIT
6 */
7"use strict";
8var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
9 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
11 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
12 return c > 3 && r && Object.defineProperty(target, key, r), r;
13};
14var __metadata = (this && this.__metadata) || function (k, v) {
15 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
16};
17Object.defineProperty(exports, "__esModule", { value: true });
18var context_1 = require("../../context/context");
19var rowNode_1 = require("../../entities/rowNode");
20var utils_1 = require("../../utils");
21var gridOptionsWrapper_1 = require("../../gridOptionsWrapper");
22var selectionController_1 = require("../../selectionController");
23var eventService_1 = require("../../eventService");
24var columnController_1 = require("../../columnController/columnController");
25var FlattenStage = (function () {
26 function FlattenStage() {
27 }
28 FlattenStage.prototype.execute = function (params) {
29 var rootNode = params.rowNode;
30 // even if not doing grouping, we do the mapping, as the client might
31 // of passed in data that already has a grouping in it somewhere
32 var result = [];
33 // putting value into a wrapper so it's passed by reference
34 var nextRowTop = { value: 0 };
35 var skipLeafNodes = this.columnController.isPivotMode();
36 // if we are reducing, and not grouping, then we want to show the root node, as that
37 // is where the pivot values are
38 var showRootNode = skipLeafNodes && rootNode.leafGroup;
39 var topList = showRootNode ? [rootNode] : rootNode.childrenAfterSort;
40 // set all row tops to null, then set row tops on all visible rows. if we don't
41 // do this, then the algorithm below only sets row tops, old row tops from old rows
42 // will still lie around
43 this.resetRowTops(rootNode);
44 this.recursivelyAddToRowsToDisplay(topList, result, nextRowTop, skipLeafNodes, 0);
45 // don't show total footer when showRootNode is true (i.e. in pivot mode and no groups)
46 var includeGroupTotalFooter = !showRootNode && this.gridOptionsWrapper.isGroupIncludeTotalFooter();
47 if (includeGroupTotalFooter) {
48 this.ensureFooterNodeExists(rootNode);
49 this.addRowNodeToRowsToDisplay(rootNode.sibling, result, nextRowTop, 0);
50 }
51 return result;
52 };
53 FlattenStage.prototype.resetRowTops = function (rowNode) {
54 rowNode.clearRowTop();
55 if (rowNode.hasChildren()) {
56 if (rowNode.childrenAfterGroup) {
57 for (var i = 0; i < rowNode.childrenAfterGroup.length; i++) {
58 this.resetRowTops(rowNode.childrenAfterGroup[i]);
59 }
60 }
61 if (rowNode.sibling) {
62 rowNode.sibling.clearRowTop();
63 }
64 }
65 };
66 FlattenStage.prototype.recursivelyAddToRowsToDisplay = function (rowsToFlatten, result, nextRowTop, skipLeafNodes, uiLevel) {
67 if (utils_1.Utils.missingOrEmpty(rowsToFlatten)) {
68 return;
69 }
70 var groupSuppressRow = this.gridOptionsWrapper.isGroupSuppressRow();
71 var hideOpenParents = this.gridOptionsWrapper.isGroupHideOpenParents();
72 // these two are mutually exclusive, so if first set, we don't set the second
73 var groupRemoveSingleChildren = this.gridOptionsWrapper.isGroupRemoveSingleChildren();
74 var groupRemoveLowestSingleChildren = !groupRemoveSingleChildren && this.gridOptionsWrapper.isGroupRemoveLowestSingleChildren();
75 for (var i = 0; i < rowsToFlatten.length; i++) {
76 var rowNode = rowsToFlatten[i];
77 // check all these cases, for working out if this row should be included in the final mapped list
78 var isParent = rowNode.hasChildren();
79 var isGroupSuppressedNode = groupSuppressRow && isParent;
80 var isSkippedLeafNode = skipLeafNodes && !isParent;
81 var isRemovedSingleChildrenGroup = groupRemoveSingleChildren && isParent && rowNode.childrenAfterGroup.length === 1;
82 var isRemovedLowestSingleChildrenGroup = groupRemoveLowestSingleChildren && isParent && rowNode.leafGroup && rowNode.childrenAfterGroup.length === 1;
83 // hide open parents means when group is open, we don't show it. we also need to make sure the
84 // group is expandable in the first place (as leaf groups are not expandable if pivot mode is on).
85 // the UI will never allow expanding leaf groups, however the user might via the API (or menu option 'expand all')
86 var neverAllowToExpand = skipLeafNodes && rowNode.leafGroup;
87 var isHiddenOpenParent = hideOpenParents && rowNode.expanded && (!neverAllowToExpand);
88 var thisRowShouldBeRendered = !isSkippedLeafNode && !isGroupSuppressedNode && !isHiddenOpenParent && !isRemovedSingleChildrenGroup && !isRemovedLowestSingleChildrenGroup;
89 if (thisRowShouldBeRendered) {
90 this.addRowNodeToRowsToDisplay(rowNode, result, nextRowTop, uiLevel);
91 }
92 // if we are pivoting, we never map below the leaf group
93 if (skipLeafNodes && rowNode.leafGroup) {
94 continue;
95 }
96 if (isParent) {
97 var excludedParent = isRemovedSingleChildrenGroup || isRemovedLowestSingleChildrenGroup;
98 // we traverse the group if it is expended, however we always traverse if the parent node
99 // was removed (as the group will never be opened if it is not displayed, we show the children instead)
100 if (rowNode.expanded || excludedParent) {
101 // if the parent was excluded, then ui level is that of the parent
102 var uiLevelForChildren = excludedParent ? uiLevel : uiLevel + 1;
103 this.recursivelyAddToRowsToDisplay(rowNode.childrenAfterSort, result, nextRowTop, skipLeafNodes, uiLevelForChildren);
104 // put a footer in if user is looking for it
105 if (this.gridOptionsWrapper.isGroupIncludeFooter()) {
106 this.ensureFooterNodeExists(rowNode);
107 this.addRowNodeToRowsToDisplay(rowNode.sibling, result, nextRowTop, uiLevel);
108 }
109 }
110 else {
111 }
112 }
113 else if (rowNode.master && rowNode.expanded) {
114 var detailNode = this.createDetailNode(rowNode);
115 this.addRowNodeToRowsToDisplay(detailNode, result, nextRowTop, uiLevel);
116 }
117 }
118 };
119 // duplicated method, it's also in floatingRowModel
120 FlattenStage.prototype.addRowNodeToRowsToDisplay = function (rowNode, result, nextRowTop, uiLevel) {
121 result.push(rowNode);
122 if (utils_1.Utils.missing(rowNode.rowHeight)) {
123 var rowHeight = this.gridOptionsWrapper.getRowHeightForNode(rowNode);
124 rowNode.setRowHeight(rowHeight);
125 }
126 rowNode.setUiLevel(uiLevel);
127 rowNode.setRowTop(nextRowTop.value);
128 rowNode.setRowIndex(result.length - 1);
129 nextRowTop.value += rowNode.rowHeight;
130 };
131 FlattenStage.prototype.ensureFooterNodeExists = function (groupNode) {
132 // only create footer node once, otherwise we have daemons and
133 // the animate screws up with the daemons hanging around
134 if (utils_1.Utils.exists(groupNode.sibling)) {
135 return;
136 }
137 var footerNode = new rowNode_1.RowNode();
138 this.context.wireBean(footerNode);
139 Object.keys(groupNode).forEach(function (key) {
140 footerNode[key] = groupNode[key];
141 });
142 footerNode.footer = true;
143 footerNode.rowTop = null;
144 footerNode.oldRowTop = null;
145 if (utils_1.Utils.exists(footerNode.id)) {
146 footerNode.id = 'rowGroupFooter_' + footerNode.id;
147 }
148 // get both header and footer to reference each other as siblings. this is never undone,
149 // only overwritten. so if a group is expanded, then contracted, it will have a ghost
150 // sibling - but that's fine, as we can ignore this if the header is contracted.
151 footerNode.sibling = groupNode;
152 groupNode.sibling = footerNode;
153 };
154 FlattenStage.prototype.createDetailNode = function (masterNode) {
155 if (utils_1.Utils.exists(masterNode.detailNode)) {
156 return masterNode.detailNode;
157 }
158 else {
159 var detailNode = new rowNode_1.RowNode();
160 this.context.wireBean(detailNode);
161 detailNode.detail = true;
162 // flower was renamed to 'detail', but keeping for backwards compatibility
163 detailNode.flower = detailNode.detail;
164 detailNode.parent = masterNode;
165 if (utils_1.Utils.exists(masterNode.id)) {
166 detailNode.id = 'detail_' + masterNode.id;
167 }
168 detailNode.data = masterNode.data;
169 detailNode.level = masterNode.level + 1;
170 masterNode.detailNode = detailNode;
171 masterNode.childFlower = masterNode.detailNode; // for backwards compatibility
172 return detailNode;
173 }
174 };
175 __decorate([
176 context_1.Autowired('gridOptionsWrapper'),
177 __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
178 ], FlattenStage.prototype, "gridOptionsWrapper", void 0);
179 __decorate([
180 context_1.Autowired('selectionController'),
181 __metadata("design:type", selectionController_1.SelectionController)
182 ], FlattenStage.prototype, "selectionController", void 0);
183 __decorate([
184 context_1.Autowired('eventService'),
185 __metadata("design:type", eventService_1.EventService)
186 ], FlattenStage.prototype, "eventService", void 0);
187 __decorate([
188 context_1.Autowired('context'),
189 __metadata("design:type", context_1.Context)
190 ], FlattenStage.prototype, "context", void 0);
191 __decorate([
192 context_1.Autowired('columnController'),
193 __metadata("design:type", columnController_1.ColumnController)
194 ], FlattenStage.prototype, "columnController", void 0);
195 FlattenStage = __decorate([
196 context_1.Bean('flattenStage')
197 ], FlattenStage);
198 return FlattenStage;
199}());
200exports.FlattenStage = FlattenStage;