dhtmlxgantt_auto_scheduling.js 18 KB

12345678910
  1. /*
  2. @license
  3. dhtmlxGantt v.6.0.2 Professional
  4. This software is covered by DHTMLX Commercial License. Usage without proper license is prohibited.
  5. (c) Dinamenta, UAB.
  6. */!function(t){var e={};function n(a){if(e[a])return e[a].exports;var r=e[a]={i:a,l:!1,exports:{}};return t[a].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=t,n.c=e,n.d=function(t,e,a){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:a})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(a,r,function(e){return t[e]}.bind(null,r));return a},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="/codebase/",n(n.s=220)}({18:function(t,e,n){var a=n(3);t.exports=function(){return{getVertices:function(t){for(var e,n={},a=0,r=t.length;a<r;a++)n[(e=t[a]).target]=e.target,n[e.source]=e.source;var i,o=[];for(var a in n)i=n[a],o.push(i);return o},topologicalSort:function(t){for(var e=this.getVertices(t),n={},a=0,r=e.length;a<r;a++)n[e[a]]={id:e[a],$source:[],$target:[],$incoming:0};for(a=0,r=t.length;a<r;a++){var i=n[t[a].target];i.$target.push(a),i.$incoming=i.$target.length,n[t[a].source].$source.push(a)}for(var o=e.filter(function(t){return!n[t].$incoming}),s=[];o.length;){var u=o.pop();s.push(u);var g=n[u];for(a=0;a<g.$source.length;a++){var c=n[t[g.$source[a]].target];c.$incoming--,c.$incoming||o.push(c.id)}}return s},groupAdjacentEdges:function(t){for(var e,n={},a=0,r=t.length;a<r;a++)n[(e=t[a]).source]||(n[e.source]=[]),n[e.source].push(e);return n},tarjanStronglyConnectedComponents:function(t,e){for(var n={},a=[],r=this.groupAdjacentEdges(e),i=!1,o=[],s=0;s<t.length;s++){var u=_(t[s]);if(!u.visited)for(var g=[u],c=0;g.length;){var l=g.pop();l.visited||(l.index=c,l.lowLink=c,c++,a.push(l),l.onStack=!0,l.visited=!0),i=!1;e=r[l.id]||[];for(var d=0;d<e.length;d++){var f=_(e[d].target);if(f.edge=e[d],void 0===f.index){g.push(l),g.push(f),i=!0;break}f.onStack&&(l.lowLink=Math.min(l.lowLink,f.index))}if(!i){if(l.index==l.lowLink){for(var h={tasks:[],links:[]};(f=a.pop()).onStack=!1,h.tasks.push(f.id),f.edge&&h.links.push(f.edge.id),f!=l;);o.push(h)}g.length&&(f=l,(l=g[g.length-1]).lowLink=Math.min(l.lowLink,f.lowLink))}}}return o;function _(t){return n[t]||(n[t]={id:t,onStack:!1,index:void 0,lowLink:void 0,edge:void 0}),n[t]}},findLoops:function(t){var e=[];a.forEach(t,function(t){t.target==t.source&&e.push([t.target,t.source])});var n=this.getVertices(t),r=this.tarjanStronglyConnectedComponents(n,t);return a.forEach(r,function(t){t.tasks.length>1&&e.push(t)}),e}}}},19:function(t,e){t.exports=function(t){t._get_linked_task=function(e,n){var a=null,r=n?e.target:e.source;return t.isTaskExists(r)&&(a=t.getTask(r)),a},t._get_link_target=function(e){return t._get_linked_task(e,!0)},t._get_link_source=function(e){return t._get_linked_task(e,!1)};var e=!1,n={},a={},r={},i={};t._isLinksCacheEnabled=function(){return e},t._startLinksCache=function(){n={},a={},r={},i={},e=!0},t._endLinksCache=function(){n={},a={},r={},i={},e=!1},t._formatLink=function(a){if(e&&n[a.id])return n[a.id];var r=[],i=this._get_link_target(a),o=this._get_link_source(a);if(!o||!i)return r;if(t.isSummaryTask(i)&&t.isChildOf(o.id,i.id)||t.isSummaryTask(o)&&t.isChildOf(i.id,o.id))return r;for(var s=this._getImplicitLinks(a,o,function(t){return 0},!0),u=t.config.auto_scheduling_move_projects,g=this.isSummaryTask(i)?this.getSubtaskDates(i.id):{start_date:i.start_date,end_date:i.end_date},c=this._getImplicitLinks(a,i,function(e){return u?e.$target.length||t.getState().drag_id==e.id?0:t.calculateDuration({start_date:g.start_date,end_date:e.start_date,task:o}):0}),l=0,d=s.length;l<d;l++)for(var f=s[l],h=0,_=c.length;h<_;h++){var v=c[h],k=1*f.lag+1*v.lag,p={id:a.id,type:a.type,source:f.task,target:v.task,lag:(1*a.lag||0)+k};r.push(t._convertToFinishToStartLink(v.task,p,o,i,f.taskParent,v.taskParent))}return e&&(n[a.id]=r),r},t._isAutoSchedulable=function(t){return!1!==t.auto_scheduling},t._getImplicitLinks=function(e,n,a,r){var i=[];if(this.isSummaryTask(n)){var o,s={};for(var u in this.eachTask(function(t){this.isSummaryTask(t)||(s[t.id]=t)},n.id),s){var g=s[u],c=r?g.$source:g.$target;o=!1;for(var l=0;l<c.length;l++){var d=t.getLink(c[l]),f=r?d.target:d.source,h=s[f];if(h&&!1!==g.auto_scheduling&&!1!==h.auto_scheduling&&(d.target==h.id&&Math.abs(d.lag)<=h.duration||d.target==g.id&&Math.abs(d.lag)<=g.duration)){o=!0;break}}o||i.push({task:g.id,taskParent:g.parent,lag:a(g)})}}else i.push({task:n.id,taskParent:n.parent,lag:0});return i},t._getDirectDependencies=function(t,e){for(var n=[],a=[],r=e?t.$source:t.$target,i=0;i<r.length;i++){var o=this.getLink(r[i]);if(this.isTaskExists(o.source)&&this.isTaskExists(o.target)){var s=this.getTask(o.target);this._isAutoSchedulable(s)&&n.push(this.getLink(r[i]))}}for(i=0;i<n.length;i++)a=a.concat(this._formatLink(n[i]));return a},t._getInheritedDependencies=function(t,n){var i,o=!1,s=[];return this.isTaskExists(t.id)&&this.eachParent(function(t){var u;o||(e&&(i=n?a:r)[t.id]?s=s.concat(i[t.id]):this.isSummaryTask(t)&&(this._isAutoSchedulable(t)?(u=this._getDirectDependencies(t,n),e&&(i[t.id]=u),s=s.concat(u)):o=!0))},t.id,this),s},t._getDirectSuccessors=function(t){return this._getDirectDependencies(t,!0)},t._getInheritedSuccessors=function(t){return this._getInheritedDependencies(t,!0)},t._getDirectPredecessors=function(t){return this._getDirectDependencies(t,!1)},t._getInheritedPredecessors=function(t){return this._getInheritedDependencies(t,!1)},t._getSuccessors=function(t,e){var n=this._getDirectSuccessors(t);return e?n:n.concat(this._getInheritedSuccessors(t))},t._getPredecessors=function(t,n){var a,r=t.id+n;if(e&&i[r])return i[r];var o=this._getDirectPredecessors(t);return a=n?o:o.concat(this._getInheritedPredecessors(t)),e&&(i[r]=a),a},t._convertToFinishToStartLink=function(e,n,a,r,i,o){var s={target:e,link:t.config.links.finish_to_start,id:n.id,lag:n.lag||0,source:n.source,preferredStart:null,sourceParent:i,targetParent:o,hashSum:null},u=0;switch(n.type){case t.config.links.start_to_start:u=-a.duration;break;case t.config.links.finish_to_finish:u=-r.duration;break;case t.config.links.start_to_finish:u=-a.duration-r.duration;break;default:u=0}return s.lag+=u,s.hashSum=s.lag+"_"+s.link+"_"+s.source+"_"+s.target,s}}},220:function(t,e,n){n(19)(gantt);var a=n(9)(gantt),r=n(18)(gantt);gantt.config.auto_scheduling=!1,gantt.config.auto_scheduling_descendant_links=!1,gantt.config.auto_scheduling_initial=!0,gantt.config.auto_scheduling_strict=!1,gantt.config.auto_scheduling_move_projects=!0,function(){function t(t,e,n){for(var a,r=[t],i=[],o={};r.length>0;)if(!n[a=r.shift()]){n[a]=!0,i.push(a);for(var s=0;s<e.length;s++){var u=e[s];u.source!=a||n[u.target]?u.target!=a||n[u.source]||(r.push(u.source),o[u.id]=!0,e.splice(s,1),s--):(r.push(u.target),o[u.id]=!0,e.splice(s,1),s--)}}var g=[];for(var s in o)g.push(s);return{tasks:i,links:g}}gantt._autoSchedulingDateResolver={isFirstSmaller:function(t,e,n){return!!(t.valueOf()<e.valueOf()&&gantt._hasDuration(t,e,n))},isSmallerOrDefault:function(t,e,n){return!(t&&!this.isFirstSmaller(t,e,n))},resolveRelationDate:function(t,e,n){for(var a,r=null,i=null,o=null,s=0;s<e.length;s++){var u=e[s];t=u.target,o=u.preferredStart,a=gantt.getTask(t);var g=this.getConstraintDate(u,n,a);this.isSmallerOrDefault(o,g,a)&&this.isSmallerOrDefault(r,g,a)&&(r=g,i=u.id)}return r&&(r=gantt.getClosestWorkTime({date:r,dir:"future",task:gantt.getTask(t)})),{link:i,task:t,start_date:r}},getConstraintDate:function(t,e,n){var a=e(t.source),r=n,i=gantt.getClosestWorkTime({date:a,dir:"future",task:r});return a&&t.lag&&1*t.lag==t.lag&&(i=gantt.calculateEndDate({start_date:a,duration:1*t.lag,task:r})),i}},gantt._autoSchedulingPlanner={generatePlan:function(t){for(var e,n,a=r.topologicalSort(t),i={},o={},s=0,u=a.length;s<u;s++){e=a[s],!1!==(_=gantt.getTask(e)).auto_scheduling&&(i[e]=[],o[e]=null)}function g(t){var e=o[t],n=gantt.getTask(t);return e&&(e.start_date||e.end_date)?e.end_date?e.end_date:gantt.calculateEndDate({start_date:e.start_date,duration:n.duration,task:n}):n.end_date}for(s=0,u=t.length;s<u;s++)i[(n=t[s]).target]&&i[n.target].push(n);var c=gantt._autoSchedulingDateResolver,l=[];for(s=0;s<a.length;s++){var d=a[s],f=c.resolveRelationDate(d,i[d]||[],g);if(f.start_date&&gantt.isLinkExists(f.link)){var h=gantt.getLink(f.link),_=gantt.getTask(d),v=gantt.getTask(h.source);if(_.start_date.valueOf()!==f.start_date.valueOf()&&!1===gantt.callEvent("onBeforeTaskAutoSchedule",[_,f.start_date,h,v]))continue}o[d]=f,f.start_date&&l.push(f)}return l},applyProjectPlan:function(t){for(var e,n,a,r,i=[],o=0;o<t.length;o++)if(a=null,r=null,(e=t[o]).task){n=gantt.getTask(e.task),e.link&&(a=gantt.getLink(e.link),r=gantt.getTask(a.source));var s=null;e.start_date&&n.start_date.valueOf()!=e.start_date.valueOf()&&(s=e.start_date),s&&(n.start_date=s,n.end_date=gantt.calculateEndDate(n),i.push(n.id),gantt.callEvent("onAfterTaskAutoSchedule",[n,s,a,r]))}return i}},gantt._autoSchedulingPreferredDates=function(t,e){for(var n=0;n<e.length;n++){var a=e[n],r=gantt.getTask(a.target);gantt.config.auto_scheduling_strict&&a.target!=t||(a.preferredStart=new Date(r.start_date))}},gantt._autoSchedule=function(t,e,n){if(!1!==gantt.callEvent("onBeforeAutoSchedule",[t])){gantt._autoscheduling_in_progress=!0;var a=[],i=r.findLoops(e);if(i.length)gantt.callEvent("onAutoScheduleCircularLink",[i]);else{var o=gantt._autoSchedulingPlanner;gantt._autoSchedulingPreferredDates(t,e);var s=o.generatePlan(e);a=o.applyProjectPlan(s),n&&n(a)}gantt._autoscheduling_in_progress=!1,gantt.callEvent("onAfterAutoSchedule",[t,a])}},gantt.autoSchedule=function(t,e){e=void 0===e||!!e;var n=a.getLinkedTasks(t,e);gantt._autoSchedule(t,n,gantt._finalizeAutoSchedulingChanges)},gantt._finalizeAutoSchedulingChanges=function(t){var e=!1;function n(){for(var e=0;e<t.length;e++)gantt.updateTask(t[e])}1==t.length?gantt.eachParent(function t(n){if(!e){var a=n.start_date.valueOf(),r=n.end_date.valueOf();if(gantt.resetProjectDates(n),n.start_date.valueOf()==a&&n.end_date.valueOf()==r)for(var i=gantt.getChildren(n.id),o=0;!e&&o<i.length;o++)t(gantt.getTask(i[o]));else e=!0}},t[0]):t.length&&(e=!0),e?gantt.batchUpdate(n):n()},gantt.isCircularLink=function(t){return!!gantt._getConnectedGroup(t)},gantt._getConnectedGroup=function(t){var e=a.getLinkedTasks();gantt.isLinkExists(t.id)||(e=e.concat(gantt._formatLink(t)));for(var n=r.findLoops(e),i=0;i<n.length;i++)for(var o=n[i].links,s=0;s<o.length;s++)if(o[s]==t.id)return n[i];return null},gantt.findCycles=function(){var t=a.getLinkedTasks();return r.findLoops(t)},gantt._attachAutoSchedulingHandlers=function(){var t,e;gantt._autoScheduleAfterLinkChange=function(t,e){gantt.config.auto_scheduling&&!this._autoscheduling_in_progress&&gantt.autoSchedule(e.source)},gantt.attachEvent("onAfterLinkUpdate",gantt._autoScheduleAfterLinkChange),gantt.attachEvent("onAfterLinkAdd",gantt._autoScheduleAfterLinkChange),gantt.attachEvent("onAfterLinkDelete",function(t,e){if(this.config.auto_scheduling&&!this._autoscheduling_in_progress&&this.isTaskExists(e.target)){var n=this.getTask(e.target),a=this._getPredecessors(n);a.length&&this.autoSchedule(a[0].source,!1)}}),gantt.attachEvent("onParse",function(){gantt.config.auto_scheduling&&gantt.config.auto_scheduling_initial&&gantt.autoSchedule()}),gantt._preventCircularLink=function(t,e){return!gantt.isCircularLink(e)||(gantt.callEvent("onCircularLinkError",[e,gantt._getConnectedGroup(e)]),!1)},gantt._preventDescendantLink=function(t,e){var n=gantt.getTask(e.source),a=gantt.getTask(e.target);return!(!gantt.config.auto_scheduling_descendant_links&&(gantt.isChildOf(n.id,a.id)&&gantt.isSummaryTask(a)||gantt.isChildOf(a.id,n.id)&&gantt.isSummaryTask(n)))},gantt.attachEvent("onBeforeLinkAdd",gantt._preventCircularLink),gantt.attachEvent("onBeforeLinkAdd",gantt._preventDescendantLink),gantt.attachEvent("onBeforeLinkUpdate",gantt._preventCircularLink),gantt.attachEvent("onBeforeLinkUpdate",gantt._preventDescendantLink),gantt._datesNotEqual=function(t,e,n,a){return t.valueOf()>e.valueOf()?this._hasDuration({start_date:e,end_date:t,task:a}):this._hasDuration({start_date:t,end_date:e,task:n})},gantt._notEqualTaskDates=function(t,e){return!!this._datesNotEqual(t.start_date,e.start_date,t,e)||(!(!this._datesNotEqual(t.start_date,e.start_date,t,e)&&(!this._datesNotEqual(t.end_date,e.end_date,t,e)&&t.duration==e.duration||t.type==gantt.config.types.milestone))||void 0)},gantt.attachEvent("onBeforeTaskDrag",function(n,r,i){return gantt.config.auto_scheduling&&gantt.config.auto_scheduling_move_projects&&(t=a.getLinkedTasks(n,!0),e=n),!0}),gantt._autoScheduleAfterDND=function(n,r){if(gantt.config.auto_scheduling&&!this._autoscheduling_in_progress){var i=this.getTask(n);gantt._notEqualTaskDates(r,i)&&(gantt.config.auto_scheduling_move_projects&&e==n?(gantt.calculateDuration(r)!=gantt.calculateDuration(i)&&function(t,e){for(var n=!1,r=0;r<e.length;r++){var i=gantt.getLink(e[r].id);!i||i.type!=gantt.config.links.start_to_start&&i.type!=gantt.config.links.start_to_finish||(e.splice(r,1),r--,n=!0)}if(n){var o={};for(r=0;r<e.length;r++)o[e[r].id]=!0;var s=a.getLinkedTasks(t,!0);for(r=0;r<s.length;r++)o[s[r].id]||e.push(s[r])}}(n,t),gantt._autoSchedule(n,t,gantt._finalizeAutoSchedulingChanges)):gantt.autoSchedule(i.id))}return t=null,e=null,!0},gantt._lightBoxChangesHandler=function(t,e){if(gantt.config.auto_scheduling&&!this._autoscheduling_in_progress){var n=this.getTask(t);gantt._notEqualTaskDates(e,n)&&(gantt._autoschedule_lightbox_id=t)}return!0},gantt._lightBoxSaveHandler=function(t,e){return gantt.config.auto_scheduling&&!this._autoscheduling_in_progress&&gantt._autoschedule_lightbox_id&&gantt._autoschedule_lightbox_id==t&&(gantt._autoschedule_lightbox_id=null,gantt.autoSchedule(e.id)),!0},gantt.attachEvent("onBeforeTaskChanged",function(t,e,n){return gantt._autoScheduleAfterDND(t,n)}),gantt.attachEvent("onLightboxSave",gantt._lightBoxChangesHandler),gantt.attachEvent("onAfterTaskUpdate",gantt._lightBoxSaveHandler)},gantt.attachEvent("onGanttReady",function(){gantt._attachAutoSchedulingHandlers(),gantt._attachAutoSchedulingHandlers=function(){}}),gantt.getConnectedGroup=function(e){var n=a.getLinkedTasks();return void 0!==e?gantt.getTask(e).type==gantt.config.types.project?{tasks:[],links:[]}:t(e,n,{}):function(e){for(var n,a,r,i={},o=[],s=0;s<e.length;s++)if(n=e[s].source,a=e[s].target,r=null,i[n]?i[a]||(r=a):r=n,r){var u=e.length;o.push(t(r,e,i)),u!=e.length&&(s=-1)}return o}(n)}}()},3:function(t,e){var n={second:1,minute:60,hour:3600,day:86400,week:604800,month:2592e3,quarter:7776e3,year:31536e3};function a(t,e){var n=[];if(t.filter)return t.filter(e);for(var a=0;a<t.length;a++)e(t[a],a)&&(n[n.length]=t[a]);return n}t.exports={getSecondsInUnit:function(t){return n[t]||n.hour},forEach:function(t,e){if(t.forEach)t.forEach(e);else for(var n=t.slice(),a=0;a<n.length;a++)e(n[a],a)},arrayMap:function(t,e){if(t.map)return t.map(e);for(var n=t.slice(),a=[],r=0;r<n.length;r++)a.push(e(n[r],r));return a},arrayFind:function(t,e){if(t.find)return t.find(e);for(var n=0;n<t.length;n++)if(e(t[n],n))return t[n]},arrayFilter:a,arrayDifference:function(t,e){return a(t,function(t,n){return!e(t,n)})},arraySome:function(t,e){if(0===t.length)return!1;for(var n=0;n<t.length;n++)if(e(t[n],n,t))return!0;return!1},hashToArray:function(t){var e=[];for(var n in t)t.hasOwnProperty(n)&&e.push(t[n]);return e},sortArrayOfHash:function(t,e,n){var a=function(t,e){return t<e};t.sort(function(t,r){return t[e]===r[e]?0:n?a(t[e],r[e]):a(r[e],t[e])})},throttle:function(t,e){var n=!1;return function(){n||(t.apply(null,arguments),n=!0,setTimeout(function(){n=!1},e))}},isArray:function(t){return Array.isArray?Array.isArray(t):t&&void 0!==t.length&&t.pop&&t.push},isDate:function(t){return!(!t||"object"!=typeof t||!(t.getFullYear&&t.getMonth&&t.getDate))},isStringObject:function(t){return t&&"object"==typeof t&&"function String() { [native code] }"===Function.prototype.toString.call(t.constructor)},isNumberObject:function(t){return t&&"object"==typeof t&&"function Number() { [native code] }"===Function.prototype.toString.call(t.constructor)},isBooleanObject:function(t){return t&&"object"==typeof t&&"function Boolean() { [native code] }"===Function.prototype.toString.call(t.constructor)},delay:function(t,e){var n;return function(){clearTimeout(n),n=setTimeout(function(){t()},e)}}}},9:function(t,e){t.exports=function(t){return{getVirtualRoot:function(){return t.mixin(t.getSubtaskDates(),{id:t.config.root_id,type:t.config.types.project,$source:[],$target:[],$virtual:!0})},getLinkedTasks:function(e,n){var a=[e],r=!1;t._isLinksCacheEnabled()||(t._startLinksCache(),r=!0);for(var i=[],o={},s={},u=0;u<a.length;u++)this._getLinkedTasks(a[u],o,n,s);for(var u in s)i.push(s[u]);return r&&t._endLinksCache(),i},_collectRelations:function(e,n,a,r){var i,o=t._getSuccessors(e,n),s=[];a&&(s=t._getPredecessors(e,n));for(var u=[],g=0;g<o.length;g++)r[i=o[g].hashSum]||(r[i]=!0,u.push(o[g]));for(g=0;g<s.length;g++)r[i=s[g].hashSum]||(r[i]=!0,u.push(s[g]));return u},_getLinkedTasks:function(e,n,a,r){for(var i,o=void 0===e?t.config.root_id:e,s=(n={},{}),u=[{from:o,includePredecessors:a,isChild:!1}];u.length;){var g=u.pop(),c=g.isChild;if(!n[o=g.from]){i=t.isTaskExists(o)?t.getTask(o):this.getVirtualRoot(),n[o]=!0;for(var l=this._collectRelations(i,c,a,s),d=0;d<l.length;d++){var f=l[d];r[f.hashSum]=f;var h=f.sourceParent==f.targetParent;n[f.target]||u.push({from:f.target,includePredecessors:!0,isChild:h})}if(t.hasChild(i.id)){var _=t.getChildren(i.id);for(d=0;d<_.length;d++)n[_[d]]||u.push({from:_[d],includePredecessors:!0,isChild:!0})}}}return r}}}}});
  7. //# sourceMappingURL=dhtmlxgantt_auto_scheduling.js.map