From 147973d7bc7040b95d32a66672c1342c212201f1 Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Mon, 16 Mar 2015 11:44:08 +0100 Subject: [PATCH] added a few features --- src/pert-ui.coffee | 1 + src/pert.coffee | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pert-ui.coffee b/src/pert-ui.coffee index 4f45258..01f6543 100644 --- a/src/pert-ui.coffee +++ b/src/pert-ui.coffee @@ -11,6 +11,7 @@ buildGraph = (data) -> connections.push from: x.startDay, to: x.endDay label: x.id+" ("+(if x.permittedDelay > 0 then x.duration+"/"+(x.duration+x.permittedDelay) else x.duration)+")" + color: if !x.permittedDelay then 'red' if x.permittedDelay > 0 connections.push from: x.endDay diff --git a/src/pert.coffee b/src/pert.coffee index 867a34b..374cc12 100755 --- a/src/pert.coffee +++ b/src/pert.coffee @@ -40,6 +40,8 @@ module.exports = class Pert item.depends.forEach (x) => @log "checking permittedDelay to dependency", x, "of", item i = @toActivity x + if !i.dependant? then i.dependant = [item.id] + else i.dependant.push item.id if !i.permittedDelay? i.permittedDelay = item.startDay - @calculateEndDay i @log "written permittedDelay to dependency", x, "of", item, "as", i.permittedDelay @@ -61,10 +63,15 @@ module.exports = class Pert @list = data return @ - calculate: (options) -> + calculate: (options,cb) -> h = @highestID() @list.forEach (x) => @log '('+x.id+'/'+h+')' @calculateEndDay x results = activities: @list, days: @days - if options?.json then JSON.stringify results else results + if options?.json + if cb? then cb(JSON.stringify results) + JSON.stringify results + else + if cb? then cb(results) + results