pbs/controllers.js

1 line
5.6 KiB
JavaScript
Raw Permalink Normal View History

2016-04-14 10:03:36 +02:00
var areYouSure,tableController;tableController=function($scope,getList){return $scope.list=[],$scope.refreshTable=function(){var data;return data=$scope.fromLocalStorage(),null!=data?$scope.list=getList(data):void 0},$scope.$on("dataChanged",$scope.refreshTable),$scope.refreshTable()},pertApp.controller("tableController",function($scope){return tableController($scope,function(data){return data.activities||[]})}),pertApp.controller("resourceTableController",function($scope){return tableController($scope,function(data){return data.resources||[]})}),pertApp.controller("pertDiagController",function($scope){return $scope.buildGraph=function(data){var connections,network,nodes,options;if(null!=data)return nodes=data.days.map(function(x){return{id:x,label:""+x}}),connections=[],data.activities.forEach(function(x){var maxDuration;return maxDuration=x.duration+(x.permittedDelay||0)+(x.chainedDelay||0),connections.push({from:x.startDay,to:x.endDay,label:x.id+" ("+(maxDuration!==x.duration?x.duration+"/"+maxDuration:x.duration)+")",color:x.critical?"red":x.permittedDelay?void 0:"orange"}),x.permittedDelay>0?connections.push({from:x.endDay,to:x.endDay+x.permittedDelay,color:"green",label:x.id+" ("+x.permittedDelay+")"}):void 0}),network?network.setData({nodes:nodes,edges:edges}):(options={edges:{style:"arrow"}},network=new vis.Network(document.getElementById("pertDiagram"),{nodes:nodes,edges:connections},options))},$scope.rebuild=function(){return $scope.buildGraph($scope.fromLocalStorage())},$scope.$on("dataChanged",$scope.rebuild),$scope.rebuild()}),pertApp.controller("ganttDiagController",function($scope){return $scope.toDates=function(list,startDay){return list.map(function(i){var r;return r={content:""+i.id,id:i.id},null!=i.startDay&&(r.start=moment(startDay).add(i.startDay,"days").format("YYYY-MM-DD")),null!=i.endDay&&(r.end=moment(startDay).add(i.endDay,"days").format("YYYY-MM-DD")),r})},$scope.buildTimeline=function(data){var timeline;if(null!=data)return timeline=new vis.Timeline(document.getElementById("timeline"),$scope.toDates(data.activities),{})},$scope.$on("dataChanged",function(){return $scope.buildTimeline($scope.fromLocalStorage())}),$scope.buildTimeline($scope.fromLocalStorage())}),areYouSure=function(text,cb){return swal({title:"Are you sure?",text:text,type:"warning",showCancelButton:!0,confirmButtonColor:"#DD6B55",confirmButtonText:"Yes",closeOnConfirm:!0},cb)},pertApp.controller("rawEditorController",function($scope){return $scope.reset=function(askConfirm){var doIt;return doIt=function(){return $scope.toLocalStorage({activities:[],resources:[]})},askConfirm?areYouSure("ALL data will be lost!",doIt):doIt()},$scope.saveData=function(askConfirm){var data,doIt,e,error;try{data=JSON.parse($scope.taData)}catch(error){return e=error,swal("Invalid Data",e,"error")}return doIt=function(){return $scope.toLocalStorage(data)},askConfirm?areYouSure("Current saved data will be replaced by the data in the RawEditor",doIt):doIt()},$scope.reloadData=function(askConfirm){var doIt;return doIt=function(){return $scope.taData=JSON.stringify($scope.fromLocalStorage({silent:!0,raw:!0}))},askConfirm?areYouSure("Current saved data will be replaced by the data in the RawEditor",doIt):doIt()},$scope.$on("dataChanged",$scope.reloadData),$scope.reloadData()}),pertApp.controller("editorController",function($scope){return $scope.activities=[],$scope.resources=[],$scope.actID="",$scope.actDur="",$scope.actDeps="",$scope.resID="",$scope.resName="",$scope.resAss="",$scope.clone=function(isResource,id){var data,i,j,l,ref;data=$scope.fromLocalStorage({raw:!0,silent:!0}),l=isResource?data.resources:data.activities,ref=$scope.fromLocalStorage({raw:!0,silent:!0}).activities;for(i in ref)if(j=ref[i],j.id===id)return $scope.addNew(j.id,j.duration,j.depends),void swal("Ok",id+" has been cloned","success");return swal("Ops","could not find "+id,"warning")},$scope["delete"]=function(isResource,index,id){var diff,i,iter,j,l,newdata;if(newdata=$scope.fromLocalStorage({raw:!0}),iter=isResource?newdata.resources:newdata.activities,l=[],null!=id)for(i in i