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 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | var context_1 = require("../context/context");
|
19 | var gridCell_1 = require("../entities/gridCell");
|
20 | var constants_1 = require("../constants");
|
21 | var mouseEventService_1 = require("./mouseEventService");
|
22 | var paginationProxy_1 = require("../rowModels/paginationProxy");
|
23 | var focusedCellController_1 = require("../focusedCellController");
|
24 | var utils_1 = require("../utils");
|
25 | var animationFrameService_1 = require("../misc/animationFrameService");
|
26 | var columnController_1 = require("../columnController/columnController");
|
27 | var gridOptionsWrapper_1 = require("../gridOptionsWrapper");
|
28 | var NavigationService = (function () {
|
29 | function NavigationService() {
|
30 | this.timeLastPageEventProcessed = 0;
|
31 | }
|
32 | NavigationService.prototype.init = function () {
|
33 | this.scrollWidth = this.gridOptionsWrapper.getScrollbarWidth();
|
34 | };
|
35 | NavigationService.prototype.registerGridComp = function (gridPanel) {
|
36 | this.gridPanel = gridPanel;
|
37 | };
|
38 | NavigationService.prototype.handlePageScrollingKey = function (event) {
|
39 | var key = event.which || event.keyCode;
|
40 | var alt = event.altKey;
|
41 | var ctrl = event.ctrlKey;
|
42 | var currentCell = this.mouseEventService.getGridCellForEvent(event).getGridCellDef();
|
43 | if (!currentCell) {
|
44 | return false;
|
45 | }
|
46 | var processed = false;
|
47 | switch (key) {
|
48 | case constants_1.Constants.KEY_PAGE_HOME:
|
49 | case constants_1.Constants.KEY_PAGE_END:
|
50 |
|
51 | if (!ctrl && !alt) {
|
52 | this.onHomeOrEndKey(key);
|
53 | processed = true;
|
54 | }
|
55 | break;
|
56 | case constants_1.Constants.KEY_LEFT:
|
57 | case constants_1.Constants.KEY_RIGHT:
|
58 |
|
59 | if (ctrl && !alt) {
|
60 | this.onCtrlLeftOrRight(key, currentCell);
|
61 | processed = true;
|
62 | }
|
63 | break;
|
64 | case constants_1.Constants.KEY_UP:
|
65 | case constants_1.Constants.KEY_DOWN:
|
66 |
|
67 | if (ctrl && !alt) {
|
68 | this.onCtrlUpOrDown(key, currentCell);
|
69 | processed = true;
|
70 | }
|
71 | break;
|
72 | case constants_1.Constants.KEY_PAGE_DOWN:
|
73 |
|
74 | if (!ctrl && !alt) {
|
75 | this.onPageDown(currentCell);
|
76 | processed = true;
|
77 | }
|
78 | break;
|
79 | case constants_1.Constants.KEY_PAGE_UP:
|
80 |
|
81 | if (!ctrl && !alt) {
|
82 | this.onPageUp(currentCell);
|
83 | processed = true;
|
84 | }
|
85 | break;
|
86 | }
|
87 | if (processed) {
|
88 | event.preventDefault();
|
89 | }
|
90 | return processed;
|
91 | };
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | NavigationService.prototype.isTimeSinceLastPageEventToRecent = function () {
|
100 | var now = new Date().getTime();
|
101 | var diff = now - this.timeLastPageEventProcessed;
|
102 | return (diff < 100);
|
103 | };
|
104 | NavigationService.prototype.setTimeLastPageEventProcessed = function () {
|
105 | this.timeLastPageEventProcessed = new Date().getTime();
|
106 | };
|
107 | NavigationService.prototype.onPageDown = function (gridCell) {
|
108 | if (this.isTimeSinceLastPageEventToRecent()) {
|
109 | return;
|
110 | }
|
111 | var scrollPosition = this.gridPanel.getVScrollPosition();
|
112 | var pixelsInOnePage = scrollPosition.bottom - scrollPosition.top;
|
113 | if (this.gridPanel.isHorizontalScrollShowing()) {
|
114 | pixelsInOnePage -= this.scrollWidth;
|
115 | }
|
116 | var pagingPixelOffset = this.paginationProxy.getPixelOffset();
|
117 | var currentPageBottomPixel = scrollPosition.top + pixelsInOnePage;
|
118 | var currentPageBottomRow = this.paginationProxy.getRowIndexAtPixel(currentPageBottomPixel + pagingPixelOffset);
|
119 | var scrollIndex = currentPageBottomRow;
|
120 | var currentCellPixel = this.paginationProxy.getRow(gridCell.rowIndex).rowTop;
|
121 | var nextCellPixel = currentCellPixel + pixelsInOnePage - pagingPixelOffset;
|
122 | var focusIndex = this.paginationProxy.getRowIndexAtPixel(nextCellPixel + pagingPixelOffset);
|
123 | var pageLastRow = this.paginationProxy.getPageLastRow();
|
124 | if (focusIndex > pageLastRow) {
|
125 | focusIndex = pageLastRow;
|
126 | }
|
127 | if (scrollIndex > pageLastRow) {
|
128 | scrollIndex = pageLastRow;
|
129 | }
|
130 | this.navigateTo(scrollIndex, 'top', null, focusIndex, gridCell.column);
|
131 | this.setTimeLastPageEventProcessed();
|
132 | };
|
133 | NavigationService.prototype.onPageUp = function (gridCell) {
|
134 | if (this.isTimeSinceLastPageEventToRecent()) {
|
135 | return;
|
136 | }
|
137 | var scrollPosition = this.gridPanel.getVScrollPosition();
|
138 | var pixelsInOnePage = scrollPosition.bottom - scrollPosition.top;
|
139 | if (this.gridPanel.isHorizontalScrollShowing()) {
|
140 | pixelsInOnePage -= this.scrollWidth;
|
141 | }
|
142 | var pagingPixelOffset = this.paginationProxy.getPixelOffset();
|
143 | var currentPageTopPixel = scrollPosition.top;
|
144 | var currentPageTopRow = this.paginationProxy.getRowIndexAtPixel(currentPageTopPixel + pagingPixelOffset);
|
145 | var scrollIndex = currentPageTopRow;
|
146 | var currentRowNode = this.paginationProxy.getRow(gridCell.rowIndex);
|
147 | var nextCellPixel = currentRowNode.rowTop + currentRowNode.rowHeight - pixelsInOnePage - pagingPixelOffset;
|
148 | var focusIndex = this.paginationProxy.getRowIndexAtPixel(nextCellPixel + pagingPixelOffset);
|
149 | var firstRow = this.paginationProxy.getPageFirstRow();
|
150 | if (focusIndex < firstRow) {
|
151 | focusIndex = firstRow;
|
152 | }
|
153 | if (scrollIndex < firstRow) {
|
154 | scrollIndex = firstRow;
|
155 | }
|
156 | this.navigateTo(scrollIndex, 'bottom', null, focusIndex, gridCell.column);
|
157 | this.setTimeLastPageEventProcessed();
|
158 | };
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 | NavigationService.prototype.navigateTo = function (scrollIndex, scrollType, scrollColumn, focusIndex, focusColumn) {
|
165 | if (utils_1._.exists(scrollColumn)) {
|
166 | this.gridPanel.ensureColumnVisible(scrollColumn);
|
167 | }
|
168 | if (utils_1._.exists(scrollIndex)) {
|
169 | this.gridPanel.ensureIndexVisible(scrollIndex, scrollType);
|
170 | }
|
171 |
|
172 | this.animationFrameService.flushAllFrames();
|
173 |
|
174 |
|
175 | this.focusedCellController.setFocusedCell(focusIndex, focusColumn, null, true);
|
176 | if (this.rangeController) {
|
177 | var gridCell = new gridCell_1.GridCell({ rowIndex: focusIndex, floating: null, column: focusColumn });
|
178 | this.rangeController.setRangeToCell(gridCell);
|
179 | }
|
180 | };
|
181 |
|
182 | NavigationService.prototype.onCtrlUpOrDown = function (key, gridCell) {
|
183 | var upKey = key === constants_1.Constants.KEY_UP;
|
184 | var rowIndexToScrollTo = upKey ? 0 : this.paginationProxy.getPageLastRow();
|
185 | this.navigateTo(rowIndexToScrollTo, null, gridCell.column, rowIndexToScrollTo, gridCell.column);
|
186 | };
|
187 |
|
188 | NavigationService.prototype.onCtrlLeftOrRight = function (key, gridCell) {
|
189 | var leftKey = key === constants_1.Constants.KEY_LEFT;
|
190 | var allColumns = this.columnController.getAllDisplayedColumns();
|
191 | var columnToSelect = leftKey ? allColumns[0] : allColumns[allColumns.length - 1];
|
192 | this.navigateTo(gridCell.rowIndex, null, columnToSelect, gridCell.rowIndex, columnToSelect);
|
193 | };
|
194 |
|
195 |
|
196 | NavigationService.prototype.onHomeOrEndKey = function (key) {
|
197 | var homeKey = key === constants_1.Constants.KEY_PAGE_HOME;
|
198 | var allColumns = this.columnController.getAllDisplayedColumns();
|
199 | var columnToSelect = homeKey ? allColumns[0] : allColumns[allColumns.length - 1];
|
200 | var rowIndexToScrollTo = homeKey ? 0 : this.paginationProxy.getPageLastRow();
|
201 | this.navigateTo(rowIndexToScrollTo, null, columnToSelect, rowIndexToScrollTo, columnToSelect);
|
202 | };
|
203 | __decorate([
|
204 | context_1.Autowired('mouseEventService'),
|
205 | __metadata("design:type", mouseEventService_1.MouseEventService)
|
206 | ], NavigationService.prototype, "mouseEventService", void 0);
|
207 | __decorate([
|
208 | context_1.Autowired('paginationProxy'),
|
209 | __metadata("design:type", paginationProxy_1.PaginationProxy)
|
210 | ], NavigationService.prototype, "paginationProxy", void 0);
|
211 | __decorate([
|
212 | context_1.Autowired('focusedCellController'),
|
213 | __metadata("design:type", focusedCellController_1.FocusedCellController)
|
214 | ], NavigationService.prototype, "focusedCellController", void 0);
|
215 | __decorate([
|
216 | context_1.Autowired('animationFrameService'),
|
217 | __metadata("design:type", animationFrameService_1.AnimationFrameService)
|
218 | ], NavigationService.prototype, "animationFrameService", void 0);
|
219 | __decorate([
|
220 | context_1.Optional('rangeController'),
|
221 | __metadata("design:type", Object)
|
222 | ], NavigationService.prototype, "rangeController", void 0);
|
223 | __decorate([
|
224 | context_1.Autowired('columnController'),
|
225 | __metadata("design:type", columnController_1.ColumnController)
|
226 | ], NavigationService.prototype, "columnController", void 0);
|
227 | __decorate([
|
228 | context_1.Autowired('gridOptionsWrapper'),
|
229 | __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
|
230 | ], NavigationService.prototype, "gridOptionsWrapper", void 0);
|
231 | __decorate([
|
232 | context_1.PostConstruct,
|
233 | __metadata("design:type", Function),
|
234 | __metadata("design:paramtypes", []),
|
235 | __metadata("design:returntype", void 0)
|
236 | ], NavigationService.prototype, "init", null);
|
237 | NavigationService = __decorate([
|
238 | context_1.Bean('navigationService')
|
239 | ], NavigationService);
|
240 | return NavigationService;
|
241 | }());
|
242 | exports.NavigationService = NavigationService;
|