mirror of
https://github.com/rickbarrette/stopwatch.git
synced 2026-08-18 22:30:44 -04:00
Fixed Issues Context Menu
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
module Stopwatch
|
module Stopwatch
|
||||||
def self.setup
|
def self.setup
|
||||||
#Stopwatch::ContextMenusControllerPatch.apply
|
|
||||||
Stopwatch::IssuesControllerPatch.apply
|
Stopwatch::IssuesControllerPatch.apply
|
||||||
::TimeEntry.prepend Stopwatch::TimeEntryPatch
|
::TimeEntry.prepend Stopwatch::TimeEntryPatch
|
||||||
::User.prepend Stopwatch::UserPatch
|
::User.prepend Stopwatch::UserPatch
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
# 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, self).stop_timer
|
|
||||||
else
|
|
||||||
link << IssueLinks.new(issue, self).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
|
|
||||||
@@ -6,5 +6,28 @@ module Stopwatch
|
|||||||
partial: 'stopwatch/hooks/layouts_base_body_bottom'
|
partial: 'stopwatch/hooks/layouts_base_body_bottom'
|
||||||
render_on :view_time_entries_context_menu_start,
|
render_on :view_time_entries_context_menu_start,
|
||||||
partial: 'stopwatch/hooks/time_entries_context_menu_start'
|
partial: 'stopwatch/hooks/time_entries_context_menu_start'
|
||||||
|
|
||||||
|
# This hook is natively provided by Redmine 7's issues context menu view
|
||||||
|
def view_issues_context_menu_start(context = {})
|
||||||
|
issues = context[:issues]
|
||||||
|
|
||||||
|
# We only append our element if exactly one issue is highlighted
|
||||||
|
return '' unless issues&.one?
|
||||||
|
|
||||||
|
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
|
||||||
|
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)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user