Skip to content

Commit

Permalink
Replace use of Fetcher with EventMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmir committed Mar 18, 2024
1 parent 0582299 commit c102ddd
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 15 deletions.
8 changes: 3 additions & 5 deletions app/components/activities/item_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,16 @@ def agenda_items_details
rendered_details
end

def agenda_item_title
def agenda_item_title # rubocop:disable Metrics/AbcSize
agenda_item = MeetingAgendaItem.find(@event.meeting_agenda_item_data.first)

if agenda_item.item_type == "work_package"
link_to agenda_item.work_package.to_s, agenda_item.work_package
elsif initial_agenda_item?
agenda_item.title.to_s
else
"Agenda item \"#{agenda_item.title}\"" # needs i18n
end
rescue ActiveRecord::RecordNotFound # rework to remove dependence on rescue
@event.meeting_agenda_item_data.last["title"].last || @event.meeting_agenda_item_data.last["title"].first
rescue ActiveRecord::RecordNotFound
"Agenda item \"#{@event.meeting_agenda_item_data.last['title'].last || @event.meeting_agenda_item_data.last['title'].first}\""
end

def meeting_activity_title
Expand Down
28 changes: 28 additions & 0 deletions app/models/activities/event.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2024 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.
#++

module Activities
Event = Struct.new(:provider,
:event_id,
Expand Down
68 changes: 68 additions & 0 deletions app/models/activities/event_mapper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2024 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.
#++

module Activities
class EventMapper
include Redmine::I18n

def self.map_to_events(journable, additional_mapper)
journable
.journals
.includes(:data)
.all
.map do |journal|
params = {
event_description: journal.notes,
event_datetime: journal.updated_at,
event_title: event_title(additional_mapper.call(journal).with_indifferent_access),
event_author: journal.data.author,
project: journal.project,
journal:
}

Activities::Event.new(**params)
end
end

# duplicates necessary behaviour from Activites::Fetcher
def self.event_title(params)
start_time = if params['meeting_start_time'].is_a?(String)
DateTime.parse(params['meeting_start_time'])
else
params['meeting_start_time']
end
end_time = start_time + params['meeting_duration'].to_f.hours

fstart_with = format_date start_time
fstart_without = format_time start_time, false
fend_without = format_time end_time, false

"#{I18n.t(:label_meeting)}: #{params['meeting_title']} (#{fstart_with} #{fstart_without}-#{fend_without})"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def association_changes(original, changed, *)
def association_changes_multiple_attributes(original, changed, association, association_name, key, values)
list = {}
values.each do |value|
binding.pry
list.store(value, get_association_changes(original, changed, association, association_name, key, value))
end

Expand Down
28 changes: 25 additions & 3 deletions modules/meeting/app/controllers/meetings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def edit
end

def history
@events = @activity.events(from: @date_from.to_datetime, to: @date_to.to_datetime)
@events = get_events
separate_events_for_history

render :history
Expand Down Expand Up @@ -353,6 +353,20 @@ def set_activity
meeting: @meeting)
end

def get_events
Activities::EventMapper.map_to_events(
@meeting,
->(journal) do
{
meeting_title: journal.data.title,
meeting_start_time: journal.data.start_time,
meeting_duration: journal.data.duration,
project_id: journal.data.project_id
}
end
)
end

def activity_scope
["meetings", "meeting_agenda_items"]
end
Expand Down Expand Up @@ -401,7 +415,7 @@ def separate_events_for_history # rubocop:disable Metrics/AbcSize,Metrics/Percei
results[:agenda_items].each do |item_data|
copy = event.clone
copy.meeting_agenda_item_data = item_data
events_dup << copy
events_dup << copy if work_package_agenda_item_exists?(copy)
details_count += item_data.last.count
end

Expand All @@ -419,7 +433,15 @@ def agenda_item_only_check(event, events_dup, count)
events_dup
end
end


def work_package_agenda_item_exists?(event)
return true if event.meeting_agenda_item_data.last["title"]&.last || event.meeting_agenda_item_data.last["title"]&.first

MeetingAgendaItem.find(event.meeting_agenda_item_data.first)
rescue ActiveRecord::RecordNotFound
false
end

def find_copy_from_meeting
return unless params[:copied_from_meeting_id]

Expand Down
7 changes: 1 addition & 6 deletions modules/meeting/app/models/meeting/journalized.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,10 @@ module Meeting::Journalized
register_journal_formatted_fields(:datetime, 'start_time')
register_journal_formatted_fields(:plaintext, 'location')

register_journal_formatted_fields(:plaintext, 'notes') # does diff exist for this?
register_journal_formatted_fields(:plaintext, 'notes')
register_journal_formatted_fields(:agenda_item_duration, 'duration_in_minutes')
register_journal_formatted_fields(:agenda_item_position, 'position')

# register_journal_formatted_fields(:plaintext, /agenda_items_\d+_title/)
# register_journal_formatted_fields(:agenda_item_position, /agenda_items_\d+_position/)
# register_journal_formatted_fields(:plaintext, /agenda_items_\d+_notes/)
# register_journal_formatted_fields(:decimal, /agenda_items_\d+_duration_in_minutes/)

def touch_and_save_journals
update_column(:updated_at, Time.current)
save_journals
Expand Down

0 comments on commit c102ddd

Please sign in to comment.