Skip to content

Commit

Permalink
Add Context Menu Support
Browse files Browse the repository at this point in the history
Addresses request from #12
  • Loading branch information
Brett Patterson committed Mar 20, 2014
1 parent adfd738 commit 8e5aac5
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ This will move the selected category to the bottom of the list for that project

# Revision History

## 0.0.5

* Add support for context menus

## 0.0.4

* Add Russian translation of plugin (#7). Thanks to AndreyBronin for the translation.
Expand Down
139 changes: 139 additions & 0 deletions app/views/context_menus/issues.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<ul>
<%= call_hook(:view_issues_context_menu_start, {:issues => @issues, :can => @can, :back => @back }) %>

<% if @issue -%>
<li><%= context_menu_link l(:button_edit), edit_issue_path(@issue),
:class => 'icon-edit', :disabled => !@can[:edit] %></li>
<% else %>
<li><%= context_menu_link l(:button_edit), bulk_edit_issues_path(:ids => @issue_ids),
:class => 'icon-edit', :disabled => !@can[:edit] %></li>
<% end %>

<% if @allowed_statuses.present? %>
<li class="folder">
<a href="#" class="submenu"><%= l(:field_status) %></a>
<ul>
<% @allowed_statuses.each do |s| -%>
<li><%= context_menu_link h(s.name), bulk_update_issues_path(:ids => @issue_ids, :issue => {:status_id => s}, :back_url => @back), :method => :post,
:selected => (@issue && s == @issue.status), :disabled => !@can[:update] %></li>
<% end -%>
</ul>
</li>
<% end %>

<% if @trackers.present? %>
<li class="folder">
<a href="#" class="submenu"><%= l(:field_tracker) %></a>
<ul>
<% @trackers.each do |t| -%>
<li><%= context_menu_link h(t.name), bulk_update_issues_path(:ids => @issue_ids, :issue => {'tracker_id' => t}, :back_url => @back), :method => :post,
:selected => (@issue && t == @issue.tracker), :disabled => !@can[:edit] %></li>
<% end -%>
</ul>
</li>
<% end %>

<% if @safe_attributes.include?('priority_id') && @priorities.present? -%>
<li class="folder">
<a href="#" class="submenu"><%= l(:field_priority) %></a>
<ul>
<% @priorities.each do |p| -%>
<li><%= context_menu_link h(p.name), bulk_update_issues_path(:ids => @issue_ids, :issue => {'priority_id' => p}, :back_url => @back), :method => :post,
:selected => (@issue && p == @issue.priority), :disabled => (!@can[:edit] || @issues.detect {|i| !i.leaf?}) %></li>
<% end -%>
</ul>
</li>
<% end %>

<% if @safe_attributes.include?('fixed_version_id') && @versions.present? -%>
<li class="folder">
<a href="#" class="submenu"><%= l(:field_fixed_version) %></a>
<ul>
<% @versions.sort.each do |v| -%>
<li><%= context_menu_link format_version_name(v), bulk_update_issues_path(:ids => @issue_ids, :issue => {'fixed_version_id' => v}, :back_url => @back), :method => :post,
:selected => (@issue && v == @issue.fixed_version), :disabled => !@can[:update] %></li>
<% end -%>
<li><%= context_menu_link l(:label_none), bulk_update_issues_path(:ids => @issue_ids, :issue => {'fixed_version_id' => 'none'}, :back_url => @back), :method => :post,
:selected => (@issue && @issue.fixed_version.nil?), :disabled => !@can[:update] %></li>
</ul>
</li>
<% end %>

<% if @safe_attributes.include?('assigned_to_id') && @assignables.present? -%>
<li class="folder">
<a href="#" class="submenu"><%= l(:field_assigned_to) %></a>
<ul>
<% if @assignables.include?(User.current) %>
<li><%= context_menu_link "<< #{l(:label_me)} >>", bulk_update_issues_path(:ids => @issue_ids, :issue => {'assigned_to_id' => User.current}, :back_url => @back), :method => :post,
:disabled => !@can[:update] %></li>
<% end %>
<% @assignables.each do |u| -%>
<li><%= context_menu_link h(u.name), bulk_update_issues_path(:ids => @issue_ids, :issue => {'assigned_to_id' => u}, :back_url => @back), :method => :post,
:selected => (@issue && u == @issue.assigned_to), :disabled => !@can[:update] %></li>
<% end -%>
<li><%= context_menu_link l(:label_nobody), bulk_update_issues_path(:ids => @issue_ids, :issue => {'assigned_to_id' => 'none'}, :back_url => @back), :method => :post,
:selected => (@issue && @issue.assigned_to.nil?), :disabled => !@can[:update] %></li>
</ul>
</li>
<% end %>

<% if @safe_attributes.include?('category_id') && @project && @project.issue_categories.any? -%>
<li class="folder">
<a href="#" class="submenu"><%= l(:field_category) %></a>
<ul class="issue_category_tree">
<%= render_issue_category_tree_context_menu_list(@project.issue_categories, false) do |u| -%>
<%= context_menu_link h(u.name), bulk_update_issues_path(:ids => @issue_ids, :issue => {'category_id' => u}, :back_url => @back), :method => :post,
:selected => (@issue && u == @issue.category), :disabled => !@can[:update] %>
<% end -%>
<li><%= context_menu_link l(:label_none), bulk_update_issues_path(:ids => @issue_ids, :issue => {'category_id' => 'none'}, :back_url => @back), :method => :post,
:selected => (@issue && @issue.category.nil?), :disabled => !@can[:update] %></li>
</ul>
</li>
<% end -%>

<% if @safe_attributes.include?('done_ratio') && Issue.use_field_for_done_ratio? %>
<li class="folder">
<a href="#" class="submenu"><%= l(:field_done_ratio) %></a>
<ul>
<% (0..10).map{|x|x*10}.each do |p| -%>
<li><%= context_menu_link "#{p}%", bulk_update_issues_path(:ids => @issue_ids, :issue => {'done_ratio' => p}, :back_url => @back), :method => :post,
:selected => (@issue && p == @issue.done_ratio), :disabled => (!@can[:edit] || @issues.detect {|i| !i.leaf?}) %></li>
<% end -%>
</ul>
</li>
<% end %>

<% @options_by_custom_field.each do |field, options| %>
<li class="folder cf_<%= field.id %>">
<a href="#" class="submenu"><%= h(field.name) %></a>
<ul>
<% options.each do |text, value| %>
<li><%= bulk_update_custom_field_context_menu_link(field, text, value || text) %></li>
<% end %>
<% unless field.is_required? %>
<li><%= bulk_update_custom_field_context_menu_link(field, l(:label_none), '__none__') %></li>
<% end %>
</ul>
</li>
<% end %>

<% if User.current.logged? %>
<li><%= watcher_link(@issues, User.current) %></li>
<% end %>

<% if @issue.present? %>
<% if @can[:log_time] -%>
<li><%= context_menu_link l(:button_log_time), new_issue_time_entry_path(@issue),
:class => 'icon-time-add' %></li>
<% end %>
<li><%= context_menu_link l(:button_copy), project_copy_issue_path(@project, @issue),
:class => 'icon-copy', :disabled => !@can[:copy] %></li>
<% else %>
<li><%= context_menu_link l(:button_copy), bulk_edit_issues_path(:ids => @issue_ids, :copy => '1'),
:class => 'icon-copy', :disabled => !@can[:move] %></li>
<% end %>
<li><%= context_menu_link l(:button_delete), issues_path(:ids => @issue_ids, :back_url => @back),
:method => :delete, :data => {:confirm => issues_destroy_confirmation_message(@issues)}, :class => 'icon-del', :disabled => !@can[:delete] %></li>

<%= call_hook(:view_issues_context_menu_end, {:issues => @issues, :can => @can, :back => @back }) %>
</ul>
64 changes: 64 additions & 0 deletions app/views/helpers/redmine_category_tree/issue_category_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,70 @@ def issue_category_tree_options_for_select(issue_categories, options={})
def issue_category_tree(issue_categories, &block)
IssueCategory.issue_category_tree(issue_categories, &block)
end

def render_issue_category_tree_list(categories, includeOuterUL=false, &block)
categories = issue_category_tree(categories) { |cat, level| nil }
return '' if categories.size == 0

output = ''
output << '<ul>' if includeOuterUL
output << '<li>'

path = [nil]

categories.each_with_index do |cat, idx|
if cat.parent_id != path.last
if path.include?(cat.parent_id)
while path.last != cat.parent_id
path.pop
output << '</li></ul>'
end
output << '</li><li>'
else
path << cat.parent_id
output << '<ul><li>'
end
elsif idx != 0
output << '</li><li>'
end
output << capture(cat, path.size - 1, &block)
end

output << '</li><ul>' * (path.length - 1)
output << '</ul>' if includeOuterUL
output.html_safe
end

def render_issue_category_tree_context_menu_list(categories, includeOuterUL=false, &block)
categories = issue_category_tree(categories) { |cat, level| nil }
return '' if categories.size == 0

output = ''
output << '<ul>' if includeOuterUL

path = [nil]

categories.each_with_index do |cat, idx|
if cat.parent_id != path.last
if path.include?(cat.parent_id)
while path.last != cat.parent_id
path.pop
output << '</ul></li>'
end
else
path << cat.parent_id
output << '<li class="category-tree-nofx"><ul>'
end
end
output << '<li>'
output << capture(cat, path.size - 1, &block)
output << '</li>'
end

output << '</ul></li>' * (path.length - 1)
output << '</ul>' if includeOuterUL
output.html_safe
end

def render_issue_category_with_tree(category)
s = ''
Expand Down
26 changes: 26 additions & 0 deletions assets/stylesheets/redmine_category_tree.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,29 @@ span.issue_category_tree span.issue_category
{
color: black;
}

/* Context Menu */
div#context-menu li.folder ul.issue_category_tree li.category-tree-nofx,
div#context-menu li.folder ul.issue_category_tree li.category-tree-nofx:hover
{
background: transparent;
border: none;

padding: 0px;
}

div#context-menu li.folder ul.issue_category_tree li.category-tree-nofx > ul
{
background: transparent;
border: none;

left: auto;
top: auto;

display: block;
position: relative;

padding-left: 20px;

width: 130px;
}
5 changes: 5 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@
unless IssuesHelper.included_modules.include?(RedmineCategoryTree::Patches::IssuesHelperPatch)
IssuesHelper.send(:include, RedmineCategoryTree::Patches::IssuesHelperPatch)
end

require_dependency 'context_menus_controller'
unless ContextMenusController.included_modules.include?(RedmineCategoryTree::Patches::ContextMenusControllerPatch)
ContextMenusController.send(:include, RedmineCategoryTree::Patches::ContextMenusControllerPatch)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require File.dirname(__FILE__) + '/../../../app/views/helpers/redmine_category_tree/issue_category_helper.rb'

module RedmineCategoryTree
module Patches
module ContextMenusControllerPatch
def self.included(base) # :nodoc:
base.extend(ClassMethods)
base.send(:include, InstanceMethods)

base.class_eval do
unloadable

helper RedmineCategoryTree::IssueCategoryHelper
end
end

module ClassMethods
end

module InstanceMethods
end
end
end
end

0 comments on commit 8e5aac5

Please sign in to comment.