diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 3bebf4de5..45c3206ce 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -71,9 +71,9 @@ class ApplicationController < ActionController::Base end # authorizes the user for the requested action. - def authorize + def authorize(ctrl = @params[:controller], action = @params[:action]) # check if action is allowed on public projects - if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ @params[:controller], @params[:action] ] + if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ ctrl, action ] return true end # if action is not public, force login @@ -82,7 +82,7 @@ class ApplicationController < ActionController::Base return true if self.logged_in_user.admin? # if not admin, check membership permission @user_membership ||= Member.find(:first, :conditions => ["user_id=? and project_id=?", self.logged_in_user.id, @project.id]) - if @user_membership and Permission.allowed_to_role( "%s/%s" % [ @params[:controller], @params[:action] ], @user_membership.role_id ) + if @user_membership and Permission.allowed_to_role( "%s/%s" % [ ctrl, action ], @user_membership.role_id ) return true end render :nothing => true, :status => 403 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ada0f3795..08b5e0b81 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -16,19 +16,19 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class ProjectsController < ApplicationController - layout 'base', :except => :export_issues_pdf + layout 'base' before_filter :find_project, :authorize, :except => [ :index, :list, :add ] before_filter :require_admin, :only => [ :add, :destroy ] helper :sort - include SortHelper - helper :search_filter - include SearchFilterHelper + include SortHelper helper :custom_fields include CustomFieldsHelper helper :ifpdf include IfpdfHelper helper IssuesHelper + helper :queries + include QueriesHelper def index list @@ -208,8 +208,7 @@ class ProjectsController < ApplicationController sort_init 'issues.id', 'desc' sort_update - search_filter_init_list_issues - search_filter_update if params[:set_filter] + retrieve_query @results_per_page_options = [ 15, 25, 50, 100 ] if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i @@ -219,14 +218,15 @@ class ProjectsController < ApplicationController @results_per_page = session[:results_per_page] || 25 end - @issue_count = Issue.count(:include => [:status, :project], :conditions => search_filter_clause) - @issue_pages = Paginator.new self, @issue_count, @results_per_page, @params['page'] - @issues = Issue.find :all, :order => sort_clause, - :include => [ :author, :status, :tracker, :project ], - :conditions => search_filter_clause, - :limit => @issue_pages.items_per_page, - :offset => @issue_pages.current.offset - + if @query.valid? + @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) + @issue_pages = Paginator.new self, @issue_count, @results_per_page, @params['page'] + @issues = Issue.find :all, :order => sort_clause, + :include => [ :author, :status, :tracker, :project ], + :conditions => @query.statement, + :limit => @issue_pages.items_per_page, + :offset => @issue_pages.current.offset + end render :layout => false if request.xhr? end @@ -235,11 +235,12 @@ class ProjectsController < ApplicationController sort_init 'issues.id', 'desc' sort_update - search_filter_init_list_issues + retrieve_query + render :action => 'list_issues' and return unless @query.valid? @issues = Issue.find :all, :order => sort_clause, :include => [ :author, :status, :tracker, :project, :custom_values ], - :conditions => search_filter_clause + :conditions => @query.statement ic = Iconv.new('ISO-8859-1', 'UTF-8') export = StringIO.new @@ -268,14 +269,16 @@ class ProjectsController < ApplicationController sort_init 'issues.id', 'desc' sort_update - search_filter_init_list_issues + retrieve_query + render :action => 'list_issues' and return unless @query.valid? @issues = Issue.find :all, :order => sort_clause, :include => [ :author, :status, :tracker, :project, :custom_values ], - :conditions => search_filter_clause + :conditions => @query.statement @options_for_rfpdf ||= {} @options_for_rfpdf[:file_name] = "export.pdf" + render :layout => false end def move_issues @@ -302,6 +305,22 @@ class ProjectsController < ApplicationController end end + def add_query + @query = Query.new(params[:query]) + @query.project = @project + @query.user = logged_in_user + + params[:fields].each do |field| + @query.add_filter(field, params[:operators][field], params[:values][field]) + end if params[:fields] + + if request.post? and @query.save + flash[:notice] = l(:notice_successful_create) + redirect_to :controller => 'reports', :action => 'issue_report', :id => @project + end + render :layout => false if request.xhr? + end + # Add a news to @project def add_news @news = News.new(:project => @project) @@ -471,4 +490,29 @@ private rescue redirect_to :action => 'list' end + + # Retrieve query from session or build a new query + def retrieve_query + if params[:query_id] + @query = @project.queries.find(params[:query_id]) + else + if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id + # Give it a name, required to be valid + @query = Query.new(:name => "_") + @query.project = @project + if params[:fields] and params[:fields].is_a? Array + params[:fields].each do |field| + @query.add_filter(field, params[:operators][field], params[:values][field]) + end + else + @query.available_filters.keys.each do |field| + @query.add_short_filter(field, params[field]) if params[field] + end + end + session[:query] = @query + else + @query = session[:query] + end + end + end end diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb new file mode 100644 index 000000000..4bdd8aaa2 --- /dev/null +++ b/app/controllers/queries_controller.rb @@ -0,0 +1,49 @@ +# redMine - project management software +# Copyright (C) 2006 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +class QueriesController < ApplicationController + layout 'base' + before_filter :require_login, :find_query + + def edit + if request.post? + @query.filters = {} + params[:fields].each do |field| + @query.add_filter(field, params[:operators][field], params[:values][field]) + end if params[:fields] + @query.attributes = params[:query] + + if @query.save + flash[:notice] = l(:notice_successful_update) + redirect_to :controller => 'projects', :action => 'list_issues', :id => @project, :query_id => @query + end + end + end + + def destroy + @query.destroy if request.post? + redirect_to :controller => 'reports', :action => 'issue_report', :id => @project + end + +private + def find_query + @query = Query.find(params[:id]) + @project = @query.project + # check if user is allowed to manage queries (same permission as add_query) + authorize('projects', 'add_query') + end +end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 985c937fc..c10929d5b 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -48,6 +48,7 @@ class ReportsController < ApplicationController @report_title = l(:field_author) render :template => "reports/issue_report_details" else + @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)] @trackers = Tracker.find(:all) @priorities = Enumeration::get_values('IPRI') @categories = @project.issue_categories diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb new file mode 100644 index 000000000..1c0b59570 --- /dev/null +++ b/app/helpers/queries_helper.rb @@ -0,0 +1,6 @@ +module QueriesHelper + + def operators_for_select(filter_type) + Query.operators_by_filter_type[filter_type].collect {|o| [l(Query.operators[o]), o]} + end +end diff --git a/app/helpers/search_filter_helper.rb b/app/helpers/search_filter_helper.rb deleted file mode 100644 index f17ffeebf..000000000 --- a/app/helpers/search_filter_helper.rb +++ /dev/null @@ -1,106 +0,0 @@ -# redMine - project management software -# Copyright (C) 2006 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -module SearchFilterHelper - - def search_filter_criteria(name, options = {}) - @search_filter ||= {} - @search_filter[name] ||= {} - @search_filter[name][:options] = [] - @search_filter[name][:conditions] = {} - yield.each { |c| - @search_filter[name][:options] << [c[0], c[1].to_s] - @search_filter[name][:conditions].store(c[1].to_s, c[2]) - } - end - - def search_filter_update - session[:search_filter] ||= {} - @search_filter.each_key {|field| session[:search_filter][field] = params[field] } - end - - def search_filter_clause - session[:search_filter] ||= {} - clause = ["1=1"] - @search_filter.each { |k, v| - filter_value = session[:search_filter][k] || v[:options][0][1] - if v[:conditions][filter_value] - clause[0] = clause[0] + " AND " + v[:conditions][filter_value].first - clause += v[:conditions][filter_value][1..-1] - end - } - clause - end - - def search_filter_tag(criteria, options = {}) - session[:search_filter] ||= {} - options[:name] = criteria - options[:class] += " active-filter" if session[:search_filter][criteria] and session[:search_filter][criteria] != @search_filter[criteria][:options][0][1] - content_tag("select", - options_for_select(@search_filter[criteria][:options], session[:search_filter][criteria]), - options - ) - end - - def search_filter_init_list_issues - search_filter_criteria('status_id') { - [ [('['+l(:label_open_issues_plural)+']'), "O", ["issue_statuses.is_closed=?", false]], - [('['+l(:label_closed_issues_plural)+']'), "C", ["issue_statuses.is_closed=?", true]], - [('['+l(:label_all)+']'), "A", nil] - ] + IssueStatus.find(:all).collect {|s| [s.name, s.id, ["issues.status_id=?", s.id]] } - } - - search_filter_criteria('tracker_id') { - [ [('['+l(:label_all)+']'), "A", nil] - ] + Tracker.find(:all).collect {|s| [s.name, s.id, ["issues.tracker_id=?", s.id]] } - } - - search_filter_criteria('priority_id') { - [ [('['+l(:label_all)+']'), "A", nil] - ] + Enumeration.find(:all, :conditions => ['opt=?','IPRI']).collect {|s| [s.name, s.id, ["issues.priority_id=?", s.id]] } - } - - search_filter_criteria('category_id') { - [ [('['+l(:label_all)+']'), "A", nil], - [('['+l(:label_none)+']'), "N", ["issues.category_id is null"]] - ] + @project.issue_categories.find(:all).collect {|s| [s.name, s.id, ["issues.category_id=?", s.id]] } - } - - search_filter_criteria('fixed_version_id') { - [ [('['+l(:label_all)+']'), "A", nil], - [('['+l(:label_none)+']'), "N", ["issues.fixed_version_id is null"]] - ] + @project.versions.collect {|s| [s.name, s.id, ["issues.fixed_version_id=?", s.id]] } - } - - search_filter_criteria('author_id') { - [ [('['+l(:label_all)+']'), "A", nil], - ] + @project.users.collect {|s| [s.display_name, s.id, ["issues.author_id=?", s.id]] } - } - - search_filter_criteria('assigned_to_id') { - [ [('['+l(:label_all)+']'), "A", nil], - [('['+l(:label_none)+']'), "N", ["issues.assigned_to_id is null"]] - ] + @project.users.collect {|s| [s.display_name, s.id, ["issues.assigned_to_id=?", s.id]] } - } - - search_filter_criteria('subproject_id') { - [ [('['+l(:label_none)+']'), "N", ["issues.project_id=?", @project.id]], - [('['+l(:label_all)+']'), "A", ["(issues.project_id=? or projects.parent_id=?)", @project.id, @project.id]] - ] - } - end -end \ No newline at end of file diff --git a/app/models/permission.rb b/app/models/permission.rb index 620974608..b9b61e619 100644 --- a/app/models/permission.rb +++ b/app/models/permission.rb @@ -25,6 +25,7 @@ class Permission < ActiveRecord::Base 200 => :label_member_plural, 300 => :label_version_plural, 400 => :label_issue_category_plural, + 600 => :label_query_plural, 1000 => :label_issue_plural, 1100 => :label_news_plural, 1200 => :label_document_plural, diff --git a/app/models/project.rb b/app/models/project.rb index ae7436910..cf17f0f5a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -21,6 +21,7 @@ class Project < ActiveRecord::Base has_many :users, :through => :members has_many :custom_values, :dependent => true, :as => :customized has_many :issues, :dependent => true, :order => "issues.created_on DESC", :include => :status + has_many :queries, :dependent => true has_many :documents, :dependent => true has_many :news, :dependent => true, :include => :author has_many :issue_categories, :dependent => true, :order => "issue_categories.name" diff --git a/app/models/query.rb b/app/models/query.rb new file mode 100644 index 000000000..4ac34bd6d --- /dev/null +++ b/app/models/query.rb @@ -0,0 +1,166 @@ +# redMine - project management software +# Copyright (C) 2006 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +class Query < ActiveRecord::Base + belongs_to :project + belongs_to :user + serialize :filters + + attr_protected :project, :user + + validates_presence_of :name, :on => :save + + @@operators = { "=" => :label_equals, + "!" => :label_not_equals, + "o" => :label_open_issues, + "c" => :label_closed_issues, + "!*" => :label_none, + "*" => :label_all, + " :label_in_less_than, + ">t+" => :label_in_more_than, + "t+" => :label_in, + "t" => :label_today, + ">t-" => :label_less_than_ago, + " :label_more_than_ago, + "t-" => :label_ago, + "~" => :label_contains, + "!~" => :label_not_contains } + + cattr_reader :operators + + @@operators_by_filter_type = { :list => [ "=", "!" ], + :list_status => [ "o", "=", "!", "c", "*" ], + :list_optional => [ "=", "!", "!*", "*" ], + :date => [ "t+", "t+", "t", ">t-", " [ ">t-", " [ "~", "!~" ] } + + cattr_reader :operators_by_filter_type + + def initialize(attributes = nil) + super attributes + self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} } + self.is_public = true + end + + def validate + filters.each_key do |field| + errors.add field.gsub(/\_id$/, ""), :activerecord_error_blank unless + # filter requires one or more values + (values_for(field) and !values_for(field).first.empty?) or + # filter doesn't require any value + ["o", "c", "!*", "*", "t"].include? operator_for(field) + end if filters + end + + def available_filters + return @available_filters if @available_filters + @available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all).collect{|s| [s.name, s.id.to_s] } }, + "tracker_id" => { :type => :list, :order => 2, :values => Tracker.find(:all).collect{|s| [s.name, s.id.to_s] } }, + "priority_id" => { :type => :list, :order => 3, :values => Enumeration.find(:all, :conditions => ['opt=?','IPRI']).collect{|s| [s.name, s.id.to_s] } }, + "subject" => { :type => :text, :order => 7 }, + "created_on" => { :type => :date_past, :order => 8 }, + "updated_on" => { :type => :date_past, :order => 9 }, + "start_date" => { :type => :date, :order => 10 }, + "due_date" => { :type => :date, :order => 11 } } + unless project.nil? + # project specific filters + @available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => @project.users.collect{|s| [s.name, s.id.to_s] } } + @available_filters["author_id"] = { :type => :list, :order => 5, :values => @project.users.collect{|s| [s.name, s.id.to_s] } } + @available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } } + # remove category filter if no category defined + @available_filters.delete "category_id" if @available_filters["category_id"][:values].empty? + end + @available_filters + end + + def add_filter(field, operator, values) + # values must be an array + return unless values and values.is_a? Array # and !values.first.empty? + # check if field is defined as an available filter + if available_filters.has_key? field + filter_options = available_filters[field] + # check if operator is allowed for that filter + #if @@operators_by_filter_type[filter_options[:type]].include? operator + # allowed_values = values & ([""] + (filter_options[:values] || []).collect {|val| val[1]}) + # filters[field] = {:operator => operator, :values => allowed_values } if (allowed_values.first and !allowed_values.first.empty?) or ["o", "c", "!*", "*", "t"].include? operator + #end + filters[field] = {:operator => operator, :values => values } + end + end + + def add_short_filter(field, expression) + return unless expression + parms = expression.scan(/^(o|c|\!|\*)?(.*)$/).first + add_filter field, (parms[0] || "="), [parms[1] || ""] + end + + def has_filter?(field) + filters and filters[field] + end + + def operator_for(field) + has_filter?(field) ? filters[field][:operator] : nil + end + + def values_for(field) + has_filter?(field) ? filters[field][:values] : nil + end + + def statement + sql = "1=1" + sql << " AND issues.project_id=%d" % project.id if project + filters.each_key do |field| + v = values_for field + next unless v and !v.empty? + sql = sql + " AND " unless sql.empty? + case operator_for field + when "=" + sql = sql + "issues.#{field} IN (" + v.each(&:to_i).join(",") + ")" + when "!" + sql = sql + "issues.#{field} NOT IN (" + v.each(&:to_i).join(",") + ")" + when "!*" + sql = sql + "issues.#{field} IS NULL" + when "*" + sql = sql + "issues.#{field} IS NOT NULL" + when "o" + sql = sql + "issue_statuses.is_closed=#{connection.quoted_false}" if field == "status_id" + when "c" + sql = sql + "issue_statuses.is_closed=#{connection.quoted_true}" if field == "status_id" + when ">t-" + sql = sql + "issues.#{field} >= '%s'" % connection.quoted_date(Date.today - v.first.to_i) + when "t+" + sql = sql + "issues.#{field} >= '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'" + when "<%= l(:label_query_new) %> + +<%= start_form_tag :action => 'add_query', :id => @project %> + <%= render :partial => 'queries/form', :locals => {:query => @query} %> + <%= submit_tag l(:button_create) %> +<%= end_form_tag %> \ No newline at end of file diff --git a/app/views/projects/list_issues.rhtml b/app/views/projects/list_issues.rhtml index e4b763887..4a49a18b3 100644 --- a/app/views/projects/list_issues.rhtml +++ b/app/views/projects/list_issues.rhtml @@ -1,34 +1,40 @@ -
-<%= l(:label_export_to) %> -<%= link_to 'CSV', {:action => 'export_issues_csv', :id => @project}, :class => 'pic picCsv' %>, -<%= link_to 'PDF', {:action => 'export_issues_pdf', :id => @project}, :class => 'pic picPdf' %> -
- -

