Revision 756:18b0f6e6d7a8 vendor/plugins/redmine_tags/lib
| vendor/plugins/redmine_tags/lib/redmine_project_filtering.rb | ||
|---|---|---|
| 1 |
module RedmineProjectFiltering |
|
| 2 |
|
|
| 3 |
# transforms a question and a list of custom fields into something that Project.search can process |
|
| 4 |
def self.calculate_tokens(question, custom_fields=nil) |
|
| 5 |
list = [] |
|
| 6 |
list << question if question.present? |
|
| 7 |
|
|
| 8 |
tokens = list.join(' ').scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)})
|
|
| 9 |
tokens = tokens.collect{ |m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '') }
|
|
| 10 |
|
|
| 11 |
# tokens must be at least 2 characters long |
|
| 12 |
tokens.select {|w| w.length > 1 }
|
|
| 13 |
end |
|
| 14 |
|
|
| 15 |
end |
|
| vendor/plugins/redmine_tags/lib/redmine_tags/hooks/model_issue_hook.rb | ||
|---|---|---|
| 1 |
# This file is a part of redmine_tags |
|
| 2 |
# redMine plugin, that adds tagging support. |
|
| 3 |
# |
|
| 4 |
# Copyright (c) 2010 Eric Davis |
|
| 5 |
# Copyright (c) 2010 Aleksey V Zapparov AKA ixti |
|
| 6 |
# |
|
| 7 |
# redmine_tags is free software: you can redistribute it and/or modify |
|
| 8 |
# it under the terms of the GNU General Public License as published by |
|
| 9 |
# the Free Software Foundation, either version 3 of the License, or |
|
| 10 |
# (at your option) any later version. |
|
| 11 |
# |
|
| 12 |
# redmine_tags is distributed in the hope that it will be useful, |
|
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
# GNU General Public License for more details. |
|
| 16 |
# |
|
| 17 |
# You should have received a copy of the GNU General Public License |
|
| 18 |
# along with redmine_tags. If not, see <http://www.gnu.org/licenses/>. |
|
| 19 |
|
|
| 20 |
module RedmineTags |
|
| 21 |
module Hooks |
|
| 22 |
class ModelIssueHook < Redmine::Hook::ViewListener |
|
| 23 |
def controller_issues_edit_before_save(context={})
|
|
| 24 |
save_tags_to_issue(context, true) |
|
| 25 |
end |
|
| 26 |
|
|
| 27 |
# Issue has an after_save method that calls reload (update_nested_set_attributes) |
|
| 28 |
# This makes it impossible for a new record to get a tag_list, it's |
|
| 29 |
# cleared on reload. So instead, hook in after the Issue#save to update |
|
| 30 |
# this issue's tag_list and call #save ourselves. |
|
| 31 |
def controller_issues_new_after_save(context={})
|
|
| 32 |
save_tags_to_issue(context, false) |
|
| 33 |
context[:issue].save |
|
| 34 |
end |
|
| 35 |
|
|
| 36 |
def save_tags_to_issue(context, create_journal) |
|
| 37 |
params = context[:params] |
|
| 38 |
|
|
| 39 |
if params && params[:issue] && !params[:issue][:tag_list].nil? |
|
| 40 |
old_tags = context[:issue].tag_list.to_s |
|
| 41 |
context[:issue].tag_list = params[:issue][:tag_list] |
|
| 42 |
new_tags = context[:issue].tag_list.to_s |
|
| 43 |
|
|
| 44 |
if create_journal and not (old_tags == new_tags || context[:issue].current_journal.blank?) |
|
| 45 |
context[:issue].current_journal.details << JournalDetail.new(:property => 'attr', |
|
| 46 |
:prop_key => 'tag_list', |
|
| 47 |
:old_value => old_tags, |
|
| 48 |
:value => new_tags) |
|
| 49 |
end |
|
| 50 |
end |
|
| 51 |
end |
|
| 52 |
end |
|
| 53 |
end |
|
| 54 |
end |
|
| vendor/plugins/redmine_tags/lib/redmine_tags/hooks/model_project_hook.rb | ||
|---|---|---|
| 1 |
# This file is a part of redmine_tags |
|
| 2 |
# redMine plugin, that adds tagging support. |
|
| 3 |
# |
|
| 4 |
# Copyright (c) 2010 Eric Davis |
|
| 5 |
# Copyright (c) 2010 Aleksey V Zapparov AKA ixti |
|
| 6 |
# |
|
| 7 |
# redmine_tags is free software: you can redistribute it and/or modify |
|
| 8 |
# it under the terms of the GNU General Public License as published by |
|
| 9 |
# the Free Software Foundation, either version 3 of the License, or |
|
| 10 |
# (at your option) any later version. |
|
| 11 |
# |
|
| 12 |
# redmine_tags is distributed in the hope that it will be useful, |
|
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
# GNU General Public License for more details. |
|
| 16 |
# |
|
| 17 |
# You should have received a copy of the GNU General Public License |
|
| 18 |
# along with redmine_tags. If not, see <http://www.gnu.org/licenses/>. |
|
| 19 |
|
|
| 20 |
module RedmineTags |
|
| 21 |
module Hooks |
|
| 22 |
class ModelProjectHook < Redmine::Hook::ViewListener |
|
| 23 |
def controller_project_before_save(context={})
|
|
| 24 |
debugger |
|
| 25 |
save_tags_to_project(context, true) |
|
| 26 |
end |
|
| 27 |
|
|
| 28 |
# Issue has an after_save method that calls reload (update_nested_set_attributes) |
|
| 29 |
# This makes it impossible for a new record to get a tag_list, it's |
|
| 30 |
# cleared on reload. So instead, hook in after the Issue#save to update |
|
| 31 |
# this issue's tag_list and call #save ourselves. |
|
| 32 |
def controller_projects_before_save(context={})
|
|
| 33 |
debugger |
|
| 34 |
save_tags_to_project(context, false) |
|
| 35 |
context[:project].save |
|
| 36 |
end |
|
| 37 |
|
|
| 38 |
def save_tags_to_project(context, create_journal) |
|
| 39 |
params = context[:params] |
|
| 40 |
debugger |
|
| 41 |
logger.error { "WORKING" }
|
|
| 42 |
|
|
| 43 |
# if params && params[:issue] && !params[:issue][:tag_list].nil? |
|
| 44 |
# old_tags = context[:issue].tag_list.to_s |
|
| 45 |
# context[:issue].tag_list = params[:issue][:tag_list] |
|
| 46 |
# new_tags = context[:issue].tag_list.to_s |
|
| 47 |
# |
|
| 48 |
# if create_journal and not (old_tags == new_tags || context[:issue].current_journal.blank?) |
|
| 49 |
# context[:issue].current_journal.details << JournalDetail.new(:property => 'attr', |
|
| 50 |
# :prop_key => 'tag_list', |
|
| 51 |
# :old_value => old_tags, |
|
| 52 |
# :value => new_tags) |
|
| 53 |
# end |
|
| 54 |
# end |
|
| 55 |
end |
|
| 56 |
end |
|
| 57 |
end |
|
| 58 |
end |
|
| vendor/plugins/redmine_tags/lib/redmine_tags/hooks/views_issues_hook.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 |
module RedmineTags |
|
| 20 |
module Hooks |
|
| 21 |
class ViewsIssuesHook < Redmine::Hook::ViewListener |
|
| 22 |
render_on :view_issues_show_details_bottom, :partial => 'issues/tags' |
|
| 23 |
render_on :view_issues_form_details_bottom, :partial => 'issues/tags_form' |
|
| 24 |
render_on :view_issues_sidebar_planning_bottom, :partial => 'issues/tags_sidebar' |
|
| 25 |
end |
|
| 26 |
end |
|
| 27 |
end |
|
| 28 |
|
|
| vendor/plugins/redmine_tags/lib/redmine_tags/hooks/views_projects_hook.rb | ||
|---|---|---|
| 1 |
module RedmineTags |
|
| 2 |
module Hooks |
|
| 3 |
class ViewsProjectsHook < Redmine::Hook::ViewListener |
|
| 4 |
render_on :view_projects_form, :partial => 'projects/tags_form' |
|
| 5 |
render_on :view_projects_show_left, :partial => 'projects/tags' |
|
| 6 |
# render_on :view_issues_sidebar_planning_bottom, :partial => 'issues/tags_sidebar' |
|
| 7 |
end |
|
| 8 |
end |
|
| 9 |
end |
|
| 10 |
|
|
| 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 |
end |
|
| 42 |
end |
|
| 43 |
end |
|
| 44 |
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 |
before_filter :add_tags_to_project, :only => [:save, :update] |
|
| 11 |
before_filter :filter_projects, :only => :index |
|
| 12 |
end |
|
| 13 |
end |
|
| 14 |
|
|
| 15 |
module InstanceMethods |
|
| 16 |
def add_tags_to_project |
|
| 17 |
|
|
| 18 |
if params && params[:project] && !params[:project][:tag_list].nil? |
|
| 19 |
old_tags = @project.tag_list.to_s |
|
| 20 |
new_tags = params[:project][:tag_list].to_s |
|
| 21 |
|
|
| 22 |
unless (old_tags == new_tags) |
|
| 23 |
@project.tag_list = new_tags |
|
| 24 |
end |
|
| 25 |
end |
|
| 26 |
end |
|
| 27 |
|
|
| 28 |
# # luisf - TO BE REMOVED? |
|
| 29 |
# def calculate_project_filtering_settings |
|
| 30 |
# @project_filtering_settings = Setting[:plugin_redmine_project_filtering] |
|
| 31 |
# end |
|
| 32 |
|
|
| 33 |
def filter_projects |
|
| 34 |
@project = Project.new |
|
| 35 |
|
|
| 36 |
respond_to do |format| |
|
| 37 |
format.any(:html, :xml) {
|
|
| 38 |
calculate_filtered_projects |
|
| 39 |
} |
|
| 40 |
format.js {
|
|
| 41 |
calculate_filtered_projects |
|
| 42 |
render :update do |page| |
|
| 43 |
page.replace_html 'projects', :partial => 'filtered_projects' |
|
| 44 |
end |
|
| 45 |
} |
|
| 46 |
format.atom {
|
|
| 47 |
projects = Project.visible.find(:all, :order => 'created_on DESC', |
|
| 48 |
:limit => Setting.feeds_limit.to_i) |
|
| 49 |
render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
|
|
| 50 |
} |
|
| 51 |
end |
|
| 52 |
end |
|
| 53 |
|
|
| 54 |
private |
|
| 55 |
|
|
| 56 |
def calculate_filtered_projects |
|
| 57 |
@question = (params[:q] || "").strip |
|
| 58 |
|
|
| 59 |
if params.has_key?(:project) |
|
| 60 |
@tag_list = (params[:project][:tag_list] || "").strip.split(",")
|
|
| 61 |
else |
|
| 62 |
@tag_list = [] |
|
| 63 |
end |
|
| 64 |
|
|
| 65 |
@projects = Project.visible |
|
| 66 |
|
|
| 67 |
@featured_projects = @projects.featured if Project.respond_to? :featured |
|
| 68 |
|
|
| 69 |
# luisf |
|
| 70 |
@projects = @projects.search_by_question(@question) unless @question == "" |
|
| 71 |
@tagged_projects_ids = Project.tagged_with(@tag_list).collect{ |project| Project.find(project.id) } unless @tag_list.empty?
|
|
| 72 |
|
|
| 73 |
debugger |
|
| 74 |
|
|
| 75 |
# intersection of both prject groups |
|
| 76 |
@projects = @projects && @tagged_projects_ids unless @tag_list.empty? |
|
| 77 |
|
|
| 78 |
@filtered_projects = @projects |
|
| 79 |
end |
|
| 80 |
end |
|
| 81 |
end |
|
| 82 |
end |
|
| 83 |
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 |
debugger |
|
| 23 |
|
|
| 24 |
custom_fields = "" |
|
| 25 |
s = "" |
|
| 26 |
if projects.any? |
|
| 27 |
tokens = RedmineProjectFiltering.calculate_tokens(question, custom_fields) |
|
| 28 |
|
|
| 29 |
s << "<div class='autoscroll'>" |
|
| 30 |
s << "<table class='list projects'>" |
|
| 31 |
s << "<thead><tr>" |
|
| 32 |
|
|
| 33 |
s << sort_header_tag('name', :caption => l("field_name"))
|
|
| 34 |
s << "<th class='managers'>" << l("label_managers") << "</th>"
|
|
| 35 |
s << "<th class='tags'>" << l("tags") << "</th>"
|
|
| 36 |
s << sort_header_tag('created_on', :default_order => 'desc')
|
|
| 37 |
s << sort_header_tag('updated_on', :default_order => 'desc')
|
|
| 38 |
|
|
| 39 |
s << "</tr></thead><tbody>" |
|
| 40 |
|
|
| 41 |
original_project = @project |
|
| 42 |
|
|
| 43 |
projects.each do |project| |
|
| 44 |
s << render_project_in_table_with_filtering(project, cycle('odd', 'even'), 0, tokens)
|
|
| 45 |
end |
|
| 46 |
|
|
| 47 |
s << "</table>" |
|
| 48 |
else |
|
| 49 |
s << "\n" |
|
| 50 |
end |
|
| 51 |
@project = original_project |
|
| 52 |
|
|
| 53 |
s |
|
| 54 |
end |
|
| 55 |
|
|
| 56 |
def render_project_in_table_with_filtering(project, oddeven, level, tokens) |
|
| 57 |
# set the project environment to please macros. |
|
| 58 |
@project = project |
|
| 59 |
|
|
| 60 |
classes = (level == 0 ? 'root' : 'child') |
|
| 61 |
|
|
| 62 |
s = "" |
|
| 63 |
|
|
| 64 |
s << "<tr class='#{oddeven} #{classes} level#{level}'>"
|
|
| 65 |
s << "<td class='firstcol' align=top><div class='name hosted_here" |
|
| 66 |
s << " no_description" if project.description.blank? |
|
| 67 |
s << "'>" << link_to( highlight_tokens(project.name, tokens), {:controller => 'projects', :action => 'show', :id => project}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}")
|
|
| 68 |
s << "</div>" |
|
| 69 |
s << render_project_short_description(project) |
|
| 70 |
s << "<td class='managers' align=top>" |
|
| 71 |
|
|
| 72 |
u = project.users_by_role |
|
| 73 |
if u |
|
| 74 |
u.keys.each do |r| |
|
| 75 |
if r.allowed_to?(:edit_project) |
|
| 76 |
mgrs = [] |
|
| 77 |
u[r].sort.each do |m| |
|
| 78 |
mgrs << link_to_user(m) |
|
| 79 |
end |
|
| 80 |
if mgrs.size < 3 |
|
| 81 |
s << '<nobr>' << mgrs.join(', ') << '</nobr>'
|
|
| 82 |
else |
|
| 83 |
s << mgrs.join(', ')
|
|
| 84 |
end |
|
| 85 |
end |
|
| 86 |
end |
|
| 87 |
end |
|
| 88 |
|
|
| 89 |
s << "</td>" |
|
| 90 |
|
|
| 91 |
# taglist |
|
| 92 |
s << "<td class='tags' align=top>" << project.tag_counts.collect{ |t| render_project_tag_link(t) }.join(', ') << "</td>"
|
|
| 93 |
s << "<td class='created_on' align=top>" << format_date(project.created_on) << "</td>" |
|
| 94 |
s << "<td class='updated_on' align=top>" << format_date(project.updated_on) << "</td>" |
|
| 95 |
|
|
| 96 |
s << "</tr>" |
|
| 97 |
|
|
| 98 |
project.children.each do |child| |
|
| 99 |
if child.is_public? or User.current.member_of?(child) |
|
| 100 |
s << render_project_in_table_with_filtering(child, oddeven, level + 1, tokens) |
|
| 101 |
end |
|
| 102 |
end |
|
| 103 |
|
|
| 104 |
s |
|
| 105 |
end |
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
# Renders a tree of projects as a nested set of unordered lists |
|
| 110 |
# The given collection may be a subset of the whole project tree |
|
| 111 |
# (eg. some intermediate nodes are private and can not be seen) |
|
| 112 |
def render_project_hierarchy_with_filtering(projects,custom_fields,question) |
|
| 113 |
s = [] |
|
| 114 |
if projects.any? |
|
| 115 |
tokens = RedmineProjectFiltering.calculate_tokens(question, custom_fields) |
|
| 116 |
debugger |
|
| 117 |
|
|
| 118 |
|
|
| 119 |
ancestors = [] |
|
| 120 |
original_project = @project |
|
| 121 |
projects.each do |project| |
|
| 122 |
# set the project environment to please macros. |
|
| 123 |
@project = project |
|
| 124 |
if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) |
|
| 125 |
s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>"
|
|
| 126 |
else |
|
| 127 |
ancestors.pop |
|
| 128 |
s << "</li>" |
|
| 129 |
while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) |
|
| 130 |
ancestors.pop |
|
| 131 |
s << "</ul></li>" |
|
| 132 |
end |
|
| 133 |
end |
|
| 134 |
classes = (ancestors.empty? ? 'root' : 'child') |
|
| 135 |
s << "<li class='#{classes}'><div class='#{classes}'>" +
|
|
| 136 |
link_to( highlight_tokens(project.name, tokens), |
|
| 137 |
{:controller => 'projects', :action => 'show', :id => project},
|
|
| 138 |
:class => "project #{User.current.member_of?(project) ? 'my-project' : nil}"
|
|
| 139 |
) |
|
| 140 |
s << "<ul class='filter_fields'>" |
|
| 141 |
|
|
| 142 |
# CustomField.usable_for_project_filtering.each do |field| |
|
| 143 |
# value_model = project.custom_value_for(field.id) |
|
| 144 |
# value = value_model.present? ? value_model.value : nil |
|
| 145 |
# s << "<li><b>#{field.name.humanize}:</b> #{highlight_tokens(value, tokens)}</li>" if value.present?
|
|
| 146 |
# end |
|
| 147 |
|
|
| 148 |
s << "</ul>" |
|
| 149 |
s << "<div class='clear'></div>" |
|
| 150 |
unless project.description.blank? |
|
| 151 |
s << "<div class='wiki description'>" |
|
| 152 |
s << "<b>#{ t(:field_description) }:</b>"
|
|
| 153 |
s << highlight_tokens(textilizable(project.short_description, :project => project), tokens) |
|
| 154 |
s << "\n</div>" |
|
| 155 |
end |
|
| 156 |
s << "</div>" |
|
| 157 |
ancestors << project |
|
| 158 |
end |
|
| 159 |
ancestors.size.times{ s << "</li></ul>" }
|
|
| 160 |
@project = original_project |
|
| 161 |
end |
|
| 162 |
s.join "\n" |
|
| 163 |
end |
|
| 164 |
|
|
| 165 |
private |
|
| 166 |
|
|
| 167 |
# copied from search_helper. This one doesn't escape html or limit the text length |
|
| 168 |
def highlight_tokens(text, tokens) |
|
| 169 |
return text unless text && tokens && !tokens.empty? |
|
| 170 |
re_tokens = tokens.collect {|t| Regexp.escape(t)}
|
|
| 171 |
regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE
|
|
| 172 |
result = '' |
|
| 173 |
text.split(regexp).each_with_index do |words, i| |
|
| 174 |
words = words.mb_chars |
|
| 175 |
if i.even? |
|
| 176 |
result << words |
|
| 177 |
else |
|
| 178 |
t = (tokens.index(words.downcase) || 0) % 4 |
|
| 179 |
result << content_tag('span', words, :class => "highlight token-#{t}")
|
|
| 180 |
end |
|
| 181 |
end |
|
| 182 |
result |
|
| 183 |
end |
|
| 184 |
|
|
| 185 |
end |
|
| 186 |
end |
|
| 187 |
end |
|
| 188 |
end |
|
| 189 |
|
|
| 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