Revision 804:548e23d4cd71 vendor/plugins/redmine_tags/lib/redmine_tags/patches
| vendor/plugins/redmine_tags/lib/redmine_tags/patches/auto_completes_controller_patch.rb | ||
|---|---|---|
| 1 |
# This file is a part of redmine_tags |
|
| 2 |
# redMine plugin, that adds tagging support. |
|
| 3 |
# |
|
| 4 |
# Copyright (c) 2010 Aleksey V Zapparov AKA ixti |
|
| 5 |
# |
|
| 6 |
# redmine_tags is free software: you can redistribute it and/or modify |
|
| 7 |
# it under the terms of the GNU General Public License as published by |
|
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
|
| 9 |
# (at your option) any later version. |
|
| 10 |
# |
|
| 11 |
# redmine_tags is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with redmine_tags. If not, see <http://www.gnu.org/licenses/>. |
|
| 18 |
|
|
| 19 |
require_dependency 'auto_completes_controller' |
|
| 20 |
|
|
| 21 |
module RedmineTags |
|
| 22 |
module Patches |
|
| 23 |
module AutoCompletesControllerPatch |
|
| 24 |
def self.included(base) |
|
| 25 |
base.send(:include, InstanceMethods) |
|
| 26 |
end |
|
| 27 |
|
|
| 28 |
|
|
| 29 |
module InstanceMethods |
|
| 30 |
def issue_tags |
|
| 31 |
@name = params[:q].to_s |
|
| 32 |
@tags = Issue.available_tags :project_id => @project, :name_like => @name |
|
| 33 |
render :layout => false, :partial => 'tag_list' |
|
| 34 |
end |
|
| 35 |
|
|
| 36 |
def project_tags |
|
| 37 |
@name = params[:q].to_s |
|
| 38 |
@tags = Project.available_tags :name_like => @name |
|
| 39 |
render :layout => false, :partial => 'tag_list' |
|
| 40 |
end |
|
| 41 |
|
|
| 42 |
def project_search_tags |
|
| 43 |
@name = params[:q].to_s |
|
| 44 |
@tags = Project.available_tags :name_like => @name |
|
| 45 |
render :layout => false, :partial => 'search_tag_list' |
|
| 46 |
end |
|
| 47 |
end |
|
| 48 |
end |
|
| 49 |
end |
|
| 50 |
end |
|
| vendor/plugins/redmine_tags/lib/redmine_tags/patches/issue_patch.rb | ||
|---|---|---|
| 1 |
# This file is a part of redmine_tags |
|
| 2 |
# redMine plugin, that adds tagging support. |
|
| 3 |
# |
|
| 4 |
# Copyright (c) 2010 Aleksey V Zapparov AKA ixti |
|
| 5 |
# |
|
| 6 |
# redmine_tags is free software: you can redistribute it and/or modify |
|
| 7 |
# it under the terms of the GNU General Public License as published by |
|
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
|
| 9 |
# (at your option) any later version. |
|
| 10 |
# |
|
| 11 |
# redmine_tags is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with redmine_tags. If not, see <http://www.gnu.org/licenses/>. |
|
| 18 |
|
|
| 19 |
require_dependency 'issue' |
|
| 20 |
|
|
| 21 |
module RedmineTags |
|
| 22 |
module Patches |
|
| 23 |
module IssuePatch |
|
| 24 |
def self.included(base) |
|
| 25 |
base.extend(ClassMethods) |
|
| 26 |
|
|
| 27 |
base.class_eval do |
|
| 28 |
unloadable |
|
| 29 |
acts_as_taggable |
|
| 30 |
end |
|
| 31 |
end |
|
| 32 |
|
|
| 33 |
module ClassMethods |
|
| 34 |
# Returns available issue tags |
|
| 35 |
# === Parameters |
|
| 36 |
# * <i>options</i> = (optional) Options hash of |
|
| 37 |
# * project - Project to search in. |
|
| 38 |
# * open_only - Boolean. Whenever search within open issues only. |
|
| 39 |
# * name_like - String. Substring to filter found tags. |
|
| 40 |
def available_tags(options = {})
|
|
| 41 |
project = options[:project] |
|
| 42 |
open_only = options[:open_only] |
|
| 43 |
name_like = options[:name_like] |
|
| 44 |
options = {}
|
|
| 45 |
visible = ARCondition.new |
|
| 46 |
|
|
| 47 |
if project |
|
| 48 |
project = project.id if project.is_a? Project |
|
| 49 |
visible << ["#{Issue.table_name}.project_id = ?", project]
|
|
| 50 |
end |
|
| 51 |
|
|
| 52 |
if open_only |
|
| 53 |
visible << ["#{Issue.table_name}.status_id IN " +
|
|
| 54 |
"( SELECT issue_status.id " + |
|
| 55 |
" FROM #{IssueStatus.table_name} issue_status " +
|
|
| 56 |
" WHERE issue_status.is_closed = ? )", false] |
|
| 57 |
end |
|
| 58 |
|
|
| 59 |
if name_like |
|
| 60 |
visible << ["#{ActsAsTaggableOn::Tag.table_name}.name LIKE ?", "%#{name_like.downcase}%"]
|
|
| 61 |
end |
|
| 62 |
|
|
| 63 |
options[:conditions] = visible.conditions |
|
| 64 |
self.all_tag_counts(options) |
|
| 65 |
end |
|
| 66 |
end |
|
| 67 |
end |
|
| 68 |
end |
|
| 69 |
end |
|
| vendor/plugins/redmine_tags/lib/redmine_tags/patches/issues_helper_patch.rb | ||
|---|---|---|
| 1 |
# This file is a part of redmine_tags |
|
| 2 |
# redMine plugin, that adds tagging support. |
|
| 3 |
# |
|
| 4 |
# Copyright (c) 2010 Aleksey V Zapparov AKA ixti |
|
| 5 |
# |
|
| 6 |
# redmine_tags is free software: you can redistribute it and/or modify |
|
| 7 |
# it under the terms of the GNU General Public License as published by |
|
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
|
| 9 |
# (at your option) any later version. |
|
| 10 |
# |
|
| 11 |
# redmine_tags is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with redmine_tags. If not, see <http://www.gnu.org/licenses/>. |
|
| 18 |
|
|
| 19 |
require_dependency 'issues_helper' |
|
| 20 |
|
|
| 21 |
module RedmineTags |
|
| 22 |
module Patches |
|
| 23 |
module IssuesHelperPatch |
|
| 24 |
def self.included(base) |
|
| 25 |
base.send(:include, InstanceMethods) |
|
| 26 |
end |
|
| 27 |
|
|
| 28 |
module InstanceMethods |
|
| 29 |
include TagsHelper |
|
| 30 |
|
|
| 31 |
def redmine_tags_settings |
|
| 32 |
@redmine_tags_settings = Setting.plugin_redmine_tags unless @redmine_tags_settings |
|
| 33 |
@redmine_tags_settings |
|
| 34 |
end |
|
| 35 |
|
|
| 36 |
def sidebar_tags |
|
| 37 |
unless @sidebar_tags |
|
| 38 |
@sidebar_tags = [] |
|
| 39 |
if :none != redmine_tags_settings[:issues_sidebar].to_sym |
|
| 40 |
@sidebar_tags = Issue.available_tags(:project => @project, |
|
| 41 |
:open_only => (redmine_tags_settings[:issues_open_only].to_i == 1)) |
|
| 42 |
end |
|
| 43 |
end |
|
| 44 |
@sidebar_tags |
|
| 45 |
end |
|
| 46 |
|
|
| 47 |
def render_sidebar_tags |
|
| 48 |
render_tags_list(sidebar_tags, |
|
| 49 |
:show_count => (redmine_tags_settings[:issues_show_count].to_i == 1), |
|
| 50 |
:open_only => (redmine_tags_settings[:issues_open_only].to_i == 1), |
|
| 51 |
:style => redmine_tags_settings[:issues_sidebar].to_sym) |
|
| 52 |
end |
|
| 53 |
end |
|
| 54 |
end |
|
| 55 |
end |
|
| 56 |
end |
|
| vendor/plugins/redmine_tags/lib/redmine_tags/patches/project_patch.rb | ||
|---|---|---|
| 1 |
# C4DM |
|
| 2 |
|
|
| 3 |
require_dependency 'project' |
|
| 4 |
|
|
| 5 |
module RedmineTags |
|
| 6 |
module Patches |
|
| 7 |
module ProjectPatch |
|
| 8 |
def self.included(base) # :nodoc: |
|
| 9 |
base.extend(ClassMethods) |
|
| 10 |
base.send(:include, InstanceMethods) |
|
| 11 |
|
|
| 12 |
base.class_eval do |
|
| 13 |
unloadable |
|
| 14 |
|
|
| 15 |
attr_accessor :tag_list |
|
| 16 |
|
|
| 17 |
acts_as_taggable |
|
| 18 |
|
|
| 19 |
end |
|
| 20 |
end |
|
| 21 |
|
|
| 22 |
def before_save_with_save_tags() |
|
| 23 |
# debugger |
|
| 24 |
logger.error { "GONNA SAVE TAG LIST" }
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
# params[:tag_list] |
|
| 28 |
|
|
| 29 |
|
|
| 30 |
# logger.error { @project.name }
|
|
| 31 |
|
|
| 32 |
# if params && params[:project] && !params[:project][:tag_list].nil? |
|
| 33 |
# old_tags = context[:project].tag_list.to_s |
|
| 34 |
# context[:project].tag_list = params[:project][:tag_list] |
|
| 35 |
# new_tags = context[:project].tag_list.to_s |
|
| 36 |
# |
|
| 37 |
# unless (old_tags == new_tags || context[:project].current_journal.blank?) |
|
| 38 |
# context[:project].current_journal.details << JournalDetail.new(:property => 'attr', |
|
| 39 |
# :prop_key => 'tag_list', |
|
| 40 |
# :old_value => old_tags, |
|
| 41 |
# :value => new_tags) |
|
| 42 |
# end |
|
| 43 |
# end |
|
| 44 |
end |
|
| 45 |
|
|
| 46 |
module InstanceMethods |
|
| 47 |
|
|
| 48 |
end |
|
| 49 |
|
|
| 50 |
module ClassMethods |
|
| 51 |
def search_by_question(question) |
|
| 52 |
if question.length > 1 |
|
| 53 |
search(RedmineProjectFiltering.calculate_tokens(question), nil, :all_words => true).first.sort_by(&:lft) |
|
| 54 |
else |
|
| 55 |
all(:order => 'lft') |
|
| 56 |
end |
|
| 57 |
end |
|
| 58 |
|
|
| 59 |
|
|
| 60 |
# Returns available project tags |
|
| 61 |
# does not show tags from private projects |
|
| 62 |
def available_tags( options = {} )
|
|
| 63 |
|
|
| 64 |
name_like = options[:name_like] |
|
| 65 |
options = {}
|
|
| 66 |
visible = ARCondition.new |
|
| 67 |
|
|
| 68 |
visible << ["#{Project.table_name}.is_public = \"1\""]
|
|
| 69 |
|
|
| 70 |
if name_like |
|
| 71 |
visible << ["#{ActsAsTaggableOn::Tag.table_name}.name LIKE ?", "%#{name_like.downcase}%"]
|
|
| 72 |
end |
|
| 73 |
|
|
| 74 |
options[:conditions] = visible.conditions |
|
| 75 |
|
|
| 76 |
self.all_tag_counts(options) |
|
| 77 |
end |
|
| 78 |
end |
|
| 79 |
end |
|
| 80 |
end |
|
| 81 |
end |
|
| vendor/plugins/redmine_tags/lib/redmine_tags/patches/projects_controller_patch.rb | ||
|---|---|---|
| 1 |
require_dependency 'projects_controller' |
|
| 2 |
|
|
| 3 |
module RedmineTags |
|
| 4 |
module Patches |
|
| 5 |
module ProjectsControllerPatch |
|
| 6 |
def self.included(base) |
|
| 7 |
base.send(:include, InstanceMethods) |
|
| 8 |
base.class_eval do |
|
| 9 |
unloadable |
|
| 10 |
skip_before_filter :authorize, :only => [:set_fieldset_status] |
|
| 11 |
skip_before_filter :find_project, :only => [:set_fieldset_status] |
|
| 12 |
before_filter :add_tags_to_project, :only => [:save, :update] |
|
| 13 |
# before_filter :filter_projects, :only => :index |
|
| 14 |
|
|
| 15 |
alias :index filtered_index |
|
| 16 |
end |
|
| 17 |
end |
|
| 18 |
|
|
| 19 |
module InstanceMethods |
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
def add_tags_to_project |
|
| 24 |
|
|
| 25 |
if params && params[:project] && !params[:project][:tag_list].nil? |
|
| 26 |
old_tags = @project.tag_list.to_s |
|
| 27 |
new_tags = params[:project][:tag_list].to_s |
|
| 28 |
|
|
| 29 |
unless (old_tags == new_tags) |
|
| 30 |
@project.tag_list = new_tags |
|
| 31 |
end |
|
| 32 |
end |
|
| 33 |
end |
|
| 34 |
|
|
| 35 |
def paginate_projects |
|
| 36 |
sort_init 'name' |
|
| 37 |
sort_update %w(name lft created_on updated_on) |
|
| 38 |
@limit = per_page_option |
|
| 39 |
@project_count = Project.visible_roots.find(@projects).count |
|
| 40 |
@project_pages = ActionController::Pagination::Paginator.new self, @project_count, @limit, params['page'] |
|
| 41 |
@offset ||= @project_pages.current.offset |
|
| 42 |
end |
|
| 43 |
|
|
| 44 |
def set_fieldset_status |
|
| 45 |
|
|
| 46 |
# luisf. test for missing parameters……… |
|
| 47 |
field = params[:field_id] |
|
| 48 |
status = params[:status] |
|
| 49 |
|
|
| 50 |
session[(field + "_status").to_sym] = status |
|
| 51 |
render :nothing => true |
|
| 52 |
end |
|
| 53 |
|
|
| 54 |
# gets the status of the collabsible fieldsets |
|
| 55 |
def get_fieldset_statuses |
|
| 56 |
if session[:my_projects_fieldset_status].nil? |
|
| 57 |
@myproj_status = "true" |
|
| 58 |
else |
|
| 59 |
@myproj_status = session[:my_projects_fieldset_status] |
|
| 60 |
end |
|
| 61 |
|
|
| 62 |
if session[:filters_fieldset_status].nil? |
|
| 63 |
@filter_status = "false" |
|
| 64 |
else |
|
| 65 |
@filter_status = session[:filters_fieldset_status] |
|
| 66 |
end |
|
| 67 |
|
|
| 68 |
if params && params[:project] && !params[:project][:tag_list].nil? |
|
| 69 |
@filter_status = "true" |
|
| 70 |
end |
|
| 71 |
|
|
| 72 |
end |
|
| 73 |
|
|
| 74 |
# Lists visible projects. Paginator is for top-level projects only |
|
| 75 |
# (subprojects belong to them) |
|
| 76 |
def filtered_index |
|
| 77 |
@project = Project.new |
|
| 78 |
filter_projects |
|
| 79 |
get_fieldset_statuses |
|
| 80 |
|
|
| 81 |
respond_to do |format| |
|
| 82 |
format.html {
|
|
| 83 |
paginate_projects |
|
| 84 |
|
|
| 85 |
@projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause) |
|
| 86 |
|
|
| 87 |
if User.current.logged? |
|
| 88 |
# seems sort_by gives us case-sensitive ordering, which we don't want |
|
| 89 |
# @user_projects = User.current.projects.sort_by(&:name) |
|
| 90 |
@user_projects = User.current.projects.all(:order => :name) |
|
| 91 |
end |
|
| 92 |
|
|
| 93 |
render :template => 'projects/index.rhtml', :layout => !request.xhr? |
|
| 94 |
} |
|
| 95 |
format.api {
|
|
| 96 |
@offset, @limit = api_offset_and_limit |
|
| 97 |
@project_count = Project.visible.count |
|
| 98 |
@projects = Project.visible.find(@projects, :offset => @offset, :limit => @limit, :order => 'lft') |
|
| 99 |
} |
|
| 100 |
format.atom {
|
|
| 101 |
projects = Project.visible.find(:all, :order => 'created_on DESC', :limit => Setting.feeds_limit.to_i) |
|
| 102 |
render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
|
|
| 103 |
} |
|
| 104 |
format.js {
|
|
| 105 |
paginate_projects |
|
| 106 |
@projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause) |
|
| 107 |
render :update do |page| |
|
| 108 |
page.replace_html 'projects', :partial => 'filtered_projects' |
|
| 109 |
end |
|
| 110 |
} |
|
| 111 |
end |
|
| 112 |
end |
|
| 113 |
|
|
| 114 |
private |
|
| 115 |
|
|
| 116 |
def filter_projects |
|
| 117 |
@question = (params[:q] || "").strip |
|
| 118 |
|
|
| 119 |
if params.has_key?(:project) |
|
| 120 |
@tag_list = (params[:project][:tag_list] || "").strip.split(",")
|
|
| 121 |
else |
|
| 122 |
@tag_list = [] |
|
| 123 |
end |
|
| 124 |
|
|
| 125 |
if @question == "" |
|
| 126 |
@projects = Project.visible |
|
| 127 |
else |
|
| 128 |
@projects = Project.visible.search_by_question(@question) |
|
| 129 |
end |
|
| 130 |
|
|
| 131 |
unless @tag_list.empty? |
|
| 132 |
@tagged_projects_ids = Project.visible.tagged_with(@tag_list).collect{ |project| Project.find(project.id) }
|
|
| 133 |
@projects = @projects & @tagged_projects_ids |
|
| 134 |
end |
|
| 135 |
|
|
| 136 |
@projects = @projects.collect{ |project| project.root }
|
|
| 137 |
@projects = @projects.uniq |
|
| 138 |
|
|
| 139 |
end |
|
| 140 |
end |
|
| 141 |
end |
|
| 142 |
end |
|
| 143 |
end |
|
| vendor/plugins/redmine_tags/lib/redmine_tags/patches/projects_helper_patch.rb | ||
|---|---|---|
| 1 |
module RedmineTags |
|
| 2 |
module Patches |
|
| 3 |
module ProjectsHelperPatch |
|
| 4 |
|
|
| 5 |
def self.included(base) # :nodoc: |
|
| 6 |
base.send(:include, InstanceMethods) |
|
| 7 |
base.class_eval do |
|
| 8 |
unloadable |
|
| 9 |
end |
|
| 10 |
end |
|
| 11 |
|
|
| 12 |
module InstanceMethods |
|
| 13 |
# Renders a tree of projects that the current user does not belong |
|
| 14 |
# to, or of all projects if the current user is not logged in. The |
|
| 15 |
# given collection may be a subset of the whole project tree |
|
| 16 |
# (eg. some intermediate nodes are private and can not be seen). We |
|
| 17 |
# are potentially interested in various things: the project name, |
|
| 18 |
# description, manager(s), creation date, last activity date, |
|
| 19 |
# general activity level, whether there is anything actually hosted |
|
| 20 |
# here for the project, etc. |
|
| 21 |
def render_project_table_with_filtering(projects, question) |
|
| 22 |
custom_fields = "" |
|
| 23 |
s = "" |
|
| 24 |
if projects.any? |
|
| 25 |
tokens = RedmineProjectFiltering.calculate_tokens(question, custom_fields) |
|
| 26 |
|
|
| 27 |
s << "<div class='autoscroll'>" |
|
| 28 |
s << "<table class='list projects'>" |
|
| 29 |
s << "<thead><tr>" |
|
| 30 |
|
|
| 31 |
s << sort_header_tag('name', :caption => l("field_name"))
|
|
| 32 |
s << "<th class='managers'>" << l("label_managers") << "</th>"
|
|
| 33 |
s << "<th class='tags'>" << l("tags") << "</th>"
|
|
| 34 |
s << sort_header_tag('created_on', :default_order => 'desc')
|
|
| 35 |
s << sort_header_tag('updated_on', :default_order => 'desc')
|
|
| 36 |
|
|
| 37 |
s << "</tr></thead><tbody>" |
|
| 38 |
|
|
| 39 |
original_project = @project |
|
| 40 |
|
|
| 41 |
projects.each do |project| |
|
| 42 |
s << render_project_in_table_with_filtering(project, cycle('odd', 'even'), 0, tokens)
|
|
| 43 |
end |
|
| 44 |
|
|
| 45 |
s << "</table>" |
|
| 46 |
else |
|
| 47 |
s << "\n" |
|
| 48 |
end |
|
| 49 |
@project = original_project |
|
| 50 |
|
|
| 51 |
s |
|
| 52 |
end |
|
| 53 |
|
|
| 54 |
def render_project_in_table_with_filtering(project, oddeven, level, tokens) |
|
| 55 |
# set the project environment to please macros. |
|
| 56 |
@project = project |
|
| 57 |
|
|
| 58 |
classes = (level == 0 ? 'root' : 'child') |
|
| 59 |
|
|
| 60 |
s = "" |
|
| 61 |
|
|
| 62 |
s << "<tr class='#{oddeven} #{classes} level#{level}'>"
|
|
| 63 |
s << "<td class='firstcol' align=top><div class='name hosted_here" |
|
| 64 |
s << " no_description" if project.description.blank? |
|
| 65 |
s << "'>" << link_to( highlight_tokens(project.name, tokens), {:controller => 'projects', :action => 'show', :id => project}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}")
|
|
| 66 |
s << "</div>" |
|
| 67 |
s << highlight_tokens(render_project_short_description(project), tokens) |
|
| 68 |
s << "<td class='managers' align=top>" |
|
| 69 |
|
|
| 70 |
u = project.users_by_role |
|
| 71 |
if u |
|
| 72 |
u.keys.each do |r| |
|
| 73 |
if r.allowed_to?(:edit_project) |
|
| 74 |
mgrs = [] |
|
| 75 |
u[r].sort.each do |m| |
|
| 76 |
mgrs << link_to_user(m) |
|
| 77 |
end |
|
| 78 |
if mgrs.size < 3 |
|
| 79 |
s << '<nobr>' << mgrs.join(', ') << '</nobr>'
|
|
| 80 |
else |
|
| 81 |
s << mgrs.join(', ')
|
|
| 82 |
end |
|
| 83 |
end |
|
| 84 |
end |
|
| 85 |
end |
|
| 86 |
|
|
| 87 |
s << "</td>" |
|
| 88 |
|
|
| 89 |
# taglist |
|
| 90 |
s << "<td class='tags' align=top>" << project.tag_counts.collect{ |t| render_project_tag_link(t) }.join(', ') << "</td>"
|
|
| 91 |
s << "<td class='created_on' align=top>" << format_date(project.created_on) << "</td>" |
|
| 92 |
s << "<td class='updated_on' align=top>" << format_date(project.updated_on) << "</td>" |
|
| 93 |
|
|
| 94 |
s << "</tr>" |
|
| 95 |
|
|
| 96 |
project.children.each do |child| |
|
| 97 |
if child.is_public? or User.current.member_of?(child) |
|
| 98 |
s << render_project_in_table_with_filtering(child, oddeven, level + 1, tokens) |
|
| 99 |
end |
|
| 100 |
end |
|
| 101 |
|
|
| 102 |
s |
|
| 103 |
end |
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
# Renders a tree of projects as a nested set of unordered lists |
|
| 108 |
# The given collection may be a subset of the whole project tree |
|
| 109 |
# (eg. some intermediate nodes are private and can not be seen) |
|
| 110 |
def render_project_hierarchy_with_filtering(projects,custom_fields,question) |
|
| 111 |
s = [] |
|
| 112 |
if projects.any? |
|
| 113 |
tokens = RedmineProjectFiltering.calculate_tokens(question, custom_fields) |
|
| 114 |
debugger |
|
| 115 |
|
|
| 116 |
|
|
| 117 |
ancestors = [] |
|
| 118 |
original_project = @project |
|
| 119 |
projects.each do |project| |
|
| 120 |
# set the project environment to please macros. |
|
| 121 |
@project = project |
|
| 122 |
if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) |
|
| 123 |
s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>"
|
|
| 124 |
else |
|
| 125 |
ancestors.pop |
|
| 126 |
s << "</li>" |
|
| 127 |
while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) |
|
| 128 |
ancestors.pop |
|
| 129 |
s << "</ul></li>" |
|
| 130 |
end |
|
| 131 |
end |
|
| 132 |
classes = (ancestors.empty? ? 'root' : 'child') |
|
| 133 |
s << "<li class='#{classes}'><div class='#{classes}'>" +
|
|
| 134 |
link_to( highlight_tokens(project.name, tokens), |
|
| 135 |
{:controller => 'projects', :action => 'show', :id => project},
|
|
| 136 |
:class => "project #{User.current.member_of?(project) ? 'my-project' : nil}"
|
|
| 137 |
) |
|
| 138 |
s << "<ul class='filter_fields'>" |
|
| 139 |
|
|
| 140 |
# CustomField.usable_for_project_filtering.each do |field| |
|
| 141 |
# value_model = project.custom_value_for(field.id) |
|
| 142 |
# value = value_model.present? ? value_model.value : nil |
|
| 143 |
# s << "<li><b>#{field.name.humanize}:</b> #{highlight_tokens(value, tokens)}</li>" if value.present?
|
|
| 144 |
# end |
|
| 145 |
|
|
| 146 |
s << "</ul>" |
|
| 147 |
s << "<div class='clear'></div>" |
|
| 148 |
unless project.description.blank? |
|
| 149 |
s << "<div class='wiki description'>" |
|
| 150 |
s << "<b>#{ t(:field_description) }:</b>"
|
|
| 151 |
s << highlight_tokens(textilizable(project.short_description, :project => project), tokens) |
|
| 152 |
s << "\n</div>" |
|
| 153 |
end |
|
| 154 |
s << "</div>" |
|
| 155 |
ancestors << project |
|
| 156 |
end |
|
| 157 |
ancestors.size.times{ s << "</li></ul>" }
|
|
| 158 |
@project = original_project |
|
| 159 |
end |
|
| 160 |
s.join "\n" |
|
| 161 |
end |
|
| 162 |
|
|
| 163 |
# Renders a tree of projects where the current user belongs |
|
| 164 |
# as a nested set of unordered lists |
|
| 165 |
# The given collection may be a subset of the whole project tree |
|
| 166 |
# (eg. some intermediate nodes are private and can not be seen) |
|
| 167 |
def render_my_project_hierarchy_with_tags(projects) |
|
| 168 |
|
|
| 169 |
s = '' |
|
| 170 |
|
|
| 171 |
original_project = @project |
|
| 172 |
|
|
| 173 |
projects.each do |project| |
|
| 174 |
if project.root? || !projects.include?(project.parent) |
|
| 175 |
s << render_my_project_in_hierarchy_with_tags(project) |
|
| 176 |
end |
|
| 177 |
end |
|
| 178 |
|
|
| 179 |
@project = original_project |
|
| 180 |
|
|
| 181 |
if s != '' |
|
| 182 |
a = '' |
|
| 183 |
a << "<ul class='projects root'>\n" |
|
| 184 |
a << s |
|
| 185 |
a << "</ul>\n" |
|
| 186 |
s = a |
|
| 187 |
end |
|
| 188 |
|
|
| 189 |
s |
|
| 190 |
|
|
| 191 |
end |
|
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| 196 |
def render_my_project_in_hierarchy_with_tags(project) |
|
| 197 |
|
|
| 198 |
s = '' |
|
| 199 |
|
|
| 200 |
if User.current.member_of?(project) |
|
| 201 |
|
|
| 202 |
# set the project environment to please macros. |
|
| 203 |
@project = project |
|
| 204 |
|
|
| 205 |
classes = (project.root? ? 'root' : 'child') |
|
| 206 |
|
|
| 207 |
s << "<li class='#{classes}'><div class='#{classes}'>" +
|
|
| 208 |
link_to_project(project, {}, :class => "project my-project")
|
|
| 209 |
if project.is_public? |
|
| 210 |
s << " <span class='public'>" << l("field_is_public") << "</span>"
|
|
| 211 |
else |
|
| 212 |
s << " <span class='private'>" << l("field_is_private") << "</span>"
|
|
| 213 |
end |
|
| 214 |
s << render_project_short_description(project) |
|
| 215 |
|
|
| 216 |
s << l(:tags) << ": " |
|
| 217 |
s << project.tag_counts.collect{ |t| render_project_tag_link(t) }.join(', ')
|
|
| 218 |
|
|
| 219 |
s << "</div>\n" |
|
| 220 |
|
|
| 221 |
cs = '' |
|
| 222 |
project.children.each do |child| |
|
| 223 |
cs << render_my_project_in_hierarchy(child) |
|
| 224 |
end |
|
| 225 |
|
|
| 226 |
if cs != '' |
|
| 227 |
s << "<ul class='projects'>\n" << cs << "</ul>\n"; |
|
| 228 |
end |
|
| 229 |
|
|
| 230 |
end |
|
| 231 |
|
|
| 232 |
s |
|
| 233 |
|
|
| 234 |
end |
|
| 235 |
|
|
| 236 |
|
|
| 237 |
|
|
| 238 |
private |
|
| 239 |
|
|
| 240 |
# copied from search_helper. This one doesn't escape html or limit the text length |
|
| 241 |
def highlight_tokens(text, tokens) |
|
| 242 |
return text unless text && tokens && !tokens.empty? |
|
| 243 |
re_tokens = tokens.collect {|t| Regexp.escape(t)}
|
|
| 244 |
regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE
|
|
| 245 |
result = '' |
|
| 246 |
text.split(regexp).each_with_index do |words, i| |
|
| 247 |
words = words.mb_chars |
|
| 248 |
if i.even? |
|
| 249 |
result << words |
|
| 250 |
else |
|
| 251 |
t = (tokens.index(words.downcase) || 0) % 4 |
|
| 252 |
result << content_tag('span', words, :class => "highlight token-#{t}")
|
|
| 253 |
end |
|
| 254 |
end |
|
| 255 |
result |
|
| 256 |
end |
|
| 257 |
|
|
| 258 |
end |
|
| 259 |
end |
|
| 260 |
end |
|
| 261 |
end |
|
| 262 |
|
|
| vendor/plugins/redmine_tags/lib/redmine_tags/patches/queries_helper_patch.rb | ||
|---|---|---|
| 1 |
# This file is a part of redmine_tags |
|
| 2 |
# redMine plugin, that adds tagging support. |
|
| 3 |
# |
|
| 4 |
# Copyright (c) 2010 Aleksey V Zapparov AKA ixti |
|
| 5 |
# |
|
| 6 |
# redmine_tags is free software: you can redistribute it and/or modify |
|
| 7 |
# it under the terms of the GNU General Public License as published by |
|
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
|
| 9 |
# (at your option) any later version. |
|
| 10 |
# |
|
| 11 |
# redmine_tags is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with redmine_tags. If not, see <http://www.gnu.org/licenses/>. |
|
| 18 |
|
|
| 19 |
require_dependency 'queries_helper' |
|
| 20 |
|
|
| 21 |
module RedmineTags |
|
| 22 |
module Patches |
|
| 23 |
module QueriesHelperPatch |
|
| 24 |
def self.included(base) |
|
| 25 |
base.send(:include, InstanceMethods) |
|
| 26 |
|
|
| 27 |
base.class_eval do |
|
| 28 |
alias_method :column_content_original, :column_content |
|
| 29 |
alias_method :column_content, :column_content_extended |
|
| 30 |
end |
|
| 31 |
end |
|
| 32 |
|
|
| 33 |
|
|
| 34 |
module InstanceMethods |
|
| 35 |
include TagsHelper |
|
| 36 |
|
|
| 37 |
|
|
| 38 |
def column_content_extended(column, issue) |
|
| 39 |
if column.name.eql? :tags |
|
| 40 |
column.value(issue).collect{ |t| render_tag_link(t) }.join(', ')
|
|
| 41 |
else |
|
| 42 |
column_content_original(column, issue) |
|
| 43 |
end |
|
| 44 |
end |
|
| 45 |
end |
|
| 46 |
end |
|
| 47 |
end |
|
| 48 |
end |
|
| vendor/plugins/redmine_tags/lib/redmine_tags/patches/query_patch.rb | ||
|---|---|---|
| 1 |
# This file is a part of redmine_tags |
|
| 2 |
# redMine plugin, that adds tagging support. |
|
| 3 |
# |
|
| 4 |
# Copyright (c) 2010 Aleksey V Zapparov AKA ixti |
|
| 5 |
# |
|
| 6 |
# redmine_tags is free software: you can redistribute it and/or modify |
|
| 7 |
# it under the terms of the GNU General Public License as published by |
|
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
|
| 9 |
# (at your option) any later version. |
|
| 10 |
# |
|
| 11 |
# redmine_tags is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with redmine_tags. If not, see <http://www.gnu.org/licenses/>. |
|
| 18 |
|
|
| 19 |
require_dependency 'query' |
|
| 20 |
|
|
| 21 |
module RedmineTags |
|
| 22 |
module Patches |
|
| 23 |
module QueryPatch |
|
| 24 |
def self.included(base) |
|
| 25 |
base.send(:include, InstanceMethods) |
|
| 26 |
|
|
| 27 |
base.class_eval do |
|
| 28 |
unloadable |
|
| 29 |
|
|
| 30 |
alias_method :statement_original, :statement |
|
| 31 |
alias_method :statement, :statement_extended |
|
| 32 |
|
|
| 33 |
alias_method :available_filters_original, :available_filters |
|
| 34 |
alias_method :available_filters, :available_filters_extended |
|
| 35 |
|
|
| 36 |
base.add_available_column(QueryColumn.new(:tags)) |
|
| 37 |
end |
|
| 38 |
end |
|
| 39 |
|
|
| 40 |
|
|
| 41 |
module InstanceMethods |
|
| 42 |
def statement_extended |
|
| 43 |
filter = filters.delete 'tags' |
|
| 44 |
clauses = statement_original |
|
| 45 |
|
|
| 46 |
if filter |
|
| 47 |
filters.merge!( 'tags' => filter ) |
|
| 48 |
|
|
| 49 |
values = values_for('tags').clone
|
|
| 50 |
compare = operator_for('tags').eql?('=') ? 'IN' : 'NOT IN'
|
|
| 51 |
ids_list = Issue.tagged_with(values).collect{ |issue| issue.id }.push(0).join(',')
|
|
| 52 |
|
|
| 53 |
clauses << " AND ( #{Issue.table_name}.id #{compare} (#{ids_list}) ) "
|
|
| 54 |
end |
|
| 55 |
|
|
| 56 |
clauses |
|
| 57 |
end |
|
| 58 |
|
|
| 59 |
|
|
| 60 |
def available_filters_extended |
|
| 61 |
unless @available_filters |
|
| 62 |
available_filters_original.merge!({ 'tags' => {
|
|
| 63 |
:type => :list, |
|
| 64 |
:order => 6, |
|
| 65 |
:values => Issue.available_tags(:project => project).collect{ |t| [t.name, t.name] }
|
|
| 66 |
}}) |
|
| 67 |
end |
|
| 68 |
@available_filters |
|
| 69 |
end |
|
| 70 |
end |
|
| 71 |
end |
|
| 72 |
end |
|
| 73 |
end |
|
| 74 |
|
|
Also available in: Unified diff