Skip to content

Commit

Permalink
Put journal "cause" as first item in journal details
Browse files Browse the repository at this point in the history
This will displayed it first in the activity views.
  • Loading branch information
cbliard committed Apr 9, 2024
1 parent a32c41b commit 4d2da2b
Showing 1 changed file with 63 additions and 47 deletions.
110 changes: 63 additions & 47 deletions lib_static/plugins/acts_as_journalized/lib/journal_changes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,57 +31,73 @@ def get_changes
return @changes if @changes
return {} if data.nil?

@changes = ::Acts::Journalized::JournableDiffer.changes(predecessor&.data, data)
changes = [
get_cause_changes,
get_data_changes,
get_attachments_changes,
get_custom_fields_changes,
get_file_links_changes,
get_agenda_items_changes
].compact

@changes[:cause] = [nil, cause] if cause.present?
@changes = changes.reduce({}, :merge!)
end

def get_cause_changes
return if cause.blank?

if journable&.attachable?
@changes.merge!(
::Acts::Journalized::JournableDiffer.association_changes(
predecessor,
self,
'attachable_journals',
'attachments',
:attachment_id,
:filename
)
)
end
{ cause: [nil, cause] }
end

if journable&.customizable?
@changes.merge!(
::Acts::Journalized::JournableDiffer.association_changes(
predecessor,
self,
'customizable_journals',
'custom_fields',
:custom_field_id,
:value
)
)
end
def get_data_changes
::Acts::Journalized::JournableDiffer.changes(predecessor&.data, data)
end

def get_attachments_changes
return unless journable&.attachable?

::Acts::Journalized::JournableDiffer.association_changes(
predecessor,
self,
"attachable_journals",
"attachments",
:attachment_id,
:filename
)
end

def get_custom_fields_changes
return unless journable&.customizable?

::Acts::Journalized::JournableDiffer.association_changes(
predecessor,
self,
"customizable_journals",
"custom_fields",
:custom_field_id,
:value
)
end

def get_file_links_changes
return unless has_file_links?

::Acts::Journalized::FileLinkJournalDiffer.get_changes_to_file_links(
predecessor,
storable_journals
)
end

if has_file_links?
@changes.merge!(
::Acts::Journalized::FileLinkJournalDiffer.get_changes_to_file_links(
predecessor,
storable_journals
)
)
end
def get_agenda_items_changes
return unless journable.respond_to?(:agenda_items)

if journable.respond_to?(:agenda_items)
@changes.merge!(
::Acts::Journalized::JournableDiffer.association_changes_multiple_attributes(
predecessor,
self,
'agenda_item_journals',
'agenda_items',
:agenda_item_id,
[:title, :duration_in_minutes, :notes, :position, :work_package_id]
)
)
end
@changes
::Acts::Journalized::JournableDiffer.association_changes_multiple_attributes(
predecessor,
self,
"agenda_item_journals",
"agenda_items",
:agenda_item_id,
%i[title duration_in_minutes notes position work_package_id]
)
end
end

0 comments on commit 4d2da2b

Please sign in to comment.