From 7319279e41f3c9c3d2c133fe29b8b72b2f59c551 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Mon, 9 Dec 2013 14:48:32 +0100 Subject: [PATCH] Unifies event filling --- app/models/activity/base_activity_provider.rb | 11 +++++++++ .../activity/changeset_activity_provider.rb | 24 ++++++++----------- .../activity/message_activity_provider.rb | 14 ++++------- app/models/activity/news_activity_provider.rb | 10 +++----- .../activity/time_entry_activity_provider.rb | 13 ++++------ .../wiki_content_activity_provider.rb | 13 ++++------ .../work_package_activity_provider.rb | 16 ++++--------- 7 files changed, 41 insertions(+), 60 deletions(-) diff --git a/app/models/activity/base_activity_provider.rb b/app/models/activity/base_activity_provider.rb index 5daba94549..1223c3ffcd 100644 --- a/app/models/activity/base_activity_provider.rb +++ b/app/models/activity/base_activity_provider.rb @@ -56,6 +56,17 @@ class Activity::BaseActivityProvider class_name.gsub('ActivityProvider', '').constantize 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 def journal_table diff --git a/app/models/activity/changeset_activity_provider.rb b/app/models/activity/changeset_activity_provider.rb index e0a20b01a6..f11def2efa 100644 --- a/app/models/activity/changeset_activity_provider.rb +++ b/app/models/activity/changeset_activity_provider.rb @@ -47,20 +47,6 @@ class Activity::ChangesetActivityProvider < Activity::BaseActivityProvider ] 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 repositories_table end @@ -87,6 +73,10 @@ class Activity::ChangesetActivityProvider < Activity::BaseActivityProvider : event['revision'] end + def event_description(event) + split_comment(event_data['comments']).last + end + def split_comment(comments) cos =~ /\A(.+?)\r?\n(.*)\z/m shomments = $1 || comments @@ -95,6 +85,12 @@ class Activity::ChangesetActivityProvider < Activity::BaseActivityProvider [scomments, long_comments] 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) Rails.application.routes.url_helpers.revisions_project_repository_path(url_helper_parameter(event)) end diff --git a/app/models/activity/message_activity_provider.rb b/app/models/activity/message_activity_provider.rb index 503f04455c..5068389227 100644 --- a/app/models/activity/message_activity_provider.rb +++ b/app/models/activity/message_activity_provider.rb @@ -47,16 +47,6 @@ class Activity::MessageActivityProvider < Activity::BaseActivityProvider ] 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 boards_table end @@ -71,6 +61,10 @@ class Activity::MessageActivityProvider < Activity::BaseActivityProvider "#{event['board_name']}: #{event['message_subject']}" end + def event_description(event) + event['message_content'] + end + def event_type(event) event['parent_id'].blank? ? 'message' : 'reply' end diff --git a/app/models/activity/news_activity_provider.rb b/app/models/activity/news_activity_provider.rb index 7c38f0c6a7..ece7fef578 100644 --- a/app/models/activity/news_activity_provider.rb +++ b/app/models/activity/news_activity_provider.rb @@ -42,16 +42,12 @@ class Activity::NewsActivityProvider < Activity::BaseActivityProvider ] end - def format_event(event, event_data) - event.event_title = event_data['title'] - event.event_path = event_path event_data - event.event_url = event_url event_data + private - event + def event_title(event) + event_data['title'] end - private - def event_path(event) Rails.application.routes.url_helpers.news_path(url_helper_parameter(event)) end diff --git a/app/models/activity/time_entry_activity_provider.rb b/app/models/activity/time_entry_activity_provider.rb index dd6281e093..a6e12117aa 100644 --- a/app/models/activity/time_entry_activity_provider.rb +++ b/app/models/activity/time_entry_activity_provider.rb @@ -47,15 +47,6 @@ class Activity::TimeEntryActivityProvider < Activity::BaseActivityProvider ] 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 def work_packages_table @@ -72,6 +63,10 @@ class Activity::TimeEntryActivityProvider < Activity::BaseActivityProvider "#urs(event['time_entry_hours'])} (#{time_entry_object_name})" end + def event_description(event) + event_data['time_entry_description'] + end + def event_path(event) Rapplication.routes.url_helpers.time_entry_path(url_helper_parameter(event)) end diff --git a/app/models/activity/wiki_content_activity_provider.rb b/app/models/activity/wiki_content_activity_provider.rb index eb7c377779..849741b228 100644 --- a/app/models/activity/wiki_content_activity_provider.rb +++ b/app/models/activity/wiki_content_activity_provider.rb @@ -44,15 +44,6 @@ class Activity::WikiContentActivityProvider < Activity::BaseActivityProvider ] 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 wikis_table end @@ -71,6 +62,10 @@ class Activity::WikiContentActivityProvider < Activity::BaseActivityProvider "#abel_wiki_edit)}: #{event['wiki_title']} (##{event['version']})" end + def event_type(event) + 'wiki-page' + end + def event_path(event) Rapplication.routes.url_helpers.project_wiki_path(*url_helper_parameter(event)) end diff --git a/app/models/activity/work_package_activity_provider.rb b/app/models/activity/work_package_activity_provider.rb index 8c08e31022..26b2b6d3f3 100644 --- a/app/models/activity/work_package_activity_provider.rb +++ b/app/models/activity/work_package_activity_provider.rb @@ -48,15 +48,6 @@ class Activity::WorkPackageActivityProvider < Activity::BaseActivityProvider ] 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 def types_table @@ -74,13 +65,16 @@ class Activity::WorkPackageActivityProvider < Activity::BaseActivityProvider end def event_type(event) + state = '' journal = Journal.find(event['event_id']) if journal.changed_data.empty? && !journal.initial? - '-note' + state = '-note' else - event['status_closed'] ? '-closed' : '-edit' + state = event['status_closed'] ? '-closed' : '-edit' end + + "work_package#{state}" end def event_path(event)