@syncfusion/ej2-gantt
Version:
Essential JS 2 Gantt Component
1,015 lines • 73.3 kB
JavaScript
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 } from '@syncfusion/ej2-base';
import { getValue, createElement, extend } from '@syncfusion/ej2-base';
import * as cls from '../base/css-constants';
import { parentsUntil, formatString, isScheduledTask, getIndex } from '../base/utils';
import { Dialog } from '@syncfusion/ej2-popups';
import { RadioButton } from '@syncfusion/ej2-buttons';
/**
* File for handling connector line edit operation in Gantt.
*
*/
var ConnectorLineEdit = /** @class */ (function () {
function ConnectorLineEdit(ganttObj) {
/**
* @private
*/
this.validationPredecessor = null;
/** @private */
this.confirmPredecessorDialog = null;
/** @private */
this.predecessorIndex = null;
/** @private */
this.childRecord = null;
this.validatedId = [];
this.validatedOffsetIds = [];
this.isPublicDependencyDelete = false;
this.parent = ganttObj;
this.dateValidateModule = this.parent.dateValidationModule;
this.parent.on('initPredessorDialog', this.initPredecessorValidationDialog, this);
}
/**
* To update connector line edit element.
*
* @param {PointerEvent} e .
* @returns {void} .
* @private
*/
ConnectorLineEdit.prototype.updateConnectorLineEditElement = function (e) {
var element = this.getConnectorLineHoverElement(e.target);
if (!getValue('editModule.taskbarEditModule.taskBarEditAction', this.parent)) {
this.highlightConnectorLineElements(element);
}
};
/**
* To get hovered connector line element.
*
* @param {EventTarget} target .
* @returns {void} .
* @private
*/
ConnectorLineEdit.prototype.getConnectorLineHoverElement = function (target) {
var isOnLine = parentsUntil(target, cls.connectorLineSVG);
var isArrow = parentsUntil(target, cls.connectorLineArrow);
var isCriticalLine = parentsUntil(target, cls.criticalConnectorLineSVG);
var isCriticalArrow = parentsUntil(target, cls.criticalConnectorArrowSVG);
if (isOnLine || isArrow || isCriticalLine || isCriticalArrow) {
return parentsUntil(target, cls.connectorLineContainer);
}
else {
return null;
}
};
/**
* To highlight connector line while hover.
*
* @param {Element} element .
* @returns {void} .
* @private
*/
ConnectorLineEdit.prototype.highlightConnectorLineElements = function (element) {
if (element) {
if (element !== this.connectorLineElement) {
this.removeHighlight();
this.addHighlight(element);
}
}
else {
this.removeHighlight();
}
};
/**
* To add connector line highlight class.
*
* @param {Element} element .
* @returns {void} .
* @private
*/
ConnectorLineEdit.prototype.addHighlight = function (element) {
this.connectorLineElement = element;
var pathElement = element.querySelector('.' + cls.connectorLineSVG);
if (pathElement) {
pathElement.setAttribute('stroke-width', (this.parent.connectorLineModule['lineStroke'] + 1).toString());
}
};
/**
* To remove connector line highlight class.
*
* @returns {void} .
* @private
*/
ConnectorLineEdit.prototype.removeHighlight = function () {
if (this.connectorLineElement) {
var pathElement = this.connectorLineElement.querySelector('.' + cls.connectorLineSVG);
if (pathElement) {
pathElement.setAttribute('stroke-width', (this.parent.connectorLineModule['lineStroke']).toString());
}
this.connectorLineElement = null;
}
};
/**
* To remove connector line highlight class.
*
* @param {IGanttData[]} records .
* @returns {DocumentFragment} .
* @private
*/
ConnectorLineEdit.prototype.getEditedConnectorLineString = function (records) {
var ganttRecord;
var predecessorsCollection;
var parentGanttRecord;
var childGanttRecord;
var connectorObj;
var idSet = new Set();
var lineFragment = document.createDocumentFragment();
for (var count = 0; count < records.length; count++) {
ganttRecord = records[count];
predecessorsCollection = ganttRecord.ganttProperties.predecessor;
if (!predecessorsCollection) {
continue;
}
for (var predecessorCount = 0; predecessorCount < predecessorsCollection.length; predecessorCount++) {
var predecessor = predecessorsCollection[predecessorCount];
var from = 'from';
var to = 'to';
var connectorLineId = 'parent' + predecessor[from] + 'child' + predecessor[to];
this.parent.connectorLineModule.removeConnectorLineById(connectorLineId);
parentGanttRecord = this.parent.connectorLineModule.getRecordByID(predecessor[from]);
childGanttRecord = this.parent.connectorLineModule.getRecordByID(predecessor[to]);
if ((!this.parent.allowParentDependency && ((parentGanttRecord && parentGanttRecord.expanded) ||
(childGanttRecord && childGanttRecord.expanded))) ||
(this.parent.allowParentDependency && (parentGanttRecord || childGanttRecord))) {
connectorObj = this.parent.predecessorModule.updateConnectorLineObject(parentGanttRecord, childGanttRecord, predecessor);
if (!isNullOrUndefined(connectorObj) && !idSet.has(connectorObj.connectorLineId)) {
var lineElement = this.parent.connectorLineModule.getConnectorLineTemplate(connectorObj);
idSet.add(connectorObj.connectorLineId);
lineFragment.appendChild(lineElement);
}
}
}
}
return lineFragment;
};
/**
* Tp refresh connector lines of edited records
*
* @param {IGanttData[]} editedRecord .
* @returns {void} .
* @private
*/
ConnectorLineEdit.prototype.refreshEditedRecordConnectorLine = function (editedRecord) {
this.parent.connectorLineModule.removePreviousConnectorLines(this.parent.previousRecords);
this.parent.connectorLineModule.expandedRecords = this.parent.virtualScrollModule && this.parent.enableVirtualization ?
this.parent.updatedRecords : this.parent.getExpandedRecords(this.parent.updatedRecords);
var editedConnectorElement = this.getEditedConnectorLineString(editedRecord);
if (editedConnectorElement) {
this.parent.connectorLineModule.svgObject.appendChild(editedConnectorElement);
}
};
ConnectorLineEdit.prototype.idFromPredecessor = function (pre) {
var preArray = pre.split(',');
var preIdArray = [];
var values = [];
var match = [];
for (var j = 0; j < preArray.length; j++) {
var strArray = [];
var firstPart = void 0;
var isAlpha = false;
var predecessorName = void 0;
var isGUId = false;
var regex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
var elSplit = preArray[j].split('-');
var id = void 0;
if (elSplit.length === 6) {
elSplit[4] = elSplit[4] + '-' + elSplit[5];
elSplit.pop();
}
if (elSplit.length === 5 && elSplit[4].length >= 12) {
id = preArray[j].substring(0, 36);
if (regex.test(id)) {
isGUId = true;
}
}
if (preArray[j].includes('-')) {
if (preArray[j].includes('-') && (preArray[j].includes('days') || preArray[j].includes('day'))) {
var splitName = preArray[j].split(/-(?=\d)/);
if (splitName.length > 0) {
predecessorName = splitName[splitName.length - 1];
}
}
if (preArray[j].includes('-') && /[A-Za-z]/.test(predecessorName)) {
var indexFS = preArray[j].indexOf(predecessorName);
if (indexFS !== -1) {
firstPart = preArray[j].substring(0, indexFS - 1);
if (firstPart.includes('-')) {
isAlpha = true;
}
}
}
}
if (isGUId) {
var split = void 0;
split = elSplit[4].split('+');
var spliceLength = void 0;
if (split.length === 1) {
values[0] = preArray[j];
}
else {
spliceLength = split[1].length;
values[0] = preArray[j].slice(0, -(spliceLength + 1));
values[1] = split[1];
}
if (elSplit[4].indexOf('-') >= 0) {
split = elSplit[4].split('-');
if (split.length === 1) {
values[0] = preArray[j];
}
else {
spliceLength = split[1].length;
values[0] = preArray[j].slice(0, -(spliceLength + 1));
values[1] = split[1];
}
}
}
else {
if (isAlpha && firstPart.includes('-')) {
values[0] = firstPart;
}
else {
values = preArray[j].split('+');
if (preArray[j].indexOf('-') >= 0) {
values = preArray[j].split('-');
}
}
}
if (!isNullOrUndefined(values[0])) {
var ids = this.parent.viewType === 'ResourceView' ? this.parent.getTaskIds() : this.parent.ids;
if (ids.indexOf(values[0]) === -1) {
if (values[0].indexOf(' ') !== -1) {
match = values[0].split(' ');
if (match.length === 1) {
match = values[0].match(/(\d+|[A-z]+)/g);
}
strArray.push(match[0]);
}
else {
if (values[0].length === 1 || values[0].length === 2) {
strArray.push(values[0]);
}
else {
strArray.push(values[0].slice(0, -2));
}
}
}
else {
strArray.push(values[0]);
}
}
preIdArray.push((strArray.join('')));
}
return preIdArray;
};
ConnectorLineEdit.prototype.predecessorValidation = function (predecessor, record) {
var recordId = record.rowUniqueID;
var currentId;
var currentRecord;
for (var count = 0; count < predecessor.length; count++) {
currentId = predecessor[count];
var visitedIdArray = [];
var predecessorCollection = predecessor.slice(0);
predecessorCollection.splice(count, 1);
var _loop_1 = function () {
var currentIdArray = [];
if (visitedIdArray.indexOf(currentId) === -1) {
//Predecessor id not in records collection
if (isNullOrUndefined(this_1.parent.connectorLineModule.getRecordByID(currentId))) {
return { value: false };
}
currentRecord = this_1.parent.connectorLineModule.getRecordByID(currentId).ganttProperties;
if (!isNullOrUndefined(currentRecord.predecessor) && currentRecord.predecessor.length > 0) {
currentRecord.predecessor.forEach(function (value) {
if (currentRecord.rowUniqueID.toString() !== value.from) {
currentIdArray.push(value.from.toString());
}
});
}
/* eslint-disable-next-line */
if (recordId.toString() === currentRecord.rowUniqueID.toString() || currentIdArray.indexOf(recordId.toString()) !== -1) {
return { value: false };
}
visitedIdArray.push(currentId);
if (!isNullOrUndefined(currentRecord.predecessor) && currentRecord.predecessor.length > 0) {
currentId = currentRecord.predecessor[0].from;
}
else {
return "break";
}
}
else {
return "break";
}
};
var this_1 = this;
while (currentId !== null) {
var state_1 = _loop_1();
if (typeof state_1 === "object")
return state_1.value;
if (state_1 === "break")
break;
}
}
return true;
};
/**
* To validate predecessor relations
*
* @param {IGanttData} ganttRecord .
* @param {string} predecessorString .
* @returns {boolean} .
* @private
*/
ConnectorLineEdit.prototype.validatePredecessorRelation = function (ganttRecord, predecessorString) {
var flag = true;
var recordId = this.parent.viewType === 'ResourceView' ? ganttRecord.ganttProperties.taskId
: ganttRecord.ganttProperties.rowUniqueID;
var predecessorIdArray;
var currentId;
if (!isNullOrUndefined(predecessorString) && predecessorString.length > 0) {
predecessorIdArray = this.idFromPredecessor(predecessorString);
var _loop_2 = function (count) {
//Check edited item has parent item in predecessor collection
if (!this_2.parent.allowParentDependency) {
var checkParent = this_2.checkParentRelation(ganttRecord, predecessorIdArray);
if (!checkParent) {
return { value: false };
}
}
else {
if (parseInt(predecessorIdArray[predecessorIdArray.length - 1], 10) !== ganttRecord[this_2.parent.taskFields.id]) {
var num = this_2.parent.ids.indexOf(predecessorIdArray[predecessorIdArray.length - 1]);
var fromRecord = this_2.parent.currentViewData[num];
if (fromRecord && ganttRecord) {
flag = this_2.parent.predecessorModule.validateParentPredecessor(fromRecord, ganttRecord);
}
}
}
// Check if predecessor exist more then one
var tempIdArray = predecessorIdArray.slice(0);
var checkArray = [];
var countFlag = true;
tempIdArray.forEach(function (value) {
if (checkArray.indexOf(value) === -1) {
checkArray.push(value);
}
else {
countFlag = false;
}
});
if (!countFlag) {
return { value: false };
}
//Cyclick check
currentId = predecessorIdArray[count];
var visitedIdArray = [];
var predecessorCollection = predecessorIdArray.slice(0);
predecessorCollection.splice(count, 1);
var _loop_3 = function () {
var currentIdArray = [];
var currentIdIndex;
var currentRecord;
if (visitedIdArray.indexOf(currentId) === -1) {
//Predecessor id not in records collection
if (isNullOrUndefined(this_2.parent.connectorLineModule.getRecordByID(currentId.toString()))) {
return { value: false };
}
currentRecord = this_2.parent.connectorLineModule.getRecordByID(currentId.toString()).ganttProperties;
// let currentPredecessor='';
if (!isNullOrUndefined(currentRecord.predecessor) && currentRecord.predecessor.length > 0) {
currentRecord.predecessor.forEach(function (value, index) {
if (currentRecord.rowUniqueID.toString() !== value.from) {
currentIdArray.push(value.from.toString());
currentIdIndex = index;
}
});
// currentPredecessor=currentRecord.predecessor[0].from
}
if (recordId.toString() === currentRecord.rowUniqueID.toString() ||
currentIdArray.indexOf(recordId.toString()) !== -1) {
return { value: false };
}
visitedIdArray.push(currentId);
if (!isNullOrUndefined(currentRecord.predecessor) && currentRecord.predecessor.length > 0) {
var result = void 0;
if (currentIdArray.length > 1) {
result = this_2.predecessorValidation(currentIdArray, ganttRecord.ganttProperties);
}
else if (currentIdArray.length === 1) {
currentId = currentRecord.predecessor[currentIdIndex].from;
}
if (result === false) {
return { value: false };
}
}
else {
return "break";
}
}
else {
return "break";
}
};
while (currentId !== null) {
var state_3 = _loop_3();
if (typeof state_3 === "object")
return state_3;
if (state_3 === "break")
break;
}
};
var this_2 = this;
for (var count = 0; count < predecessorIdArray.length; count++) {
var state_2 = _loop_2(count);
if (typeof state_2 === "object")
return state_2.value;
}
}
return flag;
};
/**
* To add dependency for Task
*
* @param {IGanttData} ganttRecord .
* @param {string} predecessorString .
* @returns {void} .
* @private
*/
ConnectorLineEdit.prototype.addPredecessor = function (ganttRecord, predecessorString) {
var tempPredecessorString = isNullOrUndefined(ganttRecord.ganttProperties.predecessorsName) ||
ganttRecord.ganttProperties.predecessorsName === '' ?
predecessorString : (ganttRecord.ganttProperties.predecessorsName + ',' + predecessorString);
this.updatePredecessorHelper(ganttRecord, tempPredecessorString);
};
/**
* To remove dependency from task
*
* @param {IGanttData} ganttRecord .
* @returns {void} .
* @private
*/
ConnectorLineEdit.prototype.removePredecessor = function (ganttRecord) {
this.isPublicDependencyDelete = true;
this.updatePredecessorHelper(ganttRecord, null);
};
/**
* To modify current dependency values of Task
*
* @param {IGanttData} ganttRecord .
* @param {string} predecessorString .
* @param {ITaskbarEditedEventArgs} editedArgs .
* @returns {boolean} .
* @private
*/
ConnectorLineEdit.prototype.updatePredecessor = function (ganttRecord, predecessorString, editedArgs) {
return this.updatePredecessorHelper(ganttRecord, predecessorString, editedArgs);
};
ConnectorLineEdit.prototype.updatePredecessorHelper = function (ganttRecord, predecessorString, editedArgs) {
if (isUndefined(predecessorString) || this.validatePredecessorRelation(ganttRecord, predecessorString)) {
this.parent.isOnEdit = true;
var predecessorCollection = [];
if (!isNullOrUndefined(predecessorString) && predecessorString !== '') {
predecessorCollection = this.parent.predecessorModule.calculatePredecessor(predecessorString, ganttRecord);
}
this.parent.setRecordValue('predecessor', predecessorCollection, ganttRecord.ganttProperties, true);
var stringValue = this.parent.predecessorModule.getPredecessorStringValue(ganttRecord);
this.parent.setRecordValue('predecessorsName', stringValue, ganttRecord.ganttProperties, true);
this.parent.setRecordValue('taskData.' + this.parent.taskFields.dependency, stringValue, ganttRecord);
this.parent.setRecordValue(this.parent.taskFields.dependency, stringValue, ganttRecord);
var args = {};
args.action = editedArgs && editedArgs.action && editedArgs.action === 'CellEditing' ? editedArgs.action : ((this.parent.contextMenuModule && this.parent.contextMenuModule['isCntxtMenuDependencyDelete']) ||
this.isPublicDependencyDelete) ? 'DeleteConnectorLine' : 'DrawConnectorLine';
args.data = ganttRecord;
this.parent.editModule.initiateUpdateAction(args);
return true;
}
else {
if (ganttRecord.taskData[this.parent.taskFields.dependency]) {
ganttRecord.taskData[this.parent.taskFields.dependency] = null;
}
var err = predecessorString + " is an invalid relation for task " + this.parent.taskFields.id + ". Kindly ensure the " + this.parent.taskFields.dependency + " field contains only valid predecessor relations.";
this.parent.trigger('actionFailure', { error: err });
return false;
}
};
ConnectorLineEdit.prototype.checkParentRelation = function (ganttRecord, predecessorIdArray) {
var editingData = ganttRecord;
var checkParent = true;
if (editingData && editingData.parentItem) {
if (predecessorIdArray.indexOf(editingData.parentItem.taskId.toString()) !== -1) {
return false;
}
}
var _loop_4 = function (p) {
var record = this_3.parent.currentViewData.filter(function (item) {
return item && item.ganttProperties.rowUniqueID.toString() === predecessorIdArray[p].toString();
});
if (record[0] && record[0].hasChildRecords) {
return { value: false };
}
};
var this_3 = this;
for (var p = 0; p < predecessorIdArray.length; p++) {
var state_4 = _loop_4(p);
if (typeof state_4 === "object")
return state_4.value;
}
return checkParent;
};
ConnectorLineEdit.prototype.initPredecessorValidationDialog = function () {
if (this.parent.taskFields.dependency && this.parent.isInPredecessorValidation) {
var dialogElement = createElement('div', {
id: this.parent.element.id + '_dialogValidationRule'
});
this.parent.element.appendChild(dialogElement);
this.renderValidationDialog();
}
};
/**
* To render validation dialog
*
* @returns {void} .
* @private
*/
ConnectorLineEdit.prototype.renderValidationDialog = function () {
var taskFields = this.parent.taskFields;
var validationHeader = (taskFields.constraintType && taskFields.constraintDate)
? this.parent.localeObj.getConstant('schedulingConflicts')
: this.parent.localeObj.getConstant('validateEditing');
var containerId = this.parent.element.id + '_dialogValidationRule';
var container = document.getElementById(containerId);
if (container) {
container.innerHTML = '';
container.style.zIndex = '2000';
}
else {
container = document.createElement('div');
container.id = containerId;
container.style.zIndex = '2000'; // Set z-index here
document.body.appendChild(container);
}
var validationDialog = new Dialog({
header: validationHeader,
isModal: true,
enableRtl: this.parent.enableRtl,
visible: false,
width: '50%',
showCloseIcon: true,
zIndex: 2000,
close: this.validationDialogClose.bind(this),
content: '',
buttons: [
{
click: this.validationDialogOkButton.bind(this),
buttonModel: {
content: this.parent.localeObj.getConstant('okText'),
isPrimary: true
}
},
{
click: this.validationDialogCancelButton.bind(this),
buttonModel: {
content: this.parent.localeObj.getConstant('cancel')
}
}
],
target: document.body,
animationSettings: { effect: 'None' }
});
validationDialog.isStringTemplate = true;
validationDialog.appendTo('#' + containerId);
this.parent.validationDialogElement = validationDialog;
};
ConnectorLineEdit.prototype.validationDialogOkButton = function () {
var currentArgs = this.parent.currentEditedArgs;
var addOffsetCheckbox = document.getElementById(this.parent.element.id + '_ValidationAddlineOffset');
var removeLineCheckbox = document.getElementById(this.parent.element.id + '_ValidationRemoveline');
var cancelCheckbox = document.getElementById(this.parent.element.id + '_ValidationCancel');
var removeConstraintCheckbox = document.getElementById(this.parent.element.id + '_RemoveConstraint');
var removeDependencyCheckbox = document.getElementById(this.parent.element.id + '_RemoveDependency');
var cancelChangeCheckbox = document.getElementById(this.parent.element.id + '_CancelChange');
var violationArgs = this.parent.editModule['violationArgs'];
var modifiedTask = violationArgs['matchedModifiedTask'];
var validationArgs = violationArgs['args'];
var pairedTask = violationArgs['matchedParedRecord'] || null;
if (removeConstraintCheckbox !== null && removeConstraintCheckbox.checked) {
modifiedTask.ganttProperties.constraintType = 4;
this.parent.constraintViolationType = '';
this.parent.editModule.initiateSaveAction(validationArgs);
}
else if (removeDependencyCheckbox !== null && removeDependencyCheckbox.checked) {
var matchedPredecessors = [];
var currentTaskId = pairedTask
? pairedTask.ganttProperties.taskId
: validationArgs.data.ganttProperties.taskId;
if (modifiedTask && Array.isArray(modifiedTask.ganttProperties.predecessor)) {
for (var _i = 0, _a = modifiedTask.ganttProperties.predecessor; _i < _a.length; _i++) {
var predecessor = _a[_i];
if (predecessor.from.toString() === currentTaskId.toString()) {
matchedPredecessors = [predecessor];
break;
}
}
}
this.parent.editModule.reUpdatePreviousRecords(undefined, undefined, modifiedTask.uniqueID);
if (modifiedTask.parentItem && modifiedTask.parentItem.taskId) {
var parentItem = this.parent.getRecordByID(modifiedTask.parentItem.taskId);
this.parent.dataOperation.updateParentItems(parentItem, true);
}
this.removePredecessors(modifiedTask, matchedPredecessors);
this.parent.editModule.initiateSaveAction(validationArgs);
}
else if (cancelChangeCheckbox !== null && cancelChangeCheckbox.checked) {
currentArgs.validateMode.respectLink = true;
this.applyPredecessorOption();
}
var noPrimaryActionTaken = !(removeConstraintCheckbox !== null && removeConstraintCheckbox.checked) &&
!(removeDependencyCheckbox !== null && removeDependencyCheckbox.checked) &&
!(cancelChangeCheckbox !== null && cancelChangeCheckbox.checked);
if (noPrimaryActionTaken) {
currentArgs.validateMode.preserveLinkWithEditing =
addOffsetCheckbox !== null && addOffsetCheckbox.checked;
currentArgs.validateMode.removeLink =
removeLineCheckbox !== null && removeLineCheckbox.checked;
currentArgs.validateMode.respectLink =
cancelCheckbox !== null && cancelCheckbox.checked;
this.applyPredecessorOption();
}
this.parent.validationDialogElement.hide();
};
ConnectorLineEdit.prototype.validationDialogCancelButton = function () {
this.parent.constraintViolationType = '';
this.parent.currentEditedArgs.validateMode.respectLink = true;
this.applyPredecessorOption();
this.parent.validationDialogElement.hide();
};
ConnectorLineEdit.prototype.validationDialogClose = function (e) {
this.parent.constraintViolationType = '';
if (getValue('isInteracted', e)) {
this.parent.currentEditedArgs.validateMode.respectLink = true;
this.applyPredecessorOption();
}
};
/**
* Validate and apply the predecessor option from validation dialog
*
* @returns {void} .
* @private
*/
ConnectorLineEdit.prototype.applyPredecessorOption = function () {
var args = this.parent.currentEditedArgs;
var ganttRecord = args.data;
if (args.validateMode.respectLink) {
this.parent.editModule.reUpdatePreviousRecords();
this.parent.chartRowsModule.refreshRecords([args.data]);
}
else if (args.validateMode.removeLink) {
this.checkChildRecords(ganttRecord);
this.parent.editModule.updateEditedTask(args.editEventArgs);
}
else if (args.validateMode.preserveLinkWithEditing) {
var connectedTaskId_1;
if (this.parent.updateOffsetOnTaskbarEdit) {
var taskId_1 = ganttRecord.ganttProperties.taskId.toString();
if (ganttRecord.ganttProperties.predecessor) {
ganttRecord.ganttProperties.predecessor.forEach(function (predecessor) {
if (taskId_1 === predecessor.from) {
connectedTaskId_1 = predecessor.to;
return;
}
});
}
}
this.parent.editModule.updateEditedTask(args.editEventArgs);
var processedPredecessor = [];
this.processPredecessor(connectedTaskId_1, processedPredecessor);
processedPredecessor = [];
}
};
ConnectorLineEdit.prototype.compareArrays = function (arr1, arr2) {
if (arr1.length !== arr2.length) {
return false;
}
var str1 = JSON.stringify(arr1);
var str2 = JSON.stringify(arr2);
return str1 === str2;
};
ConnectorLineEdit.prototype.processPredecessor = function (parentId, processedPredecessor) {
var _this = this;
if (parentId) {
var record_1 = this.parent.getRecordByID(parentId);
if (record_1 && record_1.ganttProperties && record_1.ganttProperties.predecessor) {
this.parent.connectorLineEditModule['validatedOffsetIds'] = [];
this.calculateOffset(record_1);
var isIdInclude_1 = true;
/* eslint-disable-next-line */
var matchedObject = this.validatedId.find(function (item) {
return item.id === record_1.ganttProperties.taskId;
});
if (matchedObject) {
var predecessorArray = matchedObject.value;
var areArraysEqual = this.compareArrays(predecessorArray, record_1.ganttProperties.predecessor);
if (areArraysEqual) {
isIdInclude_1 = false;
}
}
var predecessors = record_1.ganttProperties.predecessor;
predecessors.forEach(function (predecessor) {
if (record_1.ganttProperties.taskId === predecessor.from && isIdInclude_1) {
if (processedPredecessor && processedPredecessor.indexOf(predecessor.to) === -1) {
_this.processPredecessor(predecessor.to, processedPredecessor);
processedPredecessor.push(predecessor.to);
}
}
});
}
}
};
ConnectorLineEdit.prototype.checkChildRecords = function (ganttRecord) {
var matchingPredecessors = [];
var currentTaskId = ganttRecord.ganttProperties.taskId;
var allPredecessors = ganttRecord.ganttProperties.predecessor;
if (isNullOrUndefined(allPredecessors)) {
this.validationPredecessor = allPredecessors;
}
else {
for (var i = 0; i < allPredecessors.length; i++) {
var predecessorLink = allPredecessors[i];
if (predecessorLink.to.toString() === currentTaskId.toString()) {
matchingPredecessors.push(predecessorLink);
}
}
this.validationPredecessor = matchingPredecessors;
}
if (!isNullOrUndefined(this.validationPredecessor)) {
this.removePredecessors(ganttRecord, this.validationPredecessor);
}
if (ganttRecord.childRecords.length > 0) {
for (var i = 0; i < ganttRecord.childRecords.length; i++) {
var childRecord = ganttRecord.childRecords[i];
this.validationPredecessor = childRecord.ganttProperties.predecessor;
if (!isNullOrUndefined(this.validationPredecessor)) {
this.removePredecessors(childRecord, this.validationPredecessor);
}
if (childRecord.childRecords.length > 0) {
this.checkChildRecords(childRecord);
}
}
}
else if (!isNullOrUndefined(ganttRecord.parentItem)) {
var parentRecord = this.parent.getRecordByID(ganttRecord.parentItem.taskId);
this.validationPredecessor = parentRecord.ganttProperties.predecessor;
this.removePredecessors(parentRecord, this.validationPredecessor);
}
};
ConnectorLineEdit.prototype.compareObjects = function (obj1, obj2) {
var keys1 = Object.keys(obj1).filter(function (key) { return key !== 'offset'; });
var keys2 = Object.keys(obj2).filter(function (key) { return key !== 'offset'; });
if (keys1.length !== keys2.length) {
return false;
}
return keys1.every(function (key) { return obj1[key] === obj2[key]; });
};
ConnectorLineEdit.prototype.getOffsetForPredecessor = function (predecessor, parentTask, record) {
var offset = 0;
if ((parentTask.ganttProperties.startDate || parentTask.ganttProperties.endDate) &&
(record.ganttProperties.startDate || record.ganttProperties.endDate)) {
var tempStartDate = void 0;
var tempEndDate = void 0;
var tempDuration = void 0;
var isNegativeOffset = void 0;
switch (predecessor.type) {
case 'FS':
tempStartDate = new Date((parentTask.ganttProperties.endDate || parentTask.ganttProperties.startDate).getTime());
tempEndDate = new Date((record.ganttProperties.startDate || record.ganttProperties.endDate).getTime());
break;
case 'SS':
tempStartDate = new Date((parentTask.ganttProperties.startDate || parentTask.ganttProperties.endDate).getTime());
tempEndDate = new Date((record.ganttProperties.startDate || record.ganttProperties.endDate).getTime());
break;
case 'SF':
tempStartDate = new Date((parentTask.ganttProperties.startDate || parentTask.ganttProperties.endDate).getTime());
tempEndDate = new Date((record.ganttProperties.endDate || record.ganttProperties.startDate).getTime());
break;
case 'FF':
tempStartDate = new Date((parentTask.ganttProperties.endDate || parentTask.ganttProperties.startDate).getTime());
tempEndDate = new Date((record.ganttProperties.endDate || record.ganttProperties.startDate).getTime());
break;
}
if (tempStartDate.getTime() < tempEndDate.getTime()) {
tempStartDate = this.dateValidateModule.checkStartDate(tempStartDate);
tempEndDate = this.dateValidateModule.checkEndDate(tempEndDate, null);
isNegativeOffset = false;
}
else {
var tempDate = new Date(tempStartDate.getTime());
tempStartDate = this.dateValidateModule.checkStartDate(tempEndDate);
tempEndDate = this.dateValidateModule.checkEndDate(tempDate, null);
isNegativeOffset = true;
}
if (tempStartDate.getTime() < tempEndDate.getTime()) {
tempDuration = this.dateValidateModule.getDuration(tempStartDate, tempEndDate, predecessor.offsetUnit, true, false);
if (this.parent.durationUnit === predecessor.offsetUnit &&
((parentTask.ganttProperties.startDate && isNullOrUndefined(parentTask.ganttProperties.endDate)) ||
(isNullOrUndefined(parentTask.ganttProperties.startDate) && parentTask.ganttProperties.endDate))) {
tempDuration -= 1;
}
offset = isNegativeOffset ? -tempDuration : tempDuration;
}
}
return offset;
};
ConnectorLineEdit.prototype.calculateOffset = function (record, isRecursive) {
var _this = this;
if (!this.parent.autoCalculateDateScheduling || (this.parent.isLoad && this.parent.treeGrid.loadChildOnDemand
&& this.parent.taskFields.hasChildMapping)) {
return;
}
if (record && isScheduledTask(record.ganttProperties) !== null) {
var prevPredecessor = extend([], record.ganttProperties.predecessor, [], true);
var validPredecessor_1 = this.parent.predecessorModule.getValidPredecessor(record);
if (validPredecessor_1.length > 0) {
this.cumulativePredecessorChanges = prevPredecessor;
var _loop_5 = function (i) {
var predecessor = validPredecessor_1[parseInt(i.toString(), 10)];
var parentTask = this_4.parent.connectorLineModule.getRecordByID(predecessor.from);
if (this_4.parent.undoRedoModule && this_4.parent.undoRedoModule['isUndoRedoPerformed'] && this_4.parent.viewType === 'ProjectView') {
var isPresent = parentTask.ganttProperties.predecessor.filter(function (pred) {
return pred.from === validPredecessor_1[i].from && pred.to === validPredecessor_1[i].to;
});
if (isPresent.length === 0) {
parentTask.ganttProperties.predecessor.push(validPredecessor_1[i]);
}
}
var offset = this_4.getOffsetForPredecessor(predecessor, parentTask, record);
var preIndex = getIndex(predecessor, 'from', prevPredecessor, 'to');
if (preIndex !== -1) {
prevPredecessor[preIndex].offset = offset;
}
// Update predecessor in predecessor task
var parentPredecessors = extend([], parentTask.ganttProperties.predecessor, [], true);
var parentPreIndex = getIndex(predecessor, 'from', parentPredecessors, 'to');
if (parentPreIndex !== -1) {
parentPredecessors[parentPreIndex].offset = offset;
}
this_4.parent.setRecordValue('predecessor', parentPredecessors, parentTask.ganttProperties, true);
};
var this_4 = this;
for (var i = 0; i < validPredecessor_1.length; i++) {
_loop_5(i);
}
}
else {
var validPredecessor_2 = record.ganttProperties.predecessor;
if (validPredecessor_2) {
if (validPredecessor_2.length > 0) {
validPredecessor_2.forEach(function (element) {
if (_this.validatedOffsetIds.indexOf(element.to) === -1) {
if (_this.parent.viewType === 'ResourceView') {
_this.validatedOffsetIds.push(element.to);
_this.calculateOffset(_this.parent.getRecordByID((_this.parent.taskIds.indexOf('T' + element.to)).toString()), true);
}
else {
_this.calculateOffset(_this.parent.getRecordByID(element.to), true);
}
}
});
}
}
}
if (!isRecursive) {
if (validPredecessor_1.length === 0) {
this.cumulativePredecessorChanges = [];
}
if (prevPredecessor && prevPredecessor.length > 0 && this.cumulativePredecessorChanges &&
this.cumulativePredecessorChanges.length > 0) {
var matchingObjects = prevPredecessor.map(function (objectToCompare) {
var matchedObject = _this.cumulativePredecessorChanges.find(function (obj) { return _this.compareObjects(obj, objectToCompare); });
return matchedObject ? __assign({}, matchedObject) : null;
}).filter(function (matchedObject) { return matchedObject !== null; });
this.parent.setRecordValue('predecessor', matchingObjects, record.ganttProperties, true);
}
}
else {
this.parent.setRecordValue('predecessor', prevPredecessor, record.ganttProperties, true);
}
var predecessorString = this.parent.predecessorModule.getPredecessorStringValue(record);
this.parent.setRecordValue('taskData.' + this.parent.taskFields.dependency, predecessorString, record);
this.parent.setRecordValue(this.parent.taskFields.dependency, predecessorString, record);
this.parent.setRecordValue('predecessorsName', predecessorString, record.ganttProperties, true);
if (this.validatedOffsetIds.indexOf(record.ganttProperties.taskId.toString()) === -1) {
this.validatedOffsetIds.push(record.ganttProperties.taskId.toString());
}
if (record.hasChildRecords) {
for (var i = 0; i < record.childRecords.length; i++) {
if (this.validatedOffsetIds.indexOf(record.childRecords[i].ganttProperties.taskId.toString()) === -1 &&
record.childRecords[i].ganttProperties.predecessor &&
record.childRecords[i].ganttProperties.predecessor.length > 0) {
this.calculateOffset(record.childRecords[i]);
}
}
}
else if (record.parentItem) {
var currentParent = record.parentItem;
while (currentParent) {
var parentItem = this.parent.getRecordByID(currentParent.taskId);
var parentIdStr = parentItem.ganttProperties.taskId.toString();
if (this.validatedOffsetIds.indexOf(parentIdStr) === -1 &&
parentItem.ganttProperties.predecessor &&
parentItem.ganttProperties.predecessor.length > 0) {
this.calculateOffset(parentItem);
break;
}
currentParent = parentItem.parentItem;
}
}
}
};
/**
* Update predecessor value with user selection option in predecessor validation dialog
*
* @param {IGanttData} ganttRecord .
* @param {IPredecessor[]} predecessor .
* @returns {void} .
*/
ConnectorLineEdit.prototype.removePredecessors = function (ganttRecord, predecessor) {
var prevPredecessor = extend([], [], ganttRecord.ganttProperties.predecessor, true);
if (isNullOrUndefined(predecessor)) {
return;
}
var preLength = predecessor.length;
for (var i = 0; i < preLength; i++) {
var parentGanttRecord = this.parent.connectorLineModule.getRecordByID(predecessor[i].from);
var parentPredecessor = extend([], [], parentGanttRecord.ganttProperties.predecessor, true);
var index = getIndex(predecessor[i], 'from', prevPredecessor, 'to');
prevPredecessor.splice(index, 1);
var parentIndex = getIndex(predecessor[parseInt(i.toString(), 10)], 'from', parentPredecessor, 'to');
parentPredecessor.splice(parentIndex, 1);
this.parent.setRecordValue('predecessor', parentPredecessor, parentGanttRecord.ganttProperties, true);
}
if (prevPredecessor.length !== ganttRecord.ganttProperties.predecessor.length) {
this.parent.setRecordValue('predecessor', prevPredecessor, ganttRecord.ganttProperties, true);
var predecessorString = this.parent.predecessorModule.getPredecessorStringValue(ganttRecord);
this.parent.setRecordValue('predecessorsName', predecessorString, ganttRecord.ganttProperties, true);
this.parent.setRecordValue('taskData.' + this.parent.taskFields.dependency, predecessorString, ganttRecord);
this.parent.setRecordValue(this.parent.taskFields.dependency, predecessorString, ganttRecord);
}
};
ConnectorLineEdit.prototype.formatViolationType = function (violationType) {
return violationType.replace(/([a-z])([A-Z])/g, '$1 $2');
};
/**
* To open predecessor validation dialog
*
* @param {object} args .
* @returns {void} .
* @private
*/
ConnectorLineEdit.prototype.openValidationDialog = function (args) {
var contentTemplate = this.validationDialogTemplate(args);
this.parent.validationDialogElement.setProperties({ content: contentTemplate });
var contentId = this.parent.element.id + '_dialogValidationRule_dialog-content';
var contentElement = this.parent.validationDialogElement.element.querySelector('#' + contentId);
contentElement.style.paddingTop = '10px';
var headerId = this.parent.element.id + '_dialogValidationRule_dialog-header';
var headerElement = this.parent.validationDialogElement.element.querySelector('#' + headerId);
headerElement.style.padding = '8px 16px';
this.parent.validationDialogElement.show();
};
/**
* Predecessor link validation dialog template
*
* @param {object} args .
* @returns {HTMLElement} .
* @private
*/
ConnectorLineEdit.prototype.validationDialogTemplate = function (args) {
var ganttId = this.parent.element.id;
var contentdiv = createElement('div', {
className: 'e-ValidationContent'
});
var taskData = getValue('task', args);
var parenttaskData = getValue('parentTask', args);
var violationType = getValue('violationType', args);
var recordName = taskData.ganttProperties.taskName;
var dateFormat = !isNullOrUndefined(this.parent.dateFormat) ? this.parent.dateFormat : 'M/d/yyyy h:mm a';
var recordNewStartDate = this.parent.getFormatedDate(taskData.ganttProperties.startDate, dateFormat);
var parentName = parenttaskData.ganttProperties.ta