UNPKG

@true-directive/base

Version:

The set of base classes for the TrueDirective Grid

190 lines (189 loc) 7.68 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; /** * Copyright (c) 2018-2019 Aleksey Melnikov, True Directive Company. * @link https://truedirective.com/ * @license MIT */ import { AxInject } from '../classes/ax-inject.class'; import { SelectionMode, GridPart } from '../classes/enums'; import { GridLayoutRange } from '../classes/grid-layout-selection.class'; import { ColumnCollection } from '../classes/column-collection.class'; import { GridLayout } from '../classes/grid-layout.class'; import { Selection } from '../classes/selection.class'; import { DataSource } from '../classes/data-source.class'; import { GridSettings } from '../classes/grid-settings.class'; var LayoutsHandler = /** @class */ (function () { // function LayoutsHandler() { this.layout = new GridLayout(GridPart.CENTER); this.layoutDrag = new GridLayout(GridPart.DRAG_ITEM); } Object.defineProperty(LayoutsHandler.prototype, "layouts", { get: function () { return [this.layout]; }, enumerable: true, configurable: true }); Object.defineProperty(LayoutsHandler.prototype, "focusedCell", { /** * Focused cell position */ get: function () { return this.selection.focusedCell; }, set: function (cp) { this.selection.focusedCell = cp === null ? null : cp.clone(); }, enumerable: true, configurable: true }); LayoutsHandler.prototype.setLayoutsVisibility = function () { // }; /** * Gets column by field name * @param f Field name * @return Column if exists */ LayoutsHandler.prototype.columnByFieldName = function (f) { return this.columnCollection.columnByFieldName(f); }; /** * Изменение выделенной области * @param cp Позиция ячейки */ LayoutsHandler.prototype.selectionChanged = function (cp) { this.updateLayoutSelections(cp); this.events.selectEvent(cp); }; /** * Обновление индексов строк в списке выделенных областей */ LayoutsHandler.prototype.updateSelectionIndices = function () { var changed = this.selection.updateSelectionIndices(this.dataSource.model, this.dataSource.resultRows, this.settings.keyField); this.updateLayoutSelections(); if (changed) { this.events.selectEvent(null); } }; /** * Return the column index in the column list by field name * @param fieldName Name of the field to be searched * @return Column index */ LayoutsHandler.prototype.columnIndex = function (fieldName) { return this.selection.columnIndex(this.layoutColumns, fieldName); }; /** * Обновление выделенных областей для дочерних компонентов * @param scrollToCell Прокрутить до указанной ячейки после обновления */ LayoutsHandler.prototype.updateLayoutSelections = function (scrollToCell) { if (scrollToCell === void 0) { scrollToCell = null; } var sm = this.settings.selectionMode; var sel = this.selection; var lSel = this.layout.selection; this.layouts.forEach(function (l) { return l.selection.clear(); }); if (sm === SelectionMode.NONE) { return; } var A = 0; var B = A + this.layout.columns.length; var C = B; for (var _i = 0, _a = sel.ranges; _i < _a.length; _i++) { var range = _a[_i]; if (range.fromCell.rowIndex < 0) { return null; } var fromIndex = this.columnIndex(range.fromCell.fieldName); var toIndex = -1; if (range.toCell) { toIndex = this.columnIndex(range.toCell.fieldName); } if (toIndex >= 0 && toIndex < fromIndex) { var t = toIndex; toIndex = fromIndex; fromIndex = t; } if (toIndex === -1 && sm !== SelectionMode.ROW && sm !== SelectionMode.ROW_AND_RANGE) { range.toCell = range.fromCell; toIndex = fromIndex; } // Центр if (fromIndex < B || toIndex === -1) { var ci = 0; var rx = B - A - 1; var ry = 0; if (toIndex >= 0) { ci = fromIndex - A; rx = toIndex < B ? toIndex - fromIndex : B - fromIndex - 1; ry = range.toCell.rowIndex - range.fromCell.rowIndex; } var cr = new GridLayoutRange(range.fromCell.rowIndex, ci); cr.rangeX = rx; cr.rangeY = ry; lSel.ranges.push(cr); } } // Focused cell if (sel.focusedCell) { var ii = this.columnIndex(sel.focusedCell.fieldName); if (ii >= A && ii < B) { lSel.focusedRowIndex = sel.focusedCell.rowIndex; lSel.focusedColumnIndex = ii - A; } else { lSel.focusedRowIndex = -1; } } else { lSel.focusedRowIndex = -1; lSel.focusedColumnIndex = -1; } return scrollToCell; }; Object.defineProperty(LayoutsHandler.prototype, "layoutColumns", { /** * Список колонок по лэйаутам * @return Список колонок по лэйаутам */ get: function () { var res = []; this.layouts.forEach(function (l) { return l.columns.forEach(function (c) { return res.push(c); }); }); return res; }, enumerable: true, configurable: true }); __decorate([ AxInject('settings'), __metadata("design:type", GridSettings) ], LayoutsHandler.prototype, "settings", void 0); __decorate([ AxInject('events'), __metadata("design:type", Object) ], LayoutsHandler.prototype, "events", void 0); __decorate([ AxInject('dataSource'), __metadata("design:type", DataSource) ], LayoutsHandler.prototype, "dataSource", void 0); __decorate([ AxInject('selection'), __metadata("design:type", Selection) ], LayoutsHandler.prototype, "selection", void 0); __decorate([ AxInject('columns'), __metadata("design:type", ColumnCollection) ], LayoutsHandler.prototype, "columnCollection", void 0); return LayoutsHandler; }()); export { LayoutsHandler };