<%=l(:label_issue_plural)%>

- -<%= start_form_tag :action => 'list_issues' %> - - - - - - - - - - - - - -
<%=l(:field_status)%>:
<%= search_filter_tag 'status_id', :class => 'select-small' %>
<%=l(:field_tracker)%>:
<%= search_filter_tag 'tracker_id', :class => 'select-small' %>
<%=l(:field_priority)%>:
<%= search_filter_tag 'priority_id', :class => 'select-small' %>
<%=l(:field_category)%>:
<%= search_filter_tag 'category_id', :class => 'select-small' %>
<%=l(:field_fixed_version)%>:
<%= search_filter_tag 'fixed_version_id', :class => 'select-small' %>
<%=l(:field_author)%>:
<%= search_filter_tag 'author_id', :class => 'select-small' %>
<%=l(:field_assigned_to)%>:
<%= search_filter_tag 'assigned_to_id', :class => 'select-small' %>
<%=l(:label_subproject_plural)%>:
<%= search_filter_tag 'subproject_id', :class => 'select-small' %>
- <%= hidden_field_tag 'set_filter', 1 %> - <%= submit_tag l(:button_apply), :class => 'button-small' %> - - <%= link_to l(:button_clear), :action => 'list_issues', :id => @project, :set_filter => 1 %> -
-<%= end_form_tag %> - -   +<% if @query.new_record? %> +

