Skip to content

Commit b65bed9

Browse files
author
Stephan Grobler
committed
Added moment and break timer
1 parent f489a26 commit b65bed9

File tree

478 files changed

+24471
-70966
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

478 files changed

+24471
-70966
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
],
2424
"dependencies": {
2525
"angular-route": "~1.2.16",
26-
"angular": "~1.2.16"
26+
"angular": "~1.2.16",
27+
"moment": "~2.7.0"
2728
}
2829
}

src/index.html

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<meta charset="UTF-8">
44
<title>Simple Task</title>
55
<link rel="stylesheet" href="/vendor/bootstrap/dist/css/bootstrap.css">
6-
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
6+
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
77
<link href='http://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'>
88
<style>
99
body {
@@ -23,18 +23,27 @@
2323
font-size: 28px;
2424
padding: 20px;
2525
border-radius: 200px;
26-
border: 1px solid #eee;
26+
border: 1px solid #ccc;
2727
margin: 20px 5px;
2828
}
29+
.running .action{
30+
border: 1px solid #eee;
31+
32+
}
2933
</style>
3034
</head>
3135
<body ng-controller="TaskCtrl" ng-init="load()">
3236
<div class="container">
37+
<div class="pull-right">
38+
<a class="action" href ng-hide="breakTime" ng-click="startBreak()"><span class="glyphicon glyphicon-cutlery"></span></a>
39+
<a class="action" href ng-hide="!breakTime" ng-class="{'running': breakTime}" ng-click="stopBreak()"><span class="glyphicon glyphicon-cutlery"></span></a>
40+
</div>
3341
<div class="page-header">
34-
<h1>Simple Task</h1>
35-
</div>
36-
<form action method="POST" name="taskForm" class="form-inline" role="form" novalidate>
42+
<h1>Simple Task</h1>
43+
44+
</div>
3745

46+
<form action method="POST" name="taskForm" class="form-inline" role="form" novalidate>
3847
<div class="form-group">
3948
<label for="inputTaskName" class="sr-only">Task Name:</label>
4049
<div class="">
@@ -58,11 +67,16 @@ <h1>Simple Task</h1>
5867
<li ng-repeat="task in tasks track by $index" ng-hide="task.archived" ng-class="{'day-seperator': task.newDay, 'running': task.running}" >
5968
<div class="row">
6069
<div class="col-xs-12 col-sm-9">
61-
<div width="45%"><h3>{{task.name}}&nbsp;<span class="small" ng-hide="!task.total">{{task.total | toTime}} </span></h3></div>
70+
<div width="45%">
71+
<h3>{{task.name}}&nbsp;
72+
<span class="small" ng-hide="task.running">{{task.total | toTime}} </span>
73+
<span class="small" ng-show="task.running">{{ task.runningTime | toTime}}</span>
74+
</h3>
75+
</div>
6276
<div><a href ng-click="displayTimes = !displayTimes">{{task.times.length}} time entries</a></div>
6377
<div>{{task.estimate}} hrs estimated</div>
6478
<div>
65-
<span ng-hide="!task.total">{{ timeLeft[$index] | toTime}}</span>
79+
6680
</div>
6781
</div>
6882
<div class="col-xs-12 col-sm-3 text-center">
@@ -73,6 +87,7 @@ <h1>Simple Task</h1>
7387
</div>
7488
<div class="row" ng-show="displayTimes">
7589
<div class="col-xs-12">
90+
{{task.times}}
7691
<ul class="list-unstyled">
7792
<li ng-repeat="time in task.times track by $index">
7893
Time Started: {{time.start | date:"yyyy-MM-dd HH:mm:ss"}} |
@@ -89,7 +104,7 @@ <h1>Simple Task</h1>
89104
<script src="/vendor/angular-route/angular-route.js"></script>
90105
<script type="text/javascript" src="/vendor/jquery/dist/jquery.js"></script>
91106
<script type="text/javascript" src="/vendor/bootstrap/dist/js/bootstrap.js"></script>
92-
<script type="text/javascript" src="/vendor/datejs/build/date.js"></script>
107+
<script type="text/javascript" src="/vendor/moment/moment.js"></script>
93108
<script type="text/javascript" src="/src/js/app.js"></script>
94109

95110
</body>

src/js/app.js

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,48 @@ angular.module('simpleTask', ['ngRoute'])
44

