You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.7 KiB

  1. angular.module('workApp', ['chart.js'])
  2. .controller('workController', function(
  3. $scope,
  4. $interval
  5. ) {
  6. $scope.username="user";
  7. //localStorage.clear();
  8. $scope.working=false;
  9. $scope.projects=[];
  10. $scope.currentproject={};
  11. if(localStorage.getItem("w_l_projects"))
  12. {
  13. $scope.projects=JSON.parse(localStorage.getItem("w_l_projects")); //w_local_
  14. }
  15. if($scope.projects.length>0)
  16. {
  17. $scope.newproject={
  18. id: $scope.projects[$scope.projects.length-1].id+1,
  19. chart: {
  20. labels: [],
  21. series: ['Working time'],
  22. data: []
  23. }
  24. };
  25. }else{
  26. $scope.newproject={
  27. id: 0,
  28. chart: {
  29. labels: [],
  30. series: ['Working time'],
  31. data: []
  32. }
  33. };
  34. }
  35. //$scope.newproject.id=$scope.projects[$scope.projects.length-1].id+1;
  36. $scope.addNewProject = function(){
  37. $scope.newproject.totaltime="0";
  38. $scope.projects.push($scope.newproject);
  39. localStorage.setItem("w_l_projects", angular.toJson($scope.projects));
  40. $scope.newproject={
  41. id: $scope.projects[$scope.projects.length-1].id+1,
  42. chart: {
  43. labels: [],
  44. series: ['Working time'],
  45. data: []
  46. }
  47. };
  48. };
  49. $scope.editingIndex="";
  50. $scope.editProject = function(index){
  51. $scope.editingIndex=index;
  52. $scope.editingProject=angular.copy($scope.projects[index]);
  53. };
  54. $scope.cancelEditProject = function(){
  55. $scope.editingProject=false;
  56. };
  57. $scope.updateProject = function(){
  58. $scope.projects[$scope.editingIndex]=angular.copy($scope.editingProject);
  59. $scope.currentproject=angular.copy($scope.editingProject);
  60. $scope.editingProject=false;
  61. };
  62. $scope.removeProject = function(index){
  63. $scope.projects.splice(index, 1);
  64. localStorage.setItem("w_l_projects", angular.toJson($scope.projects));
  65. $scope.projectSelect(0);
  66. };
  67. $scope.projectSelect = function(index){
  68. $scope.btnStop();
  69. $scope.currentproject=$scope.projects[index];
  70. };
  71. var interval;
  72. $scope.currentStrike=0;
  73. $scope.btnWork = function(){
  74. $scope.editingProject=false;
  75. $scope.working=true;
  76. $scope.currentStrike=0;
  77. interval = $interval(function(){
  78. $scope.currentStrike++;
  79. $scope.currentproject.totaltime++;
  80. }, 1000);
  81. };
  82. $scope.btnStop = function(){
  83. $interval.cancel(interval);
  84. if($scope.working==true)
  85. {
  86. $scope.working=false;
  87. $scope.currentproject.chart.labels.push("work strike " + $scope.currentproject.chart.labels.length);
  88. $scope.currentproject.chart.data.push($scope.currentStrike);
  89. localStorage.setItem("w_l_projects", angular.toJson($scope.projects));
  90. }
  91. }
  92. $scope.openCode = function(){
  93. toastr.info("Visiting code");
  94. var urlCode="https://github.com/idoctnef/openworktime";
  95. if(typeof process !== 'undefined'){
  96. console.log(process.versions['electron']);
  97. const {shell} = require('electron');
  98. shell.openExternal(urlCode);
  99. }else{
  100. window.open(urlCode);
  101. }
  102. };
  103. //chart
  104. /*$scope.chart={
  105. labels: ['A', 'B', 'C', 'D', 'E', 'F', 'G'],
  106. series: ['Working time', 'Series B'],
  107. data: [
  108. [65, 59, 80, 81, 56, 55, 40],
  109. [28, 48, 40, 19, 86, 27, 90]
  110. ]
  111. };*/
  112. })
  113. .filter('secondsToDateTime', [function() {
  114. return function(seconds) {
  115. return new Date(2016, 0, 1).setSeconds(seconds);
  116. };
  117. }]);