<%=l(:label_issue_plural)%>

+ + <%= start_form_tag({:action => 'list_issues'}, :id => 'query_form') %> + <%= render :partial => 'queries/filters', :locals => {:query => @query} %> + <%= end_form_tag %> +
+ <%= link_to_remote l(:button_apply), + { :url => { :controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1 }, + :update => "content", + :with => "Form.serialize('query_form')" + }, :class => 'pic picCheck' %> + + <%= link_to l(:button_clear), {:controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1}, :class => 'pic picDelete' %> + <% if authorize_for('projects', 'add_query') %> + + <%= link_to_remote l(:button_save), + { :url => { :controller => 'projects', :action => "add_query", :id => @project }, + :method => 'get', + :update => "content", + :with => "Form.serialize('query_form')" + }, :class => 'pic picEdit' %> + <% end %> +
+
+<% else %> + <% if authorize_for('projects', 'add_query') %> +
+ <%= link_to l(:button_edit), {:controller => 'queries', :action => 'edit', :id => @query}, :class => 'pic picEdit' %> + <%= link_to l(:button_delete), {:controller => 'queries', :action => 'destroy', :id => @query}, :confirm => l(:text_are_you_sure), :post => true, :class => 'pic picDelete' %> +
+ <% end %> +

<%= @query.name %>