55
}
66
])
7-
.controller('TaskCtrl', ['$scope', 'Tasks',
8-
function($scope, Tasks) {
7+
.controller('TaskCtrl', ['$scope', 'Tasks', '$interval',
8+
function($scope, Tasks, $interval) {
99
Tasks.load();
10-
console.log(Tasks);
10+
1111
$scope.tasks = Tasks.tasks;
1212
$scope.createTask = function(task) {
1313
Tasks.createTask(task);
1414
$scope.task = null;
1515
};
1616
$scope.startTask = function(index) {
1717
Tasks.startTask(index);
18+
$scope.interval = $interval(function() {
19+
Tasks.runningTime(index);
20+
}, 1000);
1821
};
1922
$scope.stopTask = function(index){
2023
Tasks.stopTask(index);
24+
$interval.cancel($scope.interval);
2125
};
2226
$scope.removeTask = function(index){
2327
Tasks.removeTask(index);
2428
};
2529
$scope.archiveTask = function(index) {
2630
Tasks.archiveTask(index);
2731
};
28-
timing = function() {
29-
$timeout(function() {
30-
var now = Date.now();
31-
for (var i = tasks.length - 1; i >= 0; i--) {
32-
timeLeft[i] = now - tasks[i].start;
33-
}
34-
timing();
35-
}, 1000);
32+
$scope.startBreak = function(){
33+
Tasks.createTask({name: "Break", estimate: 0}, 'break');
34+
Tasks.startTask(0);
35+
Tasks.archiveTask(0);
36+
$scope.breakTime = true;
3637
};
38+
$scope.stopBreak = function(){
39+
Tasks.stopTask(0);
40+
$scope.breakTime = false;
41+
}
3742
}
3843
])
3944
.filter('toTime', function() {
4045
return function(input) {
4146
if (typeof input !== "undefined") {
42-
var milliseconds = parseInt((input % 1000) / 100, 10),
43-
seconds = parseInt((input / 1000) % 60, 10),
44-
minutes = parseInt((input / (1000 * 60)) % 60, 10),
45-
hours = parseInt((input / (1000 * 60 * 60)) % 24, 10);
46-
47-
hours = (hours < 10) ? "0" + hours : hours;
48-
minutes = (minutes < 10) ? "0" + minutes : minutes;
49-
seconds = (seconds < 10) ? "0" + seconds : seconds;
50-
return hours + ":" + minutes + ":" + seconds;
47+
var m = moment.duration(input);
48+
return m.get('h') + ":"+ m.get('m') +":"+ m.get('s');
5149
}
5250
};
5351
}).
@@ -72,51 +70,73 @@ factory('Tasks', function() {
7270
},
7371
persist: function() {
7472
if (Storage) {
75-
localStorage.setItem('tasks', JSON.stringify(tasks));
73+
localStorage.setItem('tasks', JSON.stringify(this.tasks));
7674
}
7775
},
78-
createTask: function(task) {
79-
tasks.unshift({
76+
createTask: function(task, type) {
77+
if (typeof type == "undefined") {
78+
type = 'work';
79+
}
80+
this.tasks.unshift({
8081
"name": task.name,
8182
"estimate": task.estimate,
82-
"times": []
83+
"type": type,
84+
"times": [],
85+
"total": 0
8386
});
8487
this.persist();
85-
task = null;
8688
},
87-
8889
startTask : function(index) {
89-
var start = Date.now();
90-
tasks[index].times.push({
90+
var start = moment().valueOf();
91+
this.tasks[index].times.push({
9192
"start": start,
9293
"end" : null
9394
});
94-
tasks[index].running = true;
95+
this.tasks[index].running = true;
9596
this.persist();
9697
},
97-
98+
runningTime: function(index){
99+
var task = this.tasks[index],
100+
latest = task.times.length - 1;
101+
task.runningTime = (moment().valueOf() - task.times[latest].start) + task.total;
102+
},
98103
removeTask: function(index) {
99-
tasks.splice(index, 1);
104+
this.tasks.splice(index, 1);
100105
this.persist();
101106
},
102107

103108
archiveTask: function(index) {
104-
tasks[index].archived = true;
109+
this.tasks[index].archived = true;
105110
this.persist();
106111
},
107112
stopTask: function(index) {
108-
var task = tasks[index],
113+
var task = this.tasks[index],
109114
timeToStop = task.times.length - 1;
110115
task.running = false;
111-
task.times[timeToStop].end = Date.now();
116+
task.times[timeToStop].end = moment().valueOf();
112117
this.calculateTime(index);
113118
this.persist();
114119
},
120+
115121
calculateTime: function(index){
116-
var task = tasks[index];
122+
var task = this.tasks[index];
117123
task.total = 0;
118124
for (var x = task.times.length - 1; x >= 0; x--) {
119-
task.total += task.times[x].end - task.times[x].start;
125+
task.times[x].total = task.times[x].end - task.times[x].start;
126+
task.total += task.times[x].total;
127+
}
128+
},
129+
getWorkTimes: function(){
130+
var workHrs = {};
131+
for (var x = this.tasks.length - 1; x >= 0; x--) {
132+
var task = this.tasks[x];
133+
if (task.type == "work") {
134+
// get days worked on
135+
for (var i = task.times.length - 1; i >= 0; i--) {
136+
var date = new Date(task.times[i].start);
137+
};
138+
var date = new Date()
139+
}
120140
}
121141
},
122142
getDailyTimes: function() {

vendor/datejs/.bower.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)