arnaucube
arnaucube/openworktimePublic Self-hosted repository
openworktime/desktopapp/controllers.js
desktopapp/controllers.jsRaw
 1
 2angular.module('workApp', [])
 3  .controller('workController', function(
 4        $scope,
 5        $interval
 6    ) {
 7        $scope.username="user";
 8        //localStorage.clear();
 9        $scope.working=false;
10    $scope.projects=[];
11    $scope.currentproject={};
12    if(localStorage.getItem("w_l_projects"))
13    {
14        $scope.projects=JSON.parse(localStorage.getItem("w_l_projects")); //w_local_
15    }
16    if($scope.projects.length>0)
17    {
18        $scope.newproject={
19            id: $scope.projects[$scope.projects.length-1].id+1
20        };
21    }else{
22        $scope.newproject={
23            id: 0
24        };
25    }
26    //$scope.newproject.id=$scope.projects[$scope.projects.length-1].id+1;
27    $scope.addNewProject = function(){
28        $scope.newproject.totaltime="0";
29        $scope.projects.push($scope.newproject);
30        localStorage.setItem("w_l_projects", angular.toJson($scope.projects));
31        $scope.newproject={
32            id: $scope.projects[$scope.projects.length-1].id+1
33        };
34    };
35    $scope.removeProject = function(index){
36        $scope.projects.splice(index, 1);
37        localStorage.setItem("w_l_projects", angular.toJson($scope.projects));
38    };
39    $scope.projectSelect = function(index){
40        $scope.currentproject=$scope.projects[index];
41    };
42    var interval;
43    $scope.currentStrike=0;
44    $scope.btnWork = function(){
45        $scope.working=true;
46        $scope.currentStrike=0;
47        interval = $interval(function(){
48            $scope.currentStrike++;
49            $scope.currentproject.totaltime++;
50        }, 1000);
51    };
52    $scope.btnStop = function(){
53        $interval.cancel(interval);
54        $scope.working=false;
55        localStorage.setItem("w_l_projects", angular.toJson($scope.projects));
56
57    }
58
59    $scope.openCode = function(){
60        toastr.info("Visiting code");
61        var urlCode="https://github.com/idoctnef/openworktime";
62        if(typeof process !== 'undefined'){
63            console.log(process.versions['electron']);
64            const {shell} = require('electron');
65
66            shell.openExternal(urlCode);
67        }else{
68            window.open(urlCode);
69        }
70    };
71
72  })
73
74  .filter('secondsToDateTime', [function() {
75    return function(seconds) {
76        return new Date(2016, 0, 1).setSeconds(seconds);
77    };
78}]);