+<% end %> +<%= error_messages_for 'query' %> +<% if @query.valid? %> +  @@ -67,9 +73,15 @@ <% end %>
<%= check_all_links 'issues_form' %>
+
+<%= l(:label_export_to) %> +<%= link_to 'CSV', {:action => 'export_issues_csv', :id => @project}, :class => 'pic picCsv' %>, +<%= link_to 'PDF', {:action => 'export_issues_pdf', :id => @project}, :class => 'pic picPdf' %> +

<%= pagination_links_full @issue_pages %> [ <%= @issue_pages.current.first_item %> - <%= @issue_pages.current.last_item %> / <%= @issue_count %> ]

<%= submit_tag l(:button_move) %> -<%= end_form_tag %> \ No newline at end of file +<%= end_form_tag %> +<% end %> \ No newline at end of file diff --git a/app/views/queries/_filters.rhtml b/app/views/queries/_filters.rhtml new file mode 100644 index 000000000..4cfce899f --- /dev/null +++ b/app/views/queries/_filters.rhtml @@ -0,0 +1,100 @@ + + +
<%= l(:label_filter_plural) %> + + + + + +
+ +<% query.available_filters.sort{|a,b| a[1][:order]<=>b[1][:order]}.each do |filter| %> + <% field = filter[0] + options = filter[1] %> + id="tr_<%= field %>"> + + + + + +<% end %> +
+ <%= check_box_tag 'fields[]', field, query.has_filter?(field), :onclick => "toggle_filter('#{field}');", :id => "cb_#{field}" %> + + + <%= select_tag "operators[#{field}]", options_for_select(operators_for_select(options[:type]), query.operator_for(field)), :onchange => "toggle_operator('#{field}');", :class => "select-small", :style => "vertical-align: top;" %> + +
+ <% case options[:type] + when :list, :list_optional, :list_status %> + + <%= link_to_function image_tag('expand'), "toggle_multi_select('#{field}');" %> + <% when :date, :date_past %> + <%= text_field_tag "values[#{field}][]", query.values_for(field), :size => 3, :class => "select-small" %> <%= l(:label_day_plural) %> + <% when :text %> + <%= text_field_tag "values[#{field}][]", query.values_for(field), :size => 30, :class => "select-small" %> + <% end %> +
+
+
+<%= l(:label_filter_add) %>: +<%= select_tag 'add_filter_select', options_for_select([["",""]] + query.available_filters.sort{|a,b| a[1][:order]<=>b[1][:order]}.collect{|field| [l(("field_"+field[0].to_s.gsub(/\_id$/, "")).to_sym), field[0]] unless query.has_filter?(field[0])}.compact), :onchange => "add_filter();", :class => "select-small" %> +
+
\ No newline at end of file diff --git a/app/views/queries/_form.rhtml b/app/views/queries/_form.rhtml new file mode 100644 index 000000000..d50b1e9b9 --- /dev/null +++ b/app/views/queries/_form.rhtml @@ -0,0 +1,12 @@ +<%= error_messages_for 'query' %> + + +
+
+

