1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | "use strict";
|
8 | var __extends = (this && this.__extends) || (function () {
|
9 | var extendStatics = Object.setPrototypeOf ||
|
10 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
11 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
12 | return function (d, b) {
|
13 | extendStatics(d, b);
|
14 | function __() { this.constructor = d; }
|
15 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
16 | };
|
17 | })();
|
18 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
19 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
20 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
21 | 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;
|
22 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
23 | };
|
24 | var __metadata = (this && this.__metadata) || function (k, v) {
|
25 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
26 | };
|
27 | Object.defineProperty(exports, "__esModule", { value: true });
|
28 | var component_1 = require("../widgets/component");
|
29 | var context_1 = require("../context/context");
|
30 | var gridOptionsWrapper_1 = require("../gridOptionsWrapper");
|
31 | var columnController_1 = require("../columnController/columnController");
|
32 | var column_1 = require("../entities/column");
|
33 | var eventService_1 = require("../eventService");
|
34 | var events_1 = require("../events");
|
35 | var utils_1 = require("../utils");
|
36 | var headerWrapperComp_1 = require("./header/headerWrapperComp");
|
37 | var headerGroupWrapperComp_1 = require("./headerGroup/headerGroupWrapperComp");
|
38 | var filterManager_1 = require("../filter/filterManager");
|
39 | var componentRecipes_1 = require("../components/framework/componentRecipes");
|
40 | var gridApi_1 = require("../gridApi");
|
41 | var HeaderRowType;
|
42 | (function (HeaderRowType) {
|
43 | HeaderRowType[HeaderRowType["COLUMN_GROUP"] = 0] = "COLUMN_GROUP";
|
44 | HeaderRowType[HeaderRowType["COLUMN"] = 1] = "COLUMN";
|
45 | HeaderRowType[HeaderRowType["FLOATING_FILTER"] = 2] = "FLOATING_FILTER";
|
46 | })(HeaderRowType = exports.HeaderRowType || (exports.HeaderRowType = {}));
|
47 | var HeaderRowComp = (function (_super) {
|
48 | __extends(HeaderRowComp, _super);
|
49 | function HeaderRowComp(dept, type, pinned, dropTarget) {
|
50 | var _this = _super.call(this, "<div class=\"ag-header-row\" role=\"presentation\"/>") || this;
|
51 | _this.headerComps = {};
|
52 | _this.dept = dept;
|
53 | _this.type = type;
|
54 | _this.pinned = pinned;
|
55 | _this.dropTarget = dropTarget;
|
56 | return _this;
|
57 | }
|
58 | HeaderRowComp.prototype.forEachHeaderElement = function (callback) {
|
59 | var _this = this;
|
60 | Object.keys(this.headerComps).forEach(function (key) {
|
61 | callback(_this.headerComps[key]);
|
62 | });
|
63 | };
|
64 | HeaderRowComp.prototype.destroy = function () {
|
65 | var idsOfAllChildren = Object.keys(this.headerComps);
|
66 | this.removeAndDestroyChildComponents(idsOfAllChildren);
|
67 | _super.prototype.destroy.call(this);
|
68 | };
|
69 | HeaderRowComp.prototype.removeAndDestroyChildComponents = function (idsToDestroy) {
|
70 | var _this = this;
|
71 | idsToDestroy.forEach(function (id) {
|
72 | var childHeaderComp = _this.headerComps[id];
|
73 | _this.getGui().removeChild(childHeaderComp.getGui());
|
74 | if (childHeaderComp.destroy) {
|
75 | childHeaderComp.destroy();
|
76 | }
|
77 | delete _this.headerComps[id];
|
78 | });
|
79 | };
|
80 | HeaderRowComp.prototype.onRowHeightChanged = function () {
|
81 | var headerRowCount = this.columnController.getHeaderRowCount();
|
82 | var sizes = [];
|
83 | var numberOfFloating = 0;
|
84 | var groupHeight;
|
85 | var headerHeight;
|
86 | if (!this.columnController.isPivotMode()) {
|
87 | if (this.gridOptionsWrapper.isFloatingFilter()) {
|
88 | headerRowCount++;
|
89 | }
|
90 | numberOfFloating = (this.gridOptionsWrapper.isFloatingFilter()) ? 1 : 0;
|
91 | groupHeight = this.gridOptionsWrapper.getGroupHeaderHeight();
|
92 | headerHeight = this.gridOptionsWrapper.getHeaderHeight();
|
93 | }
|
94 | else {
|
95 | numberOfFloating = 0;
|
96 | groupHeight = this.gridOptionsWrapper.getPivotGroupHeaderHeight();
|
97 | headerHeight = this.gridOptionsWrapper.getPivotHeaderHeight();
|
98 | }
|
99 | var numberOfNonGroups = 1 + numberOfFloating;
|
100 | var numberOfGroups = headerRowCount - numberOfNonGroups;
|
101 | for (var i = 0; i < numberOfGroups; i++) {
|
102 | sizes.push(groupHeight);
|
103 | }
|
104 | sizes.push(headerHeight);
|
105 | for (var i = 0; i < numberOfFloating; i++) {
|
106 | sizes.push(this.gridOptionsWrapper.getFloatingFiltersHeight());
|
107 | }
|
108 | var rowHeight = 0;
|
109 | for (var i = 0; i < this.dept; i++) {
|
110 | rowHeight += sizes[i];
|
111 | }
|
112 | this.getGui().style.top = rowHeight + 'px';
|
113 | this.getGui().style.height = sizes[this.dept] + 'px';
|
114 | };
|
115 |
|
116 | HeaderRowComp.prototype.init = function () {
|
117 | this.onRowHeightChanged();
|
118 | this.onVirtualColumnsChanged();
|
119 | this.setWidth();
|
120 | this.addDestroyableEventListener(this.gridOptionsWrapper, gridOptionsWrapper_1.GridOptionsWrapper.PROP_HEADER_HEIGHT, this.onRowHeightChanged.bind(this));
|
121 | this.addDestroyableEventListener(this.gridOptionsWrapper, gridOptionsWrapper_1.GridOptionsWrapper.PROP_PIVOT_HEADER_HEIGHT, this.onRowHeightChanged.bind(this));
|
122 | this.addDestroyableEventListener(this.gridOptionsWrapper, gridOptionsWrapper_1.GridOptionsWrapper.PROP_GROUP_HEADER_HEIGHT, this.onRowHeightChanged.bind(this));
|
123 | this.addDestroyableEventListener(this.gridOptionsWrapper, gridOptionsWrapper_1.GridOptionsWrapper.PROP_PIVOT_GROUP_HEADER_HEIGHT, this.onRowHeightChanged.bind(this));
|
124 | this.addDestroyableEventListener(this.gridOptionsWrapper, gridOptionsWrapper_1.GridOptionsWrapper.PROP_FLOATING_FILTERS_HEIGHT, this.onRowHeightChanged.bind(this));
|
125 | this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_VIRTUAL_COLUMNS_CHANGED, this.onVirtualColumnsChanged.bind(this));
|
126 | this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_DISPLAYED_COLUMNS_CHANGED, this.onDisplayedColumnsChanged.bind(this));
|
127 | this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_COLUMN_RESIZED, this.onColumnResized.bind(this));
|
128 | this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_GRID_COLUMNS_CHANGED, this.onGridColumnsChanged.bind(this));
|
129 | };
|
130 | HeaderRowComp.prototype.onColumnResized = function () {
|
131 | this.setWidth();
|
132 | };
|
133 | HeaderRowComp.prototype.setWidth = function () {
|
134 | var mainRowWidth = this.columnController.getContainerWidth(this.pinned) + 'px';
|
135 | this.getGui().style.width = mainRowWidth;
|
136 | };
|
137 | HeaderRowComp.prototype.onGridColumnsChanged = function () {
|
138 | this.removeAndDestroyAllChildComponents();
|
139 | };
|
140 | HeaderRowComp.prototype.removeAndDestroyAllChildComponents = function () {
|
141 | var idsOfAllChildren = Object.keys(this.headerComps);
|
142 | this.removeAndDestroyChildComponents(idsOfAllChildren);
|
143 | };
|
144 | HeaderRowComp.prototype.onDisplayedColumnsChanged = function () {
|
145 | this.onVirtualColumnsChanged();
|
146 | this.setWidth();
|
147 | };
|
148 | HeaderRowComp.prototype.onVirtualColumnsChanged = function () {
|
149 | var _this = this;
|
150 | var currentChildIds = Object.keys(this.headerComps);
|
151 | var itemsAtDepth = this.columnController.getVirtualHeaderGroupRow(this.pinned, this.type == HeaderRowType.FLOATING_FILTER ?
|
152 | this.dept - 1 :
|
153 | this.dept);
|
154 | var ensureDomOrder = this.gridOptionsWrapper.isEnsureDomOrder();
|
155 | var eBefore;
|
156 | itemsAtDepth.forEach(function (child) {
|
157 |
|
158 |
|
159 |
|
160 |
|
161 | if (child.isEmptyGroup()) {
|
162 | return;
|
163 | }
|
164 | var idOfChild = child.getUniqueId();
|
165 | var eParentContainer = _this.getGui();
|
166 |
|
167 | var colAlreadyInDom = currentChildIds.indexOf(idOfChild) >= 0;
|
168 | var headerComp;
|
169 | var eHeaderCompGui;
|
170 | if (colAlreadyInDom) {
|
171 | utils_1.Utils.removeFromArray(currentChildIds, idOfChild);
|
172 | headerComp = _this.headerComps[idOfChild];
|
173 | eHeaderCompGui = headerComp.getGui();
|
174 | if (ensureDomOrder) {
|
175 | utils_1.Utils.ensureDomOrder(eParentContainer, eHeaderCompGui, eBefore);
|
176 | }
|
177 | eBefore = eHeaderCompGui;
|
178 | }
|
179 | else {
|
180 | headerComp = _this.createHeaderComp(child);
|
181 | _this.headerComps[idOfChild] = headerComp;
|
182 | eHeaderCompGui = headerComp.getGui();
|
183 | if (ensureDomOrder) {
|
184 | utils_1.Utils.insertWithDomOrder(eParentContainer, eHeaderCompGui, eBefore);
|
185 | }
|
186 | else {
|
187 | eParentContainer.appendChild(eHeaderCompGui);
|
188 | }
|
189 | eBefore = eHeaderCompGui;
|
190 | }
|
191 | });
|
192 |
|
193 | this.removeAndDestroyChildComponents(currentChildIds);
|
194 | };
|
195 | HeaderRowComp.prototype.createHeaderComp = function (columnGroupChild) {
|
196 | var result;
|
197 | switch (this.type) {
|
198 | case HeaderRowType.COLUMN:
|
199 | result = new headerWrapperComp_1.HeaderWrapperComp(columnGroupChild, this.dropTarget, this.pinned);
|
200 | break;
|
201 | case HeaderRowType.COLUMN_GROUP:
|
202 | result = new headerGroupWrapperComp_1.HeaderGroupWrapperComp(columnGroupChild, this.dropTarget, this.pinned);
|
203 | break;
|
204 | case HeaderRowType.FLOATING_FILTER:
|
205 | var column = columnGroupChild;
|
206 | result = this.createFloatingFilterWrapper(column);
|
207 | break;
|
208 | }
|
209 | this.context.wireBean(result);
|
210 | return result;
|
211 | };
|
212 | HeaderRowComp.prototype.createFloatingFilterWrapper = function (column) {
|
213 | var _this = this;
|
214 | var floatingFilterParams = this.createFloatingFilterParams(column);
|
215 | var floatingFilterWrapper = this.componentRecipes.newFloatingFilterWrapperComponent(column, floatingFilterParams);
|
216 | this.addDestroyableEventListener(column, column_1.Column.EVENT_FILTER_CHANGED, function () {
|
217 | var filterComponentPromise = _this.filterManager.getFilterComponent(column);
|
218 | floatingFilterWrapper.onParentModelChanged(filterComponentPromise.resolveNow(null, function (filter) { return filter.getModel(); }));
|
219 | });
|
220 | var cachedFilter = this.filterManager.cachedFilter(column);
|
221 | if (cachedFilter) {
|
222 | var filterComponentPromise = this.filterManager.getFilterComponent(column);
|
223 | floatingFilterWrapper.onParentModelChanged(filterComponentPromise.resolveNow(null, function (filter) { return filter.getModel(); }));
|
224 | }
|
225 | return floatingFilterWrapper;
|
226 | };
|
227 | HeaderRowComp.prototype.createFloatingFilterParams = function (column) {
|
228 | var _this = this;
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 | var baseParams = {
|
235 | api: this.gridApi,
|
236 | column: column,
|
237 | currentParentModel: function () {
|
238 | var filterComponentPromise = _this.filterManager.getFilterComponent(column);
|
239 | var wholeParentFilter = filterComponentPromise.resolveNow(null, function (filter) {
|
240 | return (filter.getNullableModel) ?
|
241 | filter.getNullableModel() :
|
242 | filter.getModel();
|
243 | });
|
244 | return wholeParentFilter.operator != null ? wholeParentFilter.condition1 : wholeParentFilter;
|
245 | },
|
246 | onFloatingFilterChanged: function (change) {
|
247 | var captureModelChangedResolveFunc;
|
248 | var modelChanged = new utils_1.Promise(function (resolve) {
|
249 | captureModelChangedResolveFunc = resolve;
|
250 | });
|
251 | var filterComponentPromise = _this.filterManager.getFilterComponent(column);
|
252 | filterComponentPromise.then(function (filterComponent) {
|
253 | if (filterComponent.onFloatingFilterChanged) {
|
254 |
|
255 |
|
256 |
|
257 | var result = filterComponent.onFloatingFilterChanged(change);
|
258 | captureModelChangedResolveFunc(result);
|
259 | }
|
260 | else {
|
261 |
|
262 |
|
263 |
|
264 |
|
265 | filterComponent.setModel(change);
|
266 | _this.filterManager.onFilterChanged();
|
267 | captureModelChangedResolveFunc(true);
|
268 | }
|
269 | });
|
270 | return modelChanged.resolveNow(true, function (modelChanged) { return modelChanged; });
|
271 | },
|
272 |
|
273 | suppressFilterButton: false
|
274 | };
|
275 | return baseParams;
|
276 | };
|
277 | __decorate([
|
278 | context_1.Autowired('gridOptionsWrapper'),
|
279 | __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
|
280 | ], HeaderRowComp.prototype, "gridOptionsWrapper", void 0);
|
281 | __decorate([
|
282 | context_1.Autowired('gridApi'),
|
283 | __metadata("design:type", gridApi_1.GridApi)
|
284 | ], HeaderRowComp.prototype, "gridApi", void 0);
|
285 | __decorate([
|
286 | context_1.Autowired('columnController'),
|
287 | __metadata("design:type", columnController_1.ColumnController)
|
288 | ], HeaderRowComp.prototype, "columnController", void 0);
|
289 | __decorate([
|
290 | context_1.Autowired('context'),
|
291 | __metadata("design:type", context_1.Context)
|
292 | ], HeaderRowComp.prototype, "context", void 0);
|
293 | __decorate([
|
294 | context_1.Autowired('eventService'),
|
295 | __metadata("design:type", eventService_1.EventService)
|
296 | ], HeaderRowComp.prototype, "eventService", void 0);
|
297 | __decorate([
|
298 | context_1.Autowired('filterManager'),
|
299 | __metadata("design:type", filterManager_1.FilterManager)
|
300 | ], HeaderRowComp.prototype, "filterManager", void 0);
|
301 | __decorate([
|
302 | context_1.Autowired('componentRecipes'),
|
303 | __metadata("design:type", componentRecipes_1.ComponentRecipes)
|
304 | ], HeaderRowComp.prototype, "componentRecipes", void 0);
|
305 | __decorate([
|
306 | context_1.PostConstruct,
|
307 | __metadata("design:type", Function),
|
308 | __metadata("design:paramtypes", []),
|
309 | __metadata("design:returntype", void 0)
|
310 | ], HeaderRowComp.prototype, "init", null);
|
311 | return HeaderRowComp;
|
312 | }(component_1.Component));
|
313 | exports.HeaderRowComp = HeaderRowComp;
|