mirror of
https://github.com/rickbarrette/stopwatch.git
synced 2026-11-17 11:50:36 -05:00
- Maximum timer length setting (default 10h): a timer that runs past it is stopped at the limit and its entry's comment is flagged, so a forgotten timer can't add a night or weekend of hours - StopwatchTimerTickJob saves a running timer's time every minute on the server (no browser needed) and stops it at the limit on time; open tabs keep saving too - Timer updates lock the user's preference row and re-read the timer, so simultaneous saves (several tabs, the job) never add time twice - Closing an issue stops timers running on it before anything else (e.g. billing) uses its time; deleting a time entry only stops the timer running on that entry - Issue timers require a visible issue; starting again moves the timer instead of raising "timer is already running" - Tests updated and extended (limit, locking, tick job, close, delete, visibility, issue context menu); CI runs on Redmine 7.0 - Upstream's German notes translated Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
52 lines
1.3 KiB
Ruby
52 lines
1.3 KiB
Ruby
class StopwatchIssueTimersController < StopwatchController
|
|
before_action :find_issue
|
|
before_action :authorize_log_time
|
|
|
|
def start
|
|
t = Stopwatch::IssueTimer.new(issue: @issue)
|
|
if t.running?
|
|
head 422; return
|
|
end
|
|
|
|
time_entry = User.current.todays_time_entry_for(@issue)
|
|
if time_entry.new_record?
|
|
sys_default_activity = time_entry.activity
|
|
time_entry.activity = Stopwatch.default_activity_for time_entry
|
|
end
|
|
|
|
r = Stopwatch::StartTimer.new(time_entry).call
|
|
if r.success?
|
|
@started_time_entry = time_entry
|
|
render status: :created
|
|
else
|
|
@time_entry = time_entry
|
|
# in case the setting is 'always ask', still preset the form to the global default
|
|
@time_entry.activity ||= sys_default_activity
|
|
@time_entry.errors.clear
|
|
render status: :ok
|
|
end
|
|
end
|
|
|
|
def stop
|
|
r = Stopwatch::StopTimer.new.call
|
|
unless r.success?
|
|
logger.error "unable to stop timer"
|
|
head 422; return
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def authorize_log_time
|
|
User.current.allowed_to?(:log_time, @project) or deny_access
|
|
end
|
|
|
|
# Only issues the user can see (log_time on the project alone isn't enough)
|
|
def find_issue
|
|
@issue = Issue.visible.find_by(id: params[:issue_id])
|
|
return render_404 unless @issue
|
|
|
|
@project = @issue.project
|
|
end
|
|
end
|