@syncfusion/ej2-gantt
Version:
Essential JS 2 Gantt Component
1,049 lines • 96.8 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 { getIndex, isScheduledTask } from '../base/utils';
import { getValue, isNullOrUndefined, extend } from '@syncfusion/ej2-base';
import { ConstraintType } from '../base/enum';
var Dependency = /** @class */ (function () {
function Dependency(gantt) {
this.parentRecord = [];
this.parentIds = [];
this.parentPredecessors = [];
this.validatedParentIds = [];
this.storeId = null;
this.isChildRecordValidated = [];
this.validatedOffsetIds = [];
this.parent = gantt;
this.dateValidateModule = this.parent.dateValidationModule;
}
/**
* Method to populate predecessor collections in records
*
* @returns {void} .
* @private
*/
Dependency.prototype.ensurePredecessorCollection = function () {
var predecessorTasks = this.parent.predecessorsCollection;
var flatData = this.parent.flatData;
var flatDataMap = new Map();
if (flatData != null) {
for (var _i = 0, flatData_1 = flatData; _i < flatData_1.length; _i++) {
var record = flatData_1[_i];
flatDataMap.set(record.ganttProperties.rowUniqueID.toString(), record);
}
}
for (var _a = 0, predecessorTasks_1 = predecessorTasks; _a < predecessorTasks_1.length; _a++) {
var ganttData = predecessorTasks_1[_a];
if ((!ganttData.hasChildRecords && !this.parent.allowParentDependency) || this.parent.allowParentDependency) {
this.ensurePredecessorCollectionHelper(ganttData, ganttData.ganttProperties, flatDataMap);
}
}
};
/**
*
* @param {IGanttData} ganttData .
* @param {ITaskData} ganttProp .
* @param {Map<string, IGanttData>} flatDataMap .
* @returns {void} .
* @private
*/
Dependency.prototype.ensurePredecessorCollectionHelper = function (ganttData, ganttProp, flatDataMap) {
if (flatDataMap === void 0) { flatDataMap = null; }
var predecessorVal = ganttProp.predecessorsName;
if (predecessorVal && (typeof predecessorVal === 'string' || typeof predecessorVal === 'number')) {
this.parent.setRecordValue('predecessor', this.calculatePredecessor(predecessorVal, ganttData, flatDataMap), ganttProp, true);
}
else if (predecessorVal && typeof predecessorVal === 'object' && predecessorVal.length) {
var preValues = [];
for (var c = 0; c < predecessorVal.length; c++) {
var predecessorItem = predecessorVal[c];
var preValue = {};
preValue.from = getValue('from', predecessorItem) ? getValue('from', predecessorItem) : predecessorVal[c];
preValue.to = getValue('to', predecessorItem) ? getValue('to', predecessorItem) : ganttProp.rowUniqueID;
preValue.type = getValue('type', predecessorItem) ? getValue('type', predecessorItem) : 'FS';
var offsetUnits = getValue('offset', predecessorItem);
if (isNullOrUndefined(offsetUnits)) {
preValue.offset = 0;
if (!isNullOrUndefined(this.parent.durationUnit)) {
preValue.offsetUnit = this.parent.durationUnit.toLocaleLowerCase();
}
}
else if (typeof offsetUnits === 'string') {
var tempOffsetUnits = this.getOffsetDurationUnit(getValue('offset', predecessorItem));
preValue.offset = tempOffsetUnits.duration;
preValue.offsetUnit = tempOffsetUnits.durationUnit;
}
else {
preValue.offset = parseFloat(offsetUnits.toString());
if (!isNullOrUndefined(this.parent.durationUnit)) {
preValue.offsetUnit = this.parent.durationUnit.toLocaleLowerCase();
}
}
var isOwnParent = this.checkIsParent(preValue.from.toString());
if (!isOwnParent) {
preValues.push(preValue);
}
}
this.parent.setRecordValue('predecessor', preValues, ganttProp, true);
}
this.parent.setRecordValue('predecessorsName', this.getPredecessorStringValue(ganttData), ganttProp, true);
this.parent.setRecordValue('taskData.' + this.parent.taskFields.dependency, ganttProp.predecessorsName, ganttData);
this.parent.setRecordValue(this.parent.taskFields.dependency, ganttProp.predecessorsName, ganttData);
};
/**
* To render unscheduled empty task with 1 day duration during predecessor map
*
* @param {IGanttData} data .
* @returns {void} .
* @private
*/
Dependency.prototype.updateUnscheduledDependency = function (data) {
var task = this.parent.taskFields;
var prdList = !isNullOrUndefined(data[task.dependency]) ?
data[task.dependency].toString().split(',') : [];
for (var i = 0; i < prdList.length; i++) {
var predId = parseInt(prdList[i], 10);
if (!isNaN(predId)) {
var predData = this.parent.connectorLineModule.getRecordByID(predId.toString());
var record = !isNullOrUndefined(predData) ?
extend({}, {}, predData.taskData, true) : null;
if (!isNullOrUndefined(record) && isNullOrUndefined(record[task.startDate])
&& isNullOrUndefined(record[task.duration]) && isNullOrUndefined(record[task.endDate])) {
record[task.duration] = 1;
var startDate = void 0;
var parentItem = predData.parentItem;
if (parentItem) {
var parentTask = this.parent.getParentTask(predData.parentItem);
while (parentTask && !parentTask.ganttProperties.startDate) {
parentTask = this.parent.getParentTask(parentTask.parentItem);
}
startDate = parentTask ? parentTask.ganttProperties.startDate : this.parent.cloneProjectStartDate;
}
else {
startDate = this.parent.cloneProjectStartDate;
}
record[task.startDate] = startDate;
this.parent.updateRecordByID(record);
}
}
}
};
/**
*
* @param {string} fromId .
* @returns {boolean} .
*/
Dependency.prototype.checkIsParent = function (fromId) {
var boolValue = false;
var task = this.parent.connectorLineModule.getRecordByID(fromId);
if (task.hasChildRecords) {
boolValue = true;
}
return boolValue;
};
// Get the root parent of the record
Dependency.prototype.getRootParent = function (rec) {
var parentRec = rec;
if (rec.parentItem) {
parentRec = this.parent.flatData.filter(function (item) {
return item.uniqueID === rec.parentUniqueID;
})[0];
if (parentRec.parentItem) {
parentRec = this.getRootParent(parentRec);
}
return parentRec;
}
return parentRec;
};
// To check whether the predecessor drawn is valid for parent task
Dependency.prototype.validateParentPredecessor = function (fromRecord, toRecord) {
if (fromRecord && toRecord) {
if (toRecord.hasChildRecords && !fromRecord.hasChildRecords) {
if (fromRecord.parentUniqueID === toRecord.uniqueID) {
return false;
}
else {
do {
if (fromRecord.parentItem) {
fromRecord = this.parent.flatData[this.parent.ids.indexOf(fromRecord.parentItem.taskId)];
if (fromRecord.uniqueID === toRecord.uniqueID) {
return false;
}
}
} while (fromRecord.parentItem);
}
}
else if (!toRecord.hasChildRecords && fromRecord.hasChildRecords) {
if (toRecord.parentUniqueID === fromRecord.uniqueID) {
return false;
}
else {
do {
if (toRecord.parentItem) {
toRecord = this.parent.flatData[this.parent.ids.indexOf(toRecord.parentItem.taskId)];
if (toRecord.uniqueID === fromRecord.uniqueID) {
return false;
}
}
} while (toRecord.parentItem);
}
}
else if (toRecord.hasChildRecords && fromRecord.hasChildRecords) {
if (toRecord.parentItem && fromRecord.parentItem) {
if (fromRecord.parentUniqueID === toRecord.uniqueID || fromRecord.uniqueID === toRecord.parentUniqueID) {
return false;
}
}
else {
if (!toRecord.parentItem && fromRecord.parentItem) {
var fromRootParent = this.getRootParent(fromRecord);
if (fromRootParent.uniqueID === toRecord.uniqueID) {
return false;
}
}
else if (toRecord.parentItem && !fromRecord.parentItem) {
var toRootParent = this.getRootParent(toRecord);
if (toRootParent.uniqueID === fromRecord.uniqueID) {
return false;
}
}
}
}
}
return true;
};
/**
* Get predecessor collection object from predecessor string value
*
* @param {string | number} predecessorValue .
* @param {IGanttData} ganttRecord .
* @param {Map<string, IGanttData>} flatDataMap .
* @returns {IPredecessor[]} .
* @private
*/
Dependency.prototype.calculatePredecessor = function (predecessorValue, ganttRecord, flatDataMap) {
if (flatDataMap === void 0) { flatDataMap = null; }
var predecessor = predecessorValue.toString();
var collection = [];
var parentRecords = [];
var isResourceView = this.parent.viewType === 'ResourceView';
var isProjectView = this.parent.viewType === 'ProjectView';
var allowParentDependency = this.parent.allowParentDependency;
var ids = isResourceView ? this.parent.getTaskIds() : this.parent.ids;
var targetId = isResourceView
? ganttRecord.ganttProperties.taskId.toString()
: ganttRecord.ganttProperties.rowUniqueID.toString();
var guidRegex = /^[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 alphaRegex = /[A-Za-z]/;
var validTypes = new Set(['FS', 'FF', 'SF', 'SS']);
var predecessorParts = predecessor.replace(/\s+/g, '').split(',');
for (var _i = 0, predecessorParts_1 = predecessorParts; _i < predecessorParts_1.length; _i++) {
var el = predecessorParts_1[_i];
var result = this.processPredecessorElement(el, ids, isResourceView, guidRegex, alphaRegex, validTypes);
if (!result) {
continue;
}
var match = result.match, predecessorText = result.predecessorText, offsetValue = result.offsetValue, values = result.values;
var tempOffset = values.length > 1 ? offsetValue + values[1] : '0';
var offsetUnits = this.getOffsetDurationUnit(tempOffset);
var obj = {
from: match[0],
type: predecessorText,
isDrawn: false,
to: targetId,
offsetUnit: offsetUnits.durationUnit,
offset: offsetUnits.duration
};
if (!allowParentDependency) {
if (!this.checkIsParent(match[0])) {
collection.push(obj);
}
}
else {
this.handleParentDependency(obj, collection, parentRecords, flatDataMap, isProjectView);
}
}
this.handleUndoRedoParentRecords(parentRecords);
return this.removeDuplicatePredecessors(collection);
};
Dependency.prototype.processPredecessorElement = function (el, ids, isResourceView, guidRegex, alphaRegex, validTypes) {
var values = [];
var offsetValue = '+';
var predecessorText = 'FS';
var _a = this.processElementFormat(el, guidRegex, ids, isResourceView, validTypes), isGuid = _a.isGuid, processedValues = _a.processedValues, processedOffset = _a.processedOffset;
values = processedValues;
offsetValue = processedOffset;
var match = this.extractAndValidateMatch(values[0], ids, isResourceView);
if (!match) {
return null;
}
predecessorText = this.determinePredecessorType(el, match, alphaRegex, validTypes);
return { match: match, predecessorText: predecessorText, offsetValue: offsetValue, values: values };
};
Dependency.prototype.processElementFormat = function (el, guidRegex, ids, isResourceView, validTypes) {
var elSplit = el.split('-');
var values = [];
var offsetValue = '+';
var isGuid = false;
if (elSplit.length >= 5) {
var id = el.substring(0, 36);
if (guidRegex.test(id)) {
isGuid = true;
var lastPart = elSplit[4] + (elSplit[5] ? '-' + elSplit[5] : '');
if (lastPart.includes('+')) {
var split = lastPart.split('+');
values = [el.slice(0, -(split[1].length + 1)).trim(), split[1].trim()];
offsetValue = '+';
}
else if (lastPart.includes('-')) {
var split = lastPart.split('-');
if (split.length > 1) {
values = [el.slice(0, -(split[1].length + 1)).trim(), split[1].trim()];
offsetValue = '-';
}
else {
values = [el];
}
}
else {
values = [el];
}
return { isGuid: isGuid, processedValues: values, processedOffset: offsetValue };
}
}
var operator = el.includes('+') ? '+' : (el.includes('-') ? '-' : null);
if (operator !== null) {
var lastOperatorIndex = el.lastIndexOf(operator);
var base = el.substring(0, lastOperatorIndex);
var suffix = el.substring(lastOperatorIndex + 1);
var lastTwo = base.slice(-2).toUpperCase();
var finalBase = base;
if (!validTypes.has(lastTwo)) {
finalBase = base + 'FS';
}
var prefix = finalBase.slice(0, -2).trim();
var finalTestId = isResourceView ? 'T' + prefix : prefix;
if (ids.indexOf(finalTestId) === -1 || suffix === '') {
values = [el];
offsetValue = '+';
}
else {
values = [finalBase, suffix];
offsetValue = operator;
}
}
else {
var lastTwo = el.slice(-2).toUpperCase();
if (validTypes.has(lastTwo)) {
var prefix = el.slice(0, -2);
var finalTestId = isResourceView ? 'T' + prefix : prefix;
if (ids.indexOf(finalTestId) === -1) {
values = [el];
}
else {
values = [el];
}
}
else {
values = [el];
}
}
return { isGuid: isGuid, processedValues: values, processedOffset: offsetValue };
};
Dependency.prototype.extractAndValidateMatch = function (value, ids, isResourceView) {
var testId = isResourceView ? 'T' + value : value;
if (ids.indexOf(testId) !== -1) {
return [value];
}
if (ids.indexOf(value) !== -1) {
return [value];
}
var match = value.split(' ');
if (match.length === 1) {
if (value.indexOf(' ') !== -1) {
match = value.match(/(\d+|[A-z]+)/g) || [];
}
else if (value.length > 2) {
match = [value.slice(0, -2), value.slice(-2)];
}
}
var finalTestId = isResourceView ? 'T' + match[0] : match[0];
return ids.indexOf(finalTestId) !== -1 ? match : null;
};
Dependency.prototype.determinePredecessorType = function (el, match, alphaRegex, validTypes) {
if (match.length > 1) {
var type = match[1].toUpperCase();
if (validTypes.has(type)) {
return type;
}
else {
var error = "The provided dependency type, " + type + ", is invalid. Please ensure that the Dependency Type is FS or FF or SS or SF";
this.parent.trigger('actionFailure', { error: error });
return 'FS';
}
}
if (el.indexOf('-') !== -1 && alphaRegex.test(el)) {
var type = el.slice(-2).toUpperCase();
return validTypes.has(type) ? type : 'FS';
}
return 'FS';
};
Dependency.prototype.handleParentDependency = function (obj, collection, parentRecords, flatDataMap, isProjectView) {
var fromData = null;
var toData = null;
if (isProjectView && flatDataMap && flatDataMap.size > 0) {
fromData = flatDataMap.get(obj.from);
toData = flatDataMap.get(obj.to);
}
else {
fromData = this.parent.connectorLineModule.getRecordByID(obj.from);
toData = this.parent.connectorLineModule.getRecordByID(obj.to);
}
if (toData && fromData) {
var isValid = this.validateParentPredecessor(fromData, toData);
if (isValid) {
collection.push(obj);
if (fromData.hasChildRecords &&
parentRecords.indexOf(fromData) === -1 &&
this.parent.editModule && this.parent.editModule.cellEditModule && this.parent.editModule.cellEditModule.isCellEdit) {
parentRecords.push(extend([], [], [fromData], true)[0]);
}
}
}
else {
collection.push(obj);
}
};
Dependency.prototype.handleUndoRedoParentRecords = function (parentRecords) {
if (parentRecords.length > 0 &&
this.parent.undoRedoModule &&
this.parent.editModule && this.parent.editModule.cellEditModule &&
this.parent.editModule.cellEditModule.isCellEdit) {
var undoCollection = this.parent.undoRedoModule['getUndoCollection'];
var lastUndo = undoCollection[undoCollection.length - 1];
if (lastUndo) {
lastUndo['connectedRecords'] = parentRecords;
}
}
};
Dependency.prototype.removeDuplicatePredecessors = function (collection) {
var seen = new Map();
for (var _i = 0, collection_1 = collection; _i < collection_1.length; _i++) {
var data = collection_1[_i];
var key = data.from + "-" + data.to;
seen.set(key, data);
}
return Array.from(seen.values());
};
/**
* Get predecessor value as string with offset values
*
* @param {IGanttData} data .
* @returns {string} .
* @private
*/
Dependency.prototype.getPredecessorStringValue = function (data) {
var predecessors = data.ganttProperties.predecessor;
var resultString = '';
var temp1;
var match = [];
if (predecessors) {
var length_1 = predecessors.length;
for (var i = 0; i < length_1; i++) {
var currentValue = predecessors[i];
var temp = '';
var id = this.parent.viewType === 'ResourceView' ? data.ganttProperties.taskId
: data.ganttProperties.rowUniqueID;
if (currentValue.from !== id.toString()) {
temp = currentValue.from + currentValue.type;
if (typeof (data.ganttProperties.taskId) === 'string') {
match[0] = temp.slice(0, -2);
match[1] = temp.slice(-2);
temp1 = match[0] + ' ' + match[1];
}
else {
temp1 = temp;
}
temp = temp1;
if (currentValue.offset !== 0) {
temp += currentValue.offset > 0 ? ('+' + currentValue.offset + ' ') : (currentValue.offset + ' ');
var multiple = currentValue.offset !== 1;
if (currentValue.offsetUnit === 'day') {
temp += multiple ? this.parent.localeObj.getConstant('days') : this.parent.localeObj.getConstant('day');
}
else if (currentValue.offsetUnit === 'hour') {
temp += multiple ? this.parent.localeObj.getConstant('hours') : this.parent.localeObj.getConstant('hour');
}
else {
temp += multiple ? this.parent.localeObj.getConstant('minutes') : this.parent.localeObj.getConstant('minute');
}
}
if (resultString.length > 0) {
resultString = resultString + ',' + temp;
}
else {
resultString = temp;
}
}
}
}
return resultString;
};
/*Get duration and duration unit value from tasks*/
Dependency.prototype.getOffsetDurationUnit = function (val) {
var duration = 0;
var durationUnit;
if (!isNullOrUndefined(this.parent.durationUnit)) {
durationUnit = this.parent.durationUnit.toLocaleLowerCase();
}
var durationUnitLabels = this.parent.durationUnitEditText;
if (typeof val === 'string') {
var values = val.match(/[^0-9]+|[0-9]+/g);
for (var x = 0; x < values.length; x++) {
values[x] = (values[x]).trim();
}
if (values[0] === '-' && values[1]) {
values[1] = values[0] + values[1];
values.shift();
}
else if (values[0] === '+') {
values.shift();
}
if (values[1] === '.' && !isNaN(parseInt(values[2], 10))) {
values[0] += values[1] + values[2];
values.splice(1, 2);
}
if (values && values.length <= 2) {
duration = parseFloat(values[0]);
durationUnit = values[1] ? (values[1].toLowerCase()).trim() : '';
if (getValue('minute', durationUnitLabels).indexOf(durationUnit) !== -1) {
durationUnit = 'minute';
}
else if (getValue('hour', durationUnitLabels).indexOf(durationUnit) !== -1) {
durationUnit = 'hour';
}
else if (getValue('day', durationUnitLabels).indexOf(durationUnit) !== -1) {
durationUnit = 'day';
}
else {
if (!isNullOrUndefined(this.parent.durationUnit)) {
durationUnit = this.parent.durationUnit.toLocaleLowerCase();
}
}
}
}
else {
duration = val;
if (!isNullOrUndefined(this.parent.durationUnit)) {
durationUnit = this.parent.durationUnit.toLocaleLowerCase();
}
}
if (isNaN(duration)) {
var err = 'The provided value for the offset field is invalid.Please ensure the offset field contains only valid numeric values';
this.parent.trigger('actionFailure', { error: err });
duration = 0;
if (!isNullOrUndefined(this.parent.durationUnit)) {
durationUnit = this.parent.durationUnit.toLocaleLowerCase();
}
}
return {
duration: duration,
durationUnit: durationUnit
};
};
/**
* Update predecessor object in both from and to tasks collection
*
* @param {Map<string, IGanttData>} flatDataCollection .
* @returns {void} .
* @private
*/
Dependency.prototype.updatePredecessors = function (flatDataCollection) {
if (flatDataCollection === void 0) { flatDataCollection = null; }
var predecessorsCollection = this.parent.predecessorsCollection;
var ganttRecord;
var length = predecessorsCollection.length;
for (var count = 0; count < length; count++) {
ganttRecord = predecessorsCollection[count];
if ((!ganttRecord.hasChildRecords && !this.parent.allowParentDependency) || this.parent.allowParentDependency) {
this.updatePredecessorHelper(ganttRecord, predecessorsCollection, flatDataCollection);
if (!ganttRecord.ganttProperties.isAutoSchedule && this.parent.editSettings.allowEditing) {
this.validatedOffsetIds = [];
this.calculateOffset(ganttRecord);
}
}
}
};
/**
* To update predecessor collection to successor tasks
*
* @param {IGanttData} ganttRecord .
* @param {IGanttData[]} predecessorsCollection .
* @param {Map<string, IGanttData>} flatDataCollection .
* @returns {void} .
* @private
*/
Dependency.prototype.updatePredecessorHelper = function (ganttRecord, predecessorsCollection, flatDataCollection) {
if (flatDataCollection === void 0) { flatDataCollection = null; }
var connectorsCollection = ganttRecord.ganttProperties.predecessor;
var successorGanttRecord;
var connectorCount = connectorsCollection.length;
predecessorsCollection = isNullOrUndefined(predecessorsCollection) ? [] : predecessorsCollection;
for (var i = 0; i < connectorCount; i++) {
var connector = connectorsCollection[i];
if (this.parent.viewType === 'ProjectView' && !isNullOrUndefined(flatDataCollection)) {
successorGanttRecord = flatDataCollection.get(connector.from);
}
else {
successorGanttRecord = this.parent.connectorLineModule.getRecordByID(connector.from);
}
var id = this.parent.viewType === 'ResourceView' ? ganttRecord.ganttProperties.taskId
: ganttRecord.ganttProperties.rowUniqueID;
if (connector.from !== id.toString()) {
if (successorGanttRecord) {
var predecessorCollection = void 0;
if (successorGanttRecord.ganttProperties.predecessor) {
predecessorCollection = (extend([], successorGanttRecord.ganttProperties.predecessor, [], true));
predecessorCollection.push(connector);
this.parent.setRecordValue('predecessor', predecessorCollection, successorGanttRecord.ganttProperties, true);
// successorGanttRecord.ganttProperties.predecessor.push(connector);
}
else {
predecessorCollection = [];
predecessorCollection.push(connector);
this.parent.setRecordValue('predecessor', predecessorCollection, successorGanttRecord.ganttProperties, true);
// this.parent.setRecordValue('predecessor', [], successorGanttRecord.ganttProperties, true);
// successorGanttRecord.ganttProperties.predecessor.push(connector);
predecessorsCollection.push(successorGanttRecord);
}
}
}
}
};
Dependency.prototype.traverseParents = function (record, isParent) {
this.parent.dataOperation.updateParentItems(record, isParent);
};
/**
* Method to validate date of tasks with predecessor values for all records
*
* @param {Map<string, IGanttData>} flatDataCollection .
* @returns {void} .
* @private
*/
Dependency.prototype.updatedRecordsDateByPredecessor = function (flatDataCollection) {
var _this = this;
if (flatDataCollection === void 0) { flatDataCollection = null; }
if (!this.parent.autoCalculateDateScheduling ||
(this.parent.isLoad && this.parent.treeGrid.loadChildOnDemand && this.parent.taskFields.hasChildMapping)) {
return;
}
var flatData = this.parent.flatData;
var totLength = flatData.length;
if (totLength === 0) {
return;
}
if (isNullOrUndefined(flatDataCollection)) {
flatDataCollection = new Map();
for (var _i = 0, flatData_2 = flatData; _i < flatData_2.length; _i++) {
var record = flatData_2[_i];
flatDataCollection.set(record.ganttProperties.rowUniqueID.toString(), record);
}
}
var parentsToUpdate = new Set();
var isProjectView = this.parent.viewType === 'ProjectView';
var allowParentDependency = this.parent.allowParentDependency;
var validatedRecords = new Set();
for (var count = 0; count < totLength; count++) {
var currentTask = flatData[count];
var properties = currentTask.ganttProperties;
if (!properties.predecessorsName) {
continue;
}
var currentTaskKey = currentTask.ganttProperties.taskId.toString();
if (!validatedRecords.has(currentTaskKey)) {
this.validatePredecessorDates(currentTask, flatDataCollection);
}
if (currentTask.hasChildRecords && properties.startDate && allowParentDependency) {
this.updateChildItems(currentTask);
}
var predecessorCollection = properties.predecessor;
if (predecessorCollection && predecessorCollection.length > 1) {
var currentTaskId = currentTask.ganttProperties.taskId.toString();
for (var _a = 0, predecessorCollection_1 = predecessorCollection; _a < predecessorCollection_1.length; _a++) {
var predecessor = predecessorCollection_1[_a];
var validateRecord = isProjectView
? flatDataCollection.get(predecessor.to)
: this.parent.connectorLineModule.getRecordByID(predecessor.to);
if (validateRecord && validateRecord.ganttProperties.taskId.toString() !== currentTaskId) {
this.validatePredecessorDates(validateRecord, flatDataCollection);
validatedRecords.add(validateRecord.ganttProperties.taskId.toString());
}
}
}
if (currentTask.parentItem || currentTask.hasChildRecords) {
var parentId = currentTask.parentItem ? currentTask.parentItem.taskId : currentTask.ganttProperties.taskId;
parentsToUpdate.add(parentId);
}
}
if (!this.parent.isLoad) {
parentsToUpdate.forEach(function (parentId) {
if (!parentsToUpdate.has(parentId)) {
return;
}
var parentRecord = isProjectView
? flatDataCollection.get(parentId)
: _this.parent.getRecordByID(parentId);
if (parentRecord) {
_this.traverseParents(parentRecord, true);
}
});
}
this.parent.dataOperation['processedParentItems'].clear();
};
Dependency.prototype.updateParentPredecessor = function (flatDataCollection) {
if (flatDataCollection === void 0) { flatDataCollection = null; }
if (this.parent.enablePredecessorValidation) {
var parentPredecessorLength = this.parentPredecessors.length;
for (var i = parentPredecessorLength - 1; i >= 0; i--) {
var item = this.parentPredecessors[i];
this.validatePredecessorDates(item, flatDataCollection);
if (item.ganttProperties.startDate) {
this.updateChildItems(item);
}
}
}
};
/**
* To validate task date values with dependency
*
* @param {IGanttData} ganttRecord .
* @param {Map<string, IGanttData>} flatDataCollection .
* @returns {void} .
* @private
*/
Dependency.prototype.validatePredecessorDates = function (ganttRecord, flatDataCollection) {
if (flatDataCollection === void 0) { flatDataCollection = null; }
var predecessorsCollection = ganttRecord.ganttProperties.predecessor;
if (!predecessorsCollection || predecessorsCollection.length === 0) {
return;
}
var isResourceView = this.parent.viewType === 'ResourceView';
var isProjectView = this.parent.viewType === 'ProjectView';
var allowParentDependency = this.parent.allowParentDependency;
var allowTaskbarDragAndDrop = this.parent.allowTaskbarDragAndDrop;
var validateManualTasks = this.parent.validateManualTasksOnLinking;
var isLoad = this.parent.isLoad;
var hasValidFlatData = isProjectView && !isNullOrUndefined(flatDataCollection);
var currentTaskId = isResourceView
? ganttRecord.ganttProperties.taskId.toString()
: ganttRecord.ganttProperties.rowUniqueID.toString();
var predecessors = predecessorsCollection.filter(function (data) {
return data.to === currentTaskId;
});
if (predecessors.length === 0) {
return;
}
var predecessor = predecessors[0];
var parentGanttRecord;
var record;
if (hasValidFlatData) {
parentGanttRecord = flatDataCollection.get(predecessor.from);
record = flatDataCollection.get(predecessor.to);
}
else {
parentGanttRecord = this.parent.connectorLineModule.getRecordByID(predecessor.from);
record = this.parent.connectorLineModule.getRecordByID(predecessor.to);
}
if (allowParentDependency && parentGanttRecord && parentGanttRecord.hasChildRecords) {
this.parent.dataOperation.updateParentItems(parentGanttRecord);
}
if (isProjectView && allowTaskbarDragAndDrop) {
if (isNullOrUndefined(record)) {
var index = this.parent.editModule.taskbarEditModule.previousIds.indexOf(predecessor.to);
if (index !== -1) {
record = this.parent.editModule.taskbarEditModule.previousFlatData[index];
}
}
else if (isNullOrUndefined(parentGanttRecord)) {
var index = this.parent.editModule.taskbarEditModule.previousIds.indexOf(predecessor.from);
if (index !== -1) {
parentGanttRecord = this.parent.editModule.taskbarEditModule.previousFlatData[index];
}
}
}
if (allowParentDependency && isLoad &&
this.parentPredecessors.indexOf(ganttRecord) === -1 &&
(ganttRecord.hasChildRecords || (record && record.hasChildRecords))) {
this.parentPredecessors.push(ganttRecord);
}
if (record && (record.ganttProperties.isAutoSchedule || validateManualTasks)) {
this.validateChildGanttRecord(parentGanttRecord, record, flatDataCollection, predecessors);
}
};
Dependency.prototype.getConstraintDate = function (constraintType, startDate, endDate, constraintDate) {
var sourceDate = null;
switch (constraintType) {
case ConstraintType.AsSoonAsPossible:
case ConstraintType.AsLateAsPossible:
return null;
case ConstraintType.MustStartOn:
case ConstraintType.StartNoEarlierThan:
if (!constraintDate) {
return startDate;
}
sourceDate = startDate;
break;
case ConstraintType.MustFinishOn:
case ConstraintType.FinishNoEarlierThan:
case ConstraintType.StartNoLaterThan:
case ConstraintType.FinishNoLaterThan:
if (!constraintDate) {
return endDate;
}
sourceDate = endDate;
break;
default:
return null;
}
if (sourceDate) {
if (typeof constraintDate === 'string') {
constraintDate = new Date(constraintDate);
}
if (constraintDate instanceof Date) {
constraintDate.setHours(sourceDate.getHours(), sourceDate.getMinutes(), sourceDate.getSeconds(), sourceDate.getMilliseconds());
}
}
return constraintDate;
};
/**
* Method to validate task with predecessor
*
* @param {IGanttData} parentGanttRecord .
* @param {IGanttData} childGanttRecord .
* @param {Map<string, IGanttData>} flatDataCollection .
* @param {IPredecessor[]} childPredecessorCollection .
* @returns {void} .
*/
Dependency.prototype.validateChildGanttRecord = function (parentGanttRecord, childGanttRecord, flatDataCollection, childPredecessorCollection) {
if (flatDataCollection === void 0) { flatDataCollection = null; }
if (this.parent.editedPredecessorRecords.indexOf(childGanttRecord) !== -1) {
return;
}
if (parentGanttRecord && isNullOrUndefined(isScheduledTask(parentGanttRecord.ganttProperties))) {
return;
}
if (childGanttRecord && isNullOrUndefined(isScheduledTask(childGanttRecord.ganttProperties))) {
return;
}
var isInPredecessorValidation = this.parent.isInPredecessorValidation;
var validateManualTasks = this.parent.validateManualTasksOnLinking;
var childRecordProperty = childGanttRecord.ganttProperties;
if (!isInPredecessorValidation || !(childRecordProperty.isAutoSchedule || validateManualTasks)) {
return;
}
var isResourceView = this.parent.viewType === 'ResourceView';
var taskFields = this.parent.taskFields;
var hasConstraintFields = taskFields.constraintDate && taskFields.constraintType;
var isLoad = this.parent.isLoad;
var isFromOnPropertyChange = this.parent.isFromOnPropertyChange;
var updateOffsetOnTaskbarEdit = this.parent.updateOffsetOnTaskbarEdit;
var currentTaskId = isResourceView
? childRecordProperty.taskId.toString()
: childRecordProperty.rowUniqueID.toString();
var childPredecessor;
if (!isNullOrUndefined(childPredecessorCollection)) {
childPredecessor = childPredecessorCollection;
}
else {
var predecessorsCollection = childRecordProperty.predecessor;
childPredecessor = predecessorsCollection.filter(function (data) {
return data.to === currentTaskId;
});
}
var startDate = this.getPredecessorDate(childGanttRecord, childPredecessor, flatDataCollection);
this.parent.setRecordValue('startDate', startDate, childRecordProperty, true);
this.parent.dataOperation.updateMappingData(childGanttRecord, 'startDate');
if (hasConstraintFields && updateOffsetOnTaskbarEdit) {
this.calculateOffset(childGanttRecord);
}
var segments = childRecordProperty.segments;
if (isNullOrUndefined(segments) || segments.length === 0) {
this.dateValidateModule.calculateEndDate(childGanttRecord);
}
this.parent.dataOperation.updateWidthLeft(childGanttRecord);
if (!isLoad && !isFromOnPropertyChange && childGanttRecord.parentItem &&
isInPredecessorValidation &&
this.parent.getParentTask(childGanttRecord.parentItem).ganttProperties.isAutoSchedule) {
var parentUniqueID = childGanttRecord.parentItem.uniqueID;
if (this.parentIds.indexOf(parentUniqueID) === -1) {
this.parentIds.push(parentUniqueID);
this.parentRecord.push(childGanttRecord.parentItem);
}
}
if (hasConstraintFields) {
var constraintType = childRecordProperty.constraintType;
var startDate_1 = childRecordProperty.startDate;
var endDate = childRecordProperty.endDate;
var constraintDate = this.getConstraintDate(constraintType, startDate_1, endDate, childRecordProperty.constraintDate);
this.parent.setRecordValue('constraintDate', constraintDate, childRecordProperty, true);
this.parent.dataOperation.updateMappingData(childGanttRecord, 'constraintDate');
}
};
Dependency.prototype.filterPredecessorsByTarget = function (predecessorsCollection, ganttRecord, viewType) {
if (!predecessorsCollection ||
!Array.isArray(predecessorsCollection) ||
!ganttRecord ||
!ganttRecord.ganttProperties ||
!viewType) {
return [];
}
var targetId = viewType === 'ResourceView'
? ganttRecord.ganttProperties.taskId
: ganttRecord.ganttProperties.rowUniqueID;
return predecessorsCollection.filter(function (data) {
return data.to === targetId.toString();
});
};
/**
*
* @param {IGanttData} ganttRecord .
* @param {IPredecessor[]} predecessorsCollection .
* @param {Map<string, IGanttData>} flatDataCollection .
* @returns {Date} .
* @private
*/
Dependency.prototype.getPredecessorDate = function (ganttRecord, predecessorsCollection, flatDataCollection) {
if (flatDataCollection === void 0) { flatDataCollection = null; }
var validatedPredecessor = this.filterPredecessorsByTarget(predecessorsCollection, ganttRecord, this.parent.viewType);
if (!validatedPredecessor || validatedPredecessor.length === 0) {
return null;
}
var isProjectView = this.parent.viewType === 'ProjectView';
var hasValidFlatData = isProjectView && !isNullOrUndefined(flatDataCollection);
var allowTaskbarDragAndDrop = this.parent.allowTaskbarDragAndDrop;
var isConstraintMapped = !isNullOrUndefined(this.parent.taskFields.constraintDate) &&
!isNullOrUndefined(this.parent.taskFields.constraintType);
var editModule = this.parent.editModule;
var shouldCheckOffset = !isConstraintMapped && editModule && editModule.cellEditModule &&
!editModule.cellEditModule.isCellEdit &&
!editModule.dialogModule['isFromEditDialog'] &&
!this.parent.updateOffsetOnTaskbarEdit &&
!this.parent.isLoad;
var maxStartDate = null;
var length = validatedPredecessor.length;
for (var i = 0; i < length; i++) {
var predecessor = validatedPredecessor[i];
var parentGanttRecord = void 0;
var childGanttRecord = void 0;
if (hasValidFlatData) {
parentGanttRecord = flatDataCollection.get(predecessor.from);
childGanttRecord = flatDataCollection.get(predecessor.to);
}
else {
parentGanttRecord = this.parent.connectorLineModule.getRecordByID(predecessor.from);
childGanttRecord = this.parent.connectorLineModule.getRecordByID(predecessor.to);
}
if (isProjectView && allowTaskbarDragAndDrop &&
!(isNullOrUndefined(childGanttRecord) && isNullOrUndefined(parentGanttRecord))) {
if (isNullOrUndefined(childGanttRecord)) {
childGanttRecord = this.getRecord(parentGanttRecord, childGanttRecord, predecessor);
}
if (isNullOrUndefined(parentGanttRecord)) {
parentGanttRecord = this.getRecord(parentGanttRecord, childGanttRecord, predecessor);
}
}
if (shouldCheckOffset) {
var offset = this.getOffsetForPredecessor(predecessor, this.parent.connectorLineModule.getRecordByID(predecessor.from), childGanttRecord);
if (predecessor.offset !== offset && offset >= 0) {
return childGanttRecord.ganttProperties.startDate;
}
}
if (childGanttRecord && parentGanttRecord) {
var tempStartDate = this.getValidatedStartDate(childGanttRecord.ganttProperties, parentGanttRecord.ganttProperties, predecessor);
if (maxStartDate === null || this.dateValidateModule.compareDates(tempStartDate, maxStartDate) === 1) {
maxStartDate = tempStartDate;
}
}
}
if (isConstraintMapped) {
maxStartDate = this.dateValidateModule.getDateByConstraint(ganttRecord.ganttProperties, maxStartDate, length > 0);
}
return maxStartDate;
};
/**
* Get validated start date as per predecessor type
*
* @param {ITaskData} ganttProperty .
* @param {ITaskData} parentRecordProperty .
* @param {IPredecessor} predecessor .
* @returns {Date} .
*/
Dependency.prototype.getValidatedStartDate = function (ganttProperty, parentRecordProperty, predecessor) {
var type = predecessor.type;
var offset = predecessor.offset;
var tempDate;
var returnStartDate;
switch (type) {
case 'FS':
tempDate = this.dateValidateModule.getValidEndDate(parentRecordProperty);
if (!ganttProperty.isMilestone || offset !== 0) {
tempDate = this.dateValidateModule.checkStartDate(tempDate, ganttProperty);
}
if (offset !== 0) {
tempDate = this.updateDateByOffset(tempDate, predecessor, ganttProperty);
}
if (!ganttProperty.isMilestone) {
returnStartDate = this.dateValidateModule.checkStartDate(tempDate, ganttProperty);
}
else {
returnStartDate = tempDate;
}
break;
case 'FF':
case 'SF':
tempDate = type === 'FF' ? this.dateValidateModule.getValidEndDate(parentRecordProperty) :
this.dateValidateModule.getValidStartDate(parentRecordProperty);
if (offset !== 0) {
tempDate = this.updateDateByOffset(tempDate, predecessor, ganttProperty);
}
if (!ganttProperty.isMilestone) {
var date = new Date(tempDate);
date.setDate(date.getDate() - 1);
if (this.parent.allowUnscheduledTasks && isNullOrUndefined(ganttProperty.endDate) &&
isNullOrUndefined(ganttProperty.duration)) {
tempDate = this.dateValidateModule.checkStartDate(tempDate, ganttProperty);
}
else {
tempDate = this.dateValidateModule.checkEndDate(tempDate, ganttProperty);
}
}
if (ganttProperty.segments && ganttProperty.segments.length !== 0) {
var duration = this.dateValidateModule.getDuration(ganttProperty.startDate, ganttProperty.endDate, ganttProperty.durationUnit, ganttProperty.isAutoSchedule, ganttProperty.isMilestone);
returnStartDate = this.dateValidateModule.getStartDate(tempDate, duration, ganttProperty.durationUnit, ganttProperty);
}
else {
returnStartDate = this.dateValidateModule.getStartDate(tempDate, ganttProperty.duration, ganttProperty.durationUnit, ganttProperty);
}
break;
case 'SS':
tempDate = this.dateValidateModule.getValidStartDate(parentRecordProperty);
if (offset !== 0) {
tempDate = this.updateDateByOffset(tempDate, predecessor, ganttProperty);
}
if (!ganttProperty.isMilestone) {
returnStartDate = this.dateValidateModule.checkStartDate(tempDate, ganttProperty);
}
else {
returnStartDate = tempDate;
}
break;
}
return retu