UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

110 lines (109 loc) 5.31 kB
/** * DevExtreme (esm/__internal/ui/gantt/ui.gantt.custom_fields.js) * Version: 25.2.7 * Build date: Tue May 05 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import { compileGetter } from "../../../core/utils/data"; import { GanttDataCache } from "../../ui/gantt/ui.gantt.cache"; import { GanttHelper } from "../../ui/gantt/ui.gantt.helper"; const GANTT_TASKS = "tasks"; export class GanttCustomFieldsManager { constructor(gantt) { this._gantt = gantt; this._mappingHelper = gantt._mappingHelper; this.cache = new GanttDataCache } _getTaskCustomFields() { const { columns: columns } = this._gantt.option(); const columnFields = null === columns || void 0 === columns ? void 0 : columns.map(c => c.dataField); const mappedFields = this._mappingHelper.getTaskMappedFieldNames(); return columnFields ? columnFields.filter(f => !mappedFields.includes(f)) : [] } _getCustomFieldsData(data) { return this._getTaskCustomFields().reduce((previous, field) => { if (data && void 0 !== data[field]) { previous[field] = data[field] } return previous }, {}) } addCustomFieldsData(key, data) { if (data) { var _this$_gantt$_tasksOp; const modelData = null === (_this$_gantt$_tasksOp = this._gantt._tasksOption) || void 0 === _this$_gantt$_tasksOp ? void 0 : _this$_gantt$_tasksOp._getItems(); const keyGetter = compileGetter(this._gantt.option("tasks.keyExpr")); const modelItem = null === modelData || void 0 === modelData ? void 0 : modelData.filter(obj => keyGetter(obj) === key)[0]; const customFields = this._getTaskCustomFields(); if (modelItem) { for (let i = 0; i < customFields.length; i += 1) { const field = customFields[i]; if (Object.prototype.hasOwnProperty.call(modelItem, field)) { data[field] = modelItem[field] } } } } } appendCustomFields(data) { var _this$_gantt$_tasksOp2; const modelData = null === (_this$_gantt$_tasksOp2 = this._gantt._tasksOption) || void 0 === _this$_gantt$_tasksOp2 ? void 0 : _this$_gantt$_tasksOp2._getItems(); const keyGetter = this._gantt._getTaskKeyGetter(); const invertedData = GanttHelper.getInvertedData(modelData, keyGetter); return data.reduce((previous, item) => { const key = keyGetter(item); const modelItem = invertedData[key]; if (!modelItem) { previous.push(item) } else { const updatedItem = {}; for (const field in modelItem) { updatedItem[field] = Object.prototype.hasOwnProperty.call(item, field) ? item[field] : modelItem[field] } previous.push(updatedItem) } return previous }, []) } addCustomFieldsDataFromCache(key, data) { this.cache.pullDataFromCache(key, data) } saveCustomFieldsDataToCache(key, data) { let forceUpdateOnKeyExpire = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : false; let isCustomFieldsUpdateOnly = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : false; const customFieldsData = this._getCustomFieldsData(data); if (Object.keys(customFieldsData).length > 0) { const updateCallback = (key, data) => { const dataOption = this._gantt._tasksOption; if (dataOption && data) { dataOption.update(key, data, (data, key) => { var _this$_gantt$_ganttVi, _this$_gantt$_actions; const updatedCustomFields = {}; this.addCustomFieldsData(key, updatedCustomFields); dataOption._reloadDataSource().done(data => { var _this$_gantt$_ganttTr; null === (_this$_gantt$_ganttTr = this._gantt._ganttTreeList) || void 0 === _this$_gantt$_ganttTr || _this$_gantt$_ganttTr.updateDataSource(data ?? dataOption._dataSource, false, isCustomFieldsUpdateOnly) }); const selectedRowKey = this._gantt.option("selectedRowKey"); null === (_this$_gantt$_ganttVi = this._gantt._ganttView) || void 0 === _this$_gantt$_ganttVi || _this$_gantt$_ganttVi._selectTask(selectedRowKey); null === (_this$_gantt$_actions = this._gantt._actionsManager) || void 0 === _this$_gantt$_actions || _this$_gantt$_actions.raiseUpdatedAction("tasks", updatedCustomFields, key) }) } }; this.cache.saveData(key, customFieldsData, forceUpdateOnKeyExpire ? updateCallback : null) } } resetCustomFieldsDataCache(key) { this.cache.resetCache(key) } }