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 utils_1 = require("../../utils");
|
29 | var gridOptionsWrapper_1 = require("../../gridOptionsWrapper");
|
30 | var context_1 = require("../../context/context");
|
31 | var eventService_1 = require("../../eventService");
|
32 | var selectionController_1 = require("../../selectionController");
|
33 | var events_1 = require("../../events");
|
34 | var sortController_1 = require("../../sortController");
|
35 | var filterManager_1 = require("../../filter/filterManager");
|
36 | var constants_1 = require("../../constants");
|
37 | var infiniteCache_1 = require("./infiniteCache");
|
38 | var beanStub_1 = require("../../context/beanStub");
|
39 | var rowNodeCache_1 = require("../cache/rowNodeCache");
|
40 | var rowNodeBlockLoader_1 = require("../cache/rowNodeBlockLoader");
|
41 | var gridApi_1 = require("../../gridApi");
|
42 | var columnApi_1 = require("../../columnController/columnApi");
|
43 | var InfiniteRowModel = (function (_super) {
|
44 | __extends(InfiniteRowModel, _super);
|
45 | function InfiniteRowModel() {
|
46 | return _super !== null && _super.apply(this, arguments) || this;
|
47 | }
|
48 | InfiniteRowModel.prototype.getRowBounds = function (index) {
|
49 | return {
|
50 | rowHeight: this.rowHeight,
|
51 | rowTop: this.rowHeight * index
|
52 | };
|
53 | };
|
54 | InfiniteRowModel.prototype.init = function () {
|
55 | var _this = this;
|
56 | if (!this.gridOptionsWrapper.isRowModelInfinite()) {
|
57 | return;
|
58 | }
|
59 | this.rowHeight = this.gridOptionsWrapper.getRowHeightAsNumber();
|
60 | this.addEventListeners();
|
61 | this.setDatasource(this.gridOptionsWrapper.getDatasource());
|
62 | this.addDestroyFunc(function () { return _this.destroyCache(); });
|
63 | };
|
64 | InfiniteRowModel.prototype.destroyDatasource = function () {
|
65 | if (this.datasource && this.datasource.destroy) {
|
66 | this.datasource.destroy();
|
67 | }
|
68 | this.datasource = null;
|
69 | };
|
70 | InfiniteRowModel.prototype.isLastRowFound = function () {
|
71 | return this.infiniteCache ? this.infiniteCache.isMaxRowFound() : false;
|
72 | };
|
73 | InfiniteRowModel.prototype.addEventListeners = function () {
|
74 | this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_FILTER_CHANGED, this.onFilterChanged.bind(this));
|
75 | this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_SORT_CHANGED, this.onSortChanged.bind(this));
|
76 | this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_COLUMN_EVERYTHING_CHANGED, this.onColumnEverything.bind(this));
|
77 | };
|
78 | InfiniteRowModel.prototype.onFilterChanged = function () {
|
79 | if (this.gridOptionsWrapper.isEnableServerSideFilter()) {
|
80 | this.reset();
|
81 | }
|
82 | };
|
83 | InfiniteRowModel.prototype.onSortChanged = function () {
|
84 | if (this.gridOptionsWrapper.isEnableServerSideSorting()) {
|
85 | this.reset();
|
86 | }
|
87 | };
|
88 | InfiniteRowModel.prototype.onColumnEverything = function () {
|
89 |
|
90 | if (this.gridOptionsWrapper.isEnableServerSideSorting()) {
|
91 | this.reset();
|
92 | }
|
93 | };
|
94 | InfiniteRowModel.prototype.destroy = function () {
|
95 | _super.prototype.destroy.call(this);
|
96 | };
|
97 | InfiniteRowModel.prototype.getType = function () {
|
98 | return constants_1.Constants.ROW_MODEL_TYPE_INFINITE;
|
99 | };
|
100 | InfiniteRowModel.prototype.setDatasource = function (datasource) {
|
101 | this.destroyDatasource();
|
102 | this.datasource = datasource;
|
103 |
|
104 | if (datasource) {
|
105 | this.checkForDeprecated();
|
106 | this.reset();
|
107 | }
|
108 | };
|
109 | InfiniteRowModel.prototype.checkForDeprecated = function () {
|
110 | var ds = this.datasource;
|
111 |
|
112 | if (utils_1.Utils.exists(ds.maxConcurrentRequests)) {
|
113 | console.error('ag-Grid: since version 5.1.x, maxConcurrentRequests is replaced with grid property maxConcurrentDatasourceRequests');
|
114 | }
|
115 | if (utils_1.Utils.exists(ds.maxPagesInCache)) {
|
116 | console.error('ag-Grid: since version 5.1.x, maxPagesInCache is replaced with grid property maxPagesInPaginationCache');
|
117 | }
|
118 | if (utils_1.Utils.exists(ds.overflowSize)) {
|
119 | console.error('ag-Grid: since version 5.1.x, overflowSize is replaced with grid property paginationOverflowSize');
|
120 | }
|
121 | if (utils_1.Utils.exists(ds.blockSize)) {
|
122 | console.error('ag-Grid: since version 5.1.x, pageSize/blockSize is replaced with grid property infinitePageSize');
|
123 | }
|
124 | };
|
125 | InfiniteRowModel.prototype.isEmpty = function () {
|
126 | return utils_1.Utils.missing(this.infiniteCache);
|
127 | };
|
128 | InfiniteRowModel.prototype.isRowsToRender = function () {
|
129 | return utils_1.Utils.exists(this.infiniteCache);
|
130 | };
|
131 | InfiniteRowModel.prototype.getNodesInRangeForSelection = function (firstInRange, lastInRange) {
|
132 | return this.infiniteCache.getRowNodesInRange(firstInRange, lastInRange);
|
133 | };
|
134 | InfiniteRowModel.prototype.reset = function () {
|
135 |
|
136 |
|
137 | if (utils_1.Utils.missing(this.datasource)) {
|
138 | return;
|
139 | }
|
140 |
|
141 |
|
142 |
|
143 | var userGeneratingIds = utils_1.Utils.exists(this.gridOptionsWrapper.getRowNodeIdFunc());
|
144 | if (!userGeneratingIds) {
|
145 | this.selectionController.reset();
|
146 | }
|
147 | this.resetCache();
|
148 | var event = this.createModelUpdatedEvent();
|
149 | this.eventService.dispatchEvent(event);
|
150 | };
|
151 | InfiniteRowModel.prototype.createModelUpdatedEvent = function () {
|
152 | return {
|
153 | type: events_1.Events.EVENT_MODEL_UPDATED,
|
154 | api: this.gridApi,
|
155 | columnApi: this.columnApi,
|
156 |
|
157 |
|
158 | newPage: false,
|
159 | newData: false,
|
160 | keepRenderedRows: false,
|
161 | animate: false
|
162 | };
|
163 | };
|
164 | InfiniteRowModel.prototype.resetCache = function () {
|
165 |
|
166 | this.destroyCache();
|
167 | var maxConcurrentRequests = this.gridOptionsWrapper.getMaxConcurrentDatasourceRequests();
|
168 |
|
169 |
|
170 | this.rowNodeBlockLoader = new rowNodeBlockLoader_1.RowNodeBlockLoader(maxConcurrentRequests);
|
171 | this.context.wireBean(this.rowNodeBlockLoader);
|
172 | var cacheSettings = {
|
173 |
|
174 | datasource: this.datasource,
|
175 |
|
176 | filterModel: this.filterManager.getFilterModel(),
|
177 | sortModel: this.sortController.getSortModel(),
|
178 | rowNodeBlockLoader: this.rowNodeBlockLoader,
|
179 |
|
180 |
|
181 |
|
182 | maxConcurrentRequests: maxConcurrentRequests,
|
183 | overflowSize: this.gridOptionsWrapper.getCacheOverflowSize(),
|
184 | initialRowCount: this.gridOptionsWrapper.getInfiniteInitialRowCount(),
|
185 | maxBlocksInCache: this.gridOptionsWrapper.getMaxBlocksInCache(),
|
186 | blockSize: this.gridOptionsWrapper.getCacheBlockSize(),
|
187 | rowHeight: this.gridOptionsWrapper.getRowHeightAsNumber(),
|
188 |
|
189 |
|
190 | lastAccessedSequence: new utils_1.NumberSequence()
|
191 | };
|
192 |
|
193 | if (!(cacheSettings.maxConcurrentRequests >= 1)) {
|
194 | cacheSettings.maxConcurrentRequests = 2;
|
195 | }
|
196 |
|
197 |
|
198 | if (!(cacheSettings.blockSize >= 1)) {
|
199 | cacheSettings.blockSize = 100;
|
200 | }
|
201 |
|
202 | if (!(cacheSettings.initialRowCount >= 1)) {
|
203 | cacheSettings.initialRowCount = 0;
|
204 | }
|
205 |
|
206 |
|
207 | if (!(cacheSettings.overflowSize >= 1)) {
|
208 | cacheSettings.overflowSize = 1;
|
209 | }
|
210 | this.infiniteCache = new infiniteCache_1.InfiniteCache(cacheSettings);
|
211 | this.context.wireBean(this.infiniteCache);
|
212 | this.infiniteCache.addEventListener(rowNodeCache_1.RowNodeCache.EVENT_CACHE_UPDATED, this.onCacheUpdated.bind(this));
|
213 | };
|
214 | InfiniteRowModel.prototype.destroyCache = function () {
|
215 | if (this.infiniteCache) {
|
216 | this.infiniteCache.destroy();
|
217 | this.infiniteCache = null;
|
218 | }
|
219 | if (this.rowNodeBlockLoader) {
|
220 | this.rowNodeBlockLoader.destroy();
|
221 | this.rowNodeBlockLoader = null;
|
222 | }
|
223 | };
|
224 | InfiniteRowModel.prototype.onCacheUpdated = function () {
|
225 | var event = this.createModelUpdatedEvent();
|
226 | this.eventService.dispatchEvent(event);
|
227 | };
|
228 | InfiniteRowModel.prototype.getRow = function (rowIndex) {
|
229 | return this.infiniteCache ? this.infiniteCache.getRow(rowIndex) : null;
|
230 | };
|
231 | InfiniteRowModel.prototype.getRowNode = function (id) {
|
232 | var result = null;
|
233 | this.forEachNode(function (rowNode) {
|
234 | if (rowNode.id === id) {
|
235 | result = rowNode;
|
236 | }
|
237 | });
|
238 | return result;
|
239 | };
|
240 | InfiniteRowModel.prototype.forEachNode = function (callback) {
|
241 | if (this.infiniteCache) {
|
242 | this.infiniteCache.forEachNodeDeep(callback, new utils_1.NumberSequence());
|
243 | }
|
244 | };
|
245 | InfiniteRowModel.prototype.getCurrentPageHeight = function () {
|
246 | return this.getRowCount() * this.rowHeight;
|
247 | };
|
248 | InfiniteRowModel.prototype.getRowIndexAtPixel = function (pixel) {
|
249 | if (this.rowHeight !== 0) {
|
250 | var rowIndexForPixel = Math.floor(pixel / this.rowHeight);
|
251 | if (rowIndexForPixel > this.getPageLastRow()) {
|
252 | return this.getPageLastRow();
|
253 | }
|
254 | else {
|
255 | return rowIndexForPixel;
|
256 | }
|
257 | }
|
258 | else {
|
259 | return 0;
|
260 | }
|
261 | };
|
262 | InfiniteRowModel.prototype.getPageFirstRow = function () {
|
263 | return 0;
|
264 | };
|
265 | InfiniteRowModel.prototype.getPageLastRow = function () {
|
266 | return this.infiniteCache ? this.infiniteCache.getVirtualRowCount() - 1 : 0;
|
267 | };
|
268 | InfiniteRowModel.prototype.getRowCount = function () {
|
269 | return this.infiniteCache ? this.infiniteCache.getVirtualRowCount() : 0;
|
270 | };
|
271 | InfiniteRowModel.prototype.updateRowData = function (transaction) {
|
272 | if (utils_1.Utils.exists(transaction.remove) || utils_1.Utils.exists(transaction.update)) {
|
273 | console.warn('ag-Grid: updateRowData for InfiniteRowModel does not support remove or update, only add');
|
274 | return;
|
275 | }
|
276 | if (utils_1.Utils.missing(transaction.addIndex)) {
|
277 | console.warn('ag-Grid: updateRowData for InfiniteRowModel requires add and addIndex to be set');
|
278 | return;
|
279 | }
|
280 | if (this.infiniteCache) {
|
281 | this.infiniteCache.insertItemsAtIndex(transaction.addIndex, transaction.add);
|
282 | }
|
283 | };
|
284 | InfiniteRowModel.prototype.isRowPresent = function (rowNode) {
|
285 | return false;
|
286 | };
|
287 | InfiniteRowModel.prototype.refreshCache = function () {
|
288 | if (this.infiniteCache) {
|
289 | this.infiniteCache.refreshCache();
|
290 | }
|
291 | };
|
292 | InfiniteRowModel.prototype.purgeCache = function () {
|
293 | if (this.infiniteCache) {
|
294 | this.infiniteCache.purgeCache();
|
295 | }
|
296 | };
|
297 | InfiniteRowModel.prototype.getVirtualRowCount = function () {
|
298 | if (this.infiniteCache) {
|
299 | return this.infiniteCache.getVirtualRowCount();
|
300 | }
|
301 | else {
|
302 | return null;
|
303 | }
|
304 | };
|
305 | InfiniteRowModel.prototype.isMaxRowFound = function () {
|
306 | if (this.infiniteCache) {
|
307 | return this.infiniteCache.isMaxRowFound();
|
308 | }
|
309 | };
|
310 | InfiniteRowModel.prototype.setVirtualRowCount = function (rowCount, maxRowFound) {
|
311 | if (this.infiniteCache) {
|
312 | this.infiniteCache.setVirtualRowCount(rowCount, maxRowFound);
|
313 | }
|
314 | };
|
315 | InfiniteRowModel.prototype.getBlockState = function () {
|
316 | if (this.rowNodeBlockLoader) {
|
317 | return this.rowNodeBlockLoader.getBlockState();
|
318 | }
|
319 | else {
|
320 | return null;
|
321 | }
|
322 | };
|
323 | __decorate([
|
324 | context_1.Autowired('gridOptionsWrapper'),
|
325 | __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
|
326 | ], InfiniteRowModel.prototype, "gridOptionsWrapper", void 0);
|
327 | __decorate([
|
328 | context_1.Autowired('filterManager'),
|
329 | __metadata("design:type", filterManager_1.FilterManager)
|
330 | ], InfiniteRowModel.prototype, "filterManager", void 0);
|
331 | __decorate([
|
332 | context_1.Autowired('sortController'),
|
333 | __metadata("design:type", sortController_1.SortController)
|
334 | ], InfiniteRowModel.prototype, "sortController", void 0);
|
335 | __decorate([
|
336 | context_1.Autowired('selectionController'),
|
337 | __metadata("design:type", selectionController_1.SelectionController)
|
338 | ], InfiniteRowModel.prototype, "selectionController", void 0);
|
339 | __decorate([
|
340 | context_1.Autowired('eventService'),
|
341 | __metadata("design:type", eventService_1.EventService)
|
342 | ], InfiniteRowModel.prototype, "eventService", void 0);
|
343 | __decorate([
|
344 | context_1.Autowired('context'),
|
345 | __metadata("design:type", context_1.Context)
|
346 | ], InfiniteRowModel.prototype, "context", void 0);
|
347 | __decorate([
|
348 | context_1.Autowired('gridApi'),
|
349 | __metadata("design:type", gridApi_1.GridApi)
|
350 | ], InfiniteRowModel.prototype, "gridApi", void 0);
|
351 | __decorate([
|
352 | context_1.Autowired('columnApi'),
|
353 | __metadata("design:type", columnApi_1.ColumnApi)
|
354 | ], InfiniteRowModel.prototype, "columnApi", void 0);
|
355 | __decorate([
|
356 | context_1.PostConstruct,
|
357 | __metadata("design:type", Function),
|
358 | __metadata("design:paramtypes", []),
|
359 | __metadata("design:returntype", void 0)
|
360 | ], InfiniteRowModel.prototype, "init", null);
|
361 | __decorate([
|
362 | context_1.PreDestroy,
|
363 | __metadata("design:type", Function),
|
364 | __metadata("design:paramtypes", []),
|
365 | __metadata("design:returntype", void 0)
|
366 | ], InfiniteRowModel.prototype, "destroyDatasource", null);
|
367 | __decorate([
|
368 | context_1.PreDestroy,
|
369 | __metadata("design:type", Function),
|
370 | __metadata("design:paramtypes", []),
|
371 | __metadata("design:returntype", void 0)
|
372 | ], InfiniteRowModel.prototype, "destroy", null);
|
373 | InfiniteRowModel = __decorate([
|
374 | context_1.Bean('rowModel')
|
375 | ], InfiniteRowModel);
|
376 | return InfiniteRowModel;
|
377 | }(beanStub_1.BeanStub));
|
378 | exports.InfiniteRowModel = InfiniteRowModel;
|