diff --git a/app/coffeescripts/time_log/angular-code.coffee b/app/coffeescripts/time_log/angular-code.coffee index ff14160..a3f23c6 100644 --- a/app/coffeescripts/time_log/angular-code.coffee +++ b/app/coffeescripts/time_log/angular-code.coffee @@ -14,6 +14,7 @@ class @TasksController {year, month, date} = $routeParams @currentDate = new Date(year, month, date) @$xhr "get", "/api/tasks/#{year}/#{parseInt(month) + 1}/#{date}", (code, @tasks)=> + setInterval (=> @$apply(->)), 1000 TaskViewHelper: isCompleted:(task)-> !! task.completedAt @@ -32,15 +33,13 @@ 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:-> + (task for task in (@tasks or []) when (task.title is "Start")).length > 0 + + timeSinceStart:-> + - hasStarted:(tasks = [])-> - (task for task in tasks when (task.title is "Start")).length > 0 - createTask:(task)-> @$xhr "post", "/api/tasks", task, (code, data)=> @tasks.push data @@ -68,20 +67,30 @@ class @TasksController loadData:-> @$location.path "/tasks/#{@currentDate.getFullYear()}/#{@currentDate.getMonth()}/#{@currentDate.getDate()}" - totalDurations:-> + totalDurations:(condition)-> + condition ||= (->true) duration = 0 for task in (@tasks or []) - if task.duration + if task.duration and condition(task) duration += task.duration duration + totalUntagged:-> + totalDurations ((task)-> task.tag is null or task.tag.length < 1) + + totalTagged:(tag)-> + totalDurations ((task)-> task.tag is tag) + lastCompletedAt:-> maxCompletedAt = 0 - for task in @tasks + for task in (@tasks or []) if task.completedAt and task.completedAt > maxCompletedAt maxCompletedAt = task.completedAt maxCompletedAt + timeSinceStart:-> + Math.floor((@timeStamp() - @lastCompletedAt()) / 1000) + TasksController.$inject = ['$xhr', '$routeParams', '$location'] class @TaskController @@ -100,8 +109,8 @@ class @TaskController @createTask @task finish:-> + @task.duration = Math.floor((@timeStamp() - @lastCompletedAt()) / 1000) @task.completedAt = @timeStamp() - @task.duration = Math.floor((@lastCompletedAt() - @timeStamp()) / 1000) @update() unFinish:-> diff --git a/lib/server.rb b/lib/server.rb index bfa2264..7064884 100644 --- a/lib/server.rb +++ b/lib/server.rb @@ -46,11 +46,9 @@ class DemoApp < Sinatra::Base get "/api/tasks/:year/:month/:date" do |year, month, date| content_type :json - #puts @db.members tasks_for_today = @db.members.select do |task| # NOTE: JavaScript stores dates in milliseconds. time = Time.at task['createdAt'].to_i/1000 - puts time.year, time.month, time.day if time.year == year.to_i && time.month == month.to_i && time.day == date.to_i true else diff --git a/public/inside.html b/public/inside.html index 2e24a85..eac9a36 100644 --- a/public/inside.html +++ b/public/inside.html @@ -12,11 +12,11 @@

{{currentDate.toLocaleDateString()}}

-

+

tracking my time

-

+

No tasks were tracked on this day

@@ -29,13 +29,19 @@ -
+
Total
+
+
+ has elapsed +
+
+
- +