pbs/controllers.js

1 line
5.6 KiB
JavaScript

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 iter)j=iter[i],id!==j.id&&id!==j.name&&l.push(j);else for(i in iter)j=iter[i],parseInt(i)!==index&&l.push(j);return diff=iter.length-l.length,isResource?newdata.resources=l:newdata.activities=l,$scope.toLocalStorage(newdata,{silent:!0}),1!==diff?swal("Done",diff+" item(s) deleted","warning"):void 0},$scope.addNew=function(isResource,id,dur,deps){var dep,e,error,error1,i,newdata,ref,ref1;if(null==dur&&(dur=isResource?$scope.resName:$scope.actDur),null==id&&(id=isResource?$scope.resID:$scope.actID),null==deps&&(deps=isResource?$scope.resAss:$scope.actDeps,deps=deps.split(" "),1===deps.length&&""===deps[0]&&(deps=[])),!isResource)try{dur=parseInt(dur)}catch(error){return e=error,swal("Error","duration must be an integer","error")}try{isNaN(id)||(id=parseInt(id))}catch(undefined){}for(i in deps){dep=deps[i];try{isNaN(dep)||(deps[i]=parseInt(dep))}catch(error1){e=error1}}return newdata=$scope.fromLocalStorage({silent:!0,raw:!0}),isResource?null!=(null!=newdata&&null!=(ref=newdata.resources)?ref.push:void 0)?(console.log(newdata.resources),newdata.resources.push({id:id,name:dur,assignedTo:deps}),$scope.toLocalStorage(newdata,{silent:!0})):console.log("wtf cant add, data broken"):null!=(null!=newdata&&null!=(ref1=newdata.activities)?ref1.push:void 0)?(newdata.activities.push({id:id,duration:dur,depends:deps}),$scope.toLocalStorage(newdata,{silent:!0})):console.log("wtf cant add, data broken")},$scope.refreshEditor=function(){var data;return data=$scope.fromLocalStorage({silent:!0,raw:!0}),$scope.activities=data.activities||[],$scope.resources=data.resources||[]},$scope.$on("dataChanged",$scope.refreshEditor),$scope.refreshEditor()});