mirror of
https://github.com/rickbarrette/stopwatch.git
synced 2026-11-17 19:50:36 -05:00
- Colour-coded Start/Stop links use #2e7d32 / #c62828, which meet the 4.5:1 text contrast ratio on white and on the mobile backgrounds (limegreen was ~2:1, red ~4:1) - Selectors match the end of the link address (/timer/start, /timer/stop), exactly what stopwatch.js rewrites, instead of any address containing "start"/"stop" - highlighted_links setting uses a string key like default_activity, has a default, and the form sends 0 when unticked - Context-menu hook uses the calling view (hook_caller) instead of building a new view context - README: "Changes in this fork" section (GPLv3 modification notice) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
49 lines
1.2 KiB
Ruby
49 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Stopwatch
|
|
def self.setup
|
|
Stopwatch::IssuesControllerPatch.apply
|
|
::TimeEntry.prepend Stopwatch::TimeEntryPatch
|
|
::User.prepend Stopwatch::UserPatch
|
|
Stopwatch::Hooks # just load it
|
|
end
|
|
|
|
def self.settings
|
|
Setting.plugin_stopwatch
|
|
end
|
|
|
|
def self.default_activity
|
|
if id = settings['default_activity'].presence
|
|
if id.to_s =~ /^\d+$/
|
|
TimeEntryActivity.find_by_id id
|
|
else
|
|
id
|
|
end
|
|
end
|
|
end
|
|
|
|
def self.default_activity_for(time_entry)
|
|
default = Stopwatch.default_activity
|
|
return nil if default == 'always_ask'
|
|
|
|
project = time_entry.project || time_entry.issue&.project
|
|
|
|
if project.nil?
|
|
activities = TimeEntryActivity.shared.active
|
|
else
|
|
activities = project.activities
|
|
end
|
|
|
|
if default == 'system'
|
|
activities.detect(&:is_default?) || activities.detect{|a| a.parent&.is_default?} || (activities.one? && activities[0]).presence
|
|
else
|
|
return activities.detect{ |a| a == default || a.parent == default }
|
|
end
|
|
end
|
|
|
|
# Colour-code the issue Start/Stop links (green to start, red to stop)
|
|
def self.highlighted_links
|
|
settings['highlighted_links'].to_s == '1'
|
|
end
|
|
end
|