@@ -0,0 +1,22 | |||||
|
1 | --- | |||
|
2 | queries_001: | |||
|
3 | name: Multiple custom fields query | |||
|
4 | project_id: 1 | |||
|
5 | filters: | | |||
|
6 | --- | |||
|
7 | cf_1: | |||
|
8 | :values: | |||
|
9 | - MySQL | |||
|
10 | :operator: "=" | |||
|
11 | status_id: | |||
|
12 | :values: | |||
|
13 | - "1" | |||
|
14 | :operator: o | |||
|
15 | cf_2: | |||
|
16 | :values: | |||
|
17 | - "125" | |||
|
18 | :operator: "=" | |||
|
19 | ||||
|
20 | id: 1 | |||
|
21 | is_public: true | |||
|
22 | user_id: 1 |
@@ -0,0 +1,31 | |||||
|
1 | # redMine - project management software | |||
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU General Public License | |||
|
15 | # along with this program; if not, write to the Free Software | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |||
|
19 | ||||
|
20 | class QueryTest < Test::Unit::TestCase | |||
|
21 | fixtures :projects, :users, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries | |||
|
22 | ||||
|
23 | def test_query_with_multiple_custom_fields | |||
|
24 | query = Query.find(1) | |||
|
25 | assert query.valid? | |||
|
26 | assert query.statement.include?("custom_values.value IN ('MySQL')") | |||
|
27 | issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement | |||
|
28 | assert_equal 1, issues.length | |||
|
29 | assert_equal Issue.find(3), issues.first | |||
|
30 | end | |||
|
31 | end |
@@ -1,98 +1,98 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class FeedsController < ApplicationController |
|
18 | class FeedsController < ApplicationController | |
19 | before_filter :find_scope |
|
19 | before_filter :find_scope | |
20 | session :off |
|
20 | session :off | |
21 |
|
21 | |||
22 | helper :issues |
|
22 | helper :issues | |
23 | include IssuesHelper |
|
23 | include IssuesHelper | |
24 | helper :custom_fields |
|
24 | helper :custom_fields | |
25 | include CustomFieldsHelper |
|
25 | include CustomFieldsHelper | |
26 |
|
26 | |||
27 | # news feeds |
|
27 | # news feeds | |
28 | def news |
|
28 | def news | |
29 | News.with_scope(:find => @find_options) do |
|
29 | News.with_scope(:find => @find_options) do | |
30 | @news = News.find :all, :order => "#{News.table_name}.created_on DESC", :include => [ :author, :project ] |
|
30 | @news = News.find :all, :order => "#{News.table_name}.created_on DESC", :include => [ :author, :project ] | |
31 | end |
|
31 | end | |
32 | headers["Content-Type"] = "application/rss+xml" |
|
32 | headers["Content-Type"] = "application/rss+xml" | |
33 | render :action => 'news_atom' if 'atom' == params[:format] |
|
33 | render :action => 'news_atom' if 'atom' == params[:format] | |
34 | end |
|
34 | end | |
35 |
|
35 | |||
36 | # issue feeds |
|
36 | # issue feeds | |
37 | def issues |
|
37 | def issues | |
38 | if @project && params[:query_id] |
|
38 | if @project && params[:query_id] | |
39 | query = Query.find(params[:query_id]) |
|
39 | query = Query.find(params[:query_id]) | |
40 | query.executed_by = @user |
|
40 | query.executed_by = @user | |
41 | # ignore query if it's not valid |
|
41 | # ignore query if it's not valid | |
42 | query = nil unless query.valid? |
|
42 | query = nil unless query.valid? | |
43 | # override with query conditions |
|
43 | # override with query conditions | |
44 | @find_options[:conditions] = query.statement if query.valid? and @project == query.project |
|
44 | @find_options[:conditions] = query.statement if query.valid? and @project == query.project | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | Issue.with_scope(:find => @find_options) do |
|
47 | Issue.with_scope(:find => @find_options) do | |
48 |
@issues = Issue.find :all, :include => [:project, :author, :tracker, :status |
|
48 | @issues = Issue.find :all, :include => [:project, :author, :tracker, :status], | |
49 | :order => "#{Issue.table_name}.created_on DESC" |
|
49 | :order => "#{Issue.table_name}.created_on DESC" | |
50 | end |
|
50 | end | |
51 | @title = (@project ? @project.name : Setting.app_title) + ": " + (query ? query.name : l(:label_reported_issues)) |
|
51 | @title = (@project ? @project.name : Setting.app_title) + ": " + (query ? query.name : l(:label_reported_issues)) | |
52 | headers["Content-Type"] = "application/rss+xml" |
|
52 | headers["Content-Type"] = "application/rss+xml" | |
53 | render :action => 'issues_atom' if 'atom' == params[:format] |
|
53 | render :action => 'issues_atom' if 'atom' == params[:format] | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | # issue changes feeds |
|
56 | # issue changes feeds | |
57 | def history |
|
57 | def history | |
58 | if @project && params[:query_id] |
|
58 | if @project && params[:query_id] | |
59 | query = Query.find(params[:query_id]) |
|
59 | query = Query.find(params[:query_id]) | |
60 | query.executed_by = @user |
|
60 | query.executed_by = @user | |
61 | # ignore query if it's not valid |
|
61 | # ignore query if it's not valid | |
62 | query = nil unless query.valid? |
|
62 | query = nil unless query.valid? | |
63 | # override with query conditions |
|
63 | # override with query conditions | |
64 | @find_options[:conditions] = query.statement if query.valid? and @project == query.project |
|
64 | @find_options[:conditions] = query.statement if query.valid? and @project == query.project | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | Journal.with_scope(:find => @find_options) do |
|
67 | Journal.with_scope(:find => @find_options) do | |
68 |
@journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status |
|
68 | @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ], | |
69 | :order => "#{Journal.table_name}.created_on DESC" |
|
69 | :order => "#{Journal.table_name}.created_on DESC" | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | @title = (@project ? @project.name : Setting.app_title) + ": " + (query ? query.name : l(:label_changes_details)) |
|
72 | @title = (@project ? @project.name : Setting.app_title) + ": " + (query ? query.name : l(:label_changes_details)) | |
73 | headers["Content-Type"] = "application/rss+xml" |
|
73 | headers["Content-Type"] = "application/rss+xml" | |
74 | render :action => 'history_atom' if 'atom' == params[:format] |
|
74 | render :action => 'history_atom' if 'atom' == params[:format] | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | private |
|
77 | private | |
78 | # override for feeds specific authentication |
|
78 | # override for feeds specific authentication | |
79 | def check_if_login_required |
|
79 | def check_if_login_required | |
80 | @user = User.find_by_rss_key(params[:key]) |
|
80 | @user = User.find_by_rss_key(params[:key]) | |
81 | render(:nothing => true, :status => 403) and return false if !@user && Setting.login_required? |
|
81 | render(:nothing => true, :status => 403) and return false if !@user && Setting.login_required? | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def find_scope |
|
84 | def find_scope | |
85 | if params[:project_id] |
|
85 | if params[:project_id] | |
86 | # project feed |
|
86 | # project feed | |
87 | # check if project is public or if the user is a member |
|
87 | # check if project is public or if the user is a member | |
88 | @project = Project.find(params[:project_id]) |
|
88 | @project = Project.find(params[:project_id]) | |
89 | render(:nothing => true, :status => 403) and return false unless @project.is_public? || (@user && @user.role_for_project(@project)) |
|
89 | render(:nothing => true, :status => 403) and return false unless @project.is_public? || (@user && @user.role_for_project(@project)) | |
90 | scope = ["#{Project.table_name}.id=?", params[:project_id].to_i] |
|
90 | scope = ["#{Project.table_name}.id=?", params[:project_id].to_i] | |
91 | else |
|
91 | else | |
92 | # global feed |
|
92 | # global feed | |
93 | scope = ["#{Project.table_name}.is_public=?", true] |
|
93 | scope = ["#{Project.table_name}.is_public=?", true] | |
94 | end |
|
94 | end | |
95 | @find_options = {:conditions => scope, :limit => Setting.feeds_limit.to_i} |
|
95 | @find_options = {:conditions => scope, :limit => Setting.feeds_limit.to_i} | |
96 | return true |
|
96 | return true | |
97 | end |
|
97 | end | |
98 | end |
|
98 | end |
@@ -1,681 +1,681 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require 'csv' |
|
18 | require 'csv' | |
19 |
|
19 | |||
20 | class ProjectsController < ApplicationController |
|
20 | class ProjectsController < ApplicationController | |
21 | layout 'base' |
|
21 | layout 'base' | |
22 | before_filter :find_project, :except => [ :index, :list, :add ] |
|
22 | before_filter :find_project, :except => [ :index, :list, :add ] | |
23 | before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ] |
|
23 | before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ] | |
24 | before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ] |
|
24 | before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ] | |
25 |
|
25 | |||
26 | cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ] |
|
26 | cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ] | |
27 | cache_sweeper :issue_sweeper, :only => [ :add_issue ] |
|
27 | cache_sweeper :issue_sweeper, :only => [ :add_issue ] | |
28 | cache_sweeper :version_sweeper, :only => [ :add_version ] |
|
28 | cache_sweeper :version_sweeper, :only => [ :add_version ] | |
29 |
|
29 | |||
30 | helper :sort |
|
30 | helper :sort | |
31 | include SortHelper |
|
31 | include SortHelper | |
32 | helper :custom_fields |
|
32 | helper :custom_fields | |
33 | include CustomFieldsHelper |
|
33 | include CustomFieldsHelper | |
34 | helper :ifpdf |
|
34 | helper :ifpdf | |
35 | include IfpdfHelper |
|
35 | include IfpdfHelper | |
36 | helper IssuesHelper |
|
36 | helper IssuesHelper | |
37 | helper :queries |
|
37 | helper :queries | |
38 | include QueriesHelper |
|
38 | include QueriesHelper | |
39 | helper :repositories |
|
39 | helper :repositories | |
40 | include RepositoriesHelper |
|
40 | include RepositoriesHelper | |
41 | include ProjectsHelper |
|
41 | include ProjectsHelper | |
42 |
|
42 | |||
43 | def index |
|
43 | def index | |
44 | list |
|
44 | list | |
45 | render :action => 'list' unless request.xhr? |
|
45 | render :action => 'list' unless request.xhr? | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | # Lists public projects |
|
48 | # Lists public projects | |
49 | def list |
|
49 | def list | |
50 | sort_init "#{Project.table_name}.name", "asc" |
|
50 | sort_init "#{Project.table_name}.name", "asc" | |
51 | sort_update |
|
51 | sort_update | |
52 | @project_count = Project.count(:all, :conditions => Project.visible_by(logged_in_user)) |
|
52 | @project_count = Project.count(:all, :conditions => Project.visible_by(logged_in_user)) | |
53 | @project_pages = Paginator.new self, @project_count, |
|
53 | @project_pages = Paginator.new self, @project_count, | |
54 | 15, |
|
54 | 15, | |
55 | params['page'] |
|
55 | params['page'] | |
56 | @projects = Project.find :all, :order => sort_clause, |
|
56 | @projects = Project.find :all, :order => sort_clause, | |
57 | :conditions => Project.visible_by(logged_in_user), |
|
57 | :conditions => Project.visible_by(logged_in_user), | |
58 | :include => :parent, |
|
58 | :include => :parent, | |
59 | :limit => @project_pages.items_per_page, |
|
59 | :limit => @project_pages.items_per_page, | |
60 | :offset => @project_pages.current.offset |
|
60 | :offset => @project_pages.current.offset | |
61 |
|
61 | |||
62 | render :action => "list", :layout => false if request.xhr? |
|
62 | render :action => "list", :layout => false if request.xhr? | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | # Add a new project |
|
65 | # Add a new project | |
66 | def add |
|
66 | def add | |
67 | @custom_fields = IssueCustomField.find(:all) |
|
67 | @custom_fields = IssueCustomField.find(:all) | |
68 | @root_projects = Project.find(:all, :conditions => "parent_id is null") |
|
68 | @root_projects = Project.find(:all, :conditions => "parent_id is null") | |
69 | @project = Project.new(params[:project]) |
|
69 | @project = Project.new(params[:project]) | |
70 | if request.get? |
|
70 | if request.get? | |
71 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } |
|
71 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } | |
72 | else |
|
72 | else | |
73 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
73 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
74 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
74 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } | |
75 | @project.custom_values = @custom_values |
|
75 | @project.custom_values = @custom_values | |
76 | if params[:repository_enabled] && params[:repository_enabled] == "1" |
|
76 | if params[:repository_enabled] && params[:repository_enabled] == "1" | |
77 | @project.repository = Repository.factory(params[:repository_scm]) |
|
77 | @project.repository = Repository.factory(params[:repository_scm]) | |
78 | @project.repository.attributes = params[:repository] |
|
78 | @project.repository.attributes = params[:repository] | |
79 | end |
|
79 | end | |
80 | if "1" == params[:wiki_enabled] |
|
80 | if "1" == params[:wiki_enabled] | |
81 | @project.wiki = Wiki.new |
|
81 | @project.wiki = Wiki.new | |
82 | @project.wiki.attributes = params[:wiki] |
|
82 | @project.wiki.attributes = params[:wiki] | |
83 | end |
|
83 | end | |
84 | if @project.save |
|
84 | if @project.save | |
85 | flash[:notice] = l(:notice_successful_create) |
|
85 | flash[:notice] = l(:notice_successful_create) | |
86 | redirect_to :controller => 'admin', :action => 'projects' |
|
86 | redirect_to :controller => 'admin', :action => 'projects' | |
87 | end |
|
87 | end | |
88 | end |
|
88 | end | |
89 | end |
|
89 | end | |
90 |
|
90 | |||
91 | # Show @project |
|
91 | # Show @project | |
92 | def show |
|
92 | def show | |
93 | @custom_values = @project.custom_values.find(:all, :include => :custom_field) |
|
93 | @custom_values = @project.custom_values.find(:all, :include => :custom_field) | |
94 | @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role} |
|
94 | @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role} | |
95 | @subprojects = @project.active_children |
|
95 | @subprojects = @project.active_children | |
96 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
|
96 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") | |
97 | @trackers = Tracker.find(:all, :order => 'position') |
|
97 | @trackers = Tracker.find(:all, :order => 'position') | |
98 | @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false]) |
|
98 | @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false]) | |
99 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) |
|
99 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) | |
100 |
|
100 | |||
101 | @key = logged_in_user.get_or_create_rss_key.value if logged_in_user |
|
101 | @key = logged_in_user.get_or_create_rss_key.value if logged_in_user | |
102 | end |
|
102 | end | |
103 |
|
103 | |||
104 | def settings |
|
104 | def settings | |
105 | @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id]) |
|
105 | @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id]) | |
106 | @custom_fields = IssueCustomField.find(:all) |
|
106 | @custom_fields = IssueCustomField.find(:all) | |
107 | @issue_category ||= IssueCategory.new |
|
107 | @issue_category ||= IssueCategory.new | |
108 | @member ||= @project.members.new |
|
108 | @member ||= @project.members.new | |
109 | @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } |
|
109 | @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } | |
110 | end |
|
110 | end | |
111 |
|
111 | |||
112 | # Edit @project |
|
112 | # Edit @project | |
113 | def edit |
|
113 | def edit | |
114 | if request.post? |
|
114 | if request.post? | |
115 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
115 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
116 | if params[:custom_fields] |
|
116 | if params[:custom_fields] | |
117 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
117 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } | |
118 | @project.custom_values = @custom_values |
|
118 | @project.custom_values = @custom_values | |
119 | end |
|
119 | end | |
120 | if params[:repository_enabled] |
|
120 | if params[:repository_enabled] | |
121 | case params[:repository_enabled] |
|
121 | case params[:repository_enabled] | |
122 | when "0" |
|
122 | when "0" | |
123 | @project.repository = nil |
|
123 | @project.repository = nil | |
124 | when "1" |
|
124 | when "1" | |
125 | @project.repository ||= Repository.factory(params[:repository_scm]) |
|
125 | @project.repository ||= Repository.factory(params[:repository_scm]) | |
126 | @project.repository.update_attributes params[:repository] if @project.repository |
|
126 | @project.repository.update_attributes params[:repository] if @project.repository | |
127 | end |
|
127 | end | |
128 | end |
|
128 | end | |
129 | if params[:wiki_enabled] |
|
129 | if params[:wiki_enabled] | |
130 | case params[:wiki_enabled] |
|
130 | case params[:wiki_enabled] | |
131 | when "0" |
|
131 | when "0" | |
132 | @project.wiki.destroy if @project.wiki |
|
132 | @project.wiki.destroy if @project.wiki | |
133 | when "1" |
|
133 | when "1" | |
134 | @project.wiki ||= Wiki.new |
|
134 | @project.wiki ||= Wiki.new | |
135 | @project.wiki.update_attributes params[:wiki] |
|
135 | @project.wiki.update_attributes params[:wiki] | |
136 | end |
|
136 | end | |
137 | end |
|
137 | end | |
138 | @project.attributes = params[:project] |
|
138 | @project.attributes = params[:project] | |
139 | if @project.save |
|
139 | if @project.save | |
140 | flash[:notice] = l(:notice_successful_update) |
|
140 | flash[:notice] = l(:notice_successful_update) | |
141 | redirect_to :action => 'settings', :id => @project |
|
141 | redirect_to :action => 'settings', :id => @project | |
142 | else |
|
142 | else | |
143 | settings |
|
143 | settings | |
144 | render :action => 'settings' |
|
144 | render :action => 'settings' | |
145 | end |
|
145 | end | |
146 | end |
|
146 | end | |
147 | end |
|
147 | end | |
148 |
|
148 | |||
149 | def archive |
|
149 | def archive | |
150 | @project.archive if request.post? && @project.active? |
|
150 | @project.archive if request.post? && @project.active? | |
151 | redirect_to :controller => 'admin', :action => 'projects' |
|
151 | redirect_to :controller => 'admin', :action => 'projects' | |
152 | end |
|
152 | end | |
153 |
|
153 | |||
154 | def unarchive |
|
154 | def unarchive | |
155 | @project.unarchive if request.post? && !@project.active? |
|
155 | @project.unarchive if request.post? && !@project.active? | |
156 | redirect_to :controller => 'admin', :action => 'projects' |
|
156 | redirect_to :controller => 'admin', :action => 'projects' | |
157 | end |
|
157 | end | |
158 |
|
158 | |||
159 | # Delete @project |
|
159 | # Delete @project | |
160 | def destroy |
|
160 | def destroy | |
161 | @project_to_destroy = @project |
|
161 | @project_to_destroy = @project | |
162 | if request.post? and params[:confirm] |
|
162 | if request.post? and params[:confirm] | |
163 | @project_to_destroy.destroy |
|
163 | @project_to_destroy.destroy | |
164 | redirect_to :controller => 'admin', :action => 'projects' |
|
164 | redirect_to :controller => 'admin', :action => 'projects' | |
165 | end |
|
165 | end | |
166 | # hide project in layout |
|
166 | # hide project in layout | |
167 | @project = nil |
|
167 | @project = nil | |
168 | end |
|
168 | end | |
169 |
|
169 | |||
170 | # Add a new issue category to @project |
|
170 | # Add a new issue category to @project | |
171 | def add_issue_category |
|
171 | def add_issue_category | |
172 | @category = @project.issue_categories.build(params[:category]) |
|
172 | @category = @project.issue_categories.build(params[:category]) | |
173 | if request.post? and @category.save |
|
173 | if request.post? and @category.save | |
174 | respond_to do |format| |
|
174 | respond_to do |format| | |
175 | format.html do |
|
175 | format.html do | |
176 | flash[:notice] = l(:notice_successful_create) |
|
176 | flash[:notice] = l(:notice_successful_create) | |
177 | redirect_to :action => 'settings', :tab => 'categories', :id => @project |
|
177 | redirect_to :action => 'settings', :tab => 'categories', :id => @project | |
178 | end |
|
178 | end | |
179 | format.js do |
|
179 | format.js do | |
180 | # IE doesn't support the replace_html rjs method for select box options |
|
180 | # IE doesn't support the replace_html rjs method for select box options | |
181 | render(:update) {|page| page.replace "issue_category_id", |
|
181 | render(:update) {|page| page.replace "issue_category_id", | |
182 | content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]') |
|
182 | content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]') | |
183 | } |
|
183 | } | |
184 | end |
|
184 | end | |
185 | end |
|
185 | end | |
186 | end |
|
186 | end | |
187 | end |
|
187 | end | |
188 |
|
188 | |||
189 | # Add a new version to @project |
|
189 | # Add a new version to @project | |
190 | def add_version |
|
190 | def add_version | |
191 | @version = @project.versions.build(params[:version]) |
|
191 | @version = @project.versions.build(params[:version]) | |
192 | if request.post? and @version.save |
|
192 | if request.post? and @version.save | |
193 | flash[:notice] = l(:notice_successful_create) |
|
193 | flash[:notice] = l(:notice_successful_create) | |
194 | redirect_to :action => 'settings', :tab => 'versions', :id => @project |
|
194 | redirect_to :action => 'settings', :tab => 'versions', :id => @project | |
195 | end |
|
195 | end | |
196 | end |
|
196 | end | |
197 |
|
197 | |||
198 | # Add a new member to @project |
|
198 | # Add a new member to @project | |
199 | def add_member |
|
199 | def add_member | |
200 | @member = @project.members.build(params[:member]) |
|
200 | @member = @project.members.build(params[:member]) | |
201 | if request.post? && @member.save |
|
201 | if request.post? && @member.save | |
202 | respond_to do |format| |
|
202 | respond_to do |format| | |
203 | format.html { redirect_to :action => 'settings', :tab => 'members', :id => @project } |
|
203 | format.html { redirect_to :action => 'settings', :tab => 'members', :id => @project } | |
204 | format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'members'} } |
|
204 | format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'members'} } | |
205 | end |
|
205 | end | |
206 | else |
|
206 | else | |
207 | settings |
|
207 | settings | |
208 | render :action => 'settings' |
|
208 | render :action => 'settings' | |
209 | end |
|
209 | end | |
210 | end |
|
210 | end | |
211 |
|
211 | |||
212 | # Show members list of @project |
|
212 | # Show members list of @project | |
213 | def list_members |
|
213 | def list_members | |
214 | @members = @project.members.find(:all) |
|
214 | @members = @project.members.find(:all) | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | # Add a new document to @project |
|
217 | # Add a new document to @project | |
218 | def add_document |
|
218 | def add_document | |
219 | @categories = Enumeration::get_values('DCAT') |
|
219 | @categories = Enumeration::get_values('DCAT') | |
220 | @document = @project.documents.build(params[:document]) |
|
220 | @document = @project.documents.build(params[:document]) | |
221 | if request.post? and @document.save |
|
221 | if request.post? and @document.save | |
222 | # Save the attachments |
|
222 | # Save the attachments | |
223 | params[:attachments].each { |a| |
|
223 | params[:attachments].each { |a| | |
224 | Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0 |
|
224 | Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0 | |
225 | } if params[:attachments] and params[:attachments].is_a? Array |
|
225 | } if params[:attachments] and params[:attachments].is_a? Array | |
226 | flash[:notice] = l(:notice_successful_create) |
|
226 | flash[:notice] = l(:notice_successful_create) | |
227 | Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
227 | Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
228 | redirect_to :action => 'list_documents', :id => @project |
|
228 | redirect_to :action => 'list_documents', :id => @project | |
229 | end |
|
229 | end | |
230 | end |
|
230 | end | |
231 |
|
231 | |||
232 | # Show documents list of @project |
|
232 | # Show documents list of @project | |
233 | def list_documents |
|
233 | def list_documents | |
234 | @documents = @project.documents.find :all, :include => :category |
|
234 | @documents = @project.documents.find :all, :include => :category | |
235 | end |
|
235 | end | |
236 |
|
236 | |||
237 | # Add a new issue to @project |
|
237 | # Add a new issue to @project | |
238 | def add_issue |
|
238 | def add_issue | |
239 | @tracker = Tracker.find(params[:tracker_id]) |
|
239 | @tracker = Tracker.find(params[:tracker_id]) | |
240 | @priorities = Enumeration::get_values('IPRI') |
|
240 | @priorities = Enumeration::get_values('IPRI') | |
241 |
|
241 | |||
242 | default_status = IssueStatus.default |
|
242 | default_status = IssueStatus.default | |
243 | unless default_status |
|
243 | unless default_status | |
244 | flash.now[:error] = 'No default issue status defined. Please check your configuration.' |
|
244 | flash.now[:error] = 'No default issue status defined. Please check your configuration.' | |
245 | render :nothing => true, :layout => true |
|
245 | render :nothing => true, :layout => true | |
246 | return |
|
246 | return | |
247 | end |
|
247 | end | |
248 | @issue = Issue.new(:project => @project, :tracker => @tracker) |
|
248 | @issue = Issue.new(:project => @project, :tracker => @tracker) | |
249 | @issue.status = default_status |
|
249 | @issue.status = default_status | |
250 | @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user |
|
250 | @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user | |
251 | if request.get? |
|
251 | if request.get? | |
252 | @issue.start_date = Date.today |
|
252 | @issue.start_date = Date.today | |
253 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } |
|
253 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } | |
254 | else |
|
254 | else | |
255 | @issue.attributes = params[:issue] |
|
255 | @issue.attributes = params[:issue] | |
256 |
|
256 | |||
257 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) |
|
257 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) | |
258 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status |
|
258 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status | |
259 |
|
259 | |||
260 | @issue.author_id = self.logged_in_user.id if self.logged_in_user |
|
260 | @issue.author_id = self.logged_in_user.id if self.logged_in_user | |
261 | # Multiple file upload |
|
261 | # Multiple file upload | |
262 | @attachments = [] |
|
262 | @attachments = [] | |
263 | params[:attachments].each { |a| |
|
263 | params[:attachments].each { |a| | |
264 | @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0 |
|
264 | @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0 | |
265 | } if params[:attachments] and params[:attachments].is_a? Array |
|
265 | } if params[:attachments] and params[:attachments].is_a? Array | |
266 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) } |
|
266 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) } | |
267 | @issue.custom_values = @custom_values |
|
267 | @issue.custom_values = @custom_values | |
268 | if @issue.save |
|
268 | if @issue.save | |
269 | @attachments.each(&:save) |
|
269 | @attachments.each(&:save) | |
270 | flash[:notice] = l(:notice_successful_create) |
|
270 | flash[:notice] = l(:notice_successful_create) | |
271 | Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
271 | Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
272 | redirect_to :action => 'list_issues', :id => @project |
|
272 | redirect_to :action => 'list_issues', :id => @project | |
273 | end |
|
273 | end | |
274 | end |
|
274 | end | |
275 | end |
|
275 | end | |
276 |
|
276 | |||
277 | # Show filtered/sorted issues list of @project |
|
277 | # Show filtered/sorted issues list of @project | |
278 | def list_issues |
|
278 | def list_issues | |
279 | sort_init "#{Issue.table_name}.id", "desc" |
|
279 | sort_init "#{Issue.table_name}.id", "desc" | |
280 | sort_update |
|
280 | sort_update | |
281 |
|
281 | |||
282 | retrieve_query |
|
282 | retrieve_query | |
283 |
|
283 | |||
284 | @results_per_page_options = [ 15, 25, 50, 100 ] |
|
284 | @results_per_page_options = [ 15, 25, 50, 100 ] | |
285 | if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i |
|
285 | if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i | |
286 | @results_per_page = params[:per_page].to_i |
|
286 | @results_per_page = params[:per_page].to_i | |
287 | session[:results_per_page] = @results_per_page |
|
287 | session[:results_per_page] = @results_per_page | |
288 | else |
|
288 | else | |
289 | @results_per_page = session[:results_per_page] || 25 |
|
289 | @results_per_page = session[:results_per_page] || 25 | |
290 | end |
|
290 | end | |
291 |
|
291 | |||
292 | if @query.valid? |
|
292 | if @query.valid? | |
293 |
@issue_count = Issue.count(:include => [:status, :project |
|
293 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) | |
294 | @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] |
|
294 | @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] | |
295 | @issues = Issue.find :all, :order => sort_clause, |
|
295 | @issues = Issue.find :all, :order => sort_clause, | |
296 |
:include => [ :assigned_to, :status, :tracker, :project, :priority |
|
296 | :include => [ :assigned_to, :status, :tracker, :project, :priority ], | |
297 | :conditions => @query.statement, |
|
297 | :conditions => @query.statement, | |
298 | :limit => @issue_pages.items_per_page, |
|
298 | :limit => @issue_pages.items_per_page, | |
299 | :offset => @issue_pages.current.offset |
|
299 | :offset => @issue_pages.current.offset | |
300 | end |
|
300 | end | |
301 | render :layout => false if request.xhr? |
|
301 | render :layout => false if request.xhr? | |
302 | end |
|
302 | end | |
303 |
|
303 | |||
304 | # Export filtered/sorted issues list to CSV |
|
304 | # Export filtered/sorted issues list to CSV | |
305 | def export_issues_csv |
|
305 | def export_issues_csv | |
306 | sort_init "#{Issue.table_name}.id", "desc" |
|
306 | sort_init "#{Issue.table_name}.id", "desc" | |
307 | sort_update |
|
307 | sort_update | |
308 |
|
308 | |||
309 | retrieve_query |
|
309 | retrieve_query | |
310 | render :action => 'list_issues' and return unless @query.valid? |
|
310 | render :action => 'list_issues' and return unless @query.valid? | |
311 |
|
311 | |||
312 | @issues = Issue.find :all, :order => sort_clause, |
|
312 | @issues = Issue.find :all, :order => sort_clause, | |
313 | :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ], |
|
313 | :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ], | |
314 | :conditions => @query.statement, |
|
314 | :conditions => @query.statement, | |
315 | :limit => Setting.issues_export_limit.to_i |
|
315 | :limit => Setting.issues_export_limit.to_i | |
316 |
|
316 | |||
317 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') |
|
317 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') | |
318 | export = StringIO.new |
|
318 | export = StringIO.new | |
319 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| |
|
319 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| | |
320 | # csv header fields |
|
320 | # csv header fields | |
321 | headers = [ "#", l(:field_status), |
|
321 | headers = [ "#", l(:field_status), | |
322 | l(:field_project), |
|
322 | l(:field_project), | |
323 | l(:field_tracker), |
|
323 | l(:field_tracker), | |
324 | l(:field_priority), |
|
324 | l(:field_priority), | |
325 | l(:field_subject), |
|
325 | l(:field_subject), | |
326 | l(:field_assigned_to), |
|
326 | l(:field_assigned_to), | |
327 | l(:field_author), |
|
327 | l(:field_author), | |
328 | l(:field_start_date), |
|
328 | l(:field_start_date), | |
329 | l(:field_due_date), |
|
329 | l(:field_due_date), | |
330 | l(:field_done_ratio), |
|
330 | l(:field_done_ratio), | |
331 | l(:field_created_on), |
|
331 | l(:field_created_on), | |
332 | l(:field_updated_on) |
|
332 | l(:field_updated_on) | |
333 | ] |
|
333 | ] | |
334 | for custom_field in @project.all_custom_fields |
|
334 | for custom_field in @project.all_custom_fields | |
335 | headers << custom_field.name |
|
335 | headers << custom_field.name | |
336 | end |
|
336 | end | |
337 | csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
337 | csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } | |
338 | # csv lines |
|
338 | # csv lines | |
339 | @issues.each do |issue| |
|
339 | @issues.each do |issue| | |
340 | fields = [issue.id, issue.status.name, |
|
340 | fields = [issue.id, issue.status.name, | |
341 | issue.project.name, |
|
341 | issue.project.name, | |
342 | issue.tracker.name, |
|
342 | issue.tracker.name, | |
343 | issue.priority.name, |
|
343 | issue.priority.name, | |
344 | issue.subject, |
|
344 | issue.subject, | |
345 | (issue.assigned_to ? issue.assigned_to.name : ""), |
|
345 | (issue.assigned_to ? issue.assigned_to.name : ""), | |
346 | issue.author.name, |
|
346 | issue.author.name, | |
347 | issue.start_date ? l_date(issue.start_date) : nil, |
|
347 | issue.start_date ? l_date(issue.start_date) : nil, | |
348 | issue.due_date ? l_date(issue.due_date) : nil, |
|
348 | issue.due_date ? l_date(issue.due_date) : nil, | |
349 | issue.done_ratio, |
|
349 | issue.done_ratio, | |
350 | l_datetime(issue.created_on), |
|
350 | l_datetime(issue.created_on), | |
351 | l_datetime(issue.updated_on) |
|
351 | l_datetime(issue.updated_on) | |
352 | ] |
|
352 | ] | |
353 | for custom_field in @project.all_custom_fields |
|
353 | for custom_field in @project.all_custom_fields | |
354 | fields << (show_value issue.custom_value_for(custom_field)) |
|
354 | fields << (show_value issue.custom_value_for(custom_field)) | |
355 | end |
|
355 | end | |
356 | csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
356 | csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } | |
357 | end |
|
357 | end | |
358 | end |
|
358 | end | |
359 | export.rewind |
|
359 | export.rewind | |
360 | send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') |
|
360 | send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') | |
361 | end |
|
361 | end | |
362 |
|
362 | |||
363 | # Export filtered/sorted issues to PDF |
|
363 | # Export filtered/sorted issues to PDF | |
364 | def export_issues_pdf |
|
364 | def export_issues_pdf | |
365 | sort_init "#{Issue.table_name}.id", "desc" |
|
365 | sort_init "#{Issue.table_name}.id", "desc" | |
366 | sort_update |
|
366 | sort_update | |
367 |
|
367 | |||
368 | retrieve_query |
|
368 | retrieve_query | |
369 | render :action => 'list_issues' and return unless @query.valid? |
|
369 | render :action => 'list_issues' and return unless @query.valid? | |
370 |
|
370 | |||
371 | @issues = Issue.find :all, :order => sort_clause, |
|
371 | @issues = Issue.find :all, :order => sort_clause, | |
372 |
:include => [ :author, :status, :tracker, :priority, :project |
|
372 | :include => [ :author, :status, :tracker, :priority, :project ], | |
373 | :conditions => @query.statement, |
|
373 | :conditions => @query.statement, | |
374 | :limit => Setting.issues_export_limit.to_i |
|
374 | :limit => Setting.issues_export_limit.to_i | |
375 |
|
375 | |||
376 | @options_for_rfpdf ||= {} |
|
376 | @options_for_rfpdf ||= {} | |
377 | @options_for_rfpdf[:file_name] = "export.pdf" |
|
377 | @options_for_rfpdf[:file_name] = "export.pdf" | |
378 | render :layout => false |
|
378 | render :layout => false | |
379 | end |
|
379 | end | |
380 |
|
380 | |||
381 | def move_issues |
|
381 | def move_issues | |
382 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] |
|
382 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] | |
383 | redirect_to :action => 'list_issues', :id => @project and return unless @issues |
|
383 | redirect_to :action => 'list_issues', :id => @project and return unless @issues | |
384 | @projects = [] |
|
384 | @projects = [] | |
385 | # find projects to which the user is allowed to move the issue |
|
385 | # find projects to which the user is allowed to move the issue | |
386 | @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role)} |
|
386 | @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role)} | |
387 | # issue can be moved to any tracker |
|
387 | # issue can be moved to any tracker | |
388 | @trackers = Tracker.find(:all) |
|
388 | @trackers = Tracker.find(:all) | |
389 | if request.post? and params[:new_project_id] and params[:new_tracker_id] |
|
389 | if request.post? and params[:new_project_id] and params[:new_tracker_id] | |
390 | new_project = Project.find(params[:new_project_id]) |
|
390 | new_project = Project.find(params[:new_project_id]) | |
391 | new_tracker = Tracker.find(params[:new_tracker_id]) |
|
391 | new_tracker = Tracker.find(params[:new_tracker_id]) | |
392 | @issues.each { |i| |
|
392 | @issues.each { |i| | |
393 | # project dependent properties |
|
393 | # project dependent properties | |
394 | unless i.project_id == new_project.id |
|
394 | unless i.project_id == new_project.id | |
395 | i.category = nil |
|
395 | i.category = nil | |
396 | i.fixed_version = nil |
|
396 | i.fixed_version = nil | |
397 | # delete issue relations |
|
397 | # delete issue relations | |
398 | i.relations_from.clear |
|
398 | i.relations_from.clear | |
399 | i.relations_to.clear |
|
399 | i.relations_to.clear | |
400 | end |
|
400 | end | |
401 | # move the issue |
|
401 | # move the issue | |
402 | i.project = new_project |
|
402 | i.project = new_project | |
403 | i.tracker = new_tracker |
|
403 | i.tracker = new_tracker | |
404 | i.save |
|
404 | i.save | |
405 | } |
|
405 | } | |
406 | flash[:notice] = l(:notice_successful_update) |
|
406 | flash[:notice] = l(:notice_successful_update) | |
407 | redirect_to :action => 'list_issues', :id => @project |
|
407 | redirect_to :action => 'list_issues', :id => @project | |
408 | end |
|
408 | end | |
409 | end |
|
409 | end | |
410 |
|
410 | |||
411 | # Add a news to @project |
|
411 | # Add a news to @project | |
412 | def add_news |
|
412 | def add_news | |
413 | @news = News.new(:project => @project) |
|
413 | @news = News.new(:project => @project) | |
414 | if request.post? |
|
414 | if request.post? | |
415 | @news.attributes = params[:news] |
|
415 | @news.attributes = params[:news] | |
416 | @news.author_id = self.logged_in_user.id if self.logged_in_user |
|
416 | @news.author_id = self.logged_in_user.id if self.logged_in_user | |
417 | if @news.save |
|
417 | if @news.save | |
418 | flash[:notice] = l(:notice_successful_create) |
|
418 | flash[:notice] = l(:notice_successful_create) | |
419 | redirect_to :action => 'list_news', :id => @project |
|
419 | redirect_to :action => 'list_news', :id => @project | |
420 | end |
|
420 | end | |
421 | end |
|
421 | end | |
422 | end |
|
422 | end | |
423 |
|
423 | |||
424 | # Show news list of @project |
|
424 | # Show news list of @project | |
425 | def list_news |
|
425 | def list_news | |
426 | @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC" |
|
426 | @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC" | |
427 | render :action => "list_news", :layout => false if request.xhr? |
|
427 | render :action => "list_news", :layout => false if request.xhr? | |
428 | end |
|
428 | end | |
429 |
|
429 | |||
430 | def add_file |
|
430 | def add_file | |
431 | if request.post? |
|
431 | if request.post? | |
432 | @version = @project.versions.find_by_id(params[:version_id]) |
|
432 | @version = @project.versions.find_by_id(params[:version_id]) | |
433 | # Save the attachments |
|
433 | # Save the attachments | |
434 | @attachments = [] |
|
434 | @attachments = [] | |
435 | params[:attachments].each { |file| |
|
435 | params[:attachments].each { |file| | |
436 | next unless file.size > 0 |
|
436 | next unless file.size > 0 | |
437 | a = Attachment.create(:container => @version, :file => file, :author => logged_in_user) |
|
437 | a = Attachment.create(:container => @version, :file => file, :author => logged_in_user) | |
438 | @attachments << a unless a.new_record? |
|
438 | @attachments << a unless a.new_record? | |
439 | } if params[:attachments] and params[:attachments].is_a? Array |
|
439 | } if params[:attachments] and params[:attachments].is_a? Array | |
440 | Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
440 | Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
441 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
441 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project | |
442 | end |
|
442 | end | |
443 | @versions = @project.versions.sort |
|
443 | @versions = @project.versions.sort | |
444 | end |
|
444 | end | |
445 |
|
445 | |||
446 | def list_files |
|
446 | def list_files | |
447 | @versions = @project.versions.sort |
|
447 | @versions = @project.versions.sort | |
448 | end |
|
448 | end | |
449 |
|
449 | |||
450 | # Show changelog for @project |
|
450 | # Show changelog for @project | |
451 | def changelog |
|
451 | def changelog | |
452 | @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') |
|
452 | @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') | |
453 | retrieve_selected_tracker_ids(@trackers) |
|
453 | retrieve_selected_tracker_ids(@trackers) | |
454 | @versions = @project.versions.sort |
|
454 | @versions = @project.versions.sort | |
455 | end |
|
455 | end | |
456 |
|
456 | |||
457 | def roadmap |
|
457 | def roadmap | |
458 | @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position') |
|
458 | @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position') | |
459 | retrieve_selected_tracker_ids(@trackers) |
|
459 | retrieve_selected_tracker_ids(@trackers) | |
460 | @versions = @project.versions.sort |
|
460 | @versions = @project.versions.sort | |
461 | @versions = @versions.select {|v| !v.completed? } unless params[:completed] |
|
461 | @versions = @versions.select {|v| !v.completed? } unless params[:completed] | |
462 | end |
|
462 | end | |
463 |
|
463 | |||
464 | def activity |
|
464 | def activity | |
465 | if params[:year] and params[:year].to_i > 1900 |
|
465 | if params[:year] and params[:year].to_i > 1900 | |
466 | @year = params[:year].to_i |
|
466 | @year = params[:year].to_i | |
467 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
467 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
468 | @month = params[:month].to_i |
|
468 | @month = params[:month].to_i | |
469 | end |
|
469 | end | |
470 | end |
|
470 | end | |
471 | @year ||= Date.today.year |
|
471 | @year ||= Date.today.year | |
472 | @month ||= Date.today.month |
|
472 | @month ||= Date.today.month | |
473 |
|
473 | |||
474 | @date_from = Date.civil(@year, @month, 1) |
|
474 | @date_from = Date.civil(@year, @month, 1) | |
475 | @date_to = @date_from >> 1 |
|
475 | @date_to = @date_from >> 1 | |
476 |
|
476 | |||
477 | @events_by_day = Hash.new { |h,k| h[k] = [] } |
|
477 | @events_by_day = Hash.new { |h,k| h[k] = [] } | |
478 |
|
478 | |||
479 | unless params[:show_issues] == "0" |
|
479 | unless params[:show_issues] == "0" | |
480 | @project.issues.find(:all, :include => [:author], :conditions => ["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to] ).each { |i| |
|
480 | @project.issues.find(:all, :include => [:author], :conditions => ["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to] ).each { |i| | |
481 | @events_by_day[i.created_on.to_date] << i |
|
481 | @events_by_day[i.created_on.to_date] << i | |
482 | } |
|
482 | } | |
483 | @project.issue_changes.find(:all, :include => :details, :conditions => ["(#{Journal.table_name}.created_on BETWEEN ? AND ?) AND (#{JournalDetail.table_name}.prop_key = 'status_id')", @date_from, @date_to] ).each { |i| |
|
483 | @project.issue_changes.find(:all, :include => :details, :conditions => ["(#{Journal.table_name}.created_on BETWEEN ? AND ?) AND (#{JournalDetail.table_name}.prop_key = 'status_id')", @date_from, @date_to] ).each { |i| | |
484 | @events_by_day[i.created_on.to_date] << i |
|
484 | @events_by_day[i.created_on.to_date] << i | |
485 | } |
|
485 | } | |
486 | @show_issues = 1 |
|
486 | @show_issues = 1 | |
487 | end |
|
487 | end | |
488 |
|
488 | |||
489 | unless params[:show_news] == "0" |
|
489 | unless params[:show_news] == "0" | |
490 | @project.news.find(:all, :conditions => ["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to], :include => :author ).each { |i| |
|
490 | @project.news.find(:all, :conditions => ["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to], :include => :author ).each { |i| | |
491 | @events_by_day[i.created_on.to_date] << i |
|
491 | @events_by_day[i.created_on.to_date] << i | |
492 | } |
|
492 | } | |
493 | @show_news = 1 |
|
493 | @show_news = 1 | |
494 | end |
|
494 | end | |
495 |
|
495 | |||
496 | unless params[:show_files] == "0" |
|
496 | unless params[:show_files] == "0" | |
497 | Attachment.find(:all, :select => "#{Attachment.table_name}.*", |
|
497 | Attachment.find(:all, :select => "#{Attachment.table_name}.*", | |
498 | :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", |
|
498 | :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", | |
499 | :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on BETWEEN ? AND ? ", @project.id, @date_from, @date_to], |
|
499 | :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on BETWEEN ? AND ? ", @project.id, @date_from, @date_to], | |
500 | :include => :author ).each { |i| |
|
500 | :include => :author ).each { |i| | |
501 | @events_by_day[i.created_on.to_date] << i |
|
501 | @events_by_day[i.created_on.to_date] << i | |
502 | } |
|
502 | } | |
503 | @show_files = 1 |
|
503 | @show_files = 1 | |
504 | end |
|
504 | end | |
505 |
|
505 | |||
506 | unless params[:show_documents] == "0" |
|
506 | unless params[:show_documents] == "0" | |
507 | @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to] ).each { |i| |
|
507 | @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to] ).each { |i| | |
508 | @events_by_day[i.created_on.to_date] << i |
|
508 | @events_by_day[i.created_on.to_date] << i | |
509 | } |
|
509 | } | |
510 | Attachment.find(:all, :select => "attachments.*", |
|
510 | Attachment.find(:all, :select => "attachments.*", | |
511 | :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", |
|
511 | :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", | |
512 | :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on BETWEEN ? AND ? ", @project.id, @date_from, @date_to], |
|
512 | :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on BETWEEN ? AND ? ", @project.id, @date_from, @date_to], | |
513 | :include => :author ).each { |i| |
|
513 | :include => :author ).each { |i| | |
514 | @events_by_day[i.created_on.to_date] << i |
|
514 | @events_by_day[i.created_on.to_date] << i | |
515 | } |
|
515 | } | |
516 | @show_documents = 1 |
|
516 | @show_documents = 1 | |
517 | end |
|
517 | end | |
518 |
|
518 | |||
519 | unless @project.wiki.nil? || params[:show_wiki_edits] == "0" |
|
519 | unless @project.wiki.nil? || params[:show_wiki_edits] == "0" | |
520 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + |
|
520 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + | |
521 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title" |
|
521 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title" | |
522 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + |
|
522 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + | |
523 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " |
|
523 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " | |
524 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", |
|
524 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", | |
525 | @project.id, @date_from, @date_to] |
|
525 | @project.id, @date_from, @date_to] | |
526 |
|
526 | |||
527 | WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i| |
|
527 | WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i| | |
528 | # We provide this alias so all events can be treated in the same manner |
|
528 | # We provide this alias so all events can be treated in the same manner | |
529 | def i.created_on |
|
529 | def i.created_on | |
530 | self.updated_on |
|
530 | self.updated_on | |
531 | end |
|
531 | end | |
532 | @events_by_day[i.created_on.to_date] << i |
|
532 | @events_by_day[i.created_on.to_date] << i | |
533 | } |
|
533 | } | |
534 | @show_wiki_edits = 1 |
|
534 | @show_wiki_edits = 1 | |
535 | end |
|
535 | end | |
536 |
|
536 | |||
537 | unless @project.repository.nil? || params[:show_changesets] == "0" |
|
537 | unless @project.repository.nil? || params[:show_changesets] == "0" | |
538 | @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i| |
|
538 | @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i| | |
539 | def i.created_on |
|
539 | def i.created_on | |
540 | self.committed_on |
|
540 | self.committed_on | |
541 | end |
|
541 | end | |
542 | @events_by_day[i.created_on.to_date] << i |
|
542 | @events_by_day[i.created_on.to_date] << i | |
543 | } |
|
543 | } | |
544 | @show_changesets = 1 |
|
544 | @show_changesets = 1 | |
545 | end |
|
545 | end | |
546 |
|
546 | |||
547 | render :layout => false if request.xhr? |
|
547 | render :layout => false if request.xhr? | |
548 | end |
|
548 | end | |
549 |
|
549 | |||
550 | def calendar |
|
550 | def calendar | |
551 | @trackers = Tracker.find(:all, :order => 'position') |
|
551 | @trackers = Tracker.find(:all, :order => 'position') | |
552 | retrieve_selected_tracker_ids(@trackers) |
|
552 | retrieve_selected_tracker_ids(@trackers) | |
553 |
|
553 | |||
554 | if params[:year] and params[:year].to_i > 1900 |
|
554 | if params[:year] and params[:year].to_i > 1900 | |
555 | @year = params[:year].to_i |
|
555 | @year = params[:year].to_i | |
556 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
556 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
557 | @month = params[:month].to_i |
|
557 | @month = params[:month].to_i | |
558 | end |
|
558 | end | |
559 | end |
|
559 | end | |
560 | @year ||= Date.today.year |
|
560 | @year ||= Date.today.year | |
561 | @month ||= Date.today.month |
|
561 | @month ||= Date.today.month | |
562 |
|
562 | |||
563 | @date_from = Date.civil(@year, @month, 1) |
|
563 | @date_from = Date.civil(@year, @month, 1) | |
564 | @date_to = (@date_from >> 1)-1 |
|
564 | @date_to = (@date_from >> 1)-1 | |
565 | # start on monday |
|
565 | # start on monday | |
566 | @date_from = @date_from - (@date_from.cwday-1) |
|
566 | @date_from = @date_from - (@date_from.cwday-1) | |
567 | # finish on sunday |
|
567 | # finish on sunday | |
568 | @date_to = @date_to + (7-@date_to.cwday) |
|
568 | @date_to = @date_to + (7-@date_to.cwday) | |
569 |
|
569 | |||
570 | @events = [] |
|
570 | @events = [] | |
571 | @project.issues_with_subprojects(params[:with_subprojects]) do |
|
571 | @project.issues_with_subprojects(params[:with_subprojects]) do | |
572 | @events += Issue.find(:all, |
|
572 | @events += Issue.find(:all, | |
573 | :include => [:tracker, :status, :assigned_to, :priority, :project], |
|
573 | :include => [:tracker, :status, :assigned_to, :priority, :project], | |
574 | :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)) and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')})", @date_from, @date_to, @date_from, @date_to] |
|
574 | :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)) and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')})", @date_from, @date_to, @date_from, @date_to] | |
575 | ) unless @selected_tracker_ids.empty? |
|
575 | ) unless @selected_tracker_ids.empty? | |
576 | end |
|
576 | end | |
577 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
577 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) | |
578 |
|
578 | |||
579 | @ending_events_by_days = @events.group_by {|event| event.due_date} |
|
579 | @ending_events_by_days = @events.group_by {|event| event.due_date} | |
580 | @starting_events_by_days = @events.group_by {|event| event.start_date} |
|
580 | @starting_events_by_days = @events.group_by {|event| event.start_date} | |
581 |
|
581 | |||
582 | render :layout => false if request.xhr? |
|
582 | render :layout => false if request.xhr? | |
583 | end |
|
583 | end | |
584 |
|
584 | |||
585 | def gantt |
|
585 | def gantt | |
586 | @trackers = Tracker.find(:all, :order => 'position') |
|
586 | @trackers = Tracker.find(:all, :order => 'position') | |
587 | retrieve_selected_tracker_ids(@trackers) |
|
587 | retrieve_selected_tracker_ids(@trackers) | |
588 |
|
588 | |||
589 | if params[:year] and params[:year].to_i >0 |
|
589 | if params[:year] and params[:year].to_i >0 | |
590 | @year_from = params[:year].to_i |
|
590 | @year_from = params[:year].to_i | |
591 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 |
|
591 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 | |
592 | @month_from = params[:month].to_i |
|
592 | @month_from = params[:month].to_i | |
593 | else |
|
593 | else | |
594 | @month_from = 1 |
|
594 | @month_from = 1 | |
595 | end |
|
595 | end | |
596 | else |
|
596 | else | |
597 | @month_from ||= (Date.today << 1).month |
|
597 | @month_from ||= (Date.today << 1).month | |
598 | @year_from ||= (Date.today << 1).year |
|
598 | @year_from ||= (Date.today << 1).year | |
599 | end |
|
599 | end | |
600 |
|
600 | |||
601 | @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2 |
|
601 | @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2 | |
602 | @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6 |
|
602 | @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6 | |
603 |
|
603 | |||
604 | @date_from = Date.civil(@year_from, @month_from, 1) |
|
604 | @date_from = Date.civil(@year_from, @month_from, 1) | |
605 | @date_to = (@date_from >> @months) - 1 |
|
605 | @date_to = (@date_from >> @months) - 1 | |
606 |
|
606 | |||
607 | @events = [] |
|
607 | @events = [] | |
608 | @project.issues_with_subprojects(params[:with_subprojects]) do |
|
608 | @project.issues_with_subprojects(params[:with_subprojects]) do | |
609 | @events += Issue.find(:all, |
|
609 | @events += Issue.find(:all, | |
610 | :order => "start_date, due_date", |
|
610 | :order => "start_date, due_date", | |
611 | :include => [:tracker, :status, :assigned_to, :priority, :project], |
|
611 | :include => [:tracker, :status, :assigned_to, :priority, :project], | |
612 | :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to] |
|
612 | :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to] | |
613 | ) unless @selected_tracker_ids.empty? |
|
613 | ) unless @selected_tracker_ids.empty? | |
614 | end |
|
614 | end | |
615 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
615 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) | |
616 | @events.sort! {|x,y| x.start_date <=> y.start_date } |
|
616 | @events.sort! {|x,y| x.start_date <=> y.start_date } | |
617 |
|
617 | |||
618 | if params[:format]=='pdf' |
|
618 | if params[:format]=='pdf' | |
619 | @options_for_rfpdf ||= {} |
|
619 | @options_for_rfpdf ||= {} | |
620 | @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf" |
|
620 | @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf" | |
621 | render :template => "projects/gantt.rfpdf", :layout => false |
|
621 | render :template => "projects/gantt.rfpdf", :layout => false | |
622 | elsif params[:format]=='png' && respond_to?('gantt_image') |
|
622 | elsif params[:format]=='png' && respond_to?('gantt_image') | |
623 | image = gantt_image(@events, @date_from, @months, @zoom) |
|
623 | image = gantt_image(@events, @date_from, @months, @zoom) | |
624 | image.format = 'PNG' |
|
624 | image.format = 'PNG' | |
625 | send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png") |
|
625 | send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png") | |
626 | else |
|
626 | else | |
627 | render :template => "projects/gantt.rhtml" |
|
627 | render :template => "projects/gantt.rhtml" | |
628 | end |
|
628 | end | |
629 | end |
|
629 | end | |
630 |
|
630 | |||
631 | def feeds |
|
631 | def feeds | |
632 | @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)] |
|
632 | @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)] | |
633 | @key = logged_in_user.get_or_create_rss_key.value if logged_in_user |
|
633 | @key = logged_in_user.get_or_create_rss_key.value if logged_in_user | |
634 | end |
|
634 | end | |
635 |
|
635 | |||
636 | private |
|
636 | private | |
637 | # Find project of id params[:id] |
|
637 | # Find project of id params[:id] | |
638 | # if not found, redirect to project list |
|
638 | # if not found, redirect to project list | |
639 | # Used as a before_filter |
|
639 | # Used as a before_filter | |
640 | def find_project |
|
640 | def find_project | |
641 | @project = Project.find(params[:id]) |
|
641 | @project = Project.find(params[:id]) | |
642 | @html_title = @project.name |
|
642 | @html_title = @project.name | |
643 | rescue ActiveRecord::RecordNotFound |
|
643 | rescue ActiveRecord::RecordNotFound | |
644 | render_404 |
|
644 | render_404 | |
645 | end |
|
645 | end | |
646 |
|
646 | |||
647 | def retrieve_selected_tracker_ids(selectable_trackers) |
|
647 | def retrieve_selected_tracker_ids(selectable_trackers) | |
648 | if ids = params[:tracker_ids] |
|
648 | if ids = params[:tracker_ids] | |
649 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } |
|
649 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } | |
650 | else |
|
650 | else | |
651 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } |
|
651 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } | |
652 | end |
|
652 | end | |
653 | end |
|
653 | end | |
654 |
|
654 | |||
655 | # Retrieve query from session or build a new query |
|
655 | # Retrieve query from session or build a new query | |
656 | def retrieve_query |
|
656 | def retrieve_query | |
657 | if params[:query_id] |
|
657 | if params[:query_id] | |
658 | @query = @project.queries.find(params[:query_id]) |
|
658 | @query = @project.queries.find(params[:query_id]) | |
659 | @query.executed_by = logged_in_user |
|
659 | @query.executed_by = logged_in_user | |
660 | session[:query] = @query |
|
660 | session[:query] = @query | |
661 | else |
|
661 | else | |
662 | if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id |
|
662 | if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id | |
663 | # Give it a name, required to be valid |
|
663 | # Give it a name, required to be valid | |
664 | @query = Query.new(:name => "_", :executed_by => logged_in_user) |
|
664 | @query = Query.new(:name => "_", :executed_by => logged_in_user) | |
665 | @query.project = @project |
|
665 | @query.project = @project | |
666 | if params[:fields] and params[:fields].is_a? Array |
|
666 | if params[:fields] and params[:fields].is_a? Array | |
667 | params[:fields].each do |field| |
|
667 | params[:fields].each do |field| | |
668 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
668 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
669 | end |
|
669 | end | |
670 | else |
|
670 | else | |
671 | @query.available_filters.keys.each do |field| |
|
671 | @query.available_filters.keys.each do |field| | |
672 | @query.add_short_filter(field, params[field]) if params[field] |
|
672 | @query.add_short_filter(field, params[field]) if params[field] | |
673 | end |
|
673 | end | |
674 | end |
|
674 | end | |
675 | session[:query] = @query |
|
675 | session[:query] = @query | |
676 | else |
|
676 | else | |
677 | @query = session[:query] |
|
677 | @query = session[:query] | |
678 | end |
|
678 | end | |
679 | end |
|
679 | end | |
680 | end |
|
680 | end | |
681 | end |
|
681 | end |
@@ -1,240 +1,245 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class Query < ActiveRecord::Base |
|
18 | class Query < ActiveRecord::Base | |
19 | belongs_to :project |
|
19 | belongs_to :project | |
20 | belongs_to :user |
|
20 | belongs_to :user | |
21 | serialize :filters |
|
21 | serialize :filters | |
22 |
|
22 | |||
23 | attr_protected :project, :user |
|
23 | attr_protected :project, :user | |
24 | attr_accessor :executed_by |
|
24 | attr_accessor :executed_by | |
25 |
|
25 | |||
26 | validates_presence_of :name, :on => :save |
|
26 | validates_presence_of :name, :on => :save | |
27 | validates_length_of :name, :maximum => 255 |
|
27 | validates_length_of :name, :maximum => 255 | |
28 |
|
28 | |||
29 | @@operators = { "=" => :label_equals, |
|
29 | @@operators = { "=" => :label_equals, | |
30 | "!" => :label_not_equals, |
|
30 | "!" => :label_not_equals, | |
31 | "o" => :label_open_issues, |
|
31 | "o" => :label_open_issues, | |
32 | "c" => :label_closed_issues, |
|
32 | "c" => :label_closed_issues, | |
33 | "!*" => :label_none, |
|
33 | "!*" => :label_none, | |
34 | "*" => :label_all, |
|
34 | "*" => :label_all, | |
35 | "<t+" => :label_in_less_than, |
|
35 | "<t+" => :label_in_less_than, | |
36 | ">t+" => :label_in_more_than, |
|
36 | ">t+" => :label_in_more_than, | |
37 | "t+" => :label_in, |
|
37 | "t+" => :label_in, | |
38 | "t" => :label_today, |
|
38 | "t" => :label_today, | |
39 | ">t-" => :label_less_than_ago, |
|
39 | ">t-" => :label_less_than_ago, | |
40 | "<t-" => :label_more_than_ago, |
|
40 | "<t-" => :label_more_than_ago, | |
41 | "t-" => :label_ago, |
|
41 | "t-" => :label_ago, | |
42 | "~" => :label_contains, |
|
42 | "~" => :label_contains, | |
43 | "!~" => :label_not_contains } |
|
43 | "!~" => :label_not_contains } | |
44 |
|
44 | |||
45 | cattr_reader :operators |
|
45 | cattr_reader :operators | |
46 |
|
46 | |||
47 | @@operators_by_filter_type = { :list => [ "=", "!" ], |
|
47 | @@operators_by_filter_type = { :list => [ "=", "!" ], | |
48 | :list_status => [ "o", "=", "!", "c", "*" ], |
|
48 | :list_status => [ "o", "=", "!", "c", "*" ], | |
49 | :list_optional => [ "=", "!", "!*", "*" ], |
|
49 | :list_optional => [ "=", "!", "!*", "*" ], | |
50 | :list_one_or_more => [ "*", "=" ], |
|
50 | :list_one_or_more => [ "*", "=" ], | |
51 | :date => [ "<t+", ">t+", "t+", "t", ">t-", "<t-", "t-" ], |
|
51 | :date => [ "<t+", ">t+", "t+", "t", ">t-", "<t-", "t-" ], | |
52 | :date_past => [ ">t-", "<t-", "t-", "t" ], |
|
52 | :date_past => [ ">t-", "<t-", "t-", "t" ], | |
53 | :string => [ "=", "~", "!", "!~" ], |
|
53 | :string => [ "=", "~", "!", "!~" ], | |
54 | :text => [ "~", "!~" ] } |
|
54 | :text => [ "~", "!~" ] } | |
55 |
|
55 | |||
56 | cattr_reader :operators_by_filter_type |
|
56 | cattr_reader :operators_by_filter_type | |
57 |
|
57 | |||
58 | def initialize(attributes = nil) |
|
58 | def initialize(attributes = nil) | |
59 | super attributes |
|
59 | super attributes | |
60 | self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} } |
|
60 | self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} } | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | def executed_by=(user) |
|
63 | def executed_by=(user) | |
64 | @executed_by = user |
|
64 | @executed_by = user | |
65 | set_language_if_valid(user.language) if user |
|
65 | set_language_if_valid(user.language) if user | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | def validate |
|
68 | def validate | |
69 | filters.each_key do |field| |
|
69 | filters.each_key do |field| | |
70 | errors.add label_for(field), :activerecord_error_blank unless |
|
70 | errors.add label_for(field), :activerecord_error_blank unless | |
71 | # filter requires one or more values |
|
71 | # filter requires one or more values | |
72 | (values_for(field) and !values_for(field).first.empty?) or |
|
72 | (values_for(field) and !values_for(field).first.empty?) or | |
73 | # filter doesn't require any value |
|
73 | # filter doesn't require any value | |
74 | ["o", "c", "!*", "*", "t"].include? operator_for(field) |
|
74 | ["o", "c", "!*", "*", "t"].include? operator_for(field) | |
75 | end if filters |
|
75 | end if filters | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | def editable_by?(user) |
|
78 | def editable_by?(user) | |
79 | return false unless user |
|
79 | return false unless user | |
80 | return true if !is_public && self.user_id == user.id |
|
80 | return true if !is_public && self.user_id == user.id | |
81 | is_public && user.authorized_to(project, "projects/add_query") |
|
81 | is_public && user.authorized_to(project, "projects/add_query") | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def available_filters |
|
84 | def available_filters | |
85 | return @available_filters if @available_filters |
|
85 | return @available_filters if @available_filters | |
86 | @available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } }, |
|
86 | @available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } }, | |
87 | "tracker_id" => { :type => :list, :order => 2, :values => Tracker.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } }, |
|
87 | "tracker_id" => { :type => :list, :order => 2, :values => Tracker.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } }, | |
88 | "priority_id" => { :type => :list, :order => 3, :values => Enumeration.find(:all, :conditions => ['opt=?','IPRI']).collect{|s| [s.name, s.id.to_s] } }, |
|
88 | "priority_id" => { :type => :list, :order => 3, :values => Enumeration.find(:all, :conditions => ['opt=?','IPRI']).collect{|s| [s.name, s.id.to_s] } }, | |
89 | "subject" => { :type => :text, :order => 8 }, |
|
89 | "subject" => { :type => :text, :order => 8 }, | |
90 | "created_on" => { :type => :date_past, :order => 9 }, |
|
90 | "created_on" => { :type => :date_past, :order => 9 }, | |
91 | "updated_on" => { :type => :date_past, :order => 10 }, |
|
91 | "updated_on" => { :type => :date_past, :order => 10 }, | |
92 | "start_date" => { :type => :date, :order => 11 }, |
|
92 | "start_date" => { :type => :date, :order => 11 }, | |
93 | "due_date" => { :type => :date, :order => 12 } } |
|
93 | "due_date" => { :type => :date, :order => 12 } } | |
94 | unless project.nil? |
|
94 | unless project.nil? | |
95 | # project specific filters |
|
95 | # project specific filters | |
96 | user_values = [] |
|
96 | user_values = [] | |
97 | user_values << ["<< #{l(:label_me)} >>", "me"] if executed_by |
|
97 | user_values << ["<< #{l(:label_me)} >>", "me"] if executed_by | |
98 | user_values += @project.users.collect{|s| [s.name, s.id.to_s] } |
|
98 | user_values += @project.users.collect{|s| [s.name, s.id.to_s] } | |
99 |
|
99 | |||
100 | @available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } |
|
100 | @available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } | |
101 | @available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values } |
|
101 | @available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values } | |
102 | @available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } } |
|
102 | @available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } } | |
103 | @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } } |
|
103 | @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } } | |
104 | unless @project.active_children.empty? |
|
104 | unless @project.active_children.empty? | |
105 | @available_filters["subproject_id"] = { :type => :list_one_or_more, :order => 13, :values => @project.active_children.collect{|s| [s.name, s.id.to_s] } } |
|
105 | @available_filters["subproject_id"] = { :type => :list_one_or_more, :order => 13, :values => @project.active_children.collect{|s| [s.name, s.id.to_s] } } | |
106 | end |
|
106 | end | |
107 | @project.all_custom_fields.select(&:is_filter?).each do |field| |
|
107 | @project.all_custom_fields.select(&:is_filter?).each do |field| | |
108 | case field.field_format |
|
108 | case field.field_format | |
109 | when "string", "int" |
|
109 | when "string", "int" | |
110 | options = { :type => :string, :order => 20 } |
|
110 | options = { :type => :string, :order => 20 } | |
111 | when "text" |
|
111 | when "text" | |
112 | options = { :type => :text, :order => 20 } |
|
112 | options = { :type => :text, :order => 20 } | |
113 | when "list" |
|
113 | when "list" | |
114 | options = { :type => :list_optional, :values => field.possible_values, :order => 20} |
|
114 | options = { :type => :list_optional, :values => field.possible_values, :order => 20} | |
115 | when "date" |
|
115 | when "date" | |
116 | options = { :type => :date, :order => 20 } |
|
116 | options = { :type => :date, :order => 20 } | |
117 | when "bool" |
|
117 | when "bool" | |
118 | options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 } |
|
118 | options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 } | |
119 | end |
|
119 | end | |
120 | @available_filters["cf_#{field.id}"] = options.merge({ :name => field.name }) |
|
120 | @available_filters["cf_#{field.id}"] = options.merge({ :name => field.name }) | |
121 | end |
|
121 | end | |
122 | # remove category filter if no category defined |
|
122 | # remove category filter if no category defined | |
123 | @available_filters.delete "category_id" if @available_filters["category_id"][:values].empty? |
|
123 | @available_filters.delete "category_id" if @available_filters["category_id"][:values].empty? | |
124 | end |
|
124 | end | |
125 | @available_filters |
|
125 | @available_filters | |
126 | end |
|
126 | end | |
127 |
|
127 | |||
128 | def add_filter(field, operator, values) |
|
128 | def add_filter(field, operator, values) | |
129 | # values must be an array |
|
129 | # values must be an array | |
130 | return unless values and values.is_a? Array # and !values.first.empty? |
|
130 | return unless values and values.is_a? Array # and !values.first.empty? | |
131 | # check if field is defined as an available filter |
|
131 | # check if field is defined as an available filter | |
132 | if available_filters.has_key? field |
|
132 | if available_filters.has_key? field | |
133 | filter_options = available_filters[field] |
|
133 | filter_options = available_filters[field] | |
134 | # check if operator is allowed for that filter |
|
134 | # check if operator is allowed for that filter | |
135 | #if @@operators_by_filter_type[filter_options[:type]].include? operator |
|
135 | #if @@operators_by_filter_type[filter_options[:type]].include? operator | |
136 | # allowed_values = values & ([""] + (filter_options[:values] || []).collect {|val| val[1]}) |
|
136 | # allowed_values = values & ([""] + (filter_options[:values] || []).collect {|val| val[1]}) | |
137 | # filters[field] = {:operator => operator, :values => allowed_values } if (allowed_values.first and !allowed_values.first.empty?) or ["o", "c", "!*", "*", "t"].include? operator |
|
137 | # filters[field] = {:operator => operator, :values => allowed_values } if (allowed_values.first and !allowed_values.first.empty?) or ["o", "c", "!*", "*", "t"].include? operator | |
138 | #end |
|
138 | #end | |
139 | filters[field] = {:operator => operator, :values => values } |
|
139 | filters[field] = {:operator => operator, :values => values } | |
140 | end |
|
140 | end | |
141 | end |
|
141 | end | |
142 |
|
142 | |||
143 | def add_short_filter(field, expression) |
|
143 | def add_short_filter(field, expression) | |
144 | return unless expression |
|
144 | return unless expression | |
145 | parms = expression.scan(/^(o|c|\!|\*)?(.*)$/).first |
|
145 | parms = expression.scan(/^(o|c|\!|\*)?(.*)$/).first | |
146 | add_filter field, (parms[0] || "="), [parms[1] || ""] |
|
146 | add_filter field, (parms[0] || "="), [parms[1] || ""] | |
147 | end |
|
147 | end | |
148 |
|
148 | |||
149 | def has_filter?(field) |
|
149 | def has_filter?(field) | |
150 | filters and filters[field] |
|
150 | filters and filters[field] | |
151 | end |
|
151 | end | |
152 |
|
152 | |||
153 | def operator_for(field) |
|
153 | def operator_for(field) | |
154 | has_filter?(field) ? filters[field][:operator] : nil |
|
154 | has_filter?(field) ? filters[field][:operator] : nil | |
155 | end |
|
155 | end | |
156 |
|
156 | |||
157 | def values_for(field) |
|
157 | def values_for(field) | |
158 | has_filter?(field) ? filters[field][:values] : nil |
|
158 | has_filter?(field) ? filters[field][:values] : nil | |
159 | end |
|
159 | end | |
160 |
|
160 | |||
161 | def label_for(field) |
|
161 | def label_for(field) | |
162 | label = @available_filters[field][:name] if @available_filters.has_key?(field) |
|
162 | label = @available_filters[field][:name] if @available_filters.has_key?(field) | |
163 | label ||= field.gsub(/\_id$/, "") |
|
163 | label ||= field.gsub(/\_id$/, "") | |
164 | end |
|
164 | end | |
165 |
|
165 | |||
166 | def statement |
|
166 | def statement | |
167 | sql = "1=1" |
|
167 | # project/subprojects clause | |
|
168 | clause = '' | |||
168 | if has_filter?("subproject_id") |
|
169 | if has_filter?("subproject_id") | |
169 | subproject_ids = [] |
|
170 | subproject_ids = [] | |
170 | if operator_for("subproject_id") == "=" |
|
171 | if operator_for("subproject_id") == "=" | |
171 | subproject_ids = values_for("subproject_id").each(&:to_i) |
|
172 | subproject_ids = values_for("subproject_id").each(&:to_i) | |
172 | else |
|
173 | else | |
173 | subproject_ids = project.active_children.collect{|p| p.id} |
|
174 | subproject_ids = project.active_children.collect{|p| p.id} | |
174 | end |
|
175 | end | |
175 |
|
|
176 | clause << "#{Issue.table_name}.project_id IN (%d,%s)" % [project.id, subproject_ids.join(",")] if project | |
176 | else |
|
177 | else | |
177 |
|
|
178 | clause << "#{Issue.table_name}.project_id=%d" % project.id if project | |
178 | end |
|
179 | end | |
|
180 | ||||
|
181 | # filters clauses | |||
|
182 | filters_clauses = [] | |||
179 | filters.each_key do |field| |
|
183 | filters.each_key do |field| | |
180 | next if field == "subproject_id" |
|
184 | next if field == "subproject_id" | |
181 | v = values_for(field).clone |
|
185 | v = values_for(field).clone | |
182 | next unless v and !v.empty? |
|
186 | next unless v and !v.empty? | |
183 |
|
187 | |||
184 | sql = sql + " AND " unless sql.empty? |
|
188 | sql = '' | |
185 | sql << "(" |
|
|||
186 |
|
||||
187 | if field =~ /^cf_(\d+)$/ |
|
189 | if field =~ /^cf_(\d+)$/ | |
188 | # custom field |
|
190 | # custom field | |
189 | db_table = CustomValue.table_name |
|
191 | db_table = CustomValue.table_name | |
190 |
db_field = |
|
192 | db_field = 'value' | |
191 | sql << "#{db_table}.custom_field_id = #{$1} AND " |
|
193 | sql << "#{Issue.table_name}.id IN (SELECT #{db_table}.customized_id FROM #{db_table} where #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{$1} AND " | |
192 | else |
|
194 | else | |
193 | # regular field |
|
195 | # regular field | |
194 | db_table = Issue.table_name |
|
196 | db_table = Issue.table_name | |
195 | db_field = field |
|
197 | db_field = field | |
|
198 | sql << '(' | |||
196 | end |
|
199 | end | |
197 |
|
200 | |||
198 | # "me" value subsitution |
|
201 | # "me" value subsitution | |
199 | if %w(assigned_to_id author_id).include?(field) |
|
202 | if %w(assigned_to_id author_id).include?(field) | |
200 | v.push(executed_by ? executed_by.id.to_s : "0") if v.delete("me") |
|
203 | v.push(executed_by ? executed_by.id.to_s : "0") if v.delete("me") | |
201 | end |
|
204 | end | |
202 |
|
205 | |||
203 | case operator_for field |
|
206 | case operator_for field | |
204 | when "=" |
|
207 | when "=" | |
205 | sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" |
|
208 | sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" | |
206 | when "!" |
|
209 | when "!" | |
207 | sql = sql + "#{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" |
|
210 | sql = sql + "#{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" | |
208 | when "!*" |
|
211 | when "!*" | |
209 | sql = sql + "#{db_table}.#{db_field} IS NULL" |
|
212 | sql = sql + "#{db_table}.#{db_field} IS NULL" | |
210 | when "*" |
|
213 | when "*" | |
211 | sql = sql + "#{db_table}.#{db_field} IS NOT NULL" |
|
214 | sql = sql + "#{db_table}.#{db_field} IS NOT NULL" | |
212 | when "o" |
|
215 | when "o" | |
213 | sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id" |
|
216 | sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id" | |
214 | when "c" |
|
217 | when "c" | |
215 | sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id" |
|
218 | sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id" | |
216 | when ">t-" |
|
219 | when ">t-" | |
217 | sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today - v.first.to_i).to_time), connection.quoted_date((Date.today + 1).to_time)] |
|
220 | sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today - v.first.to_i).to_time), connection.quoted_date((Date.today + 1).to_time)] | |
218 | when "<t-" |
|
221 | when "<t-" | |
219 | sql = sql + "#{db_table}.#{db_field} <= '%s'" % connection.quoted_date((Date.today - v.first.to_i).to_time) |
|
222 | sql = sql + "#{db_table}.#{db_field} <= '%s'" % connection.quoted_date((Date.today - v.first.to_i).to_time) | |
220 | when "t-" |
|
223 | when "t-" | |
221 | sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today - v.first.to_i).to_time), connection.quoted_date((Date.today - v.first.to_i + 1).to_time)] |
|
224 | sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today - v.first.to_i).to_time), connection.quoted_date((Date.today - v.first.to_i + 1).to_time)] | |
222 | when ">t+" |
|
225 | when ">t+" | |
223 | sql = sql + "#{db_table}.#{db_field} >= '%s'" % connection.quoted_date((Date.today + v.first.to_i).to_time) |
|
226 | sql = sql + "#{db_table}.#{db_field} >= '%s'" % connection.quoted_date((Date.today + v.first.to_i).to_time) | |
224 | when "<t+" |
|
227 | when "<t+" | |
225 | sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Date.today.to_time), connection.quoted_date((Date.today + v.first.to_i + 1).to_time)] |
|
228 | sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Date.today.to_time), connection.quoted_date((Date.today + v.first.to_i + 1).to_time)] | |
226 | when "t+" |
|
229 | when "t+" | |
227 | sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today + v.first.to_i).to_time), connection.quoted_date((Date.today + v.first.to_i + 1).to_time)] |
|
230 | sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today + v.first.to_i).to_time), connection.quoted_date((Date.today + v.first.to_i + 1).to_time)] | |
228 | when "t" |
|
231 | when "t" | |
229 | sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Date.today.to_time), connection.quoted_date((Date.today+1).to_time)] |
|
232 | sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Date.today.to_time), connection.quoted_date((Date.today+1).to_time)] | |
230 | when "~" |
|
233 | when "~" | |
231 | sql = sql + "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(v.first)}%'" |
|
234 | sql = sql + "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(v.first)}%'" | |
232 | when "!~" |
|
235 | when "!~" | |
233 | sql = sql + "#{db_table}.#{db_field} NOT LIKE '%#{connection.quote_string(v.first)}%'" |
|
236 | sql = sql + "#{db_table}.#{db_field} NOT LIKE '%#{connection.quote_string(v.first)}%'" | |
234 | end |
|
237 | end | |
235 |
sql << |
|
238 | sql << ')' | |
236 |
|
239 | filters_clauses << sql | ||
237 | end if filters and valid? |
|
240 | end if filters and valid? | |
238 |
|
|
241 | ||
|
242 | clause << (' AND ' + filters_clauses.join(' AND ')) unless filters_clauses.empty? | |||
|
243 | clause | |||
239 | end |
|
244 | end | |
240 | end |
|
245 | end |
@@ -1,43 +1,49 | |||||
1 | --- |
|
1 | --- | |
2 | custom_values_006: |
|
2 | custom_values_006: | |
3 | customized_type: Issue |
|
3 | customized_type: Issue | |
4 | custom_field_id: 2 |
|
4 | custom_field_id: 2 | |
5 | customized_id: 3 |
|
5 | customized_id: 3 | |
6 | id: 9 |
|
6 | id: 9 | |
7 | value: "125" |
|
7 | value: "125" | |
8 | custom_values_007: |
|
8 | custom_values_007: | |
9 | customized_type: Project |
|
9 | customized_type: Project | |
10 | custom_field_id: 3 |
|
10 | custom_field_id: 3 | |
11 | customized_id: 1 |
|
11 | customized_id: 1 | |
12 | id: 10 |
|
12 | id: 10 | |
13 | value: Stable |
|
13 | value: Stable | |
14 | custom_values_001: |
|
14 | custom_values_001: | |
15 | customized_type: User |
|
15 | customized_type: User | |
16 | custom_field_id: 4 |
|
16 | custom_field_id: 4 | |
17 | customized_id: 3 |
|
17 | customized_id: 3 | |
18 | id: 2 |
|
18 | id: 2 | |
19 | value: "" |
|
19 | value: "" | |
20 | custom_values_002: |
|
20 | custom_values_002: | |
21 | customized_type: User |
|
21 | customized_type: User | |
22 | custom_field_id: 4 |
|
22 | custom_field_id: 4 | |
23 | customized_id: 4 |
|
23 | customized_id: 4 | |
24 | id: 3 |
|
24 | id: 3 | |
25 | value: 01 23 45 67 89 |
|
25 | value: 01 23 45 67 89 | |
26 | custom_values_003: |
|
26 | custom_values_003: | |
27 | customized_type: User |
|
27 | customized_type: User | |
28 | custom_field_id: 4 |
|
28 | custom_field_id: 4 | |
29 | customized_id: 2 |
|
29 | customized_id: 2 | |
30 | id: 4 |
|
30 | id: 4 | |
31 | value: "" |
|
31 | value: "" | |
32 | custom_values_004: |
|
32 | custom_values_004: | |
33 | customized_type: Issue |
|
33 | customized_type: Issue | |
34 | custom_field_id: 2 |
|
34 | custom_field_id: 2 | |
35 | customized_id: 1 |
|
35 | customized_id: 1 | |
36 | id: 7 |
|
36 | id: 7 | |
37 |
value: "1 |
|
37 | value: "125" | |
38 | custom_values_005: |
|
38 | custom_values_005: | |
39 | customized_type: Issue |
|
39 | customized_type: Issue | |
40 | custom_field_id: 2 |
|
40 | custom_field_id: 2 | |
41 | customized_id: 2 |
|
41 | customized_id: 2 | |
42 | id: 8 |
|
42 | id: 8 | |
43 | value: "" |
|
43 | value: "" | |
|
44 | custom_values_008: | |||
|
45 | customized_type: Issue | |||
|
46 | custom_field_id: 1 | |||
|
47 | customized_id: 3 | |||
|
48 | id: 11 | |||
|
49 | value: "MySQL" No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now