Unifies event filling

pull/749/head
Hagen Schink 11 years ago
parent 97a199eb91
commit 7319279e41
  1. 11
      app/models/activity/base_activity_provider.rb
  2. 24
      app/models/activity/changeset_activity_provider.rb
  3. 14
      app/models/activity/message_activity_provider.rb
  4. 10
      app/models/activity/news_activity_provider.rb
  5. 13
      app/models/activity/time_entry_activity_provider.rb
  6. 13
      app/models/activity/wiki_content_activity_provider.rb
  7. 16
      app/models/activity/work_package_activity_provider.rb

@ -56,6 +56,17 @@ class Activity::BaseActivityProvider
class_name.gsub('ActivityProvider', '').constantize class_name.gsub('ActivityProvider', '').constantize
end end
def format_event(event, event_data)
event.event_title = event_title event_data
event.event_type = event_type if respond_to? :event_type
event.event_description = event_description event_data if respond_to? :event_description
event.event_datetime = event_datetime event_data if respond_to? :event_datetime
event.event_path = event_path event_data
event.event_url = event_url event_data
event
end
protected protected
def journal_table def journal_table

@ -47,20 +47,6 @@ class Activity::ChangesetActivityProvider < Activity::BaseActivityProvider
] ]
end end
def format_event(event, event_data)
committed_on = event_data['committed_on']
committed_date = committed_on.is_a?(String) ? DateTime.parse(committed_on)
: committed_on
event.event_title = event_title event_data
event.event_description = split_comment(event_data['comments']).last
event.event_datetime = committed_date
event.event_path = event_path event_data
event.event_url = event_url event_data
event
end
def projects_reference_table def projects_reference_table
repositories_table repositories_table
end end
@ -87,6 +73,10 @@ class Activity::ChangesetActivityProvider < Activity::BaseActivityProvider
: event['revision'] : event['revision']
end end
def event_description(event)
split_comment(event_data['comments']).last
end
def split_comment(comments) def split_comment(comments)
cos =~ /\A(.+?)\r?\n(.*)\z/m cos =~ /\A(.+?)\r?\n(.*)\z/m
shomments = $1 || comments shomments = $1 || comments
@ -95,6 +85,12 @@ class Activity::ChangesetActivityProvider < Activity::BaseActivityProvider
[scomments, long_comments] [scomments, long_comments]
end end
def event_datetime(event)
committed_on = event_data['committed_on']
committed_date = committed_on.is_a?(String) ? DateTime.parse(committed_on)
: committed_on
end
def event_path(event) def event_path(event)
Rails.application.routes.url_helpers.revisions_project_repository_path(url_helper_parameter(event)) Rails.application.routes.url_helpers.revisions_project_repository_path(url_helper_parameter(event))
end end

@ -47,16 +47,6 @@ class Activity::MessageActivityProvider < Activity::BaseActivityProvider
] ]
end end
def format_event(event, event_data)
event.event_title = event_title event_data
event.event_description = event_data['message_content']
event.event_type = event_type event_data
event.event_path = event_path event_data
event.event_url = event_url event_data
event
end
def projects_reference_table def projects_reference_table
boards_table boards_table
end end
@ -71,6 +61,10 @@ class Activity::MessageActivityProvider < Activity::BaseActivityProvider
"#{event['board_name']}: #{event['message_subject']}" "#{event['board_name']}: #{event['message_subject']}"
end end
def event_description(event)
event['message_content']
end
def event_type(event) def event_type(event)
event['parent_id'].blank? ? 'message' : 'reply' event['parent_id'].blank? ? 'message' : 'reply'
end end

@ -42,16 +42,12 @@ class Activity::NewsActivityProvider < Activity::BaseActivityProvider
] ]
end end
def format_event(event, event_data) private
event.event_title = event_data['title']
event.event_path = event_path event_data
event.event_url = event_url event_data
event def event_title(event)
event_data['title']
end end
private
def event_path(event) def event_path(event)
Rails.application.routes.url_helpers.news_path(url_helper_parameter(event)) Rails.application.routes.url_helpers.news_path(url_helper_parameter(event))
end end

@ -47,15 +47,6 @@ class Activity::TimeEntryActivityProvider < Activity::BaseActivityProvider
] ]
end end
def format_event(event, event_data)
event.event_title = event_title event_data
event.event_description = event_data['time_entry_description']
event.event_path = event_path event_data
event.event_url = event_url event_data
event
end
private private
def work_packages_table def work_packages_table
@ -72,6 +63,10 @@ class Activity::TimeEntryActivityProvider < Activity::BaseActivityProvider
"#urs(event['time_entry_hours'])} (#{time_entry_object_name})" "#urs(event['time_entry_hours'])} (#{time_entry_object_name})"
end end
def event_description(event)
event_data['time_entry_description']
end
def event_path(event) def event_path(event)
Rapplication.routes.url_helpers.time_entry_path(url_helper_parameter(event)) Rapplication.routes.url_helpers.time_entry_path(url_helper_parameter(event))
end end

@ -44,15 +44,6 @@ class Activity::WikiContentActivityProvider < Activity::BaseActivityProvider
] ]
end end
def format_event(event, event_data)
event.event_title = event_title event_data
event.event_type = 'wiki-page'
event.event_path = event_path event_data
event.event_url = event_url event_data
event
end
def projects_reference_table def projects_reference_table
wikis_table wikis_table
end end
@ -71,6 +62,10 @@ class Activity::WikiContentActivityProvider < Activity::BaseActivityProvider
"#abel_wiki_edit)}: #{event['wiki_title']} (##{event['version']})" "#abel_wiki_edit)}: #{event['wiki_title']} (##{event['version']})"
end end
def event_type(event)
'wiki-page'
end
def event_path(event) def event_path(event)
Rapplication.routes.url_helpers.project_wiki_path(*url_helper_parameter(event)) Rapplication.routes.url_helpers.project_wiki_path(*url_helper_parameter(event))
end end

@ -48,15 +48,6 @@ class Activity::WorkPackageActivityProvider < Activity::BaseActivityProvider
] ]
end end
def format_event(event, event_data)
event.event_title = event_title event_data
event.event_type = "work_package#{event_type event_data}"
event.event_path = event_path event_data
event.event_url = event_url event_data
event
end
private private
def types_table def types_table
@ -74,13 +65,16 @@ class Activity::WorkPackageActivityProvider < Activity::BaseActivityProvider
end end
def event_type(event) def event_type(event)
state = ''
journal = Journal.find(event['event_id']) journal = Journal.find(event['event_id'])
if journal.changed_data.empty? && !journal.initial? if journal.changed_data.empty? && !journal.initial?
'-note' state = '-note'
else else
event['status_closed'] ? '-closed' : '-edit' state = event['status_closed'] ? '-closed' : '-edit'
end end
"work_package#{state}"
end end
def event_path(event) def event_path(event)

Loading…
Cancel
Save