bugfixing and improving...

master v0.5.1
Enrico Fasoli 2015-04-09 17:55:21 +02:00
parent d1414f2532
commit bfbd4149f4
5 changed files with 69 additions and 29 deletions

View File

@ -95,16 +95,21 @@ class PBS
calculateDelays: (item) =>
if !item.dependant? or item.dependant.length is 0 then return no
lowestFDelay = 0; fDelay = no; cDelay = 0
for j,i of item.dependant
x = @toActivity i
if !isNaN(x.permittedDelay) or x.permittedDelay < lowestFDelay or fDelay is no
@log "activity", i, "dependant on", item.id, "has the lowest delay for now ("+(x.permittedDelay or 0)+")"
lowestFDelay = x.permittedDelay or 0
cDelay = x.chainedDelay or 0
fDelay = yes
olDelay = item.chainedDelay
item.chainedDelay = lowestFDelay + cDelay
if item.critical
@log item.id, 'is critical: no chained delays'
item.chainedDelay = 0
else
lowestFDelay = 0; fDelay = no; cDelay = 0
for j,i of item.dependant
x = @toActivity i
if !isNaN(x.permittedDelay) or x.permittedDelay < lowestFDelay or fDelay is no
@log "activity", i, "dependant on", item.id, "has the lowest delay for now ("+(x.permittedDelay or 0)+")"
lowestFDelay = x.permittedDelay or 0
cDelay = x.chainedDelay or 0
fDelay = yes
olDelay = item.chainedDelay
item.chainedDelay = lowestFDelay + cDelay
@log "chained delay of", item.id, "is", item.chainedDelay
return item.chainedDelay isnt olDelay
@ -142,10 +147,15 @@ class PBS
return @
calculate: (options,cb) ->
h = @highestID()
# Calculate startDay, endDay, freeDelay
for x,i in @list
@log '('+x.id+'/'+h+')'
@log '('+i+'/'+@list.length+')'
@calculateEndDay x
# Calculate Critical Paths
for x,i in @list
if !x.depends? or x.depends.length is 0
@calculateCriticalPaths [x.id]
# Calculate chained Delays
finished = no; i = 0
while !finished
i++; finished = yes
@ -153,10 +163,9 @@ class PBS
if @calculateDelays x
finished = no
@log "Done calculating delays. Took", i, "iterations"
for x,i in @list
if !x.depends? or x.depends.length is 0
@calculateCriticalPaths [x.id]
# Compile resource information
@compileResources()
# done
results =
activities: @list
days: @days

View File

@ -42,9 +42,9 @@ pertApp.config ($stateProvider,$urlRouterProvider,$locationProvider) ->
pertController = ($scope) ->
$scope.toLocalStorage = (data,options) ->
options ?= {}
data ?= []
if !data.push? and !data.activities?.push?
return swal 'Error', 'data is not a valid PBSlib object', 'error'
data ?= activities: [], resources: []
if not data.activities?.push?
return swal 'Error', 'invalid data format. Try resetting', 'error'
try
sdata = JSON.stringify data
console.log "Saving: "+sdata

View File

@ -12,16 +12,16 @@ pertApp.controller 'tableController', ($scope) ->
tableController $scope, (data) -> data.activities or []
pertApp.controller 'resourceTableController', ($scope) ->
tableController $scope, (data) -> data.resources or []
pertApp.controller 'pertDiagController', ($scope) ->
$scope.buildGraph = (data) ->
if !data? then return
nodes = data.days.map (x) -> {id: x, label: ""+x}
connections = []
data.activities.forEach (x) ->
maxDuration = x.duration + (x.permittedDelay or 0) + (x.chainedDelay or 0)
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)+")"
label: x.id+" ("+(if maxDuration isnt x.duration then x.duration+"/"+maxDuration else x.duration)+")"
color: if x.critical then 'red' else if !x.permittedDelay then 'orange'
if x.permittedDelay > 0
connections.push
@ -55,17 +55,36 @@ pertApp.controller 'ganttDiagController', ($scope) ->
$scope.buildTimeline $scope.fromLocalStorage()
$scope.buildTimeline $scope.fromLocalStorage()
areYouSure = (text,cb) ->
swal {
title: "Are you sure?"
text: text
type: "warning"
showCancelButton: true
confirmButtonColor: "#DD6B55"
confirmButtonText: "Yes"
closeOnConfirm: yes
}, cb
pertApp.controller 'rawEditorController', ($scope) ->
$scope.reset = ->
$scope.toLocalStorage { activities: [], resources: [] }
$scope.saveData = ->
$scope.reset = (askConfirm) ->
doIt = -> $scope.toLocalStorage { activities: [], resources: [] }
if askConfirm
areYouSure "ALL data will be lost!", doIt
else doIt()
$scope.saveData = (askConfirm) ->
try
data = JSON.parse $scope.taData
catch e
swal 'Invalid Data', e, 'error'
$scope.toLocalStorage data
$scope.reloadData = ->
$scope.taData = JSON.stringify $scope.fromLocalStorage silent: yes, raw: yes
return swal 'Invalid Data', e, 'error'
doIt = -> $scope.toLocalStorage data
if askConfirm then areYouSure "Current saved data will be replaced by the data in the RawEditor", doIt
else doIt()
$scope.reloadData = (askConfirm) ->
doIt = ->
$scope.taData = JSON.stringify $scope.fromLocalStorage silent: yes, raw: yes
if askConfirm then areYouSure "Current saved data will be replaced by the data in the RawEditor", doIt
else doIt()
$scope.$on 'dataChanged', $scope.reloadData
$scope.reloadData()

View File

@ -1,4 +1,16 @@
<div class="text-center" ng-controller="pertDiagController">
<button class="btn btn-primary" ng-click="rebuild()"><i class="fa fa-spinner"></i> Redraw</button>
<div id="pertDiagram" ></div>
<h2>How to read the Graph</h2>
<b>Arrow:</b> every arrow is an activity and the ID and duration (in days) are shown over the arrow, like this: <code>activityID (minimumDuration/maximumDuration)</code>
<hr>
<p class="lead">The color of the arrow tells the type of the activity:</p>
<ul>
<li><b>Red Arrow:</b> critical activity</li>
<li><b>Green Arrow:</b> free delay of an activity, expressed this way: <code>activityID (freeDelay)</code></li>
<li><b>Yellow Arrow:</b> activity with a free delay of 0</li>
<li><b>Blue Arrow:</b> activity with a free delay over 0</li>
</ul>
<hr>
<p class="lead">Every circle represents the day of the start of one or more activities and/or the day of the end of one or more activities.</p>
</div>

View File

@ -3,10 +3,10 @@
<p class="lead">The RawEditor is intended for importing, exporting your data
and debugging.<br>Keep backups outside of this application if you rely on your data</p>
<textarea id="ta" class="form-control" ng-model="taData" rows="10"></textarea>
<button class="btn btn-primary" ng-click="saveData()">
<button class="btn btn-primary" ng-click="saveData(true)">
<i class="fa fa-check"></i> Save</button>
<button class="btn btn-info" ng-click="reloadData()">
<button class="btn btn-info" ng-click="reloadData(true)">
<i class="fa fa-refresh"></i> Reload</button>
<button class="btn btn-warning" ng-click="reset()">
<button class="btn btn-warning" ng-click="reset(true)">
<i class="fa fa-bomb"></i> Reset</button>
</div>