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 | var __param = (this && this.__param) || function (paramIndex, decorator) {
|
28 | return function (target, key) { decorator(target, key, paramIndex); }
|
29 | };
|
30 | Object.defineProperty(exports, "__esModule", { value: true });
|
31 | var context_1 = require("../../context/context");
|
32 | var eventService_1 = require("../../eventService");
|
33 | var events_1 = require("../../events");
|
34 | var logger_1 = require("../../logger");
|
35 | var infiniteBlock_1 = require("./infiniteBlock");
|
36 | var rowNodeCache_1 = require("../cache/rowNodeCache");
|
37 | var gridApi_1 = require("../../gridApi");
|
38 | var columnApi_1 = require("../../columnController/columnApi");
|
39 | var InfiniteCache = (function (_super) {
|
40 | __extends(InfiniteCache, _super);
|
41 | function InfiniteCache(params) {
|
42 | return _super.call(this, params) || this;
|
43 | }
|
44 | InfiniteCache.prototype.setBeans = function (loggerFactory) {
|
45 | this.logger = loggerFactory.create('InfiniteCache');
|
46 | };
|
47 | InfiniteCache.prototype.init = function () {
|
48 | _super.prototype.init.call(this);
|
49 |
|
50 |
|
51 | this.getRow(0);
|
52 | };
|
53 | InfiniteCache.prototype.moveItemsDown = function (block, moveFromIndex, moveCount) {
|
54 | var startRow = block.getStartRow();
|
55 | var endRow = block.getEndRow();
|
56 | var indexOfLastRowToMove = moveFromIndex + moveCount;
|
57 |
|
58 | for (var currentRowIndex = endRow - 1; currentRowIndex >= startRow; currentRowIndex--) {
|
59 |
|
60 | if (currentRowIndex < indexOfLastRowToMove) {
|
61 | continue;
|
62 | }
|
63 | var indexOfNodeWeWant = currentRowIndex - moveCount;
|
64 | var nodeForThisIndex = this.getRow(indexOfNodeWeWant, true);
|
65 | if (nodeForThisIndex) {
|
66 | block.setRowNode(currentRowIndex, nodeForThisIndex);
|
67 | }
|
68 | else {
|
69 | block.setBlankRowNode(currentRowIndex);
|
70 | block.setDirty();
|
71 | }
|
72 | }
|
73 | };
|
74 | InfiniteCache.prototype.insertItems = function (block, indexToInsert, items) {
|
75 | var pageStartRow = block.getStartRow();
|
76 | var pageEndRow = block.getEndRow();
|
77 | var newRowNodes = [];
|
78 |
|
79 | for (var index = 0; index < items.length; index++) {
|
80 | var rowIndex = indexToInsert + index;
|
81 | var currentRowInThisPage = rowIndex >= pageStartRow && rowIndex < pageEndRow;
|
82 | if (currentRowInThisPage) {
|
83 | var dataItem = items[index];
|
84 | var newRowNode = block.setNewData(rowIndex, dataItem);
|
85 | newRowNodes.push(newRowNode);
|
86 | }
|
87 | }
|
88 | return newRowNodes;
|
89 | };
|
90 | InfiniteCache.prototype.insertItemsAtIndex = function (indexToInsert, items) {
|
91 |
|
92 | var _this = this;
|
93 | var newNodes = [];
|
94 | this.forEachBlockInReverseOrder(function (block) {
|
95 | var pageEndRow = block.getEndRow();
|
96 |
|
97 | if (pageEndRow <= indexToInsert) {
|
98 | return;
|
99 | }
|
100 | _this.moveItemsDown(block, indexToInsert, items.length);
|
101 | var newNodesThisPage = _this.insertItems(block, indexToInsert, items);
|
102 | newNodesThisPage.forEach(function (rowNode) { return newNodes.push(rowNode); });
|
103 | });
|
104 | if (this.isMaxRowFound()) {
|
105 | this.hack_setVirtualRowCount(this.getVirtualRowCount() + items.length);
|
106 | }
|
107 | this.onCacheUpdated();
|
108 | var event = {
|
109 | type: events_1.Events.EVENT_ROW_DATA_UPDATED,
|
110 | api: this.gridApi,
|
111 | columnApi: this.columnApi
|
112 | };
|
113 | this.eventService.dispatchEvent(event);
|
114 | };
|
115 |
|
116 |
|
117 |
|
118 | InfiniteCache.prototype.getRow = function (rowIndex, dontCreatePage) {
|
119 | if (dontCreatePage === void 0) { dontCreatePage = false; }
|
120 | var blockId = Math.floor(rowIndex / this.cacheParams.blockSize);
|
121 | var block = this.getBlock(blockId);
|
122 | if (!block) {
|
123 | if (dontCreatePage) {
|
124 | return null;
|
125 | }
|
126 | else {
|
127 | block = this.createBlock(blockId);
|
128 | }
|
129 | }
|
130 | return block.getRow(rowIndex);
|
131 | };
|
132 | InfiniteCache.prototype.createBlock = function (blockNumber) {
|
133 | var newBlock = new infiniteBlock_1.InfiniteBlock(blockNumber, this.cacheParams);
|
134 | this.context.wireBean(newBlock);
|
135 | this.postCreateBlock(newBlock);
|
136 | return newBlock;
|
137 | };
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | InfiniteCache.prototype.refreshCache = function () {
|
143 | this.forEachBlockInOrder(function (block) { return block.setDirty(); });
|
144 | this.checkBlockToLoad();
|
145 | };
|
146 | __decorate([
|
147 | context_1.Autowired('eventService'),
|
148 | __metadata("design:type", eventService_1.EventService)
|
149 | ], InfiniteCache.prototype, "eventService", void 0);
|
150 | __decorate([
|
151 | context_1.Autowired('context'),
|
152 | __metadata("design:type", context_1.Context)
|
153 | ], InfiniteCache.prototype, "context", void 0);
|
154 | __decorate([
|
155 | context_1.Autowired('columnApi'),
|
156 | __metadata("design:type", columnApi_1.ColumnApi)
|
157 | ], InfiniteCache.prototype, "columnApi", void 0);
|
158 | __decorate([
|
159 | context_1.Autowired('gridApi'),
|
160 | __metadata("design:type", gridApi_1.GridApi)
|
161 | ], InfiniteCache.prototype, "gridApi", void 0);
|
162 | __decorate([
|
163 | __param(0, context_1.Qualifier('loggerFactory')),
|
164 | __metadata("design:type", Function),
|
165 | __metadata("design:paramtypes", [logger_1.LoggerFactory]),
|
166 | __metadata("design:returntype", void 0)
|
167 | ], InfiniteCache.prototype, "setBeans", null);
|
168 | __decorate([
|
169 | context_1.PostConstruct,
|
170 | __metadata("design:type", Function),
|
171 | __metadata("design:paramtypes", []),
|
172 | __metadata("design:returntype", void 0)
|
173 | ], InfiniteCache.prototype, "init", null);
|
174 | return InfiniteCache;
|
175 | }(rowNodeCache_1.RowNodeCache));
|
176 | exports.InfiniteCache = InfiniteCache;
|