Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add GroupMeetingsService

Mir Bhatia26152fe61614
diff --git a/app/helpers/pagination_helper.rb b/app/helpers/pagination_helper.rb
index 0000bfefc4d..eaa03cd4796 100644
--- a/app/helpers/pagination_helper.rb
+++ b/app/helpers/pagination_helper.rb
@@ -96,8 +96,8 @@ module PaginationHelper
##
# For "Show more" paginated links, we want to load an initial number of items (defaulting to 5)
# unless a higher number is provided. These values do not correspond to the per_page_options
- def show_more_limit_param(options = params, initial_limit: SHOW_MORE_DEFAULT_LIMIT)
- limit = options[:limit].to_i
+ def show_more_limit_param(limit: nil, initial_limit: SHOW_MORE_DEFAULT_LIMIT)
+ limit = limit.to_i
if limit.zero?
initial_limit
else
@@ -107,8 +107,8 @@ module PaginationHelper
##
# Paginate an AR relation for the "show more" pagination functionality
- def show_more_pagination(paginator, options = params)
- paginator.paginate(page: 1, per_page: show_more_limit_param(options))
+ def show_more_pagination(paginator, limit: nil)
+ paginator.paginate(page: 1, per_page: show_more_limit_param(limit:))
end
private
diff --git a/frontend/src/app/shared/components/autocompleter/meeting-autocompleter/meeting-autocompleter-template.component.html b/frontend/src/app/shared/components/autocompleter/meeting-autocompleter/meeting-autocompleter-template.component.html
index c8e99288364..747557d6a3e 100644
--- a/frontend/src/app/shared/components/autocompleter/meeting-autocompleter/meeting-autocompleter-template.component.html
+++ b/frontend/src/app/shared/components/autocompleter/meeting-autocompleter/meeting-autocompleter-template.component.html
@@ -1,5 +1,8 @@
<ng-template #optionTemplate let-item>
- <div>{{ item.name }}</div>
- <div>ID: {{ item.id }}</div>
- <div>time: {{ item.start_time }}</div>
+ <div>ID: {{ item.id }}</div>
+ <div>Name: {{ item.name }}</div>
+ <div>Project: {{ item.project }}</div>
+ <div>Time: {{ item.start_time }}</div>
+ <div>Date: {{ item.start_date }}</div>
+ <div *ngIf="item.frequency">Frequency: {{ item.frequency }}</div>
</ng-template>
diff --git a/frontend/src/app/shared/components/autocompleter/meeting-autocompleter/meeting-autocompleter-template.component.sass b/frontend/src/app/shared/components/autocompleter/meeting-autocompleter/meeting-autocompleter-template.component.sass
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/frontend/src/app/shared/components/autocompleter/meeting-autocompleter/meeting-autocompleter.component.sass b/frontend/src/app/shared/components/autocompleter/meeting-autocompleter/meeting-autocompleter.component.sass
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/modules/meeting/app/controllers/meetings_controller.rb b/modules/meeting/app/controllers/meetings_controller.rb
index 53b55153d01..eb6f408e70d 100644
--- a/modules/meeting/app/controllers/meetings_controller.rb
+++ b/modules/meeting/app/controllers/meetings_controller.rb
@@ -381,41 +381,13 @@ class MeetingsController < ApplicationController
# We group meetings into individual groups, but only for upcoming meetings
if params[:upcoming] == "false"
- @meetings = show_more_pagination(@query.results)
+ @meetings = show_more_pagination(@query.results, limit: params[:limit])
else
- @grouped_meetings = group_meetings(@query.results)
- end
- end
-
- def group_meetings(all_meetings) # rubocop:disable Metrics/AbcSize
- next_week = Time
- .current
- .next_occurring(OpenProject::Internationalization::Date.beginning_of_week)
- .beginning_of_day
- groups = Hash.new { |h, k| h[k] = [] }
- groups[:later] = show_more_pagination(all_meetings
- .where(start_time: next_week..)
- .order(start_time: :asc))
-
- all_meetings
- .where(start_time: ...next_week)
- .order(start_time: :asc)
- .each do |meeting|
- start_date = in_user_zone(meeting.start_time).to_date
-
- group_key =
- if start_date == Time.zone.today
- :today
- elsif start_date == Time.zone.tomorrow
- :tomorrow
- else
- :this_week
- end
+ service = ::GroupMeetingsService.new(@query.results, limit: params[:limit])
+ call = service.call
- groups[group_key] << meeting
+ @grouped_meetings = call.result
end
-
- groups
end
def build_meeting
diff --git a/modules/meeting/app/controllers/recurring_meetings_controller.rb b/modules/meeting/app/controllers/recurring_meetings_controller.rb
index d87803ba58c..f6e2cd5202a 100644
--- a/modules/meeting/app/controllers/recurring_meetings_controller.rb
+++ b/modules/meeting/app/controllers/recurring_meetings_controller.rb
@@ -26,7 +26,7 @@ class RecurringMeetingsController < ApplicationController
RecurringMeeting.visible
end
- @recurring_meetings = show_more_pagination(results)
+ @recurring_meetings = show_more_pagination(results, limit: params[:limit])
respond_to do |format|
format.html do
diff --git a/modules/meeting/app/forms/meeting_agenda_item/meeting_form.rb b/modules/meeting/app/forms/meeting_agenda_item/meeting_form.rb
index 1990da2a3d8..45e2bbdea8d 100644
--- a/modules/meeting/app/forms/meeting_agenda_item/meeting_form.rb
+++ b/modules/meeting/app/forms/meeting_agenda_item/meeting_form.rb
@@ -40,6 +40,7 @@ class MeetingAgendaItem::MeetingForm < ApplicationForm
autocomplete_options: {
component: "opce-meeting-autocompleter",
items: meeting_options,
+ group_by: "group_label",
# Do not try to load data from API (it will look for a "resource")
defaultData: false,
bindLabel: "name",
@@ -57,18 +58,13 @@ class MeetingAgendaItem::MeetingForm < ApplicationForm
end
def meeting_options
- MeetingAgendaItems::CreateContract
+ meetings = MeetingAgendaItems::CreateContract
.assignable_meetings(User.current)
.where("meetings.start_time + (interval '1 hour' * meetings.duration) >= ?", Time.zone.now)
.order("meetings.start_time")
.includes(:project)
- .map do |meeting|
- {
- id: meeting.id,
- name: meeting.title,
- start_time: format_time(meeting.start_time)
- }
- end
+
+ GroupMeetingsService.new(meetings, as_options: true).call.result
end
def append_to_container
diff --git a/modules/meeting/app/services/group_meetings_service.rb b/modules/meeting/app/services/group_meetings_service.rb
new file mode 100644
index 00000000000..5745b2eee7f
--- /dev/null
+++ b/modules/meeting/app/services/group_meetings_service.rb
@@ -0,0 +1,104 @@
+# 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 GroupMeetingsService
+ include Redmine::I18n
+ include PaginationHelper
+
+ def initialize(all_meetings, as_options: false, limit: nil)
+ @all_meetings = all_meetings
+ @as_options = as_options
+ @limit = @as_options ? @all_meetings.count : limit
+ end
+
+ def call
+ if @as_options
+ ServiceResult.success(result: build_options)
+ else
+ ServiceResult.success(result: group_meetings)
+ end
+ end
+
+ private
+
+ def group_meetings # rubocop:disable Metrics/AbcSize
+ next_week = Time
+ .current
+ .next_occurring(OpenProject::Internationalization::Date.beginning_of_week)
+ .beginning_of_day
+ groups = Hash.new { |h, k| h[k] = [] }
+ groups[:later] = show_more_pagination(@all_meetings
+ .where(start_time: next_week..)
+ .order(start_time: :asc), limit: @limit)
+
+ @all_meetings
+ .where(start_time: ...next_week)
+ .order(start_time: :asc)
+ .each do |meeting|
+ start_date = in_user_zone(meeting.start_time).to_date
+
+ group_key =
+ if start_date == Time.zone.today
+ :today
+ elsif start_date == Time.zone.tomorrow
+ :tomorrow
+ else
+ :this_week
+ end
+
+ groups[group_key] << meeting
+ end
+
+ groups
+ end
+
+ # Flattens groups into autocompleter options
+ def build_options
+ group_meetings.flat_map do |key, meetings|
+ label = I18n.t("label_meeting_index_#{key}")
+
+ meetings.map do |meeting|
+ {
+ id: meeting.id,
+ name: meeting.title,
+ project: meeting.project.name,
+ start_time: format_time(meeting.start_time, include_date: false),
+ start_date: format_date(meeting.start_time),
+ group_label: label,
+ frequency: frequency(meeting)
+ }
+ end
+ end
+ end
+
+ def frequency(meeting)
+ meeting.recurring_meeting.human_frequency if meeting.recurring_meeting.present?
+ end
+end