angular and angular-ui-router now functional

This commit is contained in:
Enrico Fasoli 2015-03-31 19:33:38 +02:00
parent 8e0fa6c3ff
commit 8848860014
11 changed files with 100 additions and 96 deletions

View File

@ -20,6 +20,8 @@
"jquery": "~2.1.3", "jquery": "~2.1.3",
"moment": "~2.9.0", "moment": "~2.9.0",
"bootstrap": "~3.3.4", "bootstrap": "~3.3.4",
"sweetalert": "~0.5.0" "sweetalert": "~0.5.0",
"angular": "~1.3.15",
"angular-ui-router": "~0.2.13"
} }
} }

View File

@ -1,5 +1,6 @@
var gulp = require('gulp') var gulp = require('gulp')
var minifyCSS = require('gulp-minify-css') var minifyCSS = require('gulp-minify-css')
var minifyHTML = require('gulp-minify-html')
var coffee = require('gulp-coffee') var coffee = require('gulp-coffee')
var uglify = require('gulp-uglify') var uglify = require('gulp-uglify')
var clean = require('gulp-clean') var clean = require('gulp-clean')
@ -10,10 +11,16 @@ gulp.task('css',function(){
.pipe(gulp.dest('dist/')) .pipe(gulp.dest('dist/'))
}) })
gulp.task('html',function(){
return gulp.src('src/*.html')
.pipe(minifyHTML({ quotes: true }))
.pipe(gulp.dest('dist/'))
})
gulp.task('coffee',function(){ gulp.task('coffee',function(){
return gulp.src('src/*.coffee') return gulp.src('src/*.coffee')
.pipe(coffee({ bare: true })) .pipe(coffee({ bare: true }))
.pipe(uglify()) .pipe(uglify({ mangle: false }))
.pipe(gulp.dest('dist/')) .pipe(gulp.dest('dist/'))
}) })
@ -24,5 +31,6 @@ gulp.task('clean',function(){
gulp.task('watch',function(){ gulp.task('watch',function(){
gulp.watch('src/*.coffee',['coffee']) gulp.watch('src/*.coffee',['coffee'])
gulp.watch('src/*.css',['css']) gulp.watch('src/*.css',['css'])
gulp.watch('src/*.html',['html'])
}) })
gulp.task('default',['css','coffee']) gulp.task('default',['html','css','coffee'])

View File

@ -1,21 +1,19 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html ng-app="pertApp">
<head> <head>
<title>Pert</title> <title>Pert</title>
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="stylesheet" href="bower_components/vis/dist/vis.min.css"> <link rel="stylesheet" href="bower_components/vis/dist/vis.min.css">
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css"> <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="dist/style.css"> <link rel="stylesheet" href="dist/style.css">
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="bower_components/vis/dist/vis.min.js"></script>
<script src="dist/pert.js"></script>
<script src="dist/app.js"></script>
</head> </head>
<body> <body>
<div class="container" ui-view></div>
<div class="container">
<textarea id="ta" class="form-control" rows="10"></textarea>
<button id="save" class="btn btn-primary">Save</button>
<a href="pert.html" class="btn btn-success">View Pert</a>
</div>
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="dist/index.js"></script>
</body> </body>
</html> </html>

View File

@ -6,6 +6,7 @@
"gulp-clean": "^0.3.1", "gulp-clean": "^0.3.1",
"gulp-coffee": "^2.3.1", "gulp-coffee": "^2.3.1",
"gulp-minify-css": "^1.0.0", "gulp-minify-css": "^1.0.0",
"gulp-minify-html": "^1.0.2",
"gulp-uglify": "^1.1.0" "gulp-uglify": "^1.1.0"
}, },
"repository": { "repository": {

View File

@ -1,28 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Pert</title>
<meta charset="utf-8">
<link rel="stylesheet" href="bower_components/vis/dist/vis.min.css">
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="bower_components/sweetalert/lib/sweet-alert.css">
<link rel="stylesheet" href="dist/style.css">
</head>
<body>
<div class="container">
<div id="pert"></div>
<div class="text-center">
<a href="index.html" class="btn btn-primary">Edit Data</a>
</div>
<!--<div id="timeline"></div>-->
</div>
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/sweetalert/lib/sweet-alert.js"></script>
<script src="bower_components/vis/dist/vis.min.js"></script>
<script src="bower_components/moment/moment.js"></script>
<script src="dist/pert.js"></script>
<script src="dist/pert-ui.js"></script>
</body>
</html>

67
src/app.coffee Normal file
View File

@ -0,0 +1,67 @@
pertApp = angular.module 'pertApp', ['ui.router']
pertApp.config ($stateProvider,$urlRouterProvider) ->
$urlRouterProvider.otherwise '/'
$stateProvider.state 'home',
url: '/'
templateUrl: 'dist/home.html'
controller: ($scope) ->
$scope.rawdata = localStorage.getItem 'ganttpert'
$stateProvider.state 'pert',
url: '/pert'
templateUrl: 'dist/pert.html'
controller: pertController
$('#save').click ->
console.log 'save'
localStorage.setItem 'ganttpert', $('#ta').val()
toDates = (list, startDay) ->
list.map (i) ->
r = content: ""+i.id, id: i.id
if i.startDay? then r.start = moment(startDay).add(i.startDay, 'days').format 'YYYY-MM-DD'
if i.endDay? then r.end = moment(startDay).add(i.endDay, 'days').format 'YYYY-MM-DD'
return r
pertController = ($scope) ->
console.log 'controller'
buildTimeline = (data) ->
timeline = new vis.Timeline (document.getElementById 'timeline'), (toDates data.activities), {}
buildGraph = (data) ->
nodes = data.days.map (x) -> {id: x, label: ""+x}
connections = []
data.activities.forEach (x) ->
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)+")"
color: if !x.permittedDelay then 'red'
if x.permittedDelay > 0
connections.push
from: x.endDay
to: x.endDay+x.permittedDelay
color: 'green'
label: x.id+" ("+x.permittedDelay+")"
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
fromLocalStorage = ->
data = localStorage.getItem 'ganttpert'
if data
try
jdata = JSON.parse data
catch e
return swal 'JSON Error', e, 'error'
if jdata
buildGraph new Pert(jdata).calculate()
else return swal 'Error', 'no JSON?', 'error'
else swal 'Error', 'no data to parse', 'error'
fromLocalStorage()

5
src/home.html Normal file
View File

@ -0,0 +1,5 @@
<div class="home">
<textarea id="ta" class="form-control" rows="10">{{rawdata}}</textarea>
<button id="save" class="btn btn-primary">Save</button>
<a href="#/pert" class="btn btn-success">View Pert</a>
</div>

View File

@ -1,7 +0,0 @@
console.log 'Pert ui'
$('#ta').val localStorage.getItem 'ganttpert'
$('#save').click ->
console.log 'save'
localStorage.setItem 'ganttpert', $('#ta').val()

View File

@ -1,47 +0,0 @@
console.log 'Pert ui'
toDates = (list, startDay) ->
list.map (i) ->
r = content: ""+i.id, id: i.id
if i.startDay? then r.start = moment(startDay).add(i.startDay, 'days').format 'YYYY-MM-DD'
if i.endDay? then r.end = moment(startDay).add(i.endDay, 'days').format 'YYYY-MM-DD'
return r
buildTimeline = (data) ->
timeline = new vis.Timeline (document.getElementById 'timeline'), (toDates data.activities), {}
buildGraph = (data) ->
nodes = data.days.map (x) -> {id: x, label: ""+x}
connections = []
data.activities.forEach (x) ->
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)+")"
color: if !x.permittedDelay then 'red'
if x.permittedDelay > 0
connections.push
from: x.endDay
to: x.endDay+x.permittedDelay
color: 'green'
label: x.id+" ("+x.permittedDelay+")"
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
fromLocalStorage = ->
data = localStorage.getItem 'ganttpert'
if data
try
jdata = JSON.parse data
catch e
return swal 'JSON Error', e, 'error'
if jdata
buildGraph new Pert(jdata).calculate()
else return swal 'Error', 'no JSON?', 'error'
else swal 'Error', 'no data to parse', 'error'
fromLocalStorage()

View File

@ -72,5 +72,4 @@ class Pert
else else
if cb? then cb(results) if cb? then cb(results)
results results
if module? then module.exports = Pert if module? then module.exports = Pert

6
src/pert.html Normal file
View File

@ -0,0 +1,6 @@
<div>
<div id="pert"></div>
<div class="text-center">
<a href="#/" class="btn btn-primary">Edit Data</a>
</div>
</div>