UNPKG

11.3 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};
17var __param = (this && this.__param) || function (paramIndex, decorator) {
18 return function (target, key) { decorator(target, key, paramIndex); }
19};
20Object.defineProperty(exports, "__esModule", { value: true });
21var gridOptionsWrapper_1 = require("./gridOptionsWrapper");
22var columnController_1 = require("./columnController/columnController");
23var eventService_1 = require("./eventService");
24var logger_1 = require("./logger");
25var events_1 = require("./events");
26var context_1 = require("./context/context");
27var context_2 = require("./context/context");
28var context_3 = require("./context/context");
29var context_4 = require("./context/context");
30var AlignedGridsService = (function () {
31 function AlignedGridsService() {
32 // flag to mark if we are consuming. to avoid cyclic events (ie other grid firing back to master
33 // while processing a master event) we mark this if consuming an event, and if we are, then
34 // we don't fire back any events.
35 this.consuming = false;
36 }
37 AlignedGridsService.prototype.setBeans = function (loggerFactory) {
38 this.logger = loggerFactory.create('AlignedGridsService');
39 };
40 AlignedGridsService.prototype.registerGridComp = function (gridPanel) {
41 this.gridPanel = gridPanel;
42 };
43 AlignedGridsService.prototype.init = function () {
44 this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_MOVED, this.fireColumnEvent.bind(this));
45 this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_VISIBLE, this.fireColumnEvent.bind(this));
46 this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_PINNED, this.fireColumnEvent.bind(this));
47 this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_GROUP_OPENED, this.fireColumnEvent.bind(this));
48 this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_RESIZED, this.fireColumnEvent.bind(this));
49 this.eventService.addEventListener(events_1.Events.EVENT_BODY_SCROLL, this.fireScrollEvent.bind(this));
50 };
51 // common logic across all the fire methods
52 AlignedGridsService.prototype.fireEvent = function (callback) {
53 // if we are already consuming, then we are acting on an event from a master,
54 // so we don't cause a cyclic firing of events
55 if (this.consuming) {
56 return;
57 }
58 // iterate through the aligned grids, and pass each aligned grid service to the callback
59 var otherGrids = this.gridOptionsWrapper.getAlignedGrids();
60 if (otherGrids) {
61 otherGrids.forEach(function (otherGridOptions) {
62 if (otherGridOptions.api) {
63 var alignedGridService = otherGridOptions.api.__getAlignedGridService();
64 callback(alignedGridService);
65 }
66 });
67 }
68 };
69 // common logic across all consume methods. very little common logic, however extracting
70 // guarantees consistency across the methods.
71 AlignedGridsService.prototype.onEvent = function (callback) {
72 this.consuming = true;
73 callback();
74 this.consuming = false;
75 };
76 AlignedGridsService.prototype.fireColumnEvent = function (event) {
77 this.fireEvent(function (alignedGridsService) {
78 alignedGridsService.onColumnEvent(event);
79 });
80 };
81 AlignedGridsService.prototype.fireScrollEvent = function (event) {
82 if (event.direction !== 'horizontal') {
83 return;
84 }
85 this.fireEvent(function (alignedGridsService) {
86 alignedGridsService.onScrollEvent(event);
87 });
88 };
89 AlignedGridsService.prototype.onScrollEvent = function (event) {
90 var _this = this;
91 this.onEvent(function () {
92 _this.gridPanel.setHorizontalScrollPosition(event.left);
93 });
94 };
95 AlignedGridsService.prototype.getMasterColumns = function (event) {
96 var result = [];
97 if (event.columns) {
98 event.columns.forEach(function (column) {
99 result.push(column);
100 });
101 }
102 else if (event.column) {
103 result.push(event.column);
104 }
105 return result;
106 };
107 AlignedGridsService.prototype.getColumnIds = function (event) {
108 var result = [];
109 if (event.columns) {
110 event.columns.forEach(function (column) {
111 result.push(column.getColId());
112 });
113 }
114 else if (event.columns) {
115 result.push(event.column.getColId());
116 }
117 return result;
118 };
119 AlignedGridsService.prototype.onColumnEvent = function (event) {
120 var _this = this;
121 this.onEvent(function () {
122 switch (event.type) {
123 case events_1.Events.EVENT_COLUMN_MOVED:
124 case events_1.Events.EVENT_COLUMN_VISIBLE:
125 case events_1.Events.EVENT_COLUMN_PINNED:
126 case events_1.Events.EVENT_COLUMN_RESIZED:
127 var colEvent = event;
128 _this.processColumnEvent(colEvent);
129 break;
130 case events_1.Events.EVENT_COLUMN_GROUP_OPENED:
131 var groupOpenedEvent = event;
132 _this.processGroupOpenedEvent(groupOpenedEvent);
133 break;
134 case events_1.Events.EVENT_COLUMN_PIVOT_CHANGED:
135 // we cannot support pivoting with aligned grids as the columns will be out of sync as the
136 // grids will have columns created based on the row data of the grid.
137 console.warn('ag-Grid: pivoting is not supported with aligned grids. ' +
138 'You can only use one of these features at a time in a grid.');
139 break;
140 }
141 });
142 };
143 AlignedGridsService.prototype.processGroupOpenedEvent = function (groupOpenedEvent) {
144 // likewise for column group
145 var masterColumnGroup = groupOpenedEvent.columnGroup;
146 var otherColumnGroup;
147 if (masterColumnGroup) {
148 var groupId = masterColumnGroup.getGroupId();
149 otherColumnGroup = this.columnController.getOriginalColumnGroup(groupId);
150 }
151 if (masterColumnGroup && !otherColumnGroup) {
152 return;
153 }
154 this.logger.log('onColumnEvent-> processing ' + event + ' expanded = ' + masterColumnGroup.isExpanded());
155 this.columnController.setColumnGroupOpened(otherColumnGroup, masterColumnGroup.isExpanded(), "alignedGridChanged");
156 };
157 AlignedGridsService.prototype.processColumnEvent = function (colEvent) {
158 var _this = this;
159 // the column in the event is from the master grid. need to
160 // look up the equivalent from this (other) grid
161 var masterColumn = colEvent.column;
162 var otherColumn;
163 if (masterColumn) {
164 otherColumn = this.columnController.getPrimaryColumn(masterColumn.getColId());
165 }
166 // if event was with respect to a master column, that is not present in this
167 // grid, then we ignore the event
168 if (masterColumn && !otherColumn) {
169 return;
170 }
171 // in time, all the methods below should use the column ids, it's a more generic way
172 // of handling columns, and also allows for single or multi column events
173 var columnIds = this.getColumnIds(colEvent);
174 var masterColumns = this.getMasterColumns(colEvent);
175 switch (colEvent.type) {
176 case events_1.Events.EVENT_COLUMN_MOVED:
177 var movedEvent = colEvent;
178 this.logger.log('onColumnEvent-> processing ' + colEvent.type + ' toIndex = ' + movedEvent.toIndex);
179 this.columnController.moveColumns(columnIds, movedEvent.toIndex, "alignedGridChanged");
180 break;
181 case events_1.Events.EVENT_COLUMN_VISIBLE:
182 var visibleEvent = colEvent;
183 this.logger.log('onColumnEvent-> processing ' + colEvent.type + ' visible = ' + visibleEvent.visible);
184 this.columnController.setColumnsVisible(columnIds, visibleEvent.visible, "alignedGridChanged");
185 break;
186 case events_1.Events.EVENT_COLUMN_PINNED:
187 var pinnedEvent = colEvent;
188 this.logger.log('onColumnEvent-> processing ' + colEvent.type + ' pinned = ' + pinnedEvent.pinned);
189 this.columnController.setColumnsPinned(columnIds, pinnedEvent.pinned, "alignedGridChanged");
190 break;
191 case events_1.Events.EVENT_COLUMN_RESIZED:
192 var resizedEvent_1 = colEvent;
193 masterColumns.forEach(function (masterColumn) {
194 _this.logger.log('onColumnEvent-> processing ' + colEvent.type + ' actualWidth = ' + masterColumn.getActualWidth());
195 _this.columnController.setColumnWidth(masterColumn.getColId(), masterColumn.getActualWidth(), false, resizedEvent_1.finished, "alignedGridChanged");
196 });
197 break;
198 }
199 };
200 __decorate([
201 context_3.Autowired('gridOptionsWrapper'),
202 __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
203 ], AlignedGridsService.prototype, "gridOptionsWrapper", void 0);
204 __decorate([
205 context_3.Autowired('columnController'),
206 __metadata("design:type", columnController_1.ColumnController)
207 ], AlignedGridsService.prototype, "columnController", void 0);
208 __decorate([
209 context_3.Autowired('eventService'),
210 __metadata("design:type", eventService_1.EventService)
211 ], AlignedGridsService.prototype, "eventService", void 0);
212 __decorate([
213 __param(0, context_2.Qualifier('loggerFactory')),
214 __metadata("design:type", Function),
215 __metadata("design:paramtypes", [logger_1.LoggerFactory]),
216 __metadata("design:returntype", void 0)
217 ], AlignedGridsService.prototype, "setBeans", null);
218 __decorate([
219 context_4.PostConstruct,
220 __metadata("design:type", Function),
221 __metadata("design:paramtypes", []),
222 __metadata("design:returntype", void 0)
223 ], AlignedGridsService.prototype, "init", null);
224 AlignedGridsService = __decorate([
225 context_1.Bean('alignedGridsService')
226 ], AlignedGridsService);
227 return AlignedGridsService;
228}());
229exports.AlignedGridsService = AlignedGridsService;