Merge pull request #1128 from nishanthvijayan/event-changelog

Improve event history page
This commit is contained in:
Stella Rouzi
2016-08-16 18:23:56 +03:00
committed by GitHub
8 changed files with 69 additions and 47 deletions

View File

@@ -86,6 +86,9 @@ 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').where_object(commercialable_id: @event.id, commercialable_type: 'Event') |
PaperTrail::Version.where(item_type: 'Commercial').where_object_changes(commercialable_id: @event.id, commercialable_type: 'Event')
end
def edit

View File

@@ -29,7 +29,7 @@ module Admin
flash[:error] = 'Revert failed. Attribute missing or invalid'
end
redirect_to admin_revision_history_path
redirect_back_or_to admin_revision_history_path
end
def revert_object
@@ -52,7 +52,7 @@ module Admin
flash[:error] = 'The item is already in the state that you are trying to revert it back to'
end
redirect_to admin_revision_history_path
redirect_back_or_to admin_revision_history_path
end
end
end

View File

@@ -493,4 +493,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

View File

@@ -210,6 +210,12 @@ class Ability
role.resource_type == 'Conference' && role.name == 'cfp' &&
(Conference.with_role(:cfp, user).pluck(:id).include? role.resource_id)
end
can [:index, :revert_object, :revert_attribute], PaperTrail::Version, item_type: 'Event', conference_id: conf_ids_for_cfp
can [:index, :revert_object, :revert_attribute], PaperTrail::Version do |version|
version.item_type == 'Commercial' && conf_ids_for_cfp.include?(version.conference_id) &&
(version.object.to_s.include?('Event') || version.object_changes.to_s.include?('Event'))
end
end
def signed_in_with_info_desk_role(user)

View File

@@ -9,29 +9,36 @@
= render 'proposal'
#history-content.tab-pane
.col-md-12
%table.table
%table.table.table-striped.table-bordered.table-hover.datatable
%thead
%th
%b Who
%th
%b Timestamp
%th
%b Modification Type
%th
%b Changes
%th ID
%th Description
%th Actions
%tbody
- @event.versions.each do |version|
%tr
%td
- unless version.whodunnit.nil?
= User.find(version.whodunnit).name
- else
No user (probably via the console)
%td
= version.created_at
%td
= version.event
%td
- version.changeset.each_key do |key|
= "#{key}: #{version.changeset[key][0]} -> #{version.changeset[key][1]}"
- @versions.each do |version|
%tr
%td
= version.id
%td
%p
= change_creator_link(version.whodunnit)
- 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'
%br
= "(#{version.created_at.strftime('%B %-d, %Y %H:%M')})"
%br
= render partial: 'shared/object_changes', locals: { version: version }
%td
= render partial: 'shared/changelog_actions', locals: { version: version }

View File

@@ -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 }
@@ -57,21 +52,7 @@
= "(#{version.created_at.strftime('%B %-d, %Y %H:%M')})"
%br
= render partial: 'object_changes', locals: { version: version }
= render partial: 'shared/object_changes', locals: { version: version }
%td.col-md-2
.btn-group{role: 'group'}
%a.btn.btn-success.btn-sm.show-changeset{id: version.id} View Changes
- if can? :revert_object, version
%button.btn.btn-default.dropdown-toggle.btn-sm.btn-primary{'data-toggle' => 'dropdown', type: 'button'}
Revert
%span.caret
%ul.dropdown-menu
%li= link_to 'All Changes', admin_revision_history_revert_object_path(id: version.id), data: { confirm: 'Are you sure you want to revert this change?' }
- if can? :revert_attribute, version
%li.divider{role: 'separator'}
- version.changeset.reject{ |_, values| values[0].blank? && values[1].blank? }.each do |attribute, values|
%li= link_to attribute, admin_revision_history_revert_attribute_path(id: version.id, attribute: attribute), data: { confirm: "Are you sure you want to revert #{attribute}?" }
- else
%button.btn.btn-sm.btn-primary.disabled Revert
= render partial: 'shared/changelog_actions', locals: { version: version }

View File

@@ -0,0 +1,15 @@
.btn-group{role: 'group'}
%a.btn.btn-success.btn-sm.show-changeset{id: version.id} View Changes
- if can? :revert_object, version
%button.btn.btn-default.dropdown-toggle.btn-sm.btn-primary{'data-toggle' => 'dropdown', type: 'button'}
Revert
%span.caret
%ul.dropdown-menu
%li= link_to 'All Changes', admin_revision_history_revert_object_path(id: version.id), data: { confirm: 'Are you sure you want to revert this change?' }
- if can? :revert_attribute, version
%li.divider{role: 'separator'}
- version.changeset.reject{ |_, values| values[0].blank? && values[1].blank? }.each do |attribute, values|
%li= link_to attribute, admin_revision_history_revert_attribute_path(id: version.id, attribute: attribute), data: { confirm: "Are you sure you want to revert #{attribute}?" }
- else
%button.btn.btn-sm.btn-primary.disabled Revert