-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15044 from hellcp-work/paper_trail
Comment history dropdown
- Loading branch information
Showing
14 changed files
with
139 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/api/app/components/comment_history_component.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
%span.dropdown | ||
(edited | ||
= link_to('#', role: 'button', data: { 'bs-toggle': 'dropdown' }, 'aria-expanded': false, class: 'dropdown-toggle') do | ||
= render TimeComponent.new(time: @comment.versions.last.created_at) | ||
) | ||
.d-block | ||
%ul.dropdown-menu | ||
- @comment.versions.each do |version| | ||
%li.dropdown-item | ||
= link_to(comment_history_path(@comment, version_id: version.id, format: 'js'), data: { remote: true }) do | ||
- if version.whodunnit | ||
= User.find(version.whodunnit).login | ||
= paper_trail_event(version.event) | ||
= render TimeComponent.new(time: version.created_at) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CommentHistoryComponent < ApplicationComponent | ||
include Webui::PaperTrailHelper | ||
|
||
def initialize(comment) | ||
super | ||
|
||
@comment = comment | ||
end | ||
|
||
def render? | ||
policy(@comment).history? && @comment.versions.where(event: 'update').present? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Webui::PaperTrailHelper | ||
include Webui::WebuiHelper | ||
|
||
PAPER_TRAIL_EVENTS = { | ||
'create' => 'created', | ||
'update' => 'updated', | ||
'destroy' => 'destroyed', | ||
'delete' => 'deleted', | ||
'moderate' => 'moderated', | ||
'release' => 'released' | ||
}.freeze | ||
|
||
def paper_trail_event(event) | ||
PAPER_TRAIL_EVENTS[event] || 'edited' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.modal.fade{ id: "comment-history-modal-#{version.id}", tabindex: -1, role: 'dialog', | ||
aria: { hidden: true } } | ||
.modal-dialog.modal-xl.modal-fullscreen-xl-down{ role: 'document' } | ||
.modal-content | ||
.modal-header | ||
%h5.modal-title | ||
- if version.whodunnit | ||
= render UserAvatarComponent.new(User.find(version.whodunnit).login) | ||
= paper_trail_event(version.event) | ||
= render TimeComponent.new(time: version.created_at) | ||
%button.btn-close{ type: 'button', data: { 'bs-dismiss': 'modal' }, aria: { label: 'Close' } } | ||
.modal-body | ||
%table.table | ||
- version.changeset.slice('moderator_id', 'user_id').each do |type, users| | ||
%thead | ||
%tr | ||
%th{ colspan: 2 }= type.delete('_id').humanize | ||
%tr | ||
%th Before | ||
%th After | ||
%tbody | ||
%tr | ||
- users.each do |user| | ||
%td | ||
- if user | ||
= render UserAvatarComponent.new(User.find(user).login) | ||
- if version.changeset.key?('body') | ||
%thead | ||
%tr | ||
%th{ colspan: 2 } Body | ||
%tr | ||
%th Before | ||
%th After | ||
%tbody | ||
%tr | ||
- version.changeset[:body].each do |body| | ||
%td= body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
$('body').append("#{escape_javascript(render(partial: 'webui/comment/history', locals: { version: @version }))}") | ||
var historyModalElement = document.getElementById('comment-history-modal-#{ @version.id }'); | ||
var historyModal = new bootstrap.Modal(historyModalElement, {}) | ||
historyModal.show(); | ||
|
||
// Remove after use | ||
historyModalElement.addEventListener('hidden.bs.modal', event => { | ||
historyModalElement.remove(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/api/spec/components/previews/comment_history_component_preview.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CommentHistoryComponentPreview < ViewComponent::Preview | ||
# Preview at http://HOST:PORT/rails/view_components/comment_history_component/preview | ||
def preview | ||
comment = Comment.last | ||
comment.body += 'a' | ||
comment.save! | ||
render(CommentHistoryComponent.new(comment)) | ||
end | ||
end |