UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

91 lines (90 loc) 3.57 kB
/** * DevExtreme (cjs/__internal/ui/gantt/ui.gantt.mapping_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.GanttMappingHelper = void 0; var _data = require("../../../core/utils/data"); var _type = require("../../../core/utils/type"); const GANTT_TASKS = "tasks"; const GANTT_MAPPED_FIELD_REGEX = /(\w*)Expr/; class GanttMappingHelper { constructor(gantt) { this._gantt = gantt } _getMappedFieldName(optionName, coreField) { let coreFieldName = coreField; if ("id" === coreField) { coreFieldName = "key" } return this._gantt.option(`${optionName}.${coreFieldName}Expr`) } getTaskMappedFieldNames() { const mappedFields = []; const mappedFieldsData = this._gantt.option("tasks"); for (const field in mappedFieldsData) { const exprMatches = GANTT_MAPPED_FIELD_REGEX.exec(field); const mappedFieldName = exprMatches && mappedFieldsData[exprMatches[0]]; if (mappedFieldName) { mappedFields.push(mappedFieldName) } } return mappedFields } convertCoreToMappedData(optionName, coreData) { return Object.keys(coreData).reduce((previous, f) => { const mappedField = this._getMappedFieldName(optionName, f); if (mappedField && !(0, _type.isFunction)(mappedField)) { const setter = (0, _data.compileSetter)(mappedField); setter(previous, coreData[f]) } return previous }, {}) } convertMappedToCoreData(optionName, mappedData) { const coreData = {}; if (mappedData) { const mappedFields = this._gantt.option(optionName); for (const field in mappedFields) { const exprMatches = GANTT_MAPPED_FIELD_REGEX.exec(field); const mappedFieldName = exprMatches && mappedFields[exprMatches[0]]; if (mappedFieldName && void 0 !== mappedData[mappedFieldName]) { const getter = (0, _data.compileGetter)(mappedFieldName); const coreFieldName = exprMatches[1]; coreData[coreFieldName] = getter(mappedData) } } } return coreData } convertCoreToMappedFields(optionName, fields) { return fields.reduce((previous, f) => { const mappedField = this._getMappedFieldName(optionName, f); if (mappedField) { previous.push(mappedField) } return previous }, []) } convertMappedToCoreFields(optionName, fields) { const coreFields = []; const mappedFields = this._gantt.option(optionName); for (const field in mappedFields) { const exprMatches = GANTT_MAPPED_FIELD_REGEX.exec(field); const mappedFieldName = exprMatches && mappedFields[exprMatches[0]]; if (mappedFieldName && fields.indexOf(mappedFieldName) > -1) { const coreFieldName = exprMatches[1]; coreFields.push(coreFieldName) } } return coreFields } } exports.GanttMappingHelper = GanttMappingHelper;