+<%= text_field 'query', 'name', :size => 80 %>

+
+ +<%= render :partial => 'queries/filters', :locals => {:query => query}%> +
+ \ No newline at end of file diff --git a/app/views/queries/edit.rhtml b/app/views/queries/edit.rhtml new file mode 100644 index 000000000..71f146f1b --- /dev/null +++ b/app/views/queries/edit.rhtml @@ -0,0 +1,6 @@ +

<%= l(:label_query) %>

+ +<%= start_form_tag :action => 'edit', :id => @query %> + <%= render :partial => 'form', :locals => {:query => @query} %> + <%= submit_tag l(:button_save) %> +<%= end_form_tag %> \ No newline at end of file diff --git a/app/views/reports/_details.rhtml b/app/views/reports/_details.rhtml index be4c82e77..12a16c1e7 100644 --- a/app/views/reports/_details.rhtml +++ b/app/views/reports/_details.rhtml @@ -29,17 +29,17 @@ :controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1, "#{field_name}" => row.id, - "status_id" => "O" %> + "status_id" => "o" %> <%= link_to (aggregate data, { field_name => row.id, "closed" => 1 }), :controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1, "#{field_name}" => row.id, - "status_id" => "C" %> + "status_id" => "c" %> <%= link_to (aggregate data, { field_name => row.id }), :controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1, "#{field_name}" => row.id, - "status_id" => "A" %> + "status_id" => "*" %> <% end %> diff --git a/app/views/reports/_simple.rhtml b/app/views/reports/_simple.rhtml index 3be1281c5..778b9cbde 100644 --- a/app/views/reports/_simple.rhtml +++ b/app/views/reports/_simple.rhtml @@ -18,17 +18,17 @@ :controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1, "#{field_name}" => row.id, - "status_id" => "O" %> + "status_id" => "o" %> <%= link_to (aggregate data, { field_name => row.id, "closed" => 1 }), :controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1, "#{field_name}" => row.id, - "status_id" => "C" %> + "status_id" => "c" %> <%= link_to (aggregate data, { field_name => row.id }), :controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1, "#{field_name}" => row.id, - "status_id" => "A" %> + "status_id" => "*" %> <% end %> diff --git a/app/views/reports/issue_report.rhtml b/app/views/reports/issue_report.rhtml index 4927186a9..b4a854f32 100644 --- a/app/views/reports/issue_report.rhtml +++ b/app/views/reports/issue_report.rhtml @@ -1,18 +1,30 @@

