To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / vendor / plugins / redmine_tags / lib / redmine_tags / patches / projects_controller_patch.rb @ 765:7fd52a786954
History | View | Annotate | Download (2.55 KB)
| 1 | 730:4a9bb3b8d5cd | luis | 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 | 749:3f28aebc5fc1 | luis | before_filter :filter_projects, :only => :index |
| 12 | 730:4a9bb3b8d5cd | luis | end
|
| 13 | end
|
||
| 14 | |||
| 15 | module InstanceMethods |
||
| 16 | 752:ded6cd947ade | luis | def add_tags_to_project |
| 17 | |||
| 18 | 731:3f87a3b61d9c | luis | 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 | 752:ded6cd947ade | luis | |
| 22 | 731:3f87a3b61d9c | luis | unless (old_tags == new_tags)
|
| 23 | @project.tag_list = new_tags
|
||
| 24 | end
|
||
| 25 | 739:b7ac21913927 | luis | end
|
| 26 | 730:4a9bb3b8d5cd | luis | end
|
| 27 | 752:ded6cd947ade | luis | |
| 28 | 755:bde9c5bfb559 | luis | # # luisf - TO BE REMOVED?
|
| 29 | # def calculate_project_filtering_settings
|
||
| 30 | # @project_filtering_settings = Setting[:plugin_redmine_project_filtering]
|
||
| 31 | # end
|
||
| 32 | 752:ded6cd947ade | luis | |
| 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 | 755:bde9c5bfb559 | luis | def calculate_filtered_projects |
| 57 | 752:ded6cd947ade | luis | @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 | 739:b7ac21913927 | luis | end
|
| 64 | |||
| 65 | 752:ded6cd947ade | luis | @projects = Project.visible |
| 66 | 749:3f28aebc5fc1 | luis | |
| 67 | 752:ded6cd947ade | luis | @featured_projects = @projects.featured if Project.respond_to? :featured |
| 68 | 739:b7ac21913927 | luis | |
| 69 | 752:ded6cd947ade | luis | # 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 | 739:b7ac21913927 | luis | |
| 73 | 755:bde9c5bfb559 | luis | debugger |
| 74 | |||
| 75 | 752:ded6cd947ade | luis | # intersection of both prject groups
|
| 76 | @projects = @projects && @tagged_projects_ids unless @tag_list.empty? |
||
| 77 | 755:bde9c5bfb559 | luis | |
| 78 | 760:b2a9e64b8283 | luis | debugger |
| 79 | 755:bde9c5bfb559 | luis | @filtered_projects = @projects |
| 80 | 752:ded6cd947ade | luis | end
|
| 81 | 730:4a9bb3b8d5cd | luis | end
|
| 82 | end
|
||
| 83 | end
|
||
| 84 | end |