1// public/core.js 2var galton = angular.module('galton', []); 3 4// configure our routes 5galton.config(function ($routeProvider) 6 { 7 $routeProvider 8 9 // route for the projects page 10 .when('/', { 11 templateUrl: '/static/projects.html', 12 controller: 'mainController' 13 }) 14 15 // route for the project report 16 .when('/report/:projectId', { 17 templateUrl: '/static/report.html', 18 controller: 'reportController' 19 }) 20 21 // route for the project editor 22 .when('/edit/:projectId', { 23 templateUrl: '/static/editor.html', 24 controller: 'reportController' 25 }); 26 }); 27 28galton.filter('onlyIncluded', function() { 29 return function(tasks) { 30 var onlyIncluded = []; 31 32 for (var i in tasks) { 33 var task = tasks[i]; 34 35 if (task.include) { 36 onlyIncluded.push(task); 37 } 38 } 39 40 return onlyIncluded; 41 }; 42}); 43 44galton.controller('mainController', 45 function ($scope, $http, $location) { 46 $scope.formData = {}; 47 48 $http.get('/login') 49 .success(function (data) { 50 $scope.session = data; 51 console.log(data); 52 }) 53 .error(function (data) { 54 console.log('Error: ' + data); 55 }); 56 57 // when landing on the page, get all todos and show them 58 $http.get('/api/projects') 59 .success(function (data) { 60 $scope.projects = data; 61 console.log(data); 62 }) 63 .error(function (data) { 64 console.log('Error: ' + data); 65 }); 66 67 $scope.createProject = function() { 68 //console.log('create project: ' + $scope.formData); 69 $http.post('/api/project/create', $scope.formData) 70 .success(function(id) { 71 console.log('create success ' + id); 72 73 if (id > 0) { 74 $location.path("/edit/" + id); 75 } 76 }); 77 }; 78 79 $scope.copyProject = function (projectId) { 80 81 $http.get('/api/project/copy/' + projectId) 82 .success(function (id) { 83 84 if (id > 0) { 85 $location.path("/edit/" + id); 86 } 87 }) 88 .error(function (data) { 89 console.log('Error: ' + data); 90 }); 91 }; 92 }); 93 94galton.controller('reportController', 95 function ($scope, $http, $routeParams, $location) { 96 97 var title; 98 var units; 99 100 $scope.taskNone = { description: 'no risk', count: 1, estimate: 10, risk: 'none', include: true }; 101 $scope.taskLow = { description: 'low risk', count: 1, estimate: 10, risk: 'low', include: true }; 102 $scope.taskMedium = { description: 'medium risk', count: 1, estimate: 10, risk: 'medium', include: true }; 103 $scope.taskHigh = { description: 'high risk', count: 1, estimate: 10, risk: 'high', include: true }; 104 $scope.taskVeryHigh = { description: 'very high risk', count: 1, estimate: 10, risk: 'very high', include: true }; 105 106 $scope.getProject = function() { 107 $http.get('/api/project/' + $routeParams.projectId) 108 .success(function(data) { 109 if (data.length == 1) { 110 $scope.project = data[0]; 111 112 // convert ints to booleans for angular 113 $scope.project.publish = !!$scope.project.publish; 114 115 // chart config 116 title = $scope.project.description; 117 units = $scope.project.units; 118 119 $scope.status = ""; 120 } 121 }) 122 .error(function(data) { 123 console.log('Error: ' + data); 124 }); 125 }; 126 127 $scope.getTasks = function() { 128 $http.get('/api/tasks/' + $routeParams.projectId) 129 .success(function(data) { 130 $scope.tasks = data; 131 132 // convert ints to booleans for angular 133 for (var i in $scope.tasks) { 134 var task = $scope.tasks[i]; 135 task.include = !!task.include; 136 console.log(task); 137 }; 138 139 //console.log('tasks...'); 140 //console.log(data); 141 142 $scope.newtask = { description: 'new task', count: 1, estimate: 1, risk: 'medium', include: false }; 143 }) 144 .error(function(data) { 145 console.log('Error: ' + data); 146 }); 147 }; 148 149 var resetChart = function () { 150 $scope.results = 0; 151 document.getElementById('graph').innerHTML = 'loading simulation results...'; 152 }; 153 154 $scope.runSimulation = function () { 155 156 resetChart(); 157
158 $http.get('/api/results/' + $routeParams.projectId) 159 .success(function(data) { 160 $scope.results = data; 161 162 console.log('results...'); 163 console.log(data); 164 165 if (data.schedule) { 166 drawSchedule(title, data.schedule); 167 } else { 168 drawChart(title, units, data.cumprob); 169 } 170 }) 171 .error(function(data) { 172 console.log('Error: ' + data); 173 }); 174 }; 175 176 $scope.resetProject = function() { 177 $scope.getProject(); 178 $scope.getTasks(); 179 $scope.runSimulation(); 180 }; 181 182 // Run project, tasks and run the simulation on entry 183 $scope.resetProject(); 184 185 $scope.projectChanged = function() { 186 $scope.status = "changes pending"; 187 }; 188 189 $scope.saveProject = function () { 190 191 $scope.status = "saving project..."; 192 193 var saveTasks = []; 194 195 for (var i in $scope.tasks) { 196 var task = $scope.tasks[i]; 197 198 if (!task.remove) { 199 saveTasks.push(task); 200 } 201 } 202 203 if ($scope.newtask.include) { 204 saveTasks.push($scope.newtask); 205 } 206 207 $http.post('/api/project/save', { project: $scope.project, tasks: saveTasks }) 208 .success(function (data) { 209 $scope.resetProject(); 210 }) 211 .error(function (data) { 212 console.log('Error: ' + data); 213 $scope.status = 'Error: ' + data; 214 }); 215 }; 216 217 $scope.copyProject = function () { 218 219 var projectId = $scope.project.id; 220 221 $http.get('/api/project/copy/' + projectId) 222 .success(function (id) { 223 224 if (id > 0) { 225 $location.path("/edit/" + id); 226 } 227 }) 228 .error(function (data) { 229 console.log('Error: ' + data); 230 }); 231 232 }; 233 234 $scope.deleteProject = function () { 235 236 var projectId = $scope.project.id; 237 var description = $scope.project.description; 238 239 if (!confirm('Delete project "' + description + '" irreversibly?')) { 240 return; 241 } 242 243 $http.get('/api/project/delete/' + projectId) 244 .success(function (id) { 245 246 if (id == projectId) { 247 $location.path("/"); 248 } 249 }) 250 .error(function (data) { 251 console.log('Error: ' + data); 252 }); 253 254 }; 255 256 $scope.runProject = function () { 257 258 resetChart(); 259 260 $http.post('/api/simulate/project', { project: $scope.project, tasks: $scope.tasks }) 261 .success(function (data) { 262 $scope.results = data; 263 264 console.log('results...'); 265 console.log(data); 266 267 if (data.schedule) { 268 drawSchedule(title, data.schedule); 269 } else { 270 drawChart(title, units, data.cumprob); 271 } 272 }) 273 .error(function (data) { 274 console.log('Error: ' + data); 275 $scope.status = 'Error: ' + data; 276 }); 277 }; 278 279 $scope.runTask = function(task) { 280 281 resetChart(); 282 283 $http.post('/api/simulate/task', { project: $scope.project, tasks: [task] }) 284 .success(function (data) { 285 $scope.results = data; 286 287 console.log('results...'); 288 console.log(data); 289 290 var chartTitle = 'task: ' + task.description; 291 292 if (data.schedule) { 293 drawSchedule(chartTitle, data.schedule); 294 } else { 295 drawChart(chartTitle, units, data.cumprob); 296 } 297 }) 298 .error(function (data) { 299 console.log('Error: ' + data); 300 $scope.status = 'Error: ' + data; 301 }); 302 }; 303 }); 304 305 306function drawChart(title, units, myData) { 307 var myChart = new JSChart('graph', 'line'); 308 309 myChart.setSize(800, 600); 310 myChart.setDataArray(myData); 311 myChart.setLineSpeed(100); 312 myChart.setLineColor('#8D9386'); 313 myChart.setLineWidth(4); 314 myChart.setTitleColor('#7D7D7D'); 315 myChart.setAxisColor('#9F0505'); 316 myChart.setGridColor('#a4a4a4'); 317 myChart.setAxisValuesColor('#333639'); 318 myChart.setAxisNameColor('#333639'); 319 myChart.setTextPaddingLeft(0); 320 myChart.setAxisNameX(sprintf("Effort (%s)", units)); 321 myChart.setAxisNameY("Confidence"); 322 myChart.setTitle(title); 323 myChart.draw(); 324}; 325 326function drawSchedule(title, myData) { 327 var myChart = new JSChart('graph', 'line'); 328 329 myChart.setSize(800, 600); 330 myChart.setDataArray(myData); 331 myChart.setLineSpeed(100); 332 myChart.setLineColor('#8D9386'); 333 myChart.setLineWidth(4); 334 myChart.setTitleColor('#7D7D7D'); 335 myChart.setAxisColor('#9F0505'); 336 myChart.setGridColor('#a4a4a4'); 337 myChart.setAxisValuesColor('#333639'); 338 myChart.setAxisNameColor('#333639'); 339 myChart.setTextPaddingLeft(0); 340 myChart.setAxisPaddingBottom(80); 341 myChart.setAxisNameX('Date'); 342 myChart.setAxisValuesAngle(45); 343 myChart.setAxisNameY("Confidence"); 344 //myChart.setAxisValuesNumberX(10); 345 //myChart.setShowXValues(false); 346 myChart.setAxisValuesNumberY(11); 347 myChart.setTitle(title); 348 myChart.draw(); 349};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.