diff --git a/bower.json b/bower.json index 4af0234..f0c2326 100644 --- a/bower.json +++ b/bower.json @@ -20,6 +20,8 @@ "jquery": "~2.1.3", "moment": "~2.9.0", "bootstrap": "~3.3.4", - "sweetalert": "~0.5.0" + "sweetalert": "~0.5.0", + "angular": "~1.3.15", + "angular-ui-router": "~0.2.13" } } diff --git a/gulpfile.js b/gulpfile.js index 04698e4..a422bcc 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,5 +1,6 @@ var gulp = require('gulp') var minifyCSS = require('gulp-minify-css') +var minifyHTML = require('gulp-minify-html') var coffee = require('gulp-coffee') var uglify = require('gulp-uglify') var clean = require('gulp-clean') @@ -10,10 +11,16 @@ gulp.task('css',function(){ .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(){ return gulp.src('src/*.coffee') .pipe(coffee({ bare: true })) - .pipe(uglify()) + .pipe(uglify({ mangle: false })) .pipe(gulp.dest('dist/')) }) @@ -24,5 +31,6 @@ gulp.task('clean',function(){ gulp.task('watch',function(){ gulp.watch('src/*.coffee',['coffee']) gulp.watch('src/*.css',['css']) + gulp.watch('src/*.html',['html']) }) -gulp.task('default',['css','coffee']) +gulp.task('default',['html','css','coffee']) diff --git a/index.html b/index.html index 34630ac..0ae444a 100644 --- a/index.html +++ b/index.html @@ -1,21 +1,19 @@ - + Pert + + + + + + - -
- - - View Pert -
- - - +
diff --git a/package.json b/package.json index 75bd92b..2f93db7 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "gulp-clean": "^0.3.1", "gulp-coffee": "^2.3.1", "gulp-minify-css": "^1.0.0", + "gulp-minify-html": "^1.0.2", "gulp-uglify": "^1.1.0" }, "repository": { diff --git a/pert.html b/pert.html deleted file mode 100644 index cab93b0..0000000 --- a/pert.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - Pert - - - - - - - - -
-
-
- Edit Data -
- -
- - - - - - - - - diff --git a/src/app.coffee b/src/app.coffee new file mode 100644 index 0000000..572757a --- /dev/null +++ b/src/app.coffee @@ -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() diff --git a/src/home.html b/src/home.html new file mode 100644 index 0000000..cae0fcd --- /dev/null +++ b/src/home.html @@ -0,0 +1,5 @@ +
+ + + View Pert +
diff --git a/src/index.coffee b/src/index.coffee deleted file mode 100644 index 7b65057..0000000 --- a/src/index.coffee +++ /dev/null @@ -1,7 +0,0 @@ -console.log 'Pert ui' - -$('#ta').val localStorage.getItem 'ganttpert' - -$('#save').click -> - console.log 'save' - localStorage.setItem 'ganttpert', $('#ta').val() diff --git a/src/pert-ui.coffee b/src/pert-ui.coffee deleted file mode 100644 index b15cc35..0000000 --- a/src/pert-ui.coffee +++ /dev/null @@ -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() diff --git a/src/pert.coffee b/src/pert.coffee index 8c025f7..02f14e5 100644 --- a/src/pert.coffee +++ b/src/pert.coffee @@ -72,5 +72,4 @@ class Pert else if cb? then cb(results) results - if module? then module.exports = Pert diff --git a/src/pert.html b/src/pert.html new file mode 100644 index 0000000..344fd8a --- /dev/null +++ b/src/pert.html @@ -0,0 +1,6 @@ +
+
+
+ Edit Data +
+