Support for Redmine 3.x

This commit is contained in:
Alexander Meindl 2015-08-01 19:15:27 +02:00
parent b91ed93a8d
commit 96d8c70ac2
8 changed files with 60 additions and 29 deletions

View File

@ -49,9 +49,9 @@ Restart Redmine and have a fun!
{{list_users(123)}} or {{list_users(identifier)}} or {{list_users(My project)}} := Lists all users of the project with project id 123 (or identifier or project name) {{list_users(123)}} or {{list_users(identifier)}} or {{list_users(My project)}} := Lists all users of the project with project id 123 (or identifier or project name)
{{list_users(123, Manager)}} := Lists all users of the project with project id 123 and the role "Manager". If you want to use multiple roles as filters, you have to use a | as separator. {{list_users(123, title=Manager)}} := Lists all users of the project with project id 123 and the role "Manager". If you want to use multiple roles as filters, you have to use a | as separator.
{{list_users(123, Manager, Manager only)}} := Lists all users of the project with project id 123 and the role "Manager" and adds the heading "Manager only" {{list_users(123, title=Manager, role=Manager only)}} := Lists all users of the project with project id 123 and the role "Manager" and adds the heading "Manager only"
### Project list macros ### Project list macros
@ -62,7 +62,7 @@ Lists projects of current user
{{list_projects}} := lists all projects of current users {{list_projects}} := lists all projects of current users
{{list_projects(My title)}} := lists all projects of current users and adds the heading "My title" {{list_projects(title=My title)}} := lists all projects of current users and adds the heading "My title"
### Wiki date macros ### Wiki date macros
@ -103,6 +103,12 @@ Note: Redmine must be restarted after changing "Custom Help URL"</tt> value befo
## Changelog ## Changelog
### 0.5.3
- Redmine 3.0.x and 3.1.x supported
- "New issue" link with list_projects macro
- Parameter syntax changed for list_users and list_projects marcos (sorry for that)
### 0.5.2 ### 0.5.2
- "Edit closed issue" permission has been added - "Edit closed issue" permission has been added

View File

@ -1 +1 @@
0.5.2 0.5.3

View File

@ -49,8 +49,8 @@ end
<fieldset class="box tabular" id="project_trackers"><legend><%=l(:label_tracker_plural)%></legend> <fieldset class="box tabular" id="project_trackers"><legend><%=l(:label_tracker_plural)%></legend>
<% @trackers.each do |tracker| %> <% @trackers.each do |tracker| %>
<label class="floating"> <label class="floating">
<%= check_box_tag 'project[tracker_ids][]', tracker.id, @project.trackers.include?(tracker), :id => nil %> <%= check_box_tag 'project[tracker_ids][]', tracker.id, @project.trackers.to_a.include?(tracker), :id => nil %>
<%=h tracker %> <%= tracker %>
</label> </label>
<% end %> <% end %>
<%= hidden_field_tag 'project[tracker_ids][]', '' %> <%= hidden_field_tag 'project[tracker_ids][]', '' %>
@ -64,7 +64,11 @@ end
<%= check_box_tag 'project[issue_custom_field_ids][]', custom_field.id, (@project.all_issue_custom_fields.include? custom_field), <%= check_box_tag 'project[issue_custom_field_ids][]', custom_field.id, (@project.all_issue_custom_fields.include? custom_field),
:disabled => (custom_field.is_for_all? ? "disabled" : nil), :disabled => (custom_field.is_for_all? ? "disabled" : nil),
:id => nil %> :id => nil %>
<%=h custom_field.name %> <% if ActiveRecord::VERSION::MAJOR < 4 %>
<%= custom_field.name %>
<% else %>
<%= custom_field_name_tag(custom_field) %>
<% end %>
</label> </label>
<% end %> <% end %>
<%= hidden_field_tag 'project[issue_custom_field_ids][]', '' %> <%= hidden_field_tag 'project[issue_custom_field_ids][]', '' %>

View File

@ -1,10 +1,15 @@
<div class="projects box"> <div class="projects box">
<% if @list_title %><h3><%= @list_title %></h3><% end %> <% if list_title %><h3><%= list_title %></h3><% end %>
<ul> <ul>
<% <%
@projects.each {|project| %> @projects.each {|project| %>
<li class="project <%= cycle("odd", "even") %>"><span style="font-weight: bold;"><%= link_to_project(project) %></span><% <li class="project <%= cycle("odd", "even") %>"><span style="font-weight: bold;"><%= link_to_project(project) %></span><%
if project.homepage? %>: <%= link_to(project.homepage, project.homepage, @html_options) %><% end %></li> if project.homepage? %>: <%= link_to(project.homepage, project.homepage, @html_options) %><% end %>
<% if with_create_issue %>
<%= link_to('', {controller: 'issues',action: 'new', project_id: project },
class: 'icon icon-add', title: l(:label_issue_new)) if User.current.allowed_to?(:add_issues, project) %>
<% end %>
</li>
<% } %> <% } %>
</ul> </ul>
</div> </div>

View File

