comment updates

This commit is contained in:
Mark Moser 2017-02-13 18:08:51 -06:00
parent 39ba1a8369
commit 906b62247b
6 changed files with 110 additions and 11 deletions

28
.sass-lint.yml Normal file
View File

@ -0,0 +1,28 @@
# https://github.com/sasstools/sass-lint/tree/master/docs/rules
files:
include: app/assets/stylesheets/**/*.scss
options:
formatter: stylish
merge-default-rules: true
rules:
class-name-format: 0
id-name-format: 0
leading-zero:
- 1
- include: true
no-duplicate-properties:
- 1
-
exclude:
- src # for @font mixins
no-qualifying-elements:
- 1
- allow-element-with-attribute: true # input[type='email'] but not div.class-name
quotes: 0
no-vendor-prefixes:
-
excluded-identifiers:
- -moz-osx-font-smoothing
- -webkit-font-smoothing

View File

@ -34,10 +34,42 @@
margin-bottom: 30px;
text-align: right;
&:before {
&::before {
content: '- ';
}
}
.comment-edit-stamp {
color: rgba($gray-dark, 0.65);
font-size: 0.75em;
text-align: right;
}
.comment-edit-btn {
cursor: pointer;
display: inline-block;
font-size: 0.85em;
font-weight: bold;
padding: 2px 5px;
&:hover {
background-color: $gray-base;
color: $gray-lighter;
}
}
.comment-edit-form {
display: none;
margin: 30px 0;
padding: 10px 0;
}
[type="checkbox"] {
&:checked + .comment-edit-form {
display: block;
}
}
}
.review_meta {

View File

@ -4,4 +4,8 @@ class QuizComment < ApplicationRecord
belongs_to :candidate, foreign_key: :test_hash, primary_key: :test_hash
validates :message, presence: true
def edits?
updated_at > (created_at + 5.seconds)
end
end

View File

@ -1,2 +1,21 @@
<div class="comment-message"><%= comment.message %></div>
<div class="comment-message">
<%= comment.message %>
<% if policy(comment).update? %>
<label class="comment-edit-btn" for="comment-<%= comment.id %>">edit</label>
<% end %>
<% if comment.edits? %>
<div class="comment-edit-stamp">Updated <%= time_ago_in_words(comment.updated_at) %> ago</div>
<% end %>
</div>
<div class="comment-author"><%= comment.user.name %></div>
<% if policy(comment).update? %>
<input type="checkbox" id="comment-<%= comment.id %>">
<div class="comment-edit-form">
<%= render partial: 'comment_form', locals: {comment: comment, test_hash: comment.test_hash } %>
</div>
<% end %>

View File

@ -1,11 +1,25 @@
<%= render partial: 'shared/form_model_errors', locals: { obj: @comment } %>
<%= render partial: 'shared/form_model_errors', locals: { obj: comment } %>
<% # admin_update_comment_path # admin_create_comment_path %>
<%= form_for @comment, url: admin_create_comment_path(test_hash), method: :post do |form| %>
<% if comment.id.nil? %>
<%= form_for comment, url: admin_create_comment_path(test_hash: test_hash), method: :post do |form| %>
<div class="form-group">
<%= form.label :message, "Comment" %>
<%= form.label :message, "New Comment" %>
<%= form.text_area :message %>
</div>
<%= submit_tag "Save Comment" %>
<% end %>
<% else %>
<%= form_for comment, url: admin_update_comment_path(test_hash: test_hash, id: comment.id), method: :post do |form| %>
<div class="form-group">
<%= form.label :message, "Update Comment" %>
<%= form.text_area :message %>
</div>
<%= submit_tag "Update" %>
<% end %>
<% end %>

View File

@ -46,6 +46,8 @@
<div class="review-comments">
<h2 class="prft-heading">Comments</h2>
<%= render partial: 'comment', collection: @comments, locals: { test_hash: @candidate.test_hash } %>
<div><%= render partial: 'comment_form', locals: { test_hash: @candidate.test_hash } %></div>
<% if policy(QuizComment).create? %>
<%= render partial: 'comment_form', locals: {comment: @comment, test_hash: @candidate.test_hash } %>
<% end %>
</div>
</div>