@@ -1,162 +1,160 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | # |
|
2 | # | |
3 | # Redmine - project management software |
|
3 | # Redmine - project management software | |
4 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
4 | # Copyright (C) 2006-2013 Jean-Philippe Lang | |
5 | # |
|
5 | # | |
6 | # This program is free software; you can redistribute it and/or |
|
6 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
7 | # modify it under the terms of the GNU General Public License | |
8 | # as published by the Free Software Foundation; either version 2 |
|
8 | # as published by the Free Software Foundation; either version 2 | |
9 | # of the License, or (at your option) any later version. |
|
9 | # of the License, or (at your option) any later version. | |
10 | # |
|
10 | # | |
11 | # This program is distributed in the hope that it will be useful, |
|
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. |
|
14 | # GNU General Public License for more details. | |
15 | # |
|
15 | # | |
16 | # You should have received a copy of the GNU General Public License |
|
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software |
|
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 |
|
19 | |||
20 | module QueriesHelper |
|
20 | module QueriesHelper | |
21 | def filters_options_for_select(query) |
|
21 | def filters_options_for_select(query) | |
22 | options_for_select(filters_options(query)) |
|
22 | options_for_select(filters_options(query)) | |
23 | end |
|
23 | end | |
24 |
|
24 | |||
25 | def filters_options(query) |
|
25 | def filters_options(query) | |
26 | options = [[]] |
|
26 | options = [[]] | |
27 | sorted_options = query.available_filters.sort do |a, b| |
|
27 | sorted_options = query.available_filters.sort do |a, b| | |
28 | ord = 0 |
|
28 | ord = 0 | |
29 | if !(a[1][:order] == 20 && b[1][:order] == 20) |
|
29 | if !(a[1][:order] == 20 && b[1][:order] == 20) | |
30 | ord = a[1][:order] <=> b[1][:order] |
|
30 | ord = a[1][:order] <=> b[1][:order] | |
31 | else |
|
31 | else | |
32 | cn = (CustomField::CUSTOM_FIELDS_NAMES.index(a[1][:field].class.name) <=> |
|
32 | cn = (CustomField::CUSTOM_FIELDS_NAMES.index(a[1][:field].class.name) <=> | |
33 | CustomField::CUSTOM_FIELDS_NAMES.index(b[1][:field].class.name)) |
|
33 | CustomField::CUSTOM_FIELDS_NAMES.index(b[1][:field].class.name)) | |
34 | if cn != 0 |
|
34 | if cn != 0 | |
35 | ord = cn |
|
35 | ord = cn | |
36 | else |
|
36 | else | |
37 | f = (a[1][:field] <=> b[1][:field]) |
|
37 | f = (a[1][:field] <=> b[1][:field]) | |
38 | if f != 0 |
|
38 | if f != 0 | |
39 | ord = f |
|
39 | ord = f | |
40 | else |
|
40 | else | |
41 | # assigned_to or author |
|
41 | # assigned_to or author | |
42 | ord = (a[0] <=> b[0]) |
|
42 | ord = (a[0] <=> b[0]) | |
43 | end |
|
43 | end | |
44 | end |
|
44 | end | |
45 | end |
|
45 | end | |
46 | ord |
|
46 | ord | |
47 | end |
|
47 | end | |
48 | options += sorted_options.map do |field, field_options| |
|
48 | options += sorted_options.map do |field, field_options| | |
49 | [field_options[:name], field] |
|
49 | [field_options[:name], field] | |
50 | end |
|
50 | end | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def available_block_columns_tags(query) |
|
53 | def available_block_columns_tags(query) | |
54 | tags = ''.html_safe |
|
54 | tags = ''.html_safe | |
55 | query.available_block_columns.each do |column| |
|
55 | query.available_block_columns.each do |column| | |
56 | tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column)) + " #{column.caption}", :class => 'inline') |
|
56 | tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column)) + " #{column.caption}", :class => 'inline') | |
57 | end |
|
57 | end | |
58 | tags |
|
58 | tags | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def column_header(column) |
|
61 | def column_header(column) | |
62 | column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption, |
|
62 | column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption, | |
63 | :default_order => column.default_order) : |
|
63 | :default_order => column.default_order) : | |
64 | content_tag('th', h(column.caption)) |
|
64 | content_tag('th', h(column.caption)) | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | def column_content(column, issue) |
|
67 | def column_content(column, issue) | |
68 | value = column.value(issue) |
|
68 | value = column.value(issue) | |
69 | if value.is_a?(Array) |
|
69 | if value.is_a?(Array) | |
70 | value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe |
|
70 | value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe | |
71 | else |
|
71 | else | |
72 | column_value(column, issue, value) |
|
72 | column_value(column, issue, value) | |
73 | end |
|
73 | end | |
74 | end |
|
74 | end | |
75 |
|
75 | |||
76 | def column_value(column, issue, value) |
|
76 | def column_value(column, issue, value) | |
77 | case value.class.name |
|
77 | case value.class.name | |
78 | when 'String' |
|
78 | when 'String' | |
79 | if column.name == :subject |
|
79 | if column.name == :subject | |
80 | link_to(h(value), :controller => 'issues', :action => 'show', :id => issue) |
|
80 | link_to(h(value), :controller => 'issues', :action => 'show', :id => issue) | |
81 | elsif column.name == :description |
|
81 | elsif column.name == :description | |
82 | issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : '' |
|
82 | issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : '' | |
83 | else |
|
83 | else | |
84 | h(value) |
|
84 | h(value) | |
85 | end |
|
85 | end | |
86 | when 'Time' |
|
86 | when 'Time' | |
87 | format_time(value) |
|
87 | format_time(value) | |
88 | when 'Date' |
|
88 | when 'Date' | |
89 | format_date(value) |
|
89 | format_date(value) | |
90 |
when 'Fixnum' |
|
90 | when 'Fixnum' | |
91 | if column.name == :done_ratio |
|
91 | if column.name == :done_ratio | |
92 | progress_bar(value, :width => '80px') |
|
92 | progress_bar(value, :width => '80px') | |
93 | elsif column.name == :spent_hours |
|
|||
94 | sprintf "%.2f", value |
|
|||
95 | elsif column.name == :hours |
|
|||
96 | html_hours("%.2f" % value) |
|
|||
97 | else |
|
93 | else | |
98 |
|
|
94 | value.to_s | |
99 | end |
|
95 | end | |
|
96 | when 'Float' | |||
|
97 | sprintf "%.2f", value | |||
100 | when 'User' |
|
98 | when 'User' | |
101 | link_to_user value |
|
99 | link_to_user value | |
102 | when 'Project' |
|
100 | when 'Project' | |
103 | link_to_project value |
|
101 | link_to_project value | |
104 | when 'Version' |
|
102 | when 'Version' | |
105 | link_to(h(value), :controller => 'versions', :action => 'show', :id => value) |
|
103 | link_to(h(value), :controller => 'versions', :action => 'show', :id => value) | |
106 | when 'TrueClass' |
|
104 | when 'TrueClass' | |
107 | l(:general_text_Yes) |
|
105 | l(:general_text_Yes) | |
108 | when 'FalseClass' |
|
106 | when 'FalseClass' | |
109 | l(:general_text_No) |
|
107 | l(:general_text_No) | |
110 | when 'Issue' |
|
108 | when 'Issue' | |
111 | value.visible? ? link_to_issue(value) : "##{value.id}" |
|
109 | value.visible? ? link_to_issue(value) : "##{value.id}" | |
112 | when 'IssueRelation' |
|
110 | when 'IssueRelation' | |
113 | other = value.other_issue(issue) |
|
111 | other = value.other_issue(issue) | |
114 | content_tag('span', |
|
112 | content_tag('span', | |
115 | (l(value.label_for(issue)) + " " + link_to_issue(other, :subject => false, :tracker => false)).html_safe, |
|
113 | (l(value.label_for(issue)) + " " + link_to_issue(other, :subject => false, :tracker => false)).html_safe, | |
116 | :class => value.css_classes_for(issue)) |
|
114 | :class => value.css_classes_for(issue)) | |
117 | else |
|
115 | else | |
118 | h(value) |
|
116 | h(value) | |
119 | end |
|
117 | end | |
120 | end |
|
118 | end | |
121 |
|
119 | |||
122 | # Retrieve query from session or build a new query |
|
120 | # Retrieve query from session or build a new query | |
123 | def retrieve_query |
|
121 | def retrieve_query | |
124 | if !params[:query_id].blank? |
|
122 | if !params[:query_id].blank? | |
125 | cond = "project_id IS NULL" |
|
123 | cond = "project_id IS NULL" | |
126 | cond << " OR project_id = #{@project.id}" if @project |
|
124 | cond << " OR project_id = #{@project.id}" if @project | |
127 | @query = IssueQuery.find(params[:query_id], :conditions => cond) |
|
125 | @query = IssueQuery.find(params[:query_id], :conditions => cond) | |
128 | raise ::Unauthorized unless @query.visible? |
|
126 | raise ::Unauthorized unless @query.visible? | |
129 | @query.project = @project |
|
127 | @query.project = @project | |
130 | session[:query] = {:id => @query.id, :project_id => @query.project_id} |
|
128 | session[:query] = {:id => @query.id, :project_id => @query.project_id} | |
131 | sort_clear |
|
129 | sort_clear | |
132 | elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) |
|
130 | elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) | |
133 | # Give it a name, required to be valid |
|
131 | # Give it a name, required to be valid | |
134 | @query = IssueQuery.new(:name => "_") |
|
132 | @query = IssueQuery.new(:name => "_") | |
135 | @query.project = @project |
|
133 | @query.project = @project | |
136 | @query.build_from_params(params) |
|
134 | @query.build_from_params(params) | |
137 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} |
|
135 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} | |
138 | else |
|
136 | else | |
139 | # retrieve from session |
|
137 | # retrieve from session | |
140 | @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id] |
|
138 | @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id] | |
141 | @query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) |
|
139 | @query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) | |
142 | @query.project = @project |
|
140 | @query.project = @project | |
143 | end |
|
141 | end | |
144 | end |
|
142 | end | |
145 |
|
143 | |||
146 | def retrieve_query_from_session |
|
144 | def retrieve_query_from_session | |
147 | if session[:query] |
|
145 | if session[:query] | |
148 | if session[:query][:id] |
|
146 | if session[:query][:id] | |
149 | @query = IssueQuery.find_by_id(session[:query][:id]) |
|
147 | @query = IssueQuery.find_by_id(session[:query][:id]) | |
150 | return unless @query |
|
148 | return unless @query | |
151 | else |
|
149 | else | |
152 | @query = IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) |
|
150 | @query = IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) | |
153 | end |
|
151 | end | |
154 | if session[:query].has_key?(:project_id) |
|
152 | if session[:query].has_key?(:project_id) | |
155 | @query.project_id = session[:query][:project_id] |
|
153 | @query.project_id = session[:query][:project_id] | |
156 | else |
|
154 | else | |
157 | @query.project = @project |
|
155 | @query.project = @project | |
158 | end |
|
156 | end | |
159 | @query |
|
157 | @query | |
160 | end |
|
158 | end | |
161 | end |
|
159 | end | |
162 | end |
|
160 | end |
General Comments 0
You need to be logged in to leave comments.
Login now