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.

132 lines
4.0 KiB

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