mirror of
https://github.com/fazo96/pbs.git
synced 2025-01-27 14:34:19 +01:00
sucks a little but works
This commit is contained in:
parent
ec0d878a49
commit
9ae7972d53
@ -11,11 +11,7 @@ pertApp.config ($stateProvider,$urlRouterProvider) ->
|
||||
$stateProvider.state 'rawedit',
|
||||
url: '/rawedit'
|
||||
templateUrl: 'rawedit.html'
|
||||
controller: ($scope) ->
|
||||
$scope.rawdata = localStorage.getItem 'ganttpert'
|
||||
$scope.saveData = ->
|
||||
swal 'Saved', 'Your data has been updated', 'success'
|
||||
localStorage.setItem 'ganttpert', $('#ta').val()
|
||||
controller: pertController
|
||||
|
||||
$stateProvider.state 'edit',
|
||||
url: '/edit'
|
||||
@ -38,20 +34,28 @@ pertApp.config ($stateProvider,$urlRouterProvider) ->
|
||||
controller: pertController
|
||||
|
||||
pertController = ($scope) ->
|
||||
$scope.toLocalStorage = (data) ->
|
||||
$scope.toLocalStorage = (data,options) ->
|
||||
options = options || {}
|
||||
try
|
||||
console.log data
|
||||
localStorage.setItem 'ganttpert', JSON.stringify data
|
||||
swal 'Ok', 'Data updated', 'success'
|
||||
unless options.silent
|
||||
swal 'Ok', 'Data updated', 'success'
|
||||
$scope.$broadcast 'dataChanged'
|
||||
catch e
|
||||
swal 'Error', 'could not save data', 'error'
|
||||
$scope.fromLocalStorage = (item) ->
|
||||
data = localStorage.getItem item || 'ganttpert'
|
||||
if data
|
||||
try
|
||||
jdata = JSON.parse data
|
||||
catch e
|
||||
return swal 'JSON Error', e, 'error'
|
||||
if jdata
|
||||
return new Pert(jdata).calculate()
|
||||
else return swal 'Error', 'no JSON?', 'error'
|
||||
else swal 'Error', 'no data to parse', 'error'
|
||||
swal 'Error', e, 'error'
|
||||
|
||||
$scope.fromLocalStorage = (options) ->
|
||||
options = options || {}
|
||||
data = localStorage.getItem options.name || 'ganttpert'
|
||||
try
|
||||
jdata = JSON.parse data
|
||||
catch e
|
||||
unless options.silent
|
||||
swal 'JSON Error', e, 'error'
|
||||
if options.raw
|
||||
return []
|
||||
else return activities: [], days: []
|
||||
if options.raw
|
||||
return jdata
|
||||
else return new Pert(jdata).calculate()
|
||||
|
@ -27,6 +27,8 @@ pertApp.controller 'pertDiagController', ($scope) ->
|
||||
edges:
|
||||
style: 'arrow'
|
||||
network = new vis.Network (document.getElementById 'pertDiagram'), { nodes: nodes, edges: connections }, options
|
||||
$scope.$on 'dataChanged', ->
|
||||
$scope.buildGraph $scope.fromLocalStorage()
|
||||
$scope.buildGraph $scope.fromLocalStorage()
|
||||
|
||||
pertApp.controller 'ganttDiagController', ($scope) ->
|
||||
@ -39,40 +41,49 @@ pertApp.controller 'ganttDiagController', ($scope) ->
|
||||
$scope.buildTimeline = (data) ->
|
||||
if !data? then return
|
||||
timeline = new vis.Timeline (document.getElementById 'timeline'), ($scope.toDates data.activities), {}
|
||||
$scope.$on 'dataChanged', ->
|
||||
$scope.buildTimeline $scope.fromLocalStorage()
|
||||
$scope.buildTimeline $scope.fromLocalStorage()
|
||||
|
||||
pertApp.controller 'rawEditorController', ($scope) ->
|
||||
$scope.rawdata = $scope.fromLocalStorage silent: yes, raw: yes
|
||||
|
||||
pertApp.controller 'editorController', ($scope) ->
|
||||
$scope.clone = (id) ->
|
||||
for i,j of $scope.fromLocalStorage().activities
|
||||
console.log j
|
||||
for i,j of $scope.fromLocalStorage({raw: yes, silent: yes}).activities
|
||||
if j.id is id
|
||||
$scope.addNew j.id, j.duration, j.depends
|
||||
swal 'Ok', id+' has been cloned', 'success'
|
||||
return
|
||||
swal 'Ops', 'could not find '+id, 'warning'
|
||||
|
||||
$scope.delete = (id) ->
|
||||
rawdata = localStorage.getItem 'ganttpert'
|
||||
try
|
||||
newdata = JSON.parse rawdata
|
||||
catch e
|
||||
swal 'Error', e, 'error'
|
||||
if newdata
|
||||
l = []
|
||||
for i,j of newdata
|
||||
if j.id isnt id
|
||||
l.push j
|
||||
localStorage.setItem 'ganttpert', JSON.stringify l
|
||||
swal 'Ok', 'done', 'success'
|
||||
newdata = $scope.fromLocalStorage raw: yes
|
||||
l = []
|
||||
for i,j of newdata
|
||||
if j.id isnt id
|
||||
l.push j
|
||||
$scope.toLocalStorage l, silent: yes
|
||||
swal 'Ok', 'done', 'success'
|
||||
|
||||
$scope.addNew = (id, dur, deps) ->
|
||||
ndur = dur || $('#new-duration').val()
|
||||
nid = id || $('#new-id').val()
|
||||
ndeps = deps || []
|
||||
rawdata = localStorage.getItem 'ganttpert'
|
||||
dur ?= $('#new-duration').val()
|
||||
id ?= $('#new-id').val()
|
||||
if !deps?
|
||||
deps = $('#new-deps').val().split(' ')
|
||||
if deps.length is 1 and deps[0] is ''
|
||||
deps = []
|
||||
try
|
||||
newdata = JSON.parse rawdata
|
||||
dur = parseInt dur
|
||||
catch e
|
||||
swal 'Error', e, 'error'
|
||||
newdata.push {id: nid, duration: dur, depends: ndeps}
|
||||
$scope.toLocalStorage newdata
|
||||
data = $scope.fromLocalStorage()
|
||||
if data? then $scope.list = data.activities
|
||||
return swal 'Error', 'duration must be an integer', 'error'
|
||||
newdata = $scope.fromLocalStorage silent: yes, raw: yes
|
||||
newdata.push { id: id, duration: dur, depends: deps }
|
||||
$scope.toLocalStorage newdata, silent: yes
|
||||
|
||||
$scope.refreshEditor = ->
|
||||
console.log 'drawing editor'
|
||||
data = $scope.fromLocalStorage { silent: yes, raw: yes }
|
||||
$scope.list = data || []
|
||||
$scope.$on 'dataChanged', $scope.refreshEditor
|
||||
$scope.refreshEditor()
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div ng-controller="editorController">
|
||||
<div ng-controller="editorController" class="activity-list">
|
||||
<div class="panel panel-default" ng-repeat="item in list">
|
||||
<div class="panel-heading">
|
||||
<div class="input-group">
|
||||
@ -7,11 +7,11 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="input-group">
|
||||
<div class="input-group duration">
|
||||
<span class="input-group-addon">Duration</span>
|
||||
<input class="form-control" value="{{item.duration}}" placeholder="(days)">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<div class="input-group dependencies">
|
||||
<span class="input-group-addon">Dependencies</span>
|
||||
<input class="form-control" placeholder="id1 id2 id3" value="{{item.depends.join(' ')}}">
|
||||
</div>
|
||||
@ -24,19 +24,19 @@
|
||||
<div class="panel-heading">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">ID</span>
|
||||
<input class="form-control" placeholder="New Activity" id="new-id">
|
||||
<input class="form-control" placeholder="New Activity" ng-model="newid" id="new-id">
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="input-group">
|
||||
<div class="input-group duration">
|
||||
<span class="input-group-addon">Duration</span>
|
||||
<input class="form-control" id="new-duration" placeholder="(days)">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<div class="input-group dependencies">
|
||||
<span class="input-group-addon">Dependencies</span>
|
||||
<input class="form-control" placeholder="id1 id2 id3">
|
||||
<input class="form-control" placeholder="id1 id2 id3" id="new-deps">
|
||||
</div>
|
||||
<button ng-click="addNew($event)" class="btn btn-primary">Add</button>
|
||||
<button ng-click="addNew()" class="btn btn-primary">Add</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div class="home">
|
||||
<div ng-controller="rawEditorController">
|
||||
<textarea id="ta" class="form-control" rows="10">{{rawdata}}</textarea>
|
||||
<button class="btn btn-primary" ng-click="saveData($event)">Save</button>
|
||||
<button class="btn btn-primary" ng-click="toLocalStorage($('#ta').val())">Save</button>
|
||||
</div>
|
||||
|
@ -6,7 +6,15 @@
|
||||
}
|
||||
|
||||
.container {
|
||||
padding-top: 4em;
|
||||
padding-top: 5em;
|
||||
}
|
||||
|
||||
.input-group.dependencies {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.input-group.duration {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
#ta {
|
||||
|
Loading…
Reference in New Issue
Block a user