From c80f37f3ff09bf97856e8e6c89e5641763f66285 Mon Sep 17 00:00:00 2001 From: Nishanth Vijayan Date: Tue, 9 Aug 2016 12:22:43 +0530 Subject: [PATCH] Change look of event history page similar to changelog --- app/controllers/admin/versions_controller.rb | 4 +- app/views/admin/events/show.html.haml | 45 +++++++++---------- .../admin/versions/_changelog_actions.haml | 15 +++++++ app/views/admin/versions/index.html.haml | 16 +------ 4 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 app/views/admin/versions/_changelog_actions.haml diff --git a/app/controllers/admin/versions_controller.rb b/app/controllers/admin/versions_controller.rb index d103e874..07108d38 100644 --- a/app/controllers/admin/versions_controller.rb +++ b/app/controllers/admin/versions_controller.rb @@ -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 diff --git a/app/views/admin/events/show.html.haml b/app/views/admin/events/show.html.haml index 9372ecbf..4b22eb2c 100644 --- a/app/views/admin/events/show.html.haml +++ b/app/views/admin/events/show.html.haml @@ -9,29 +9,28 @@ = 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]}" + - @event.versions.each do |version| + %tr + %td + = version.id + %td + %p + = change_creator_link(version.whodunnit) + = event_change_description(version) + = "event #{@event.title}" + + %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: 'admin/versions/object_changes', locals: { version: version } + %td + = render partial: 'admin/versions/changelog_actions', locals: { version: version } \ No newline at end of file diff --git a/app/views/admin/versions/_changelog_actions.haml b/app/views/admin/versions/_changelog_actions.haml new file mode 100644 index 00000000..07480650 --- /dev/null +++ b/app/views/admin/versions/_changelog_actions.haml @@ -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 \ No newline at end of file diff --git a/app/views/admin/versions/index.html.haml b/app/views/admin/versions/index.html.haml index af604820..c5a90b58 100644 --- a/app/views/admin/versions/index.html.haml +++ b/app/views/admin/versions/index.html.haml @@ -60,18 +60,4 @@ = render partial: '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: 'changelog_actions', locals: { version: version }