1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | "use strict";
|
8 | var __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 | };
|
14 | var __metadata = (this && this.__metadata) || function (k, v) {
|
15 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
16 | };
|
17 | var __param = (this && this.__param) || function (paramIndex, decorator) {
|
18 | return function (target, key) { decorator(target, key, paramIndex); }
|
19 | };
|
20 | Object.defineProperty(exports, "__esModule", { value: true });
|
21 | var utils_1 = require("./utils");
|
22 | var context_1 = require("./context/context");
|
23 | var context_2 = require("./context/context");
|
24 | var logger_1 = require("./logger");
|
25 | var eventService_1 = require("./eventService");
|
26 | var events_1 = require("./events");
|
27 | var context_3 = require("./context/context");
|
28 | var gridOptionsWrapper_1 = require("./gridOptionsWrapper");
|
29 | var context_4 = require("./context/context");
|
30 | var constants_1 = require("./constants");
|
31 | var columnApi_1 = require("./columnController/columnApi");
|
32 | var gridApi_1 = require("./gridApi");
|
33 | var SelectionController = (function () {
|
34 | function SelectionController() {
|
35 | }
|
36 | SelectionController.prototype.setBeans = function (loggerFactory) {
|
37 | this.logger = loggerFactory.create('SelectionController');
|
38 | this.reset();
|
39 | if (this.gridOptionsWrapper.isRowModelDefault()) {
|
40 | this.eventService.addEventListener(events_1.Events.EVENT_ROW_DATA_CHANGED, this.reset.bind(this));
|
41 | }
|
42 | else {
|
43 | this.logger.log('dont know what to do here');
|
44 | }
|
45 | };
|
46 | SelectionController.prototype.init = function () {
|
47 | this.groupSelectsChildren = this.gridOptionsWrapper.isGroupSelectsChildren();
|
48 | this.eventService.addEventListener(events_1.Events.EVENT_ROW_SELECTED, this.onRowSelected.bind(this));
|
49 | };
|
50 | SelectionController.prototype.setLastSelectedNode = function (rowNode) {
|
51 | this.lastSelectedNode = rowNode;
|
52 | };
|
53 | SelectionController.prototype.getLastSelectedNode = function () {
|
54 | return this.lastSelectedNode;
|
55 | };
|
56 | SelectionController.prototype.getSelectedNodes = function () {
|
57 | var selectedNodes = [];
|
58 | utils_1.Utils.iterateObject(this.selectedNodes, function (key, rowNode) {
|
59 | if (rowNode) {
|
60 | selectedNodes.push(rowNode);
|
61 | }
|
62 | });
|
63 | return selectedNodes;
|
64 | };
|
65 | SelectionController.prototype.getSelectedRows = function () {
|
66 | var selectedRows = [];
|
67 | utils_1.Utils.iterateObject(this.selectedNodes, function (key, rowNode) {
|
68 | if (rowNode && rowNode.data) {
|
69 | selectedRows.push(rowNode.data);
|
70 | }
|
71 | });
|
72 | return selectedRows;
|
73 | };
|
74 | SelectionController.prototype.removeGroupsFromSelection = function () {
|
75 | var _this = this;
|
76 | utils_1.Utils.iterateObject(this.selectedNodes, function (key, rowNode) {
|
77 | if (rowNode && rowNode.group) {
|
78 | _this.selectedNodes[rowNode.id] = undefined;
|
79 | }
|
80 | });
|
81 | };
|
82 |
|
83 | SelectionController.prototype.updateGroupsFromChildrenSelections = function () {
|
84 |
|
85 | if (!this.gridOptionsWrapper.isGroupSelectsChildren()) {
|
86 | return;
|
87 | }
|
88 |
|
89 | if (this.rowModel.getType() !== constants_1.Constants.ROW_MODEL_TYPE_CLIENT_SIDE) {
|
90 | return;
|
91 | }
|
92 | var clientSideRowModel = this.rowModel;
|
93 | clientSideRowModel.getTopLevelNodes().forEach(function (rowNode) {
|
94 | rowNode.depthFirstSearch(function (rowNode) {
|
95 | if (rowNode.group) {
|
96 | rowNode.calculateSelectedFromChildren();
|
97 | }
|
98 | });
|
99 | });
|
100 | };
|
101 | SelectionController.prototype.getNodeForIdIfSelected = function (id) {
|
102 | return this.selectedNodes[id];
|
103 | };
|
104 | SelectionController.prototype.clearOtherNodes = function (rowNodeToKeepSelected) {
|
105 | var _this = this;
|
106 | var groupsToRefresh = {};
|
107 | var updatedCount = 0;
|
108 | utils_1.Utils.iterateObject(this.selectedNodes, function (key, otherRowNode) {
|
109 | if (otherRowNode && otherRowNode.id !== rowNodeToKeepSelected.id) {
|
110 | var rowNode = _this.selectedNodes[otherRowNode.id];
|
111 | updatedCount += rowNode.setSelectedParams({ newValue: false, clearSelection: false, suppressFinishActions: true });
|
112 | if (_this.groupSelectsChildren && otherRowNode.parent) {
|
113 | groupsToRefresh[otherRowNode.parent.id] = otherRowNode.parent;
|
114 | }
|
115 | }
|
116 | });
|
117 | utils_1.Utils.iterateObject(groupsToRefresh, function (key, group) {
|
118 | group.calculateSelectedFromChildren();
|
119 | });
|
120 | return updatedCount;
|
121 | };
|
122 | SelectionController.prototype.onRowSelected = function (event) {
|
123 | var rowNode = event.node;
|
124 |
|
125 | if (this.groupSelectsChildren && rowNode.group) {
|
126 | return;
|
127 | }
|
128 | if (rowNode.isSelected()) {
|
129 | this.selectedNodes[rowNode.id] = rowNode;
|
130 | }
|
131 | else {
|
132 | this.selectedNodes[rowNode.id] = undefined;
|
133 | }
|
134 | };
|
135 | SelectionController.prototype.syncInRowNode = function (rowNode, oldNode) {
|
136 | this.syncInOldRowNode(rowNode, oldNode);
|
137 | this.syncInNewRowNode(rowNode);
|
138 | };
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 | SelectionController.prototype.syncInOldRowNode = function (rowNode, oldNode) {
|
151 | var oldNodeHasDifferentId = utils_1.Utils.exists(oldNode) && (rowNode.id !== oldNode.id);
|
152 | if (oldNodeHasDifferentId) {
|
153 | var oldNodeSelected = utils_1.Utils.exists(this.selectedNodes[oldNode.id]);
|
154 | if (oldNodeSelected) {
|
155 | this.selectedNodes[oldNode.id] = oldNode;
|
156 | }
|
157 | }
|
158 | };
|
159 | SelectionController.prototype.syncInNewRowNode = function (rowNode) {
|
160 | if (utils_1.Utils.exists(this.selectedNodes[rowNode.id])) {
|
161 | rowNode.setSelectedInitialValue(true);
|
162 | this.selectedNodes[rowNode.id] = rowNode;
|
163 | }
|
164 | else {
|
165 | rowNode.setSelectedInitialValue(false);
|
166 | }
|
167 | };
|
168 | SelectionController.prototype.reset = function () {
|
169 | this.logger.log('reset');
|
170 | this.selectedNodes = {};
|
171 | this.lastSelectedNode = null;
|
172 | };
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 | SelectionController.prototype.getBestCostNodeSelection = function () {
|
179 | if (this.rowModel.getType() !== constants_1.Constants.ROW_MODEL_TYPE_CLIENT_SIDE) {
|
180 | console.warn('getBestCostNodeSelection is only avilable when using normal row model');
|
181 | }
|
182 | var clientSideRowModel = this.rowModel;
|
183 | var topLevelNodes = clientSideRowModel.getTopLevelNodes();
|
184 | if (topLevelNodes === null) {
|
185 | console.warn('selectAll not available doing rowModel=virtual');
|
186 | return;
|
187 | }
|
188 | var result = [];
|
189 |
|
190 | function traverse(nodes) {
|
191 | for (var i = 0, l = nodes.length; i < l; i++) {
|
192 | var node = nodes[i];
|
193 | if (node.isSelected()) {
|
194 | result.push(node);
|
195 | }
|
196 | else {
|
197 |
|
198 |
|
199 | if (node.group && node.children) {
|
200 | traverse(node.children);
|
201 | }
|
202 | }
|
203 | }
|
204 | }
|
205 | traverse(topLevelNodes);
|
206 | return result;
|
207 | };
|
208 | SelectionController.prototype.setRowModel = function (rowModel) {
|
209 | this.rowModel = rowModel;
|
210 | };
|
211 | SelectionController.prototype.isEmpty = function () {
|
212 | var count = 0;
|
213 | utils_1.Utils.iterateObject(this.selectedNodes, function (nodeId, rowNode) {
|
214 | if (rowNode) {
|
215 | count++;
|
216 | }
|
217 | });
|
218 | return count === 0;
|
219 | };
|
220 | SelectionController.prototype.deselectAllRowNodes = function (justFiltered) {
|
221 | if (justFiltered === void 0) { justFiltered = false; }
|
222 | var callback = function (rowNode) { return rowNode.selectThisNode(false); };
|
223 | var rowModelClientSide = this.rowModel.getType() === constants_1.Constants.ROW_MODEL_TYPE_CLIENT_SIDE;
|
224 | if (justFiltered) {
|
225 | if (!rowModelClientSide) {
|
226 | console.error('ag-Grid: selecting just filtered only works with In Memory Row Model');
|
227 | return;
|
228 | }
|
229 | var clientSideRowModel = this.rowModel;
|
230 | clientSideRowModel.forEachNodeAfterFilter(callback);
|
231 | }
|
232 | else {
|
233 | utils_1.Utils.iterateObject(this.selectedNodes, function (id, rowNode) {
|
234 |
|
235 | if (rowNode) {
|
236 | callback(rowNode);
|
237 | }
|
238 | });
|
239 |
|
240 | this.reset();
|
241 | }
|
242 |
|
243 | if (rowModelClientSide && this.groupSelectsChildren) {
|
244 | this.updateGroupsFromChildrenSelections();
|
245 | }
|
246 | var event = {
|
247 | type: events_1.Events.EVENT_SELECTION_CHANGED,
|
248 | api: this.gridApi,
|
249 | columnApi: this.columnApi
|
250 | };
|
251 | this.eventService.dispatchEvent(event);
|
252 | };
|
253 | SelectionController.prototype.selectAllRowNodes = function (justFiltered) {
|
254 | if (justFiltered === void 0) { justFiltered = false; }
|
255 | if (this.rowModel.getType() !== constants_1.Constants.ROW_MODEL_TYPE_CLIENT_SIDE) {
|
256 | throw "selectAll only available with normal row model, ie not " + this.rowModel.getType();
|
257 | }
|
258 | var clientSideRowModel = this.rowModel;
|
259 | var callback = function (rowNode) { return rowNode.selectThisNode(true); };
|
260 | if (justFiltered) {
|
261 | clientSideRowModel.forEachNodeAfterFilter(callback);
|
262 | }
|
263 | else {
|
264 | clientSideRowModel.forEachNode(callback);
|
265 | }
|
266 |
|
267 | if (this.rowModel.getType() === constants_1.Constants.ROW_MODEL_TYPE_CLIENT_SIDE && this.groupSelectsChildren) {
|
268 | this.updateGroupsFromChildrenSelections();
|
269 | }
|
270 | var event = {
|
271 | type: events_1.Events.EVENT_SELECTION_CHANGED,
|
272 | api: this.gridApi,
|
273 | columnApi: this.columnApi
|
274 | };
|
275 | this.eventService.dispatchEvent(event);
|
276 | };
|
277 |
|
278 | SelectionController.prototype.selectNode = function (rowNode, tryMulti) {
|
279 | rowNode.setSelectedParams({ newValue: true, clearSelection: !tryMulti });
|
280 | };
|
281 |
|
282 | SelectionController.prototype.deselectIndex = function (rowIndex) {
|
283 | var node = this.rowModel.getRow(rowIndex);
|
284 | this.deselectNode(node);
|
285 | };
|
286 |
|
287 | SelectionController.prototype.deselectNode = function (rowNode) {
|
288 | rowNode.setSelectedParams({ newValue: false, clearSelection: false });
|
289 | };
|
290 |
|
291 | SelectionController.prototype.selectIndex = function (index, tryMulti) {
|
292 | var node = this.rowModel.getRow(index);
|
293 | this.selectNode(node, tryMulti);
|
294 | };
|
295 | __decorate([
|
296 | context_3.Autowired('eventService'),
|
297 | __metadata("design:type", eventService_1.EventService)
|
298 | ], SelectionController.prototype, "eventService", void 0);
|
299 | __decorate([
|
300 | context_3.Autowired('rowModel'),
|
301 | __metadata("design:type", Object)
|
302 | ], SelectionController.prototype, "rowModel", void 0);
|
303 | __decorate([
|
304 | context_3.Autowired('gridOptionsWrapper'),
|
305 | __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
|
306 | ], SelectionController.prototype, "gridOptionsWrapper", void 0);
|
307 | __decorate([
|
308 | context_3.Autowired('columnApi'),
|
309 | __metadata("design:type", columnApi_1.ColumnApi)
|
310 | ], SelectionController.prototype, "columnApi", void 0);
|
311 | __decorate([
|
312 | context_3.Autowired('gridApi'),
|
313 | __metadata("design:type", gridApi_1.GridApi)
|
314 | ], SelectionController.prototype, "gridApi", void 0);
|
315 | __decorate([
|
316 | __param(0, context_2.Qualifier('loggerFactory')),
|
317 | __metadata("design:type", Function),
|
318 | __metadata("design:paramtypes", [logger_1.LoggerFactory]),
|
319 | __metadata("design:returntype", void 0)
|
320 | ], SelectionController.prototype, "setBeans", null);
|
321 | __decorate([
|
322 | context_4.PostConstruct,
|
323 | __metadata("design:type", Function),
|
324 | __metadata("design:paramtypes", []),
|
325 | __metadata("design:returntype", void 0)
|
326 | ], SelectionController.prototype, "init", null);
|
327 | SelectionController = __decorate([
|
328 | context_1.Bean('selectionController')
|
329 | ], SelectionController);
|
330 | return SelectionController;
|
331 | }());
|
332 | exports.SelectionController = SelectionController;
|