"Fossies" - the Fresh Open Source Software Archive

Member "redmine-4.1.1/app/models/project_query.rb" (6 Apr 2020, 3888 Bytes) of package /linux/www/redmine-4.1.1.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "project_query.rb": 4.1.0_vs_4.1.1.

    1 # frozen_string_literal: true
    2 
    3 # Redmine - project management software
    4 # Copyright (C) 2006-2017  Jean-Philippe Lang
    5 #
    6 # This program is free software; you can redistribute it and/or
    7 # modify it under the terms of the GNU General Public License
    8 # as published by the Free Software Foundation; either version 2
    9 # of the License, or (at your option) any later version.
   10 #
   11 # This program is distributed in the hope that it will be useful,
   12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 # GNU General Public License for more details.
   15 #
   16 # You should have received a copy of the GNU General Public License
   17 # along with this program; if not, write to the Free Software
   18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   19 
   20 class ProjectQuery < Query
   21 
   22   self.queried_class = Project
   23   self.view_permission = :search_project
   24 
   25   validate do |query|
   26     # project must be blank for ProjectQuery
   27     errors.add(:project_id, :exclusion) if query.project_id.present?
   28   end
   29 
   30   self.available_columns = [
   31     QueryColumn.new(:name, :sortable => "#{Project.table_name}.name"),
   32     QueryColumn.new(:status, :sortable => "#{Project.table_name}.status"),
   33     QueryColumn.new(:short_description, :sortable => "#{Project.table_name}.description", :caption => :field_description),
   34     QueryColumn.new(:homepage, :sortable => "#{Project.table_name}.homepage"),
   35     QueryColumn.new(:identifier, :sortable => "#{Project.table_name}.identifier"),
   36     QueryColumn.new(:parent_id, :sortable => "#{Project.table_name}.lft ASC", :default_order => 'desc', :caption => :field_parent),
   37     QueryColumn.new(:is_public, :sortable => "#{Project.table_name}.is_public", :groupable => true),
   38     QueryColumn.new(:created_on, :sortable => "#{Project.table_name}.created_on", :default_order => 'desc')
   39   ]
   40 
   41   def initialize(attributes=nil, *args)
   42     super attributes
   43     self.filters ||= { 'status' => {:operator => "=", :values => ['1']} }
   44   end
   45 
   46   def initialize_available_filters
   47     add_available_filter(
   48       "status",
   49       :type => :list, :values => lambda { project_statuses_values }
   50     )
   51     add_available_filter(
   52       "id",
   53       :type => :list, :values => lambda { project_values }, :label => :field_project
   54     )
   55     add_available_filter "name", :type => :text
   56     add_available_filter "description", :type => :text
   57     add_available_filter(
   58       "parent_id",
   59       :type => :list_subprojects, :values => lambda { project_values }, :label => :field_parent
   60     )
   61     add_available_filter(
   62       "is_public",
   63       :type => :list,
   64       :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]]
   65     )
   66     add_available_filter "created_on", :type => :date_past
   67     add_custom_fields_filters(project_custom_fields)
   68   end
   69 
   70   def available_columns
   71     return @available_columns if @available_columns
   72     @available_columns = self.class.available_columns.dup
   73     @available_columns += ProjectCustomField.visible.
   74                             map {|cf| QueryCustomFieldColumn.new(cf) }
   75     @available_columns
   76   end
   77 
   78   def available_display_types
   79     ['board', 'list']
   80   end
   81 
   82   def default_columns_names
   83     @default_columns_names = Setting.project_list_defaults.symbolize_keys[:column_names].map(&:to_sym)
   84   end
   85 
   86   def default_sort_criteria
   87     [[]]
   88   end
   89 
   90   def base_scope
   91     Project.visible.where(statement)
   92   end
   93 
   94   def results_scope(options={})
   95     order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?)
   96 
   97     order_option << "#{Project.table_name}.lft ASC"
   98     scope = base_scope.
   99       order(order_option).
  100       joins(joins_for_order_statement(order_option.join(',')))
  101 
  102     if has_custom_field_column?
  103       scope = scope.preload(:custom_values)
  104     end
  105 
  106     if has_column?(:parent_id)
  107       scope = scope.preload(:parent)
  108     end
  109 
  110     scope
  111   end
  112 end