start/stop tracking: issue context menu entry

This commit is contained in:
Jens Kraemer
2021-10-05 10:27:09 +08:00
parent 033e1739d2
commit 78e47f5b75
4 changed files with 34 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
<% if @started_time_entry %> <% if @started_time_entry %>
contextMenuHide();
window.stopwatch.timerStarted( window.stopwatch.timerStarted(
<%= raw Stopwatch::Timer.new(User.current).to_json %> <%= raw Stopwatch::Timer.new(User.current).to_json %>
); );

View File

@@ -1,3 +1,4 @@
contextMenuHide();
window.stopwatch.updateStartStopLink( window.stopwatch.updateStartStopLink(
'#stopwatch_stop_timer_<%= @issue.id %>', '#stopwatch_stop_timer_<%= @issue.id %>',
'<%= j Stopwatch::IssueLinks.new(@issue).start_timer %>' '<%= j Stopwatch::IssueLinks.new(@issue).start_timer %>'

View File

@@ -22,8 +22,9 @@ Redmine::Plugin.register :stopwatch do
end end
Rails.configuration.to_prepare do Rails.configuration.to_prepare do
Stopwatch::UserPatch.apply Stopwatch::ContextMenusControllerPatch.apply
Stopwatch::TimeEntryPatch.apply
Stopwatch::IssuesControllerPatch.apply Stopwatch::IssuesControllerPatch.apply
Stopwatch::TimeEntryPatch.apply
Stopwatch::UserPatch.apply
end end

View File

@@ -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