devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
191 lines (189 loc) • 8.3 kB
JavaScript
/**
* DevExtreme (cjs/__internal/ui/gantt/ui.gantt.export_helper.js)
* Version: 25.2.8
* Build date: Mon Jun 08 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GanttExportHelper = void 0;
var _date = _interopRequireDefault(require("../../../common/core/localization/date"));
var _number = _interopRequireDefault(require("../../../common/core/localization/number"));
var _type = require("../../../core/utils/type");
var _window = require("../../../core/utils/window");
var _m_utils = _interopRequireDefault(require("../../grids/grid_core/m_utils"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : {
default: e
}
}
const window = (0, _window.getWindow)();
const TREELIST_EMPTY_SPACE = "dx-treelist-empty-space";
const TREELIST_TABLE = "dx-treelist-table";
class GanttExportHelper {
constructor(gantt) {
this._gantt = gantt;
this._treeList = gantt._treeList;
this._cache = {}
}
reset() {
this._cache = {}
}
getTreeListTableStyle() {
const table = this._getTreeListTable();
const style = window.getComputedStyle(table);
return {
color: style.color,
backgroundColor: style.backgroundColor,
fontSize: style.fontSize,
fontFamily: style.fontFamily,
fontWeight: style.fontWeight,
fontStyle: style.fontStyle,
textAlign: "left",
verticalAlign: "middle"
}
}
getTreeListColCount() {
const headerView = this._getHeaderView();
const widths = headerView.getColumnWidths().filter(w => w > 0);
return widths.length
}
getTreeListHeaderInfo(colIndex) {
const element = this._getHeaderElement(colIndex);
if (!element) {
return null
}
const style = window.getComputedStyle(element);
const styleForExport = {
color: style.color,
padding: style.padding,
paddingLeft: style.paddingLeft,
paddingTop: style.paddingTop,
paddingRight: style.paddingRight,
paddingBottom: style.paddingBottom,
verticalAlign: style.verticalAlign,
width: this._getColumnWidth(colIndex)
};
return {
content: element.textContent,
styles: styleForExport
}
}
getTreeListCellInfo(key, colIndex) {
var _this$_treeList, _this$_treeList2;
const node = null === (_this$_treeList = this._treeList) || void 0 === _this$_treeList ? void 0 : _this$_treeList.getNodeByKey(key);
const visibleRowIndex = null === (_this$_treeList2 = this._treeList) || void 0 === _this$_treeList2 ? void 0 : _this$_treeList2.getRowIndexByKey(key);
const cell = visibleRowIndex > -1 ? this._getDataCell(visibleRowIndex, colIndex) : null;
const style = cell ? window.getComputedStyle(cell) : this._getColumnCellStyle(colIndex);
const styleForExport = {
color: style.color,
padding: style.padding,
paddingLeft: style.paddingLeft,
paddingTop: style.paddingTop,
paddingRight: style.paddingRight,
paddingBottom: style.paddingBottom,
width: this._getColumnWidth(colIndex)
};
if (0 === colIndex) {
styleForExport.extraLeftPadding = this._getEmptySpaceWidth(node.level)
}
return {
content: (null === cell || void 0 === cell ? void 0 : cell.textContent) ?? this._getDisplayText(key, colIndex),
styles: styleForExport
}
}
getTreeListEmptyDataCellInfo() {
var _this$_treeList3;
return {
content: null === (_this$_treeList3 = this._treeList) || void 0 === _this$_treeList3 ? void 0 : _this$_treeList3.option("noDataText")
}
}
_ensureColumnWidthCache(colIndex) {
var _a;
(_a = this._cache).columnWidths ?? (_a.columnWidths = {});
if (!this._cache.columnWidths[colIndex]) {
const header = this._getHeaderElement(colIndex);
this._cache.columnWidths[colIndex] = (null === header || void 0 === header ? void 0 : header.clientWidth) ?? 0
}
}
_getColumnWidth(colIndex) {
this._ensureColumnWidthCache(colIndex);
const widths = this._cache.columnWidths;
return null === widths || void 0 === widths ? void 0 : widths[colIndex]
}
_getEmptySpaceWidth(level) {
var _a;
if (!this._cache.emptyWidth) {
const element = this._getTreeListElement(TREELIST_EMPTY_SPACE);
(_a = this._cache).emptyWidth ?? (_a.emptyWidth = (null === element || void 0 === element ? void 0 : element.offsetWidth) ?? 0)
}
return this._cache.emptyWidth * (level + 1)
}
_getColumnCellStyle(colIndex) {
this._ensureColumnCellStyleCache(colIndex);
return this._cache.columnStyles[colIndex]
}
_ensureColumnCellStyleCache(colIndex) {
var _a;
(_a = this._cache).columnStyles ?? (_a.columnStyles = {});
if (!this._cache.columnStyles[colIndex]) {
const cell = this._getDataCell(0, colIndex);
this._cache.columnStyles[colIndex] = window.getComputedStyle(cell)
}
}
_getTask(key) {
this._ensureTaskCache(key);
return this._cache.tasks[key]
}
_ensureTaskCache(key) {
var _a, _b;
(_a = this._cache).tasks ?? (_a.tasks = {});
(_b = this._cache.tasks)[key] ?? (_b[key] = this._gantt._findTaskByKey(key))
}
_getTreeListTable() {
return this._getTreeListElement(TREELIST_TABLE)
}
_getTreeListElement(className) {
var _this$_treeList4;
return null === (_this$_treeList4 = this._treeList) || void 0 === _this$_treeList4 ? void 0 : _this$_treeList4.$element().find(`.${className}`).get(0)
}
_getDataCell(rowIndex, colIndex) {
const treeList = this._treeList;
const cellElement = null === treeList || void 0 === treeList ? void 0 : treeList.getCellElement(rowIndex, colIndex);
return null !== cellElement && void 0 !== cellElement && cellElement.length ? cellElement[0] : cellElement
}
_getHeaderElement(index) {
return this._getHeaderView().getHeaderElement(index).get(0)
}
_getHeaderView() {
var _this$_treeList5;
return null === (_this$_treeList5 = this._treeList) || void 0 === _this$_treeList5 ? void 0 : _this$_treeList5._views.columnHeadersView
}
_getDisplayText(key, colIndex) {
const task = this._getTask(key);
return task && this._getGridDisplayText(colIndex, task)
}
_getGridDisplayText(colIndex, data) {
var _this$_treeList6;
const columns = null === (_this$_treeList6 = this._treeList) || void 0 === _this$_treeList6 ? void 0 : _this$_treeList6.getController("columns").getVisibleColumns();
const column = columns[colIndex];
const field = null === column || void 0 === column ? void 0 : column.dataField;
const format = null === column || void 0 === column ? void 0 : column.format;
const value = _m_utils.default.getDisplayValue(column, data[field], data, "data");
if ((0, _type.isDefined)(format)) {
if ("date" === (null === column || void 0 === column ? void 0 : column.dataType) || "datetime" === (null === column || void 0 === column ? void 0 : column.dataType)) {
const date = (0, _type.isDate)(value) ? value : new Date(value);
return _date.default.format(date, format)
}
if ((0, _type.isNumeric)(value)) {
return _number.default.format(value, format)
}
}
return "string" === typeof value ? value : null === value || void 0 === value ? void 0 : value.toString()
}
}
exports.GanttExportHelper = GanttExportHelper;