diff --git a/README.md b/README.md index f88cb40..926251c 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,17 @@ Minimal plugin that aims to make tracking your time with Redmine much easier.  +## Changes in this fork + +This is a fork of [jkraemer/stopwatch](https://github.com/jkraemer/stopwatch), modified by +Rick Barrette (2026): + +- **Redmine 7:** requires Redmine 7.0+. The issue context-menu Start/Stop entry now uses Redmine 7's + `view_issues_context_menu_start` hook instead of patching `ContextMenusController` (July 2026). +- **Colour-coded Start/Stop:** an optional setting ("Color-code Start/Stop") shows the issue Start + link in green and Stop in red, with tinted buttons on mobile (March 2026; colours adjusted for + readable contrast in October 2026). + ## Installation Add the plugin to your Redmine installation's `plugins` folder, run `bundle diff --git a/app/views/stopwatch/_settings.html.erb b/app/views/stopwatch/_settings.html.erb index 7d08f64..fe715de 100644 --- a/app/views/stopwatch/_settings.html.erb +++ b/app/views/stopwatch/_settings.html.erb @@ -5,5 +5,6 @@
- <%= check_box_tag 'settings[highlighted_links]', 1, Setting.plugin_stopwatch[:highlighted_links] %> + <%= hidden_field_tag 'settings[highlighted_links]', '0', id: nil %> + <%= check_box_tag 'settings[highlighted_links]', '1', Stopwatch.highlighted_links, id: 'settings_highlighted_links' %>
\ No newline at end of file diff --git a/assets/stylesheets/highlighted_links.css b/assets/stylesheets/highlighted_links.css index 7f5c5c7..6abd1f5 100644 --- a/assets/stylesheets/highlighted_links.css +++ b/assets/stylesheets/highlighted_links.css @@ -1,22 +1,27 @@ -a.stopwatch_issue_timer[href*="stop"] { - color: red; +/* Colour-codes the issue Start/Stop tracking links (enabled in the plugin settings). + Matches the end of the link address, which stopwatch.js rewrites between ".../timer/start" and + ".../timer/stop" when a timer starts or stops, so the colour always follows the link. + Colours meet the 4.5:1 contrast ratio for readable text, on white and on the mobile backgrounds. */ + +a.stopwatch_issue_timer[href$="/timer/stop"] { + color: #c62828; } -a.stopwatch_issue_timer[href*="start"] { - color: limegreen; +a.stopwatch_issue_timer[href$="/timer/start"] { + color: #2e7d32; } /* Mobile only */ @media (max-width: 899px) { - a.stopwatch_issue_timer[href*="stop"] { - color: red; + a.stopwatch_issue_timer[href$="/timer/stop"] { + color: #c62828; background-color: #ffe5e5; - border: 1px solid red; + border: 1px solid #c62828; } - a.stopwatch_issue_timer[href*="start"] { - color: limegreen; - background-color: #eaffea; - border: 1px solid limegreen; + a.stopwatch_issue_timer[href$="/timer/start"] { + color: #2e7d32; + background-color: #eaffea; + border: 1px solid #2e7d32; } -} \ No newline at end of file +} diff --git a/init.rb b/init.rb index e54f12a..ed5a8d0 100644 --- a/init.rb +++ b/init.rb @@ -8,6 +8,7 @@ Redmine::Plugin.register :stopwatch do requires_redmine version_or_higher: '7.0.0' settings default: { 'default_activity' => 'always_ask', + 'highlighted_links' => '0', }, partial: 'stopwatch/settings' menu :account_menu, :stopwatch, diff --git a/lib/stopwatch.rb b/lib/stopwatch.rb index 4ab9e0b..0d1a11a 100644 --- a/lib/stopwatch.rb +++ b/lib/stopwatch.rb @@ -41,7 +41,8 @@ module Stopwatch end end + # Colour-code the issue Start/Stop links (green to start, red to stop) def self.highlighted_links - settings[:highlighted_links] + settings['highlighted_links'].to_s == '1' end end diff --git a/lib/stopwatch/hooks.rb b/lib/stopwatch/hooks.rb index e981576..64111f7 100644 --- a/lib/stopwatch/hooks.rb +++ b/lib/stopwatch/hooks.rb @@ -17,17 +17,17 @@ module Stopwatch issue = issues.first return '' unless User.current.allowed_to?(:log_time, issue.project) - # 'controller' in this context gives access to view helper context - view = context[:controller].view_context + # hook_caller is the view rendering the context menu + view = context[:hook_caller] timer = Stopwatch::IssueTimer.new(issue: issue) - + link = if timer.running? IssueLinks.new(issue, view).stop_timer else IssueLinks.new(issue, view).start_timer end - view.content_tag(:li, link.html_safe) + view.content_tag(:li, link) end end end