UNPKG

@syncfusion/ej2-gantt

Version:
952 lines (951 loc) 279 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { isNullOrUndefined, isUndefined, extend, setValue, getValue, deleteObject, createElement } from '@syncfusion/ej2-base'; import { DataManager, Query, ODataAdaptor, WebApiAdaptor, ODataV4Adaptor } from '@syncfusion/ej2-data'; import { getSwapKey, isScheduledTask, getTaskData, isRemoteData, getIndex, isCountRequired, updateDates } from '../base/utils'; import { ConstraintType } from '../base/enum'; import { CellEdit } from './cell-edit'; import { TaskbarEdit } from './taskbar-edit'; import { DialogEdit } from './dialog-edit'; import { Dialog } from '@syncfusion/ej2-popups'; import { MultiSelect, CheckBoxSelection, DropDownList } from '@syncfusion/ej2-dropdowns'; import { ConnectorLineEdit } from './connector-line-edit'; import { TreeGrid, Edit as TreeGridEdit } from '@syncfusion/ej2-treegrid'; /** * The Edit Module is used to handle editing actions. * */ var Edit = /** @class */ (function () { function Edit(parent) { this.isFromDeleteMethod = false; this.targetedRecords = []; this.isValidatedEditedRecord = false; this.createArray = true; this.violationArgs = {}; this.deletedRecord = []; this.canReset = false; this.isFlatDataHaveUnAsignedTask = false; /** @hidden */ this.updateParentRecords = []; /** @hidden */ this.isaddtoBottom = false; this.confirmDialog = null; this.taskbarMoved = false; this.predecessorUpdated = false; this.isBreakLoop = false; this.isDialogEditing = false; /** * @private */ this.deletedTaskDetails = []; this.parent = parent; this.parent.predecessorModule.validatedChildItems = []; if (this.parent.editSettings.allowEditing && this.parent.editSettings.mode === 'Auto') { this.cellEditModule = new CellEdit(this.parent); } if (this.parent.taskFields.dependency) { this.parent.connectorLineEditModule = new ConnectorLineEdit(this.parent); } if (this.parent.editSettings.allowAdding || (this.parent.editSettings.allowEditing && (this.parent.editSettings.mode === 'Dialog' || this.parent.editSettings.mode === 'Auto'))) { this.dialogModule = new DialogEdit(this.parent); } if (this.parent.editSettings.allowTaskbarEditing) { this.taskbarEditModule = new TaskbarEdit(this.parent); } if (this.parent.editSettings.allowDeleting) { var confirmDialog = createElement('div', { id: this.parent.element.id + '_deleteConfirmDialog' }); this.parent.element.appendChild(confirmDialog); this.renderDeleteConfirmDialog(); } this.parent.treeGrid.recordDoubleClick = this.recordDoubleClick.bind(this); this.parent.treeGrid.editSettings.allowAdding = this.parent.editSettings.allowAdding; this.parent.treeGrid.editSettings.allowDeleting = this.parent.editSettings.allowDeleting; this.parent.treeGrid.editSettings.showDeleteConfirmDialog = this.parent.editSettings.showDeleteConfirmDialog; this.parent.treeGrid.editSettings.allowNextRowEdit = this.parent.editSettings.allowNextRowEdit; if (this.parent.editSettings.mode === 'Dialog') { TreeGrid.Inject(TreeGridEdit); } this.updateDefaultColumnEditors(); } Edit.prototype.getModuleName = function () { return 'edit'; }; /** * Method to update default edit params and editors for Gantt * * @returns {void} . */ Edit.prototype.updateDefaultColumnEditors = function () { var customEditorColumns = [this.parent.taskFields.id, this.parent.taskFields.progress, this.parent.taskFields.resourceInfo, this.parent.taskFields.type, 'taskType']; for (var i = 0; i < customEditorColumns.length; i++) { if (!isNullOrUndefined(customEditorColumns[i]) && customEditorColumns[i].length > 0) { var column = this.parent.getColumnByField(customEditorColumns[parseInt(i.toString(), 10)], this.parent.treeGridModule.treeGridColumns); if (column) { if (column.field === this.parent.taskFields.id) { this.updateIDColumnEditParams(column); } else if (column.field === this.parent.taskFields.progress && isNullOrUndefined(column.edit)) { this.updateProgessColumnEditParams(column); } else if (column.field === this.parent.taskFields.resourceInfo) { this.updateResourceColumnEditor(column); } else if (column.field === this.parent.taskFields.type || column.field === 'taskType') { this.updateTaskTypeColumnEditor(column); } } } } }; /** * Method to update editors for id column in Gantt * * @param {ColumnModel} column . * @returns {void} . */ Edit.prototype.updateIDColumnEditParams = function (column) { var editParam = { min: 0, decimals: 0, enableRtl: this.parent.enableRtl, validateDecimalOnType: true, format: 'n0', showSpinButton: false }; this.updateEditParams(column, editParam); }; /** * Method to update edit params of default progress column * * @param {ColumnModel} column . * @returns {void} . */ Edit.prototype.updateProgessColumnEditParams = function (column) { var editParam = { min: 0, enableRtl: this.parent.enableRtl, decimals: 0, validateDecimalOnType: true, max: 100, format: 'n0' }; this.updateEditParams(column, editParam); }; /** * Assign edit params for id and progress columns * * @param {ColumnModel} column . * @param {object} editParam . * @returns {void} . */ Edit.prototype.updateEditParams = function (column, editParam) { if (isNullOrUndefined(column.edit)) { column.edit = {}; column.edit.params = {}; } else if (isNullOrUndefined(column.edit.params)) { column.edit.params = {}; } extend(editParam, column.edit.params); column.edit.params = editParam; var ganttColumn = this.parent.getColumnByField(column.field, this.parent.ganttColumns); ganttColumn.edit = column.edit; }; /** * Method to update resource column editor for default resource column * * @param {ColumnModel} column . * @returns {void} . */ Edit.prototype.updateResourceColumnEditor = function (column) { this.parent.treeGridModule.currentEditRow = {}; if (this.parent.editSettings.allowEditing && isNullOrUndefined(column.edit) && this.parent.editSettings.mode === 'Auto') { column.editType = 'dropdownedit'; column.edit = this.getResourceEditor(); var ganttColumn = this.parent.getColumnByField(column.field, this.parent.ganttColumns); ganttColumn.editType = 'dropdownedit'; ganttColumn.edit = column.edit; } }; /** * Method to create resource custom editor * * @returns {IEditCell} . */ Edit.prototype.getResourceEditor = function () { var _this = this; var resourceSettings = this.parent.resourceFields; var editObject = {}; var editor; MultiSelect.Inject(CheckBoxSelection); editObject.write = function (args) { _this.parent.treeGridModule.currentEditRow = {}; editor = new MultiSelect({ dataSource: new DataManager(_this.parent.resources), fields: { text: resourceSettings.name, value: resourceSettings.id }, enableRtl: _this.parent.enableRtl, mode: 'CheckBox', showDropDownIcon: true, popupHeight: '350px', delimiterChar: ',', value: _this.parent.treeGridModule.getResourceIds(args.rowData) }); editor.appendTo(args.element); }; editObject.read = function (element) { var value = element.ej2_instances[0].value; var resourcesName = []; if (isNullOrUndefined(value)) { value = []; } for (var i = 0; i < value.length; i++) { for (var j = 0; j < _this.parent.resources.length; j++) { if (_this.parent.resources[j][resourceSettings.id] === value[i]) { resourcesName.push(_this.parent.resources[j][resourceSettings.name]); break; } } } _this.parent.treeGridModule.currentEditRow[_this.parent.taskFields.resourceInfo] = value; return resourcesName.join(','); }; editObject.destroy = function () { if (editor) { editor.destroy(); } }; return editObject; }; /** * Method to update task type column editor for task type * * @param {ColumnModel} column . * @returns {void} . */ Edit.prototype.updateTaskTypeColumnEditor = function (column) { if (this.parent.editSettings.allowEditing && isNullOrUndefined(column.edit) && this.parent.editSettings.mode === 'Auto') { column.editType = 'dropdownedit'; column.edit = this.getTaskTypeEditor(); var ganttColumn = this.parent.getColumnByField(column.field, this.parent.ganttColumns); ganttColumn.editType = 'dropdownedit'; ganttColumn.edit = column.edit; } }; /** * Method to create task type custom editor * * @returns {IEditCell} . */ Edit.prototype.getTaskTypeEditor = function () { var _this = this; var editObject = {}; var editor; var types = [{ 'ID': 1, 'Value': 'FixedUnit' }, { 'ID': 2, 'Value': 'FixedWork' }, { 'ID': 3, 'Value': 'FixedDuration' }]; editObject.write = function (args) { _this.parent.treeGridModule.currentEditRow = {}; editor = new DropDownList({ dataSource: new DataManager(types), enableRtl: _this.parent.enableRtl, fields: { value: 'Value' }, popupHeight: '350px', value: getValue('taskType', args.rowData.ganttProperties) }); editor.appendTo(args.element); }; editObject.read = function (element) { var value = element.ej2_instances[0].value; var key = _this.parent.taskFields.type || 'taskType'; _this.parent.treeGridModule.currentEditRow[key] = value; return value; }; editObject.destroy = function () { if (editor) { editor.destroy(); } }; return editObject; }; /** * @returns {void} . * @private */ Edit.prototype.reUpdateEditModules = function () { var editSettings = this.parent.editSettings; if (editSettings.allowEditing) { if (this.parent.editModule.cellEditModule && editSettings.mode === 'Dialog') { this.cellEditModule.destroy(); this.parent.treeGrid.recordDoubleClick = this.recordDoubleClick.bind(this); } else if (isNullOrUndefined(this.parent.editModule.cellEditModule) && editSettings.mode === 'Auto') { this.cellEditModule = new CellEdit(this.parent); } if (this.parent.editModule.dialogModule && editSettings.mode === 'Auto') { this.parent.treeGrid.recordDoubleClick = undefined; } else if (isNullOrUndefined(this.parent.editModule.dialogModule)) { this.dialogModule = new DialogEdit(this.parent); } } else { if (this.cellEditModule) { this.cellEditModule.destroy(); } if (this.dialogModule) { this.dialogModule.destroy(); } } if (editSettings.allowDeleting && editSettings.showDeleteConfirmDialog) { if (isNullOrUndefined(this.confirmDialog)) { var confirmDialog = createElement('div', { id: this.parent.element.id + '_deleteConfirmDialog' }); this.parent.element.appendChild(confirmDialog); this.renderDeleteConfirmDialog(); } } else if (!editSettings.allowDeleting || !editSettings.showDeleteConfirmDialog) { if (this.confirmDialog && !this.confirmDialog.isDestroyed) { this.confirmDialog.destroy(); } } if (editSettings.allowTaskbarEditing) { if (isNullOrUndefined(this.parent.editModule.taskbarEditModule)) { this.taskbarEditModule = new TaskbarEdit(this.parent); } } else { if (this.taskbarEditModule) { this.taskbarEditModule.destroy(); } } }; Edit.prototype.recordDoubleClick = function (args) { if (this.parent.editSettings.allowEditing && this.parent.editSettings.mode === 'Dialog') { var ganttData = void 0; if (args.row) { var rowIndex = getValue('rowIndex', args.row); ganttData = this.parent.currentViewData[rowIndex]; } if (!isNullOrUndefined(ganttData)) { this.dialogModule.openEditDialog(ganttData); } } this.parent.ganttChartModule.recordDoubleClick(args); }; /** * @returns {void} . * @private */ Edit.prototype.destroy = function () { if (this.cellEditModule) { this.cellEditModule.destroy(); } if (this.taskbarEditModule) { this.taskbarEditModule.destroy(); } if (this.dialogModule) { this.dialogModule.destroy(); } if (this.confirmDialog && !this.confirmDialog.isDestroyed) { this.confirmDialog.destroy(); } }; /** * Method to update record with new values. * * @param {Object} data - Defines new data to update. * @returns {void} . */ Edit.prototype.updateRecordByID = function (data) { var _this = this; if (this.parent.enableImmutableMode && this.parent.editSettings.allowEditing && this.parent.treeGrid.element.getElementsByClassName('e-editedbatchcell').length > 0) { this.parent.treeGrid.endEdit(); } if (!this.parent.readOnly) { var tasks = this.parent.taskFields; if (isNullOrUndefined(data) || isNullOrUndefined(data[tasks.id])) { return; } var ganttData = this.parent.viewType === 'ResourceView' ? this.parent.flatData[this.parent.getTaskIds().indexOf((data['hasChildRecords'] ? 'R' : 'T') + data[tasks.id])] : this.parent.getRecordByID(data[tasks.id]); if (!isNullOrUndefined(ganttData[tasks.milestone])) { if (ganttData[tasks.milestone] === true) { ganttData[tasks.milestone] = false; } } if (this.parent.undoRedoModule && !this.parent.undoRedoModule['isUndoRedoPerformed'] && this.parent['isUndoRedoItemPresent']('Edit') && ganttData) { this.parent.undoRedoModule['createUndoCollection'](); var details = {}; details['requestType'] = ((this.parent.contextMenuModule && this.parent.contextMenuModule.item) ? this.parent.contextMenuModule.item : 'methodUpdate'); details['modifiedRecords'] = extend([], [ganttData], [], true); this.parent.undoRedoModule['getUndoCollection'][this.parent.undoRedoModule['getUndoCollection'].length - 1] = details; } if (!isNullOrUndefined(this.parent.editModule) && ganttData) { this.parent.isOnEdit = true; this.validateUpdateValues(data, ganttData, true); if (this.parent.undoRedoModule && this.parent.undoRedoModule['isUndoRedoPerformed']) { if (this.parent.viewType === 'ProjectView' && data['ganttProperties'].predecessor && ganttData['ganttProperties'].predecessor) { var _loop_1 = function (i) { var isValid = ganttData.ganttProperties.predecessor.filter(function (pred) { if ((pred.from === data['ganttProperties'].predecessor[i].from && pred.to === data['ganttProperties'].predecessor[i].to && data['ganttProperties'].predecessor[i].offset !== pred.offset)) { var record = _this.parent.flatData[_this.parent.ids.indexOf(pred.to)]; var changeValue = record.ganttProperties.predecessor.filter(function (pred) { return (pred.from === data['ganttProperties'].predecessor[i].from && pred.to === data['ganttProperties'].predecessor[i].to); }); changeValue[0].offset = data['ganttProperties'].predecessor[i].offset; } return pred.from !== data['ganttProperties'].predecessor[i].from && pred.from !== data['ganttProperties'].predecessor[i].to; }); if (isValid.length > 0) { for (var j = 0; j < isValid.length; j++) { var record = this_1.parent.flatData[this_1.parent.ids.indexOf(isValid[j].from)]; for (var k = 0; k < record.ganttProperties.predecessor.length; k++) { if (record.ganttProperties.predecessor[k].from === isValid[j].from && record.ganttProperties.predecessor[k].to === isValid[j].to) { record.ganttProperties.predecessor.splice(k, 1); break; } } } return "break"; } }; var this_1 = this; for (var i = 0; i < data['ganttProperties'].predecessor.length; i++) { var state_1 = _loop_1(i); if (state_1 === "break") break; } } else if (!data['ganttProperties'].predecessor && ganttData.ganttProperties.predecessor) { for (var i = 0; i < ganttData.ganttProperties.predecessor.length; i++) { var id = void 0; if (ganttData.ganttProperties.taskId.toString() === ganttData.ganttProperties.predecessor[i].from) { id = ganttData.ganttProperties.predecessor[i].to; } else { id = ganttData.ganttProperties.predecessor[i].from; } var parentRec = this.parent.flatData[this.parent.ids.indexOf(id)]; if (!isNullOrUndefined(parentRec) && !isNullOrUndefined(parentRec.ganttProperties) && !isNullOrUndefined(parentRec.ganttProperties.predecessor)) { for (var j = 0; j < parentRec.ganttProperties.predecessor.length; j++) { if (parentRec.ganttProperties.predecessor[j].from === ganttData.ganttProperties.predecessor[i].from && parentRec.ganttProperties.predecessor[j].to === ganttData.ganttProperties.predecessor[i].to) { parentRec.ganttProperties.predecessor.splice(j, 1); } } } } } ganttData.ganttProperties.resourceInfo = data['ganttProperties'].resourceInfo; ganttData[this.parent.taskFields.resourceInfo] = data[this.parent.taskFields.resourceInfo]; ganttData['taskData'][this.parent.taskFields.resourceInfo] = data['taskData'][this.parent.taskFields.resourceInfo]; this.parent.setRecordValue('resourceNames', data['ganttProperties'].resourceNames, ganttData.ganttProperties, true); this.parent.setRecordValue('predecessorsName', data['ganttProperties'].predecessorsName, ganttData.ganttProperties, true); if (this.parent.taskFields.dependency) { this.parent.setRecordValue(this.parent.taskFields.dependency, data[this.parent.taskFields.dependency], ganttData); } this.parent.setRecordValue('predecessor', data['ganttProperties'].predecessor, ganttData.ganttProperties, true); } if (data[this.parent.taskFields.resourceInfo]) { if (ganttData.ganttProperties.duration === 0 && (ganttData.ganttProperties.taskType !== 'FixedWork' || this.parent['isConvertedMilestone'])) { this.parent.dataOperation.updateWorkWithDuration(ganttData); } if (!this.parent.undoRedoModule || !this.parent.undoRedoModule['isUndoRedoPerformed']) { this.updateResourceRelatedFields(ganttData, 'resource'); } this.parent.dateValidationModule.calculateEndDate(ganttData); } var keys = Object.keys(data); if (keys.indexOf(tasks.startDate) !== -1 || keys.indexOf(tasks.endDate) !== -1 || keys.indexOf(tasks.duration) !== -1) { this.parent.dataOperation.calculateScheduledValues(ganttData, ganttData.taskData, false); } if (keys.indexOf(tasks.baselineDuration) !== -1) { this.parent.dataOperation.calculateScheduledValuesforBaseline(ganttData, ganttData.taskData, false); } this.parent.dataOperation.updateWidthLeft(ganttData); if (!isUndefined(data[this.parent.taskFields.dependency]) && data[this.parent.taskFields.dependency] !== ganttData.ganttProperties.predecessorsName) { this.parent.connectorLineEditModule.updatePredecessor(ganttData, data[this.parent.taskFields.dependency]); } else { var args = {}; args.data = ganttData; if (this.parent.viewType === 'ResourceView') { args.action = 'methodUpdate'; } this.parent.editModule.initiateUpdateAction(args); } } } }; /** * * @param {object} data . * @param {IGanttData} ganttData . * @param {boolean} isFromDialog . * @returns {void} . * @private */ Edit.prototype.validateUpdateValues = function (data, ganttData, isFromDialog) { var ganttObj = this.parent; var tasks = ganttObj.taskFields; var ganttPropByMapping = getSwapKey(ganttObj.columnMapping); var scheduleFieldNames = []; var isScheduleValueUpdated = false; for (var _i = 0, _b = Object.keys(data); _i < _b.length; _i++) { var key = _b[_i]; if (tasks.startDate === key || tasks.endDate === key || tasks.duration === key || tasks.baselineDuration === key) { var isBaseline = (tasks.baselineDuration === key) ? true : false; if (isNullOrUndefined(data["" + key]) && !ganttObj.allowUnscheduledTasks) { continue; } var ganttProps = ganttData.ganttProperties; var isDurationKey = tasks.duration === key || tasks.baselineDuration === key; if (isFromDialog) { if (isDurationKey) { ganttObj.dataOperation.updateDurationValue(data[key], ganttProps, isBaseline); if (!isBaseline && ganttProps.duration > 0 && ganttProps.isMilestone) { this.parent.setRecordValue('isMilestone', false, ganttProps, true); } } else { var tempDate = typeof data[key] === 'string' ? new Date(data[key]) : data[key]; if (key === tasks.endDate && isNullOrUndefined(ganttProps.startDate) && (isNullOrUndefined(data[tasks.duration]) || data[tasks.duration] === '' || Number.isNaN(data[tasks.duration]))) { tempDate = this.parent.editModule.dialogModule['isFromEditDialog'] ? ganttData.ganttProperties.endDate : data[tasks.endDate]; } ganttObj.setRecordValue(ganttPropByMapping[key], tempDate, ganttProps, true); if (ganttData[tasks.startDate] && !(ganttData[tasks.startDate] instanceof Date)) { ganttData[tasks.startDate] = new Date(ganttData[tasks.startDate]); } if (ganttData[tasks.endDate] && !(ganttData[tasks.endDate] instanceof Date)) { ganttData[tasks.endDate] = new Date(ganttData[tasks.endDate]); } } ganttObj.dataOperation.updateMappingData(ganttData, ganttPropByMapping[key]); } else { scheduleFieldNames.push(key); isScheduleValueUpdated = true; } } else if (tasks.resourceInfo === key) { var resourceData = ganttObj.dataOperation.setResourceInfo(data); if (this.parent.viewType === 'ResourceView') { if (JSON.stringify(resourceData) !== JSON.stringify(ganttData.ganttProperties.resourceInfo)) { this.parent.editModule.dialogModule.isResourceUpdate = true; this.parent.editModule.dialogModule.previousResource = !isNullOrUndefined(ganttData.ganttProperties.resourceInfo) ? ganttData.ganttProperties.resourceInfo.slice() : []; } else { this.parent.editModule.dialogModule.isResourceUpdate = false; } } if (!this.parent.undoRedoModule || !this.parent.undoRedoModule['isUndoRedoPerformed']) { ganttData.ganttProperties.resourceInfo = resourceData; } ganttObj.dataOperation.updateMappingData(ganttData, 'resourceInfo'); } else if (tasks.dependency === key) { //.. } else if ([ tasks.progress, tasks.notes, tasks.durationUnit, tasks.milestone, tasks.name, tasks.baselineStartDate, tasks.baselineEndDate, tasks.id, tasks.segments, tasks.cssClass, tasks.constraintDate, tasks.constraintType ].indexOf(key) !== -1) { var column = ganttObj.columnByField[key]; /* eslint-disable-next-line */ var value = data[key]; // Handles for both updateRecordByID() & Dialog-save update actions: if (tasks.progress === key) { value = this.parent.dataOperation['formatProgressValue'](value, key); value = (100 < value) ? 100 : value; } if (!isNullOrUndefined(column) && (column.editType === 'datepickeredit' || column.editType === 'datetimepickeredit')) { value = ganttObj.dataOperation.getDateFromFormat(value); } var ganttPropKey = ganttPropByMapping[key]; switch (key) { case tasks.id: ganttPropKey = 'taskId'; break; case tasks.name: ganttPropKey = 'taskName'; break; case tasks.constraintDate: ganttPropKey = 'constraintDate'; break; case tasks.constraintType: ganttPropKey = 'constraintType'; break; case tasks.cssClass: ganttPropKey = 'cssClass'; break; case tasks.milestone: ganttPropKey = 'isMilestone'; if (!isNullOrUndefined(tasks.duration)) { var ganttProp = ganttData.ganttProperties; var durationValue = data[tasks.duration]; if (value) { durationValue = 0; } else { durationValue = durationValue <= 0 ? 1 : durationValue; } ganttObj.setRecordValue(tasks.duration, durationValue, ganttData, true); ganttObj.setRecordValue('duration', durationValue, ganttProp, true); ganttObj.setRecordValue('taskData.' + tasks.duration, durationValue, ganttData); } break; case tasks.segments: if (ganttData.ganttProperties.segments) { ganttPropKey = 'segments'; /* eslint-disable-next-line */ if (data && !isNullOrUndefined(data[tasks.segments]) && data[tasks.segments].length > 0 && data['ganttProperties'] && data['ganttProperties'].segments) { if (this.parent.undoRedoModule && this.parent.undoRedoModule['isUndoRedoPerformed']) { ganttData.ganttProperties.segments = data['ganttProperties'].segments; } var totDuration = ganttData.ganttProperties.segments.reduce(function (acc, segment) { return acc + segment.duration; }, 0); var sdate = ganttData.ganttProperties.startDate; /* eslint-disable-next-line */ var edate = this.parent.dataOperation.getEndDate(sdate, totDuration, ganttData.ganttProperties.durationUnit, ganttData.ganttProperties, false); ganttObj.setRecordValue('endDate', ganttObj.dataOperation.getDateFromFormat(edate), ganttData.ganttProperties, true); } } break; } if (!isNullOrUndefined(ganttPropKey)) { var seg = []; if (ganttPropKey === 'segments' && value && value.length > 0 && !isNullOrUndefined(ganttData.ganttProperties.segments)) { for (var i = 0; i < value.length; i++) { var segment = {}; if (value[i][tasks.startDate]) { segment['startDate'] = value[i][tasks.startDate]; } if (value[i][tasks.endDate]) { segment['endDate'] = value[i][tasks.endDate]; } if (value[i][tasks.duration]) { segment['duration'] = parseFloat(value[i][tasks.duration]); } if (value[i][tasks.id]) { segment['id'] = value[i][tasks.id]; } seg.push(segment); } ganttObj.setRecordValue(ganttPropKey, seg, ganttData.ganttProperties, true); } else { if (ganttPropKey !== 'segments' || (ganttPropKey === 'segments' && isNullOrUndefined(value))) { ganttObj.setRecordValue(ganttPropKey, value, ganttData.ganttProperties, true); } } } if ((key === tasks.baselineStartDate || key === tasks.baselineEndDate) && (ganttData.ganttProperties.baselineStartDate && ganttData.ganttProperties.baselineEndDate)) { var ganttProps = ganttData.ganttProperties; ganttObj.setRecordValue('baselineStartDate', ganttObj.dataOperation.checkBaselineStartDate(ganttProps.baselineStartDate, ganttProps), ganttProps, true); var dayEndTime = this.parent['getCurrentDayEndTime'](ganttProps.baselineEndDate); if (ganttProps.baselineEndDate && ganttProps.baselineEndDate.getHours() === 0 && dayEndTime !== 86400) { ganttObj.dataOperation.setTime(dayEndTime, ganttProps.baselineEndDate); } if ((ganttProps.baselineStartDate && ganttProps.baselineEndDate && (ganttProps.baselineStartDate.getTime() > ganttProps.baselineEndDate.getTime())) || ((!isNullOrUndefined(ganttProps.baselineStartDate) && !isNullOrUndefined(ganttProps.startDate) && (ganttProps.baselineStartDate.getTime() === ganttProps.startDate.getTime())) && (!isNullOrUndefined(ganttProps.baselineEndDate) && !isNullOrUndefined(ganttProps.endDate) && (ganttProps.baselineEndDate.toLocaleDateString() === ganttProps.endDate.toLocaleDateString())) && ganttProps.isMilestone)) { ganttProps.baselineEndDate = ganttProps.baselineStartDate; } ganttObj.setRecordValue('baselineEndDate', ganttObj.dataOperation.checkBaselineEndDate(ganttProps.baselineEndDate), ganttProps, true); ganttObj.setRecordValue('baselineLeft', ganttObj.dataOperation.calculateBaselineLeft(ganttProps), ganttProps, true); ganttObj.setRecordValue('baselineWidth', ganttObj.dataOperation.calculateBaselineWidth(ganttProps), ganttProps, true); if (ganttData[tasks.baselineStartDate] && !(ganttData[tasks.baselineStartDate] instanceof Date)) { ganttData[tasks.baselineStartDate] = new Date(ganttData[tasks.baselineStartDate]); } if (ganttData[tasks.baselineEndDate] && !(ganttData[tasks.baselineEndDate] instanceof Date)) { ganttData[tasks.baselineEndDate] = new Date(ganttData[tasks.baselineEndDate]); } } ganttObj.setRecordValue('taskData.' + key, value, ganttData); /* eslint-disable-next-line */ if (key === tasks.segments && data && !isNullOrUndefined(data[tasks.segments]) && data[tasks.segments].length > 0) { if (this.parent.undoRedoModule && this.parent.undoRedoModule['isUndoRedoPerformed'] && data['ganttProperties'] && data['ganttProperties'].segments) { ganttData.ganttProperties.segments = data['ganttProperties'].segments; } ganttObj.dataOperation.setSegmentsInfo(ganttData, true); } ganttObj.setRecordValue(key, value, ganttData); } else if (tasks.indicators === key) { var value = data[key]; ganttObj.setRecordValue('indicators', value, ganttData.ganttProperties, true); ganttObj.setRecordValue('taskData.' + key, value, ganttData); ganttObj.setRecordValue(key, value, ganttData); } else if (tasks.work === key) { ganttObj.setRecordValue('work', data[key], ganttData.ganttProperties, true); this.parent.dataOperation.updateMappingData(ganttData, 'work'); this.parent.dataOperation.updateMappingData(ganttData, 'duration'); this.parent.dataOperation.updateMappingData(ganttData, 'endDate'); } else if (key === tasks.type) { var value = data[key]; ganttObj.setRecordValue('taskType', value, ganttData.ganttProperties, true); ganttObj.setRecordValue(key, value, ganttData); ganttObj.setRecordValue('taskData.' + key, value, ganttData); } else if (key === tasks.expandState) { var value = data[key]; this.parent.setRecordValue('taskData.' + key, value, ganttData); this.parent.setRecordValue(this.parent.taskFields.expandState, value, ganttData); this.parent.setRecordValue('expanded', value, ganttData); this.parent.treeGrid.refresh(); } else if (ganttObj.customColumns.indexOf(key) !== -1) { var column = ganttObj.columnByField[key]; /* eslint-disable-next-line */ var value = data[key]; if (isNullOrUndefined(column.edit)) { if (column.editType === 'datepickeredit' || column.editType === 'datetimepickeredit') { value = ganttObj.dataOperation.getDateFromFormat(value); } } ganttObj.setRecordValue('taskData.' + key, value, ganttData); ganttObj.setRecordValue(key, value, ganttData); } else if (tasks.manual === key) { ganttObj.setRecordValue('isAutoSchedule', !data[key], ganttData.ganttProperties, true); this.parent.setRecordValue(key, data[key], ganttData); this.updateTaskScheduleModes(ganttData); } } if (isScheduleValueUpdated) { this.validateScheduleValues(scheduleFieldNames, ganttData, data); } }; /** * To update duration, work, resource unit * * @param {IGanttData} currentData . * @param {string} column . * @returns {void} . */ Edit.prototype.updateResourceRelatedFields = function (currentData, column) { var ganttProp = currentData.ganttProperties; var previousdata = this.parent.previousRecords; var taskType = ganttProp.taskType ? ganttProp.taskType : this.parent.taskType; var isEffectDriven; var isAutoSchedule = ganttProp.isAutoSchedule; var resources = (this.parent.editModule.dialogModule && this.parent.editModule.dialogModule['currentResources']) ? this.parent.editModule.dialogModule['currentResources'] : currentData.ganttProperties.resourceInfo; if (!isNullOrUndefined(resources)) { switch (taskType) { case 'FixedUnit': if (!isNullOrUndefined(previousdata[ganttProp.uniqueID]) && !isNullOrUndefined(previousdata[ganttProp.uniqueID].ganttProperties) && (previousdata[ganttProp.uniqueID].ganttProperties.resourceNames === null || previousdata[ganttProp.uniqueID].ganttProperties.resourceNames === '')) { this.parent.dataOperation.updateWorkWithDuration(currentData); } if (resources.length === 0) { return; } else if (isAutoSchedule && resources.length) { if (column === 'resource' || column === 'work') { this.parent.dataOperation.updateDurationWithWork(currentData); } else if (column === 'duration' || column === 'endDate') { this.parent.dataOperation.updateWorkWithDuration(currentData); if (ganttProp.duration === 0) { this.parent.setRecordValue('isMilestone', true, ganttProp, true); } } } else if (!isAutoSchedule && column === 'work') { this.parent.dataOperation.updateUnitWithWork(currentData); } else { this.parent.dataOperation.updateWorkWithDuration(currentData); } break; case 'FixedWork': if (resources.length === 0) { return; } else if (isAutoSchedule) { if (column === 'duration' || column === 'endDate') { this.parent.dataOperation.updateUnitWithWork(currentData); if (ganttProp.duration === 0) { this.parent.setRecordValue('isMilestone', true, ganttProp, true); } } else { this.parent.dataOperation.updateDurationWithWork(currentData); } } else { if (column === 'work') { this.parent.dataOperation.updateUnitWithWork(currentData); } else { this.parent.dataOperation.updateWorkWithDuration(currentData); } } break; case 'FixedDuration': if (resources.length === 0) { // To validate the work column, if set duration as 0 via celledit action, where resource colection is 0 this.parent.dataOperation.updateWorkWithDuration(currentData); return; } if (resources.length && (column === 'work' || (isAutoSchedule && isEffectDriven && (column === 'resource')))) { if (column === 'work') { this.parent.dataOperation.updateUnitWithWork(currentData); } else { this.parent.dataOperation.updateWorkWithDuration(currentData); } } else { this.parent.dataOperation.updateWorkWithDuration(currentData); } break; } } // To validate the work colum if set duration as 0, while resource is null/undefined else if (isNullOrUndefined(resources) && taskType === 'FixedDuration' && ganttProp.duration === 0) { this.parent.dataOperation.updateWorkWithDuration(currentData); } }; Edit.prototype.validateScheduleValues = function (fieldNames, ganttData, data) { var ganttObj = this.parent; if (fieldNames.length > 2) { ganttObj.dataOperation.calculateScheduledValues(ganttData, data, false); } else if (fieldNames.length > 1) { this.validateScheduleByTwoValues(data, fieldNames, ganttData); } else { this.dialogModule.validateScheduleValuesByCurrentField(fieldNames[0], data[fieldNames[0]], ganttData); } }; Edit.prototype.validateScheduleByTwoValues = function (data, fieldNames, ganttData) { var ganttObj = this.parent; var startDate; var endDate; var duration; var tasks = ganttObj.taskFields; var ganttProp = ganttData.ganttProperties; var isUnscheduledTask = ganttObj.allowUnscheduledTasks; if (fieldNames.indexOf(tasks.startDate) !== -1) { startDate = data[tasks.startDate]; } if (fieldNames.indexOf(tasks.endDate) !== -1) { endDate = data[tasks.endDate]; } if (fieldNames.indexOf(tasks.duration) !== -1) { duration = data[tasks.duration]; } if (startDate && endDate || (isUnscheduledTask && (fieldNames.indexOf(tasks.startDate) !== -1) && (fieldNames.indexOf(tasks.endDate) !== -1))) { ganttObj.setRecordValue('startDate', ganttObj.dataOperation.getDateFromFormat(startDate), ganttProp, true); ganttObj.setRecordValue('endDate', ganttObj.dataOperation.getDateFromFormat(endDate), ganttProp, true); ganttObj.dataOperation.calculateDuration(ganttData); } else if (endDate && duration || (isUnscheduledTask && (fieldNames.indexOf(tasks.endDate) !== -1) && (fieldNames.indexOf(tasks.duration) !== -1))) { ganttObj.setRecordValue('endDate', ganttObj.dataOperation.getDateFromFormat(endDate), ganttProp, true); ganttObj.dataOperation.updateDurationValue(duration, ganttProp); } else if (startDate && duration || (isUnscheduledTask && (fieldNames.indexOf(tasks.startDate) !== -1) && (fieldNames.indexOf(tasks.duration) !== -1))) { ganttObj.setRecordValue('startDate', ganttObj.dataOperation.getDateFromFormat(startDate), ganttProp, true); ganttObj.dataOperation.updateDurationValue(duration, ganttProp); } }; Edit.prototype.isTaskbarMoved = function (data) { var isMoved = false; var taskData = data.ganttProperties; var prevData = this.parent.previousRecords && this.parent.previousRecords[data.uniqueID]; if (prevData && prevData.ganttProperties) { var prevStart = getValue('ganttProperties.startDate', prevData); var prevEnd = getValue('ganttProperties.endDate', prevData); var prevDuration = getValue('ganttProperties.duration', prevData); var prevDurationUnit = getValue('ganttProperties.durationUnit', prevData); var keys = Object.keys(prevData.ganttProperties); if (keys.indexOf('startDate') !== -1 || keys.indexOf('endDate') !== -1 || keys.indexOf('duration') !== -1 || keys.indexOf('durationUnit') !== -1) { if ((isNullOrUndefined(prevStart) && !isNullOrUndefined(taskData.startDate)) || (isNullOrUndefined(prevEnd) && !isNullOrUndefined(taskData.endDate)) || (isNullOrUndefined(taskData.startDate) && !isNullOrUndefined(prevStart)) || (isNullOrUndefined(taskData.endDate) && !isNullOrUndefined(prevEnd)) || (prevStart && prevStart.getTime() !== taskData.startDate.getTime()) || (prevEnd && prevEnd.getTime() !== taskData.endDate.getTime()) || (!isNullOrUndefined(prevDuration) && prevDuration !== taskData.duration) || (!isNullOrUndefined(prevDuration) && prevDuration === taskData.duration && prevDurationUnit !== taskData.durationUnit)) { isMoved = true; } } } return isMoved; }; Edit.prototype.removeImmediateParentDependency = function (predecessorArray, ganttInstance) { if (!Array.isArray(predecessorArray)) { return []; } var filtered = []; for (var i = 0; i < predecessorArray.length; i++) { var dependency = predecessorArray[i]; var fromTask = ganttInstance.getRecordByID(dependency.from); var toTask = ganttInstance.getRecordByID(dependency.to); if (!fromTask || !toTask || !fromTask.ganttProperties || !toTask.ganttProperties) { filtered.push(dependency); continue; } var fromTaskId = fromTask.ganttProperties.taskId; var toTaskId = toTask.ganttProperties.taskId; var fromParent = fromTask.parentItem; var toParent = toTask.parentItem;