From e2659ae907cf6aa7f52f978266a99e08bec1814e Mon Sep 17 00:00:00 2001 From: Nishanth Vijayan Date: Sat, 13 Aug 2016 23:45:46 +0530 Subject: [PATCH] Show changes to event commercials in event changelog --- app/controllers/admin/events_controller.rb | 1 + app/helpers/application_helper.rb | 10 ++++++++++ app/models/ability.rb | 2 +- app/views/admin/events/show.html.haml | 14 +++++++++++--- app/views/admin/versions/index.html.haml | 7 +------ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index 37633e22..67559f3c 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -86,6 +86,7 @@ module Admin @comment_count = @event.comment_threads.count @ratings = @event.votes.includes(:user) @difficulty_levels = @program.difficulty_levels + @versions = @event.versions | PaperTrail::Version.where(item_type: 'Commercial', item_id: @event.commercials.pluck(:id)) end def edit diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 09f69484..a0466d6a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -491,4 +491,14 @@ module ApplicationHelper end end end + + def general_change_description(version) + if version.event == 'create' + 'created new' + elsif version.event == 'update' + "updated #{updated_attributes(version)} of" + else + 'deleted' + end + end end diff --git a/app/models/ability.rb b/app/models/ability.rb index 837f20a3..96ca5b59 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -212,7 +212,7 @@ class Ability end can [:index, :revert_object, :revert_attribute], PaperTrail::Version do |version| - version.item_type == 'Event' && (conf_ids_for_cfp.include? version.conference_id) + %w(Event Commercial).include?(version.item_type) && (conf_ids_for_cfp.include? version.conference_id) end end diff --git a/app/views/admin/events/show.html.haml b/app/views/admin/events/show.html.haml index 44232a7d..02dd85c7 100644 --- a/app/views/admin/events/show.html.haml +++ b/app/views/admin/events/show.html.haml @@ -15,15 +15,23 @@ %th Description %th Actions %tbody - - @event.versions.each do |version| + - @versions.each do |version| %tr %td = version.id %td %p = change_creator_link(version.whodunnit) - = event_change_description(version) - = "event #{@event.title}" + + - if version.item_type == 'Event' + = event_change_description(version) + = "event #{@event.title}" + + - else + = general_change_description(version) + = link_to 'commercial', + edit_admin_conference_program_event_path(conference_id: @conference.short_title, + id: @event.id, anchor: 'commercials-content') %small.text-muted = distance_of_time_in_words(Time.now,version.created_at) + ' ago' diff --git a/app/views/admin/versions/index.html.haml b/app/views/admin/versions/index.html.haml index fd2022ba..2929b497 100644 --- a/app/views/admin/versions/index.html.haml +++ b/app/views/admin/versions/index.html.haml @@ -42,12 +42,7 @@ = user_change_description(version) - else - - if version.event == 'create' - = 'created new' - - elsif version.event == 'update' - = "updated #{updated_attributes(version)} of" - - else - = 'deleted' + = general_change_description(version) = render partial: 'object_desc_and_link', locals: { version: version }