From 6c51ef795ad29907991dd3789f36127d0b2b5348 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Tue, 31 Aug 2021 14:24:24 +0800 Subject: [PATCH] always show the running timer in the timers list #5 --- app/controllers/stopwatch_timers_controller.rb | 4 +++- lib/stopwatch/user_patch.rb | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/stopwatch_timers_controller.rb b/app/controllers/stopwatch_timers_controller.rb index 76e9b10..8337cdc 100644 --- a/app/controllers/stopwatch_timers_controller.rb +++ b/app/controllers/stopwatch_timers_controller.rb @@ -86,7 +86,9 @@ class StopwatchTimersController < ApplicationController end def load_todays_entries - @entries = time_entries.where(spent_on: User.current.today).order(created_on: :asc) + @entries = time_entries.where(spent_on: User.current.today).or( + time_entries.where(id: User.current.running_time_entry_id) + ).order(created_on: :asc) end def time_entries diff --git a/lib/stopwatch/user_patch.rb b/lib/stopwatch/user_patch.rb index c0a5d36..63deb30 100644 --- a/lib/stopwatch/user_patch.rb +++ b/lib/stopwatch/user_patch.rb @@ -9,8 +9,13 @@ module Stopwatch end def is_running_timer?(time_entry) + id = running_time_entry_id + id.present? and time_entry.id == id + end + + def running_time_entry_id timer = Stopwatch::Timer.new(self) - timer.running? and timer.time_entry_id == time_entry.id + timer.time_entry_id if timer.running? end end end