diff --git a/client/bower.json b/client/bower.json
index ee54d8c..19d429d 100644
--- a/client/bower.json
+++ b/client/bower.json
@@ -16,6 +16,7 @@
"tests"
],
"dependencies": {
- "vis": "~3.11.0"
+ "vis": "~3.11.0",
+ "jquery": "~2.1.3"
}
}
diff --git a/client/index.html b/client/index.html
index 04888cd..a08aa58 100644
--- a/client/index.html
+++ b/client/index.html
@@ -4,9 +4,10 @@
Pert
diff --git a/src/pert-cli.coffee b/src/pert-cli.coffee
index 98afe3a..a1c4ed2 100755
--- a/src/pert-cli.coffee
+++ b/src/pert-cli.coffee
@@ -42,7 +42,8 @@ cli
.command 'graph '
.description 'serve HTTP GUI with pert graph of given JSON document'
.alias 'g'
- .action (file) ->
+ .option '-r, --read-only', 'disallow data editing'
+ .action (file,options) ->
didSomething = yes
fs.readFile file, (error,content) ->
if error then err error
@@ -52,6 +53,9 @@ cli
app = express()
app.use express.static 'client'
app.get '/data', (req,res) -> res.json data
+ if !options.readOnly then app.post '/data', (req,res) ->
+ data = req.body
+ pert.setData(data).calculate()
app.listen 3000
console.log chalk.green('Started Web Server'), 'on port', chalk.bold(3000)
diff --git a/src/pert-ui.coffee b/src/pert-ui.coffee
index 9f5ef97..4f45258 100644
--- a/src/pert-ui.coffee
+++ b/src/pert-ui.coffee
@@ -1,6 +1,10 @@
-$.get 'data', (data) ->
- console.log data
- i = 0
+$.get 'data', (d) ->
+ # Serve the server data
+ list = d
+ console.log list
+ buildGraph list
+
+buildGraph = (data) ->
nodes = data.days.map (x) -> {id: x, label: ""+x}
connections = []
data.activities.forEach (x) ->
@@ -8,10 +12,17 @@ $.get 'data', (data) ->
from: x.startDay, to: x.endDay
label: x.id+" ("+(if x.permittedDelay > 0 then x.duration+"/"+(x.duration+x.permittedDelay) else x.duration)+")"
if x.permittedDelay > 0
- connections.push from: x.endDay, to: x.endDay+x.permittedDelay, color: 'green', label: "("+x.permittedDelay+")"
+ connections.push
+ from: x.endDay
+ to: x.endDay+x.permittedDelay
+ color: 'green'
+ label: x.id+" ("+x.permittedDelay+")"
console.log nodes
console.log connections
- options =
- edges:
- style: 'arrow'
- network = new vis.Network (document.getElementById 'pert'), { nodes: nodes, edges: connections }, options
+ if network
+ network.setData { nodes: nodes, edges: edges }
+ else
+ options =
+ edges:
+ style: 'arrow'
+ network = new vis.Network (document.getElementById 'pert'), { nodes: nodes, edges: connections }, options
diff --git a/src/pert.coffee b/src/pert.coffee
index fa30383..867a34b 100755
--- a/src/pert.coffee
+++ b/src/pert.coffee
@@ -57,8 +57,14 @@ module.exports = class Pert
if day is d then return
@days.push day
- calculate: (options) ->
- @calculateEndDay @toActivity @highestID()
- results = activities: @list, days: @days
- if options?.json then JSON.stringify results else results
+ setData: (data) ->
+ @list = data
+ return @
+ calculate: (options) ->
+ 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