mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
156 lines
4.7 KiB
Ruby
156 lines
4.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# -- copyright
|
|
# OpenProject is an open source project management software.
|
|
# Copyright (C) the OpenProject GmbH
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License version 3.
|
|
#
|
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
|
#
|
|
# 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.
|
|
#
|
|
# See COPYRIGHT and LICENSE files for more details.
|
|
# ++
|
|
|
|
class ProjectQueries::Static
|
|
ACTIVE = "active"
|
|
MY = "my"
|
|
FAVORITED = "favorited"
|
|
ARCHIVED = "archived"
|
|
ON_TRACK = "on_track"
|
|
OFF_TRACK = "off_track"
|
|
AT_RISK = "at_risk"
|
|
|
|
ACTIVE_PORTFOLIOS = "active_portfolios"
|
|
MY_PORTFOLIOS = "my_portfolios"
|
|
FAVORITED_PORTFOLIOS = "favorited_portfolios"
|
|
ARCHIVED_PORTFOLIOS = "archived_portfolios"
|
|
|
|
DEFAULT = ACTIVE
|
|
|
|
class << self
|
|
def query(id)
|
|
case id
|
|
when ACTIVE, nil
|
|
static_query_active
|
|
when ACTIVE_PORTFOLIOS
|
|
static_query_active_portfolios
|
|
when MY
|
|
static_query_my
|
|
when MY_PORTFOLIOS
|
|
static_query_my_portfolios
|
|
when FAVORITED
|
|
static_query_favorited
|
|
when FAVORITED_PORTFOLIOS
|
|
static_query_favorited_portfolios
|
|
when ARCHIVED
|
|
static_query_archived
|
|
when ARCHIVED_PORTFOLIOS
|
|
static_query_archived_portfolios
|
|
when ON_TRACK
|
|
static_query_status_on_track
|
|
when OFF_TRACK
|
|
static_query_status_off_track
|
|
when AT_RISK
|
|
static_query_status_at_risk
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def static_query_active
|
|
list_with(:"projects.lists.active") do |query|
|
|
query.where("active", "=", OpenProject::Database::DB_VALUE_TRUE)
|
|
end
|
|
end
|
|
|
|
def static_query_active_portfolios
|
|
list_with(:"portfolios.lists.active") do |query|
|
|
query.where("active", "=", OpenProject::Database::DB_VALUE_TRUE)
|
|
end
|
|
end
|
|
|
|
def static_query_my
|
|
list_with(:"projects.lists.my") do |query|
|
|
query.where("member_of", "=", OpenProject::Database::DB_VALUE_TRUE)
|
|
end
|
|
end
|
|
|
|
def static_query_my_portfolios
|
|
list_with(:"portfolios.lists.my") do |query|
|
|
query.where("member_of", "=", OpenProject::Database::DB_VALUE_TRUE)
|
|
end
|
|
end
|
|
|
|
def static_query_favorited
|
|
list_with(:"projects.lists.favorited") do |query|
|
|
query.where("favorited", "=", OpenProject::Database::DB_VALUE_TRUE)
|
|
end
|
|
end
|
|
|
|
def static_query_favorited_portfolios
|
|
list_with(:"portfolios.lists.favorited") do |query|
|
|
query.where("favorited", "=", OpenProject::Database::DB_VALUE_TRUE)
|
|
end
|
|
end
|
|
|
|
def static_query_archived
|
|
list_with(:"projects.lists.archived") do |query|
|
|
query.where("active", "=", OpenProject::Database::DB_VALUE_FALSE)
|
|
end
|
|
end
|
|
|
|
def static_query_archived_portfolios
|
|
list_with(:"portfolios.lists.archived") do |query|
|
|
query.where("active", "=", OpenProject::Database::DB_VALUE_FALSE)
|
|
end
|
|
end
|
|
|
|
def static_query_status_on_track
|
|
list_with(:"activerecord.attributes.project.status_codes.on_track") do |query|
|
|
query.where("project_status_code", "=", Project.status_codes[:on_track])
|
|
end
|
|
end
|
|
|
|
def static_query_status_off_track
|
|
list_with(:"activerecord.attributes.project.status_codes.off_track") do |query|
|
|
query.where("project_status_code", "=", Project.status_codes[:off_track])
|
|
end
|
|
end
|
|
|
|
def static_query_status_at_risk
|
|
list_with(:"activerecord.attributes.project.status_codes.at_risk") do |query|
|
|
query.where("project_status_code", "=", Project.status_codes[:at_risk])
|
|
end
|
|
end
|
|
|
|
def list_with(name)
|
|
ProjectQuery.new(name: I18n.t(name)) do |query|
|
|
query.order("lft" => "asc")
|
|
query.select(*Setting.enabled_projects_columns, add_not_existing: false)
|
|
|
|
yield query
|
|
|
|
# This method is used to create static queries, so assume clean state after building
|
|
query.clear_changes_information
|
|
end
|
|
end
|
|
end
|
|
end
|