Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I need help in dependency task #191

Open
shubham-proprofs opened this issue Sep 8, 2022 · 0 comments
Open

I need help in dependency task #191

shubham-proprofs opened this issue Sep 8, 2022 · 0 comments

Comments

@shubham-proprofs
Copy link

Hi ,

I need help in dependency task. I am not able to draw line to show depended task.
I need help in this line var sup = this.tasks[parseInt(supStr)-1]; how we are subtract please help me.
of this function GanttMaster.prototype.updateLinks in ganttmaster file.

GanttMaster.prototype.updateLinks = function (task) {
//console.debug("updateLinks",task);
//var prof= new Profiler("gm_updateLinks");

// defines isLoop function
function isLoop(task, target, visited) {
//var prof= new Profiler("gm_isLoop");
//console.debug("isLoop :"+task.name+" - "+target.name);
if (target == task) {
return true;
}

var sups = task.getSuperiors();

//my parent' superiors are my superiors too
var p = task.getParent();
while (p) {
  sups = sups.concat(p.getSuperiors());
  p = p.getParent();
}

//my children superiors are my superiors too
var chs = task.getChildren();
for (var i = 0; i < chs.length; i++) {
  sups = sups.concat(chs[i].getSuperiors());
}

var loop = false;
//check superiors
for (var i = 0; i < sups.length; i++) {
  var supLink = sups[i];
  if (supLink.from == target) {
    loop = true;
    break;
  } else {
    if (visited.indexOf(supLink.from.id + "x" + target.id) <= 0) {
      visited.push(supLink.from.id + "x" + target.id);
      if (isLoop(supLink.from, target, visited)) {
        loop = true;
        break;
      }
    }
  }
}

//check target parent
var tpar = target.getParent();
if (tpar) {
  if (visited.indexOf(task.id + "x" + tpar.id) <= 0) {
    visited.push(task.id + "x" + tpar.id);
    if (isLoop(task, tpar, visited)) {
      loop = true;
    }
  }
}

//prof.stop();
return loop;

}

//remove my depends
this.links = this.links.filter(function (link) {
return link.to != task;
});

var todoOk = true;
if (task.depends) {
//cannot depend from an ancestor
var parents = task.getParents();
//cannot depend from descendants
var descendants = task.getDescendant();

var deps = task.depends.split(",");
var newDepsString = "";
var visited = [];
var depsEqualCheck = [];
console.log('deps.length', deps.length); 
console.log('deps', deps); 

for (var j = 0; j < deps.length; j++) {
  var depString = deps[j]; // in the form of row(lag) e.g. 2:3,3:4,5
  var supStr =depString;
  var lag = 0;
  var pos = depString.indexOf(":");
  if (pos>0){
    supStr=depString.substr(0,pos);
    var lagStr=depString.substr(pos+1);
    lag=Math.ceil((stringToDuration(lagStr)) / Date.workingPeriodResolution) * Date.workingPeriodResolution;
  }

  var sup = this.tasks[parseInt(supStr)-1];
  console.log('this.tasks', this.tasks);
  console.log('[parseInt(supStr)-1]', [parseInt(supStr)-1]);
  if (sup) {
    if (parents && parents.indexOf(sup) >= 0) {
      this.setErrorOnTransaction("\""+task.name + "\"\n" + GanttMaster.messages.CANNOT_DEPENDS_ON_ANCESTORS + "\n\"" + sup.name+"\"");
      todoOk = false;

    } else if (descendants && descendants.indexOf(sup) >= 0) {
      this.setErrorOnTransaction("\""+task.name + "\"\n" + GanttMaster.messages.CANNOT_DEPENDS_ON_DESCENDANTS + "\n\"" + sup.name+"\"");
      todoOk = false;

    } else if (isLoop(sup, task, visited)) {
      todoOk = false;
      this.setErrorOnTransaction(GanttMaster.messages.CIRCULAR_REFERENCE + "\n\"" + task.id +" - "+ task.name + "\" -> \"" + sup.id +" - "+sup.name+"\"");

    } else if(depsEqualCheck.indexOf(sup)>=0) {
      this.setErrorOnTransaction(GanttMaster.messages.CANNOT_CREATE_SAME_LINK + "\n\"" + sup.name+"\" -> \""+task.name+"\"");
      todoOk = false;

    } else {
      this.links.push(new Link(sup, task, lag));
      newDepsString = newDepsString + (newDepsString.length > 0 ? "," : "") + supStr+(lag==0?"":":"+durationToString(lag));
    }

    if (todoOk)
      depsEqualCheck.push(sup);
  }
}
task.depends = newDepsString;

}
//prof.stop();

return todoOk;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant