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