forked from excid3/simple_discussion
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into topic_search
- Loading branch information
Showing
26 changed files
with
453 additions
and
72 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
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
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,15 @@ | ||
class SpamReport < ApplicationRecord | ||
belongs_to :forum_post | ||
belongs_to :user | ||
|
||
validates :forum_post_id, :user_id, :reason, presence: true | ||
validates :details, presence: true, if: -> { reason == "others" } | ||
|
||
enum reason: { | ||
sexual_content: 0, | ||
violent_content: 1, | ||
irrelevant_content: 2, | ||
misleading_content: 3, | ||
others: 4 | ||
} | ||
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
68 changes: 68 additions & 0 deletions
68
app/views/simple_discussion/forum_posts/_report_post_modal_form.html.erb
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,68 @@ | ||
<div class="modal fade" id="reportPostModal" tabindex="-1" role="dialog" aria-labelledby="reportSpamModalLabel" aria-hidden="true"> | ||
<div class="modal-dialog modal-dialog-centered" role="document"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title" id="reportSpamModalLabel">Report Post as Spam</h5> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
<%= form_with id:"reportPostForm", url: simple_discussion.forum_thread_path(forum_thread), method: :post, local: true do |f| %> | ||
<% if @spam_report && @spam_report.errors.any? %> | ||
<div class="alert alert-danger" role="alert"> | ||
<% @spam_report.errors.full_messages.each do |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
<div class="form-group"> | ||
<%= f.collection_radio_buttons :reason, SpamReport.reasons.keys, :to_s, :humanize, include_hidden: false do |b| %> | ||
<div class="form-check"> | ||
<%= b.radio_button(class: "form-check-input toggle-reason", required: true) %> | ||
<%= b.label(class: "form-check-label") %> | ||
</div> | ||
<% end %> | ||
</div> | ||
<div class="form-group" id="details-group" style="display: none;"> | ||
<%= f.label :details, "Reason in detail (if others)" %> | ||
<%= f.text_area :details, class: "form-control", rows: 2, id: "details-input" %> | ||
<div class="invalid-feedback">Please provide details for 'Other' reason.</div> | ||
</div> | ||
<%= f.submit "Report", class: "btn btn-danger" %> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
$(document).ready(function() { | ||
const $detailsGroup = $('#details-group'); | ||
const $detailsInput = $('#details-input'); | ||
const $form = $('#reportPostForm'); | ||
|
||
$('.toggle-reason').change(function() { | ||
if ($(this).val() === 'others') { | ||
$detailsGroup.show(); | ||
$detailsInput.attr('required', true); | ||
} else { | ||
$detailsGroup.hide(); | ||
$detailsInput.removeAttr('required'); | ||
} | ||
}); | ||
|
||
$form.on('submit', function(e) { | ||
if ($('input[name="reason"]:checked').val() === 'others' && $detailsInput.val().trim() === '') { | ||
e.preventDefault(); | ||
$detailsInput.addClass('is-invalid'); | ||
} else { | ||
$detailsInput.removeClass('is-invalid'); | ||
} | ||
}); | ||
|
||
$detailsInput.on('input', function() { | ||
$(this).removeClass('is-invalid'); | ||
}); | ||
}); | ||
</script> |
57 changes: 57 additions & 0 deletions
57
app/views/simple_discussion/forum_posts/_spam_report.html.erb
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,57 @@ | ||
<%= content_tag :tr, id: dom_id(spam_report), class: "forum-post" do %> | ||
<td> | ||
<div class="border rounded-lg"> | ||
<div class="forum-post-header"> | ||
<div class="user-details d-flex flex-row"> | ||
<div class="user-avatar mr-2" ><img src="<%= gravatar_url_for(spam_report.forum_post.user.email, size: 30) %>" alt="avatar of user" ></div> | ||
<div class="details d-flex flex-column justify-content-between"> | ||
<p class="title"> | ||
<%= spam_report.forum_post.user.name %> <%= forum_user_badge(spam_report.forum_post.user) %> | ||
</p> | ||
<p class="subtitle"><%= t('on') %> <%= spam_report.forum_post.created_at.strftime("%b %d, %Y") %></p> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="card-body p-3"> | ||
<%= formatted_content spam_report.forum_post.body %> | ||
</div> | ||
</div> | ||
</td> | ||
|
||
<td> | ||
<div class="d-flex flex-row justify-content-between align-items-center p-2"> | ||
<% if spam_report.reason == "others" %> | ||
Other:<%= spam_report.details %> | ||
<% else %> | ||
<%= spam_report.reason.humanize %> | ||
<% end %> | ||
</div> | ||
</td> | ||
|
||
<td> | ||
<div class="d-flex flex-row justify-content-between align-items-center p-2"> | ||
<%= link_to spam_report.user.name, user_path(spam_report.user), class: "btn btn-outline-primary", title: t('user_profile') %> | ||
</div> | ||
</td> | ||
<td> | ||
<div class="d-flex flex-row justify-content-between align-items-center p-2"> | ||
<%= link_to simple_discussion.forum_thread_path(spam_report.forum_post.forum_thread, anchor: "forum_post_#{spam_report.forum_post.id}"), | ||
class: "btn btn-dark", | ||
data: { toggle: "tooltip", placement: "left" } do %> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-square-arrow-out-up-right"><path d="M21 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h6"/><path d="m21 3-9 9"/><path d="M15 3h6v6"/></svg> | ||
<% end %> | ||
</div> | ||
</td> | ||
<td> | ||
<div class="d-flex flex-row justify-content-between align-items-center p-2"> | ||
<%= link_to simple_discussion.forum_thread_forum_post_path(spam_report.forum_post.forum_thread, spam_report.forum_post, from: "moderators_page"), | ||
method: :delete, | ||
data: { toggle: "tooltip", placement: "left", confirm: "Are you sure you want to delete this post?" }, | ||
title: t('delete_this_post'), | ||
class: "btn btn-danger" do %> | ||
<i class="fas fa-trash-alt"></i> | ||
<% end %> | ||
</div> | ||
</td> | ||
<% end %> |
Oops, something went wrong.