diff --git a/.sass-lint.yml b/.sass-lint.yml new file mode 100644 index 0000000..84ba9b0 --- /dev/null +++ b/.sass-lint.yml @@ -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 diff --git a/app/assets/stylesheets/molecules/_admin_review.scss b/app/assets/stylesheets/molecules/_admin_review.scss index 8cbab59..9077423 100644 --- a/app/assets/stylesheets/molecules/_admin_review.scss +++ b/app/assets/stylesheets/molecules/_admin_review.scss @@ -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 { diff --git a/app/models/quiz_comment.rb b/app/models/quiz_comment.rb index 8819997..a918447 100644 --- a/app/models/quiz_comment.rb +++ b/app/models/quiz_comment.rb @@ -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 diff --git a/app/views/admin/result/_comment.html.erb b/app/views/admin/result/_comment.html.erb index b260eca..d47d8be 100644 --- a/app/views/admin/result/_comment.html.erb +++ b/app/views/admin/result/_comment.html.erb @@ -1,2 +1,21 @@ -
<%= comment.message %>
+
+ <%= comment.message %> + + <% if policy(comment).update? %> + + <% end %> + + <% if comment.edits? %> +
Updated <%= time_ago_in_words(comment.updated_at) %> ago
+ <% end %> +
+
<%= comment.user.name %>
+ + +<% if policy(comment).update? %> + +
+ <%= render partial: 'comment_form', locals: {comment: comment, test_hash: comment.test_hash } %> +
+<% end %> diff --git a/app/views/admin/result/_comment_form.html.erb b/app/views/admin/result/_comment_form.html.erb index c2ab89c..701cb7a 100644 --- a/app/views/admin/result/_comment_form.html.erb +++ b/app/views/admin/result/_comment_form.html.erb @@ -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| %> -
- <%= form.label :message, "Comment" %> - <%= form.text_area :message %> -
+<% if comment.id.nil? %> + + <%= form_for comment, url: admin_create_comment_path(test_hash: test_hash), method: :post do |form| %> +
+ <%= form.label :message, "New Comment" %> + <%= form.text_area :message %> +
+ + <%= 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| %> +
+ <%= form.label :message, "Update Comment" %> + <%= form.text_area :message %> +
+ + <%= submit_tag "Update" %> + <% end %> - <%= submit_tag "Save Comment" %> <% end %> diff --git a/app/views/admin/result/view.html.erb b/app/views/admin/result/view.html.erb index b07c69a..bcc3a8b 100644 --- a/app/views/admin/result/view.html.erb +++ b/app/views/admin/result/view.html.erb @@ -46,6 +46,8 @@

Comments

<%= render partial: 'comment', collection: @comments, locals: { test_hash: @candidate.test_hash } %> -
<%= render partial: 'comment_form', locals: { test_hash: @candidate.test_hash } %>
+ <% if policy(QuizComment).create? %> + <%= render partial: 'comment_form', locals: {comment: @comment, test_hash: @candidate.test_hash } %> + <% end %>