@@ -14,6 +14,7 @@ class @TasksController
14
14
{year , month , date } = $routeParams
15
15
@currentDate = new Date (year, month, date)
16
16
@ $xhr " get" , " /api/tasks/#{ year} /#{ parseInt (month) + 1 } /#{ date} " , (code , @tasks )=>
17
+ setInterval (=> @ $apply (-> )), 1000
17
18
18
19
TaskViewHelper :
19
20
isCompleted : (task )-> !! task .completedAt
@@ -32,15 +33,13 @@ class @TasksController
32
33
startTimer : ->
33
34
task = {tag : null , title : " Start" , completedAt : @ timeStamp (), duration : 0 , createdAt : @ timeStamp ()}
34
35
@ createTask task
35
- @time = 0
36
- setInterval @tick , 1000
37
36
38
- tick : =>
39
- @time += 1000
37
+ hasStarted : ->
38
+ (task for task in (@tasks or []) when (task .title is " Start" )).length > 0
39
+
40
+ timeSinceStart : ->
41
+
40
42
41
- hasStarted : (tasks = [])->
42
- (task for task in tasks when (task .title is " Start" )).length > 0
43
-
44
43
createTask : (task )->
45
44
@ $xhr " post" , " /api/tasks" , task, (code , data )=>
46
45
@tasks .push data
@@ -68,20 +67,30 @@ class @TasksController
68
67
loadData : ->
69
68
@$location .path " /tasks/#{ @currentDate .getFullYear ()} /#{ @currentDate .getMonth ()} /#{ @currentDate .getDate ()} "
70
69
71
- totalDurations : ->
70
+ totalDurations : (condition )->
71
+ condition ||= (-> true )
72
72
duration = 0
73
73
for task in (@tasks or [])
74
- if task .duration
74
+ if task .duration and condition (task)
75
75
duration += task .duration
76
76
duration
77
77
78
+ totalUntagged : ->
79
+ totalDurations ((task )-> task .tag is null or task .tag .length < 1 )
80
+
81
+ totalTagged : (tag )->
82
+ totalDurations ((task )-> task .tag is tag)
83
+
78
84
lastCompletedAt : ->
79
85
maxCompletedAt = 0
80
- for task in @tasks
86
+ for task in ( @tasks or [])
81
87
if task .completedAt and task .completedAt > maxCompletedAt
82
88
maxCompletedAt = task .completedAt
83
89
maxCompletedAt
84
90
91
+ timeSinceStart : ->
92
+ Math .floor ((@ timeStamp () - @ lastCompletedAt ()) / 1000 )
93
+
85
94
TasksController .$inject = [' $xhr' , ' $routeParams' , ' $location' ]
86
95
87
96
class @TaskController
@@ -100,8 +109,8 @@ class @TaskController
100
109
@ createTask @task
101
110
102
111
finish : ->
112
+ @task .duration = Math .floor ((@ timeStamp () - @ lastCompletedAt ()) / 1000 )
103
113
@task .completedAt = @ timeStamp ()
104
- @task .duration = Math .floor ((@ lastCompletedAt () - @ timeStamp ()) / 1000 )
105
114
@ update ()
106
115
107
116
unFinish : ->
0 commit comments