@ -1,11 +1,11 @@
<div class="users box"> <div class="users box">
<% <%
if @list_title %><h3><%= @list_title %></h3><% end if list_title %><h3><%= list_title %></h3><% end
users.each {|user| %> users.each {|user| %>
<div class="user box <%= cycle("odd", "even") %>"> <div class="user box <%= cycle("odd", "even") %>">
<div style="float: left; display: block; margin-right: 5px;"><%= avatar(user, :size => "50") %></div> <div style="float: left; display: block; margin-right: 5px;"><%= avatar(user, :size => "50") %></div>
<div class="user line" style="font-weight: bold;"><%= link_to(user.firstname + ' ' + user.lastname, '/users/' + user.id.to_s()) %></div> <div class="user line" style="font-weight: bold;"><%= link_to(user.firstname + ' ' + user.lastname, '/users/' + user.id.to_s()) %></div>
<% if user['role'] %><div class="user line"><%= l(:field_role) %>: <%= user['role'].join(", ").html_safe %></div><% end %> <% if user_roles[user.id] %><div class="user line"><%= l(:field_role) %>: <%= user_roles[user.id].join(", ").html_safe %></div><% end %>
<div class="user line"><%= l(:field_login) %>: <%= link_to user.login, '/users/' + user.id.to_s() %></div> <div class="user line"><%= l(:field_login) %>: <%= link_to user.login, '/users/' + user.id.to_s() %></div>
<% if !user.pref.hide_mail %> <% if !user.pref.hide_mail %>
<div class="user line"><%= l(:field_mail) %>: <%= mail_to(h(user.mail), nil, :encode => 'javascript') %></div> <div class="user line"><%= l(:field_mail) %>: <%= mail_to(h(user.mail), nil, :encode => 'javascript') %></div>

View File

@ -5,7 +5,7 @@ Redmine::Plugin.register :redmine_tweaks do
name 'Redmine Tweaks' name 'Redmine Tweaks'
author 'AlphaNodes GmbH' author 'AlphaNodes GmbH'
description 'Wiki and content extensions' description 'Wiki and content extensions'
version '0.5.2' version '0.5.3'
author_url 'https://alphanodes.com/' author_url 'https://alphanodes.com/'
url 'https://github.com/alexandermeindl/redmine_tweaks' url 'https://github.com/alexandermeindl/redmine_tweaks'

View File

@ -5,30 +5,43 @@ module RedmineTweaks
Redmine::WikiFormatting::Macros.register do Redmine::WikiFormatting::Macros.register do
desc <<-EOHELP desc <<-EOHELP
Display projects. Examples: Display projects.
Syntax:
{{list_projects(title=My project list,with_create_issue=BOOL)}}
Examples:
{{list_projects}} {{list_projects}}
...List all project, which I am member of ...List all project, which I am member of
{{list_projects(My project list)}} {{list_projects(title=My project list)}}
...List all project with title "My project list", which I am member of ...List all project with title "My project list", which I am member of
{{list_projects(with_create_issue=true)}}
...List all project with link to create new issue, which I am member of
EOHELP EOHELP
macro :list_projects do |obj, args| macro :list_projects do |obj, args|
@list_title = args[0] args, options = extract_macro_options(args, :title, :with_create_issue)
@projects = RedmineTweaks.load_projects @projects = RedmineTweaks.load_projects
return '' if @projects.nil? return '' if @projects.nil?
@html_options = {:class => 'external'} @html_options = {:class => 'external'}
render :partial => 'wiki/project_macros', :locals => {:projects => @projects, :html_options => @html_options, :list_title => @list_title} render :partial => 'wiki/project_macros', :locals => {:projects => @projects,
:list_title => options[:title],
:with_create_issue => options[:with_create_issue]}
end end
end end
def self.load_projects def self.load_projects
scope = Project if ActiveRecord::VERSION::MAJOR < 4
scope = scope.active all_projects = Project.active.visible(User.current).find(:all, :order => "projects.name")
all_projects = scope.visible(User.current).find(:all, :order => "projects.name") else
all_projects = Project.visible.sorted
end
my_projects = [] my_projects = []
all_projects.each do |p| all_projects.each do |p|
if User.current.member_of?(p) if User.current.member_of?(p)

View File

@ -25,9 +25,10 @@ Display users. Examples:
EOHELP EOHELP
macro :list_users do |obj, args| macro :list_users do |obj, args|
args, options = extract_macro_options(args, :role, :title)
project_id = args[0] project_id = args[0]
roles_limit = args[1] user_roles = []
@list_title = args[2]
if project_id.present? if project_id.present?
project_id.strip! project_id.strip!
@ -37,26 +38,28 @@ EOHELP
project ||= Project.visible.find_by_name(project_id) project ||= Project.visible.find_by_name(project_id)
return '' if project.nil? return '' if project.nil?
raw_users = User.active.find(:all, :conditions => ["#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id=(?))", project.id]).sort raw_users = User.active.where(["#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id=(?))", project.id]).sort
return '' if raw_users.nil? return '' if raw_users.nil?
users = []; users = []
raw_users.each {|user| raw_users.each {|user|
user['role'] = user.roles_for_project(project) user_roles[user.id] = user.roles_for_project(project)
if !roles_limit.present? or RedmineTweaks.check_role_matches(user['role'], roles_limit) if !options[:role].present? or RedmineTweaks.check_role_matches(user_roles[user.id], options[:role])
users << user users << user
end end
} }
else else
project_ids = Project.all(:conditions => Project.visible_condition(User.current)).collect(&:id) project_ids = Project.visible.collect(&:id)
if project_ids.any? if project_ids.any?
# members of the user's projects # members of the user's projects
users = User.active.find(:all, :conditions => ["#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id IN (?))", project_ids]).sort users = User.active.where(["#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id IN (?))", project_ids]).sort
else else
return '' return ''
end end
end end
render :partial => 'wiki/user_macros', :locals => {:users => users} render :partial => 'wiki/user_macros', :locals => {:users => users,
:user_roles => user_roles,
:list_title => options[:title]}
end end
end end