<%=l(:label_report_plural)%>

+

<%= l(:label_query_plural) %>

+
+<%= link_to_if_authorized l(:label_query_new), {:controller => 'projects', :action => 'add_query', :id => @project}, :class => 'pic picAdd' %> +
+ +<% if @queries.empty? %>

<%=l(:label_no_data)%>

<% end %> +
    +<% @queries.each do |query| %> +
  • <%= link_to query.name, :controller => 'projects', :action => 'list_issues', :id => @project, :query_id => query %>
  • +<% end %> +
+
-

<%=l(:field_tracker)%>  <%= link_to image_tag('details'), :detail => 'author' %>

+

<%=l(:field_tracker)%>  <%= link_to image_tag('details'), :detail => 'tracker' %>

<%= render :partial => 'simple', :locals => { :data => @issues_by_tracker, :field_name => "tracker_id", :rows => @trackers } %>
-

<%=l(:field_priority)%>  <%= link_to image_tag('details'), :detail => 'priority' %>

-<%= render :partial => 'simple', :locals => { :data => @issues_by_priority, :field_name => "priority_id", :rows => @priorities } %> -

<%=l(:field_author)%>  <%= link_to image_tag('details'), :detail => 'author' %>

<%= render :partial => 'simple', :locals => { :data => @issues_by_author, :field_name => "author_id", :rows => @authors } %>
+

<%=l(:field_priority)%>  <%= link_to image_tag('details'), :detail => 'priority' %>

+<%= render :partial => 'simple', :locals => { :data => @issues_by_priority, :field_name => "priority_id", :rows => @priorities } %> +

<%=l(:field_category)%>  <%= link_to image_tag('details'), :detail => 'category' %>

<%= render :partial => 'simple', :locals => { :data => @issues_by_category, :field_name => "category_id", :rows => @categories } %>
diff --git a/db/migrate/013_create_queries.rb b/db/migrate/013_create_queries.rb new file mode 100644 index 000000000..e0e8c90c0 --- /dev/null +++ b/db/migrate/013_create_queries.rb @@ -0,0 +1,15 @@ +class CreateQueries < ActiveRecord::Migration + def self.up + create_table :queries, :force => true do |t| + t.column "project_id", :integer + t.column "name", :string, :default => "", :null => false + t.column "filters", :text + t.column "user_id", :integer, :default => 0, :null => false + t.column "is_public", :boolean, :default => false, :null => false + end + end + + def self.down + drop_table :queries + end +end diff --git a/db/migrate/014_add_queries_permissions.rb b/db/migrate/014_add_queries_permissions.rb new file mode 100644 index 000000000..27d674650 --- /dev/null +++ b/db/migrate/014_add_queries_permissions.rb @@ -0,0 +1,9 @@ +class AddQueriesPermissions < ActiveRecord::Migration + def self.up + Permission.create :controller => "projects", :action => "add_query", :description => "button_create", :sort => 600, :is_public => false, :mail_option => 0, :mail_enabled => 0 + end + + def self.down + Permission.find(:first, :conditions => ["controller=? and action=?", 'projects', 'add_query']).destroy + end +end diff --git a/lang/de.yml b/lang/de.yml index 95c2612b5..aa091961b 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -265,6 +265,23 @@ label_comment_plural: Anmerkungen label_comment_add: Anmerkung addieren label_comment_added: Anmerkung fügte hinzu label_comment_delete: Anmerkungen löschen +label_query: Benutzerdefiniertes Frage +label_query_plural: Benutzerdefinierte Fragen +label_query_new: Neue Frage +label_filter_add: Filter addieren +label_filter_plural: Filter +label_equals: ist +label_not_equals: ist nicht +label_in_less_than: an weniger als +label_in_more_than: an mehr als +label_in: an +label_today: heute +label_less_than_ago: vor weniger als +label_more_than_ago: vor mehr als +label_ago: vor +label_contains: enthält +label_not_contains: enthält nicht +label_day_plural: Tage button_login: Einloggen button_submit: Einreichen diff --git a/lang/en.yml b/lang/en.yml index 4ea41e0e5..8c2de4bc3 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -265,6 +265,23 @@ label_comment_plural: Comments label_comment_add: Add a comment label_comment_added: Comment added label_comment_delete: Delete comments +label_query: Custom query +label_query_plural: Custom queries +label_query_new: New query +label_filter_add: Add filter +label_filter_plural: Filters +label_equals: is +label_not_equals: is not +label_in_less_than: in less than +label_in_more_than: in more than +label_in: in +label_today: today +label_less_than_ago: less than days ago +label_more_than_ago: more than days ago +label_ago: days ago +label_contains: contains +label_not_contains: doesn't contain +label_day_plural: days button_login: Login button_submit: Submit diff --git a/lang/es.yml b/lang/es.yml index 5bdb0e447..ce19ef658 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -265,6 +265,23 @@ label_comment_plural: Comentarios label_comment_add: Agregar un comentario label_comment_added: Comentario agregó label_comment_delete: Suprimir comentarios +label_query: Pregunta personalizada +label_query_plural: Preguntas personalizadas +label_query_new: Nueva preguntas +label_filter_add: Agregar el filtro +label_filter_plural: Filtros +label_equals: igual +label_not_equals: no igual +label_in_less_than: en menos que +label_in_more_than: en más que +label_in: en +label_today: hoy +label_less_than_ago: hace menos de +label_more_than_ago: hace más de +label_ago: hace +label_contains: contiene +label_not_contains: no contiene +label_day_plural: días button_login: Conexión button_submit: Someter diff --git a/lang/fr.yml b/lang/fr.yml index 630acd152..a351a5a92 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -238,16 +238,16 @@ label_confirmation: Confirmation label_export_to: Exporter en label_read: Lire... label_public_projects: Projets publics -label_open_issues: Ouverte -label_open_issues_plural: Ouvertes -label_closed_issues: Fermée -label_closed_issues_plural: Fermées +label_open_issues: ouvert +label_open_issues_plural: ouverts +label_closed_issues: fermé +label_closed_issues_plural: fermés label_total: Total label_permissions: Permissions label_current_status: Statut actuel label_new_statuses_allowed: Nouveaux statuts autorisés -label_all: Tous -label_none: Aucun +label_all: tous +label_none: aucun label_next: Suivant label_previous: Précédent label_used_by: Utilisé par @@ -266,6 +266,23 @@ label_comment_plural: Commentaires label_comment_add: Ajouter un commentaire label_comment_added: Commentaire ajouté label_comment_delete: Supprimer les commentaires +label_query: Rapport personnalisé +label_query_plural: Rapports personnalisés +label_query_new: Nouveau rapport +label_filter_add: Ajouter le filtre +label_filter_plural: Filtres +label_equals: égal +label_not_equals: différent +label_in_less_than: dans moins de +label_in_more_than: dans plus de +label_in: dans +label_today: aujourd'hui +label_less_than_ago: il y a moins de +label_more_than_ago: il y a plus de +label_ago: il y a +label_contains: contient +label_not_contains: ne contient pas +label_day_plural: jours button_login: Connexion button_submit: Soumettre diff --git a/public/images/check.png b/public/images/check.png new file mode 100644 index 000000000..c348be65e Binary files /dev/null and b/public/images/check.png differ diff --git a/public/images/edit_small.png b/public/images/edit.png similarity index 100% rename from public/images/edit_small.png rename to public/images/edit.png diff --git a/public/images/expand.png b/public/images/expand.png new file mode 100644 index 000000000..3e3aaa441 Binary files /dev/null and b/public/images/expand.png differ diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 68d8a377a..f00ffc62a 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -128,10 +128,11 @@ background-color: #80b0da; .picLogout { background: url(../images/logout.png) no-repeat 4px 50%; } .picHelp { background: url(../images/help.png) no-repeat 4px 50%; } -.picEdit { background: url(../images/edit_small.png) no-repeat 4px 50%; } +.picEdit { background: url(../images/edit.png) no-repeat 4px 50%; } .picDelete { background: url(../images/delete.png) no-repeat 4px 50%; } .picAdd { background: url(../images/add.png) no-repeat 4px 50%; } .picMove { background: url(../images/move.png) no-repeat 4px 50%; } +.picCheck { background: url(../images/check.png) no-repeat 4px 70%; } .picPdf { background: url(../images/pdf.png) no-repeat 4px 50%;} .picCsv { background: url(../images/csv.png) no-repeat 4px 50%;} @@ -221,7 +222,7 @@ select { vertical-align: middle; } -select.select-small +.select-small { border: 1px solid #7F9DB9; padding: 1px;