|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# -- copyright |
| 4 | +# OpenProject is an open source project management software. |
| 5 | +# Copyright (C) the OpenProject GmbH |
| 6 | +# |
| 7 | +# This program is free software; you can redistribute it and/or |
| 8 | +# modify it under the terms of the GNU General Public License version 3. |
| 9 | +# |
| 10 | +# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
| 11 | +# Copyright (C) 2006-2013 Jean-Philippe Lang |
| 12 | +# Copyright (C) 2010-2013 the ChiliProject Team |
| 13 | +# |
| 14 | +# This program is free software; you can redistribute it and/or |
| 15 | +# modify it under the terms of the GNU General Public License |
| 16 | +# as published by the Free Software Foundation; either version 2 |
| 17 | +# of the License, or (at your option) any later version. |
| 18 | +# |
| 19 | +# This program is distributed in the hope that it will be useful, |
| 20 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | +# GNU General Public License for more details. |
| 23 | +# |
| 24 | +# You should have received a copy of the GNU General Public License |
| 25 | +# along with this program; if not, write to the Free Software |
| 26 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 27 | +# |
| 28 | +# See COPYRIGHT and LICENSE files for more details. |
| 29 | +# ++ |
| 30 | + |
| 31 | +module Backlogs::Concerns |
| 32 | + module ContainerLoading |
| 33 | + extend ActiveSupport::Concern |
| 34 | + |
| 35 | + def load_container_data |
| 36 | + load_sprint_data |
| 37 | + load_backlog_data |
| 38 | + end |
| 39 | + |
| 40 | + def load_sprint_data |
| 41 | + @sprints = Sprint.for_project(@project) |
| 42 | + .not_completed |
| 43 | + .order_by_date |
| 44 | + .includes(:project, :task_boards) |
| 45 | + @active_sprint_ids = @sprints.select(&:active?).map(&:id) |
| 46 | + |
| 47 | + @work_packages_by_sprint_id = WorkPackage |
| 48 | + .where(sprint: @sprints, project: @project) |
| 49 | + .includes(:type, :status, :assigned_to, :priority, :parent) |
| 50 | + .order_by_position |
| 51 | + .group_by(&:sprint_id) |
| 52 | + end |
| 53 | + |
| 54 | + def load_backlog_data |
| 55 | + @backlog_buckets = BacklogBucket.for_project(@project) |
| 56 | + |
| 57 | + # Includes the work packages of both the buckets and the inbox. |
| 58 | + # This has the drawback of loading more work packages than are displayed in the inbox as pagination |
| 59 | + # will only show the top 50 and lowest 10 work packages. |
| 60 | + # But doing only a single query (+ includes) to the database has its benefits, and currently this seems quicker. |
| 61 | + @work_packages_by_backlog_id = WorkPackage |
| 62 | + .in_backlog_for(project: @project) |
| 63 | + .includes(:type, :status, :assigned_to, :priority, :parent) |
| 64 | + .group_by(&:backlog_bucket_id) |
| 65 | + end |
| 66 | + end |
| 67 | +end |
0 commit comments