From d551a9c6db66b761e3c00f8d1121a396950e185c Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Tue, 7 Apr 2015 15:03:57 +0200 Subject: [PATCH] bugfix and cleanup --- src/app.coffee | 12 ++++++++---- src/controllers.coffee | 11 ++++------- src/pert.coffee | 1 - 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/app.coffee b/src/app.coffee index f0ccefa..1e9f607 100644 --- a/src/app.coffee +++ b/src/app.coffee @@ -38,6 +38,8 @@ pertController = ($scope) -> $scope.toLocalStorage = (data,options) -> options ?= {} data ?= [] + if !data.push? + return swal 'Error', 'data is not a list', 'error' try console.log "Saving: "+data localStorage.setItem 'ganttpert', JSON.stringify data @@ -50,21 +52,23 @@ pertController = ($scope) -> $scope.fromLocalStorage = (options) -> options = options || {} data = localStorage.getItem options.name || 'ganttpert' + if data is null then data = "[]" try jdata = JSON.parse data + if jdata is null then jdata = [] catch e unless options.silent swal 'JSON Error', e, 'error' if options.raw - console.log 'Loading: []' + #console.log 'Loading: []' return [] else - console.log 'Loading: {list: [], days: []}' + #console.log 'Loading: {list: [], days: []}' return list: [], days: [] if options.raw - console.log 'Loading: '+jdata + #console.log 'Loading: '+jdata return jdata else r = new Pert(jdata).calculate() - console.log 'Loading: '+r + #console.log 'Loading: '+r return r diff --git a/src/controllers.coffee b/src/controllers.coffee index 83a98a4..fc988dd 100644 --- a/src/controllers.coffee +++ b/src/controllers.coffee @@ -12,7 +12,6 @@ pertApp.controller 'pertDiagController', ($scope) -> if !data? then return nodes = data.days.map (x) -> {id: x, label: ""+x} connections = [] - console.log data.criticalPaths data.activities.forEach (x) -> connections.push from: x.startDay, to: x.endDay @@ -101,18 +100,16 @@ pertApp.controller 'editorController', ($scope) -> catch e return swal 'Error', 'duration must be an integer', 'error' try - id = parseInt id - catch e - return + unless isNaN id + id = parseInt id for i,dep of deps try - deps[i] = parseInt dep + unless isNaN dep + deps[i] = parseInt dep catch e - return newdata = $scope.fromLocalStorage silent: yes, raw: yes if !newdata? or newdata is null or !newdata.push? newdata = [] - console.log newdata newdata.push { id: id, duration: dur, depends: deps } $scope.toLocalStorage newdata, silent: yes diff --git a/src/pert.coffee b/src/pert.coffee index c320148..0659ea8 100644 --- a/src/pert.coffee +++ b/src/pert.coffee @@ -106,7 +106,6 @@ class Pert finished = no @log "Done calculating delays. Took", i, "iterations" for x,i in @list - console.log x if !x.depends? or x.depends.length is 0 @calculateCriticalPaths [x.id] results = activities: @list, days: @days, criticalPaths: @criticalPaths