Skip to content

Commit

Permalink
timing totals
Browse files Browse the repository at this point in the history
  • Loading branch information
ludicast committed Dec 10, 2011
1 parent 917c4ad commit 512d22e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
21 changes: 21 additions & 0 deletions app/coffeescripts/time_log/angular-code.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class @TasksController
startTimer:->
task = {tag:null, title:"Start", completedAt:@timeStamp(), duration:0, createdAt:@timeStamp()}
@createTask task
@time = 0
setInterval @tick, 1000

tick:=>
@time += 1000

hasStarted:(tasks = [])->
(task for task in tasks when (task.title is "Start")).length > 0
Expand Down Expand Up @@ -63,6 +68,20 @@ class @TasksController
loadData:->
@$location.path "/tasks/#{@currentDate.getFullYear()}/#{@currentDate.getMonth()}/#{@currentDate.getDate()}"

totalDurations:->
duration = 0
for task in (@tasks or [])
if task.duration
duration += task.duration
duration

lastCompletedAt:->
maxCompletedAt = 0
for task in @tasks
if task.completedAt and task.completedAt > maxCompletedAt
maxCompletedAt = task.completedAt
maxCompletedAt

TasksController.$inject = ['$xhr', '$routeParams', '$location']

class @TaskController
Expand All @@ -82,10 +101,12 @@ class @TaskController

finish:->
@task.completedAt = @timeStamp()
@task.duration = Math.floor((@lastCompletedAt() - @timeStamp()) / 1000)
@update()

unFinish:->
@task.completedAt = null
@task.duration = null
@update()

update:->
Expand Down
11 changes: 9 additions & 2 deletions public/inside.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@
<div class="title-done">{{task.title}}</div>
<div class="tag">{{task.tag}}</div>
</li>
</ul>

</ul>

<div class="clocks" ng:show="isToday() && hasStarted(tasks)">
<div class="total-clock">
<time class="total-duration">{{totalDurations() | formatSecondsAsTime}}</time>
<div class="total-time">Total</div>
</div>
</div>

<ul id="tasks-to-complete" ng:repeat="task in tasks.$filter(TaskViewHelper.isNotCompleted).$orderBy('createdAt', false)">
<li class="task" ng:show="!(task.deleted) && !(task.editing)" ng:controller="TaskController">
<input class="is-done" type="checkbox" ng:click="finish()" />
Expand Down

0 comments on commit 512d22e

Please sign in to comment.