From 78e47f5b7574c4f72cc583be409718ca736c9c52 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Tue, 5 Oct 2021 10:27:09 +0800 Subject: [PATCH] start/stop tracking: issue context menu entry --- app/views/stopwatch_issue_timers/start.js.erb | 1 + app/views/stopwatch_issue_timers/stop.js.erb | 1 + init.rb | 5 ++-- .../context_menus_controller_patch.rb | 29 +++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 lib/stopwatch/context_menus_controller_patch.rb diff --git a/app/views/stopwatch_issue_timers/start.js.erb b/app/views/stopwatch_issue_timers/start.js.erb index 58ab882..83a4531 100644 --- a/app/views/stopwatch_issue_timers/start.js.erb +++ b/app/views/stopwatch_issue_timers/start.js.erb @@ -1,4 +1,5 @@ <% if @started_time_entry %> + contextMenuHide(); window.stopwatch.timerStarted( <%= raw Stopwatch::Timer.new(User.current).to_json %> ); diff --git a/app/views/stopwatch_issue_timers/stop.js.erb b/app/views/stopwatch_issue_timers/stop.js.erb index 19ce178..0df980b 100644 --- a/app/views/stopwatch_issue_timers/stop.js.erb +++ b/app/views/stopwatch_issue_timers/stop.js.erb @@ -1,3 +1,4 @@ +contextMenuHide(); window.stopwatch.updateStartStopLink( '#stopwatch_stop_timer_<%= @issue.id %>', '<%= j Stopwatch::IssueLinks.new(@issue).start_timer %>' diff --git a/init.rb b/init.rb index c592d68..fe6b7d5 100644 --- a/init.rb +++ b/init.rb @@ -22,8 +22,9 @@ Redmine::Plugin.register :stopwatch do end Rails.configuration.to_prepare do - Stopwatch::UserPatch.apply - Stopwatch::TimeEntryPatch.apply + Stopwatch::ContextMenusControllerPatch.apply Stopwatch::IssuesControllerPatch.apply + Stopwatch::TimeEntryPatch.apply + Stopwatch::UserPatch.apply end diff --git a/lib/stopwatch/context_menus_controller_patch.rb b/lib/stopwatch/context_menus_controller_patch.rb new file mode 100644 index 0000000..575e6c7 --- /dev/null +++ b/lib/stopwatch/context_menus_controller_patch.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Stopwatch + module ContextMenusControllerPatch + module Helper + def watcher_link(objects, user) + link = +'' + if params[:action] == 'issues' and + objects.one? and (issue = objects[0]).is_a?(Issue) and + User.current.allowed_to?(:log_time, issue.project) + t = Stopwatch::IssueTimer.new(issue: issue) + if t.running? + link << IssueLinks.new(issue).stop_timer + else + link << IssueLinks.new(issue).start_timer + end + end + super + content_tag(:li, link.html_safe) + end + end + + def self.apply + ContextMenusController.class_eval do + helper Helper + end + end + end +end +