biovision-comment 0.0.170914
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +26 -0
- data/app/assets/config/biovision_comment_manifest.js +2 -0
- data/app/assets/javascripts/biovision/comment/application.js +13 -0
- data/app/assets/stylesheets/biovision/comment/comments.scss +104 -0
- data/app/controllers/admin/comments_controller.rb +28 -0
- data/app/controllers/biovision/comment/application_controller.rb +7 -0
- data/app/controllers/comments_controller.rb +78 -0
- data/app/controllers/my/comments_controller.rb +8 -0
- data/app/helpers/biovision/comment/application_helper.rb +6 -0
- data/app/jobs/biovision/comment/application_job.rb +6 -0
- data/app/mailers/biovision/comment/application_mailer.rb +8 -0
- data/app/mailers/comment_mailer.rb +8 -0
- data/app/models/biovision/comment/application_record.rb +7 -0
- data/app/models/comment.rb +79 -0
- data/app/views/admin/comments/_comment.html.erb +22 -0
- data/app/views/admin/comments/_nav_item.html.erb +6 -0
- data/app/views/admin/comments/entity/_in_list.html.erb +28 -0
- data/app/views/admin/comments/index.html.erb +16 -0
- data/app/views/admin/comments/show.html.erb +40 -0
- data/app/views/comment_mailer/entry_reply.text.erb +11 -0
- data/app/views/comments/_comment.html.erb +25 -0
- data/app/views/comments/_form.html.erb +23 -0
- data/app/views/comments/_list.html.erb +19 -0
- data/app/views/comments/edit.html.erb +18 -0
- data/app/views/comments/new.html.erb +7 -0
- data/app/views/comments/show.html.erb +27 -0
- data/app/views/layouts/biovision/comment/application.html.erb +14 -0
- data/config/locales/comments-ru.yml +65 -0
- data/config/routes.rb +17 -0
- data/db/migrate/20170914000001_create_comments.rb +31 -0
- data/lib/biovision/comment.rb +7 -0
- data/lib/biovision/comment/engine.rb +10 -0
- data/lib/biovision/comment/version.rb +5 -0
- data/lib/tasks/biovision/comment_tasks.rake +4 -0
- metadata +192 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 42b4d68a57878423df075040480f47f7877d482e
|
4
|
+
data.tar.gz: 4a73ca36f8890d352a006d63df544278e99bc9b1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 25a605215d087254f6b33db40b1f5d0b28cec7f45e5e3347bea22d2514e10189fd6052bc4f722b525a890f48fa8837e2b4f2b00927a14368d8dff733df8101dd
|
7
|
+
data.tar.gz: ab4e6b87a99a95de1bb1423ba096066da667160a4d74f4bfd28e476cbcd12a9a267d488eabdb806ae9069852cc9b1994359e01d5ee1fc36f16db518ead1222d7
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Maxim Khan-Magomedov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Biovision::Comment
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'biovision-comment'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install biovision-comment
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Biovision::Comment'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,104 @@
|
|
1
|
+
$border-primary: .1rem solid rgb(127, 127, 127) !default;
|
2
|
+
$font-size-decreased: 1.2rem !default;
|
3
|
+
$font-size-small: 1rem !default;
|
4
|
+
$row-background-even: #f0f0f0 !default;
|
5
|
+
$row-background-odd: #fafafa !default;
|
6
|
+
|
7
|
+
section.comments {
|
8
|
+
margin: 1.6rem 0;
|
9
|
+
padding: 0 0.8rem;
|
10
|
+
border-top: $border-primary;
|
11
|
+
|
12
|
+
> h2 {
|
13
|
+
margin: 0.8rem 0;
|
14
|
+
}
|
15
|
+
|
16
|
+
> div {
|
17
|
+
background-color: $row-background-odd;
|
18
|
+
padding: 0.4rem;
|
19
|
+
|
20
|
+
&:nth-of-type(even) {
|
21
|
+
background-color: $row-background-even;
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
div.comment {
|
27
|
+
position: relative;
|
28
|
+
|
29
|
+
.deleted {
|
30
|
+
font-size: $font-size-decreased;
|
31
|
+
font-style: italic;
|
32
|
+
padding: 0 .8rem;
|
33
|
+
|
34
|
+
&::before {
|
35
|
+
content: '[';
|
36
|
+
}
|
37
|
+
|
38
|
+
&::after {
|
39
|
+
content: ']';
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
.title {
|
44
|
+
padding: 0 0 0.4rem 0;
|
45
|
+
border-bottom: dotted 0.1rem;
|
46
|
+
margin: 0.8rem 0;
|
47
|
+
|
48
|
+
cite {
|
49
|
+
&:before {
|
50
|
+
content: open-quote;
|
51
|
+
}
|
52
|
+
|
53
|
+
&:after {
|
54
|
+
content: close-quote;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
.body {
|
60
|
+
background: #ffffff;
|
61
|
+
margin: 0.8rem;
|
62
|
+
padding: 0.8rem;
|
63
|
+
position: relative;
|
64
|
+
}
|
65
|
+
|
66
|
+
.author {
|
67
|
+
display: flex;
|
68
|
+
justify-content: space-between;
|
69
|
+
align-items: center;
|
70
|
+
padding: 0 0.8rem;
|
71
|
+
|
72
|
+
time {
|
73
|
+
font-size: $font-size-decreased;
|
74
|
+
font-style: italic;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
.footer {
|
79
|
+
padding: 0.8rem 1.6rem;
|
80
|
+
|
81
|
+
> ul {
|
82
|
+
display: flex;
|
83
|
+
margin: 0;
|
84
|
+
padding: 0;
|
85
|
+
justify-content: flex-end;
|
86
|
+
|
87
|
+
> li {
|
88
|
+
list-style: none;
|
89
|
+
margin: 0 0.4rem;
|
90
|
+
padding: 0;
|
91
|
+
font-size: $font-size-small;
|
92
|
+
text-align: right;
|
93
|
+
|
94
|
+
&:before {
|
95
|
+
content: '[';
|
96
|
+
}
|
97
|
+
|
98
|
+
&:after {
|
99
|
+
content: ']';
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Admin::CommentsController < AdminController
|
2
|
+
include ToggleableEntity
|
3
|
+
include LockableEntity
|
4
|
+
|
5
|
+
before_action :set_entity, except: [:index]
|
6
|
+
|
7
|
+
# get /admin/comments
|
8
|
+
def index
|
9
|
+
@collection = Comment.page_for_administration(current_page)
|
10
|
+
end
|
11
|
+
|
12
|
+
# get /admin/comments/:id
|
13
|
+
def show
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def restrict_access
|
19
|
+
require_privilege :moderator
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_entity
|
23
|
+
@entity = Comment.find_by(id: params[:id])
|
24
|
+
if @entity.nil?
|
25
|
+
handle_http_404('Cannot find comment')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
class CommentsController < ApplicationController
|
2
|
+
before_action :restrict_anonymous_access
|
3
|
+
before_action :restrict_access, except: [:create]
|
4
|
+
before_action :set_entity, only: [:show, :edit, :update, :destroy]
|
5
|
+
|
6
|
+
layout 'admin'
|
7
|
+
|
8
|
+
# post /comments
|
9
|
+
def create
|
10
|
+
@entity = Comment.new creation_parameters
|
11
|
+
if @entity.save
|
12
|
+
notify_participants
|
13
|
+
redirect_to(@entity.commentable || admin_comment_path(@entity.id), notice: t('comments.create.success'))
|
14
|
+
else
|
15
|
+
render :new, layout: 'application', status: :bad_request
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# get /comments/:id
|
20
|
+
def show
|
21
|
+
end
|
22
|
+
|
23
|
+
# get /comments/:id/edit
|
24
|
+
def edit
|
25
|
+
end
|
26
|
+
|
27
|
+
# patch /comments/:id
|
28
|
+
def update
|
29
|
+
if @entity.update entity_parameters
|
30
|
+
redirect_to admin_comment_path(@entity.id), notice: t('comments.update.success')
|
31
|
+
else
|
32
|
+
render :edit, status: :bad_request
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# delete /comments/:id
|
37
|
+
def destroy
|
38
|
+
if @entity.update deleted: true
|
39
|
+
flash[:notice] = t('comments.destroy.success')
|
40
|
+
end
|
41
|
+
redirect_to(@entity.commentable || admin_comments_path)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def restrict_access
|
47
|
+
require_privilege :moderator
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_entity
|
51
|
+
@entity = Comment.find_by(id: params[:id])
|
52
|
+
if @entity.nil?
|
53
|
+
handle_http_404('Cannot find comment')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def entity_parameters
|
58
|
+
permitted = current_user_has_privilege?(:moderator, nil) ? Comment.administrative_parameters : Comment.entity_parameters
|
59
|
+
params.require(:comment).permit(permitted)
|
60
|
+
end
|
61
|
+
|
62
|
+
def creation_parameters
|
63
|
+
params.require(:comment).permit(Comment.creation_parameters).merge(owner_for_entity(true))
|
64
|
+
end
|
65
|
+
|
66
|
+
def notify_participants
|
67
|
+
commentable = @entity.commentable
|
68
|
+
unless commentable.owned_by?(current_user)
|
69
|
+
category = Notification.category_from_object(commentable)
|
70
|
+
Notification.notify(commentable.user, category, commentable.id)
|
71
|
+
# begin
|
72
|
+
# Comments.entry_reply(@entity).deliver_now if @entity.notify_entry_owner?
|
73
|
+
# rescue Net::SMTPAuthenticationError => error
|
74
|
+
# logger.warn error.message
|
75
|
+
# end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
class Comment < ApplicationRecord
|
2
|
+
include HasOwner
|
3
|
+
include Toggleable
|
4
|
+
include VotableItem
|
5
|
+
|
6
|
+
PER_PAGE = 20
|
7
|
+
|
8
|
+
toggleable :visible
|
9
|
+
|
10
|
+
belongs_to :user, optional: true, counter_cache: true, touch: false
|
11
|
+
belongs_to :agent, optional: true
|
12
|
+
belongs_to :commentable, polymorphic: true, counter_cache: true, touch: false
|
13
|
+
|
14
|
+
validates_presence_of :body
|
15
|
+
validate :commentable_is_commentable
|
16
|
+
|
17
|
+
scope :recent, -> { order 'id desc' }
|
18
|
+
scope :visible, -> { where(deleted: false, visible: true) }
|
19
|
+
|
20
|
+
# @param [Integer] page
|
21
|
+
def self.page_for_administration(page)
|
22
|
+
recent.page(page).per(PER_PAGE)
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param [Integer] page
|
26
|
+
def self.page_for_visitor(page)
|
27
|
+
recent.visible.page(page).per(PER_PAGE)
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param [User] user
|
31
|
+
# @param [Integer] page
|
32
|
+
def self.page_for_owner(user, page)
|
33
|
+
owned_by(user).where(deleted: false).recent.page(page).per(PER_PAGE)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.entity_parameters
|
37
|
+
%i(body)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.creation_parameters
|
41
|
+
entity_parameters + %i(commentable_id commentable_type)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.administrative_parameters
|
45
|
+
entity_parameters + %i(deleted)
|
46
|
+
end
|
47
|
+
|
48
|
+
# @param [User] user
|
49
|
+
def visible_to?(user)
|
50
|
+
if self.commentable.respond_to? :visible_to?
|
51
|
+
if deleted?
|
52
|
+
UserPrivilege.user_has_privilege?(user, :administrator) && commentable.visible_to?(user)
|
53
|
+
else
|
54
|
+
commentable.visible_to?(user)
|
55
|
+
end
|
56
|
+
else
|
57
|
+
!deleted? || UserPrivilege.user_has_privilege?(user, :administrator)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def notify_entry_owner?
|
62
|
+
entry_owner = commentable.user
|
63
|
+
if entry_owner.is_a?(User) && !owned_by?(entry_owner)
|
64
|
+
entry_owner.can_receive_letters?
|
65
|
+
else
|
66
|
+
false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def commentable_is_commentable
|
73
|
+
if self.commentable.respond_to? :commentable_by?
|
74
|
+
unless self.commentable.commentable_by? self.user
|
75
|
+
errors.add(:commentable, I18n.t('activerecord.errors.models.comment.attributes.commentable.not_commentable'))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<div class="comment">
|
2
|
+
<div class="title">
|
3
|
+
<%= comment.commentable.model_name.human %>
|
4
|
+
<cite><%= link_to comment.commentable.title, comment.commentable %></cite>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<div class="author">
|
8
|
+
<%= user_link comment.user %>
|
9
|
+
<%= time_tag comment.created_at %>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<div class="body">
|
13
|
+
<%= prepare_comment_text(comment) %>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div class="footer">
|
17
|
+
<ul>
|
18
|
+
<li><%= link_to t(:view), comment %></li>
|
19
|
+
<li><%= link_to t(:edit), edit_comment_path(comment) %></li>
|
20
|
+
</ul>
|
21
|
+
</div>
|
22
|
+
</div>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<div class="image">
|
2
|
+
<%= profile_avatar(entity.user) %>
|
3
|
+
</div>
|
4
|
+
<div class="data">
|
5
|
+
<div>
|
6
|
+
<%= admin_comment_link(entity) %>
|
7
|
+
|
8
|
+
<% if entity.deleted? %>
|
9
|
+
(<%= t('activerecord.attributes.comment.deleted') %>)
|
10
|
+
<% end %>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<div class="info">
|
14
|
+
<%= admin_user_link(entity.user) %>,
|
15
|
+
<%= time_tag entity.created_at %>
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<div class="info">
|
19
|
+
<%= prepare_comment_text(entity) %>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<ul class="actions">
|
23
|
+
<li><%= edit_icon(edit_comment_path(entity.id)) %></li>
|
24
|
+
<% unless entity.deleted? %>
|
25
|
+
<li class="danger"><%= destroy_icon(entity) %></li>
|
26
|
+
<% end %>
|
27
|
+
</ul>
|
28
|
+
</div>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<% content_for :meta_title, t('.title', page: current_page) %>
|
2
|
+
<% content_for :breadcrumbs do %>
|
3
|
+
<span><%= t('admin.comments.nav_item.text') %></span>
|
4
|
+
<% end %>
|
5
|
+
|
6
|
+
<article class="comments">
|
7
|
+
<h1><%= t('.heading') %></h1>
|
8
|
+
|
9
|
+
<ul class="actions">
|
10
|
+
<li><%= back_icon(admin_path) %></li>
|
11
|
+
</ul>
|
12
|
+
|
13
|
+
<%= paginate @collection %>
|
14
|
+
<%= render partial: 'shared/admin/list', locals: { collection: @collection } %>
|
15
|
+
<%= paginate @collection %>
|
16
|
+
</article>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<% content_for :meta_title, t('.title', id: @entity.id) %>
|
2
|
+
<% content_for :breadcrumbs do %>
|
3
|
+
<%= link_to(t('admin.comments.nav_item.text'), admin_comments_path) %>
|
4
|
+
<span>
|
5
|
+
<%= @entity.id %> (<%= @entity.commentable.model_name.human %>
|
6
|
+
<cite><%= @entity.commentable.title %></cite>)
|
7
|
+
</span>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<article>
|
11
|
+
<h1><%= @entity.commentable.title %></h1>
|
12
|
+
|
13
|
+
<ul class="actions">
|
14
|
+
<li><%= back_icon(admin_comments_path) %></li>
|
15
|
+
<% unless @entity.locked? %>
|
16
|
+
<li><%= edit_icon edit_comment_path(@entity.id) %></li>
|
17
|
+
<% end %>
|
18
|
+
</ul>
|
19
|
+
|
20
|
+
<% if @entity.deleted? %>
|
21
|
+
<div class="message-box-alert"><%= t(:deleted_entity) %></div>
|
22
|
+
<% end %>
|
23
|
+
|
24
|
+
<dl>
|
25
|
+
<dt><%= t('activerecord.attributes.comment.user_id') %></dt>
|
26
|
+
<dd><%= admin_user_link(@entity.user) %></dd>
|
27
|
+
|
28
|
+
<dt><%= t('activerecord.attributes.comment.commentable') %></dt>
|
29
|
+
<dd><%= comment_link(@entity) %></dd>
|
30
|
+
|
31
|
+
<dt><%= t(:created_at) %></dt>
|
32
|
+
<dd><%= time_tag(@entity.created_at) %></dd>
|
33
|
+
|
34
|
+
<dt><%= t('activerecord.attributes.comment.body') %></dt>
|
35
|
+
<dd>
|
36
|
+
<%= prepare_comment_text(@entity) %>
|
37
|
+
</dd>
|
38
|
+
</dl>
|
39
|
+
|
40
|
+
</article>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Здравствуйте, <%= @comment.commentable.user.name_for_letter %>.
|
2
|
+
|
3
|
+
На вашу запись «<%= @comment.commentable.title %>» на сайте party-npk.ru
|
4
|
+
<%= url_for @comment.commentable %>
|
5
|
+
|
6
|
+
Сам комментарий (<%= @comment.user.nil? ? 'анонимный' : @comment.user.profile_name %>):
|
7
|
+
<%= simple_format @comment.body %>
|
8
|
+
|
9
|
+
--
|
10
|
+
С уважением.
|
11
|
+
автоматический уведомитель
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<div id="comment-<%= comment.id %>" itemscope itemtype="http://schema.org/Comment" class="comment">
|
2
|
+
<% if comment.deleted? %>
|
3
|
+
<div class="deleted"><%= t('.deleted') %></div>
|
4
|
+
<% else %>
|
5
|
+
<meta itemprop="url" content="<%= comment_url comment %>"/>
|
6
|
+
<div class="author">
|
7
|
+
<span itemprop="author" itemscope itemtype="http://schema.org/Person">
|
8
|
+
<span itemprop="name"><%= user_link comment.user %></span>
|
9
|
+
</span>
|
10
|
+
<%= time_tag comment.created_at %>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<div class="body" itemprop="about">
|
14
|
+
<%= prepare_comment_text(comment) %>
|
15
|
+
<% if UserPrivilege.user_has_privilege?(current_user, :moderator) %>
|
16
|
+
<ul class="actions">
|
17
|
+
<li><%= edit_icon(edit_comment_path(comment.id)) %></li>
|
18
|
+
<li class="danger"><%= destroy_icon(comment) %></li>
|
19
|
+
</ul>
|
20
|
+
<% end %>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<%= render partial: 'votes/vote_block', locals: { votable: comment } %>
|
24
|
+
<% end %>
|
25
|
+
</div>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<%= render partial: 'shared/list_of_errors', locals: { entity: entity } %>
|
2
|
+
|
3
|
+
<%= form_for entity do |f| %>
|
4
|
+
<dl>
|
5
|
+
<dt><%= f.label :body %></dt>
|
6
|
+
<dd><%= f.text_area :body, required: true, cols: 60, rows: 7 %></dd>
|
7
|
+
</dl>
|
8
|
+
<% if current_user_has_privilege?(:administrator) && !entity.id.nil? %>
|
9
|
+
<ul class="flags">
|
10
|
+
<li>
|
11
|
+
<%= f.check_box :deleted %>
|
12
|
+
<%= f.label :deleted %>
|
13
|
+
</li>
|
14
|
+
</ul>
|
15
|
+
<% end %>
|
16
|
+
<div class="buttons">
|
17
|
+
<% if entity.id.nil? %>
|
18
|
+
<%= f.hidden_field :commentable_id %>
|
19
|
+
<%= f.hidden_field :commentable_type %>
|
20
|
+
<% end %>
|
21
|
+
<%= f.button t(:submit), type: 'submit' %>
|
22
|
+
</div>
|
23
|
+
<% end %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<section class="comments">
|
2
|
+
<% if comments.any? %>
|
3
|
+
<h2><%= t(:comments_list) %></h2>
|
4
|
+
|
5
|
+
<% comments.recent.each do |comment| %>
|
6
|
+
<%= render comment %>
|
7
|
+
<% end %>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<% if commentable.respond_to?(:commentable_by?) && commentable.commentable_by?(current_user) %>
|
11
|
+
<section class="reply-container">
|
12
|
+
<h2><%= t(:add_comment) %></h2>
|
13
|
+
|
14
|
+
<div class="container">
|
15
|
+
<%= render partial: 'comments/form', locals: { entity: Comment.new(commentable: commentable) } %>
|
16
|
+
</div>
|
17
|
+
</section>
|
18
|
+
<% end %>
|
19
|
+
</section>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<% content_for :meta_title, t('.title') %>
|
2
|
+
<% content_for :breadcrumbs do %>
|
3
|
+
<%= link_to(t('admin.comments.nav_item.text'), admin_comments_path) %>
|
4
|
+
<%= admin_comment_link(@entity) %>
|
5
|
+
<span><%= t(:edit) %></span>
|
6
|
+
<% end %>
|
7
|
+
|
8
|
+
<article class="edit-comment">
|
9
|
+
<h1><%= t('.title') %></h1>
|
10
|
+
|
11
|
+
<ul class="actions">
|
12
|
+
<li><%= return_icon(admin_comment_path(@entity.id)) %></li>
|
13
|
+
<li><%= world_icon(@entity.commentable) %></li>
|
14
|
+
<li class="danger"><%= destroy_icon(@entity) %></li>
|
15
|
+
</ul>
|
16
|
+
|
17
|
+
<%= render partial: 'form', locals: { entity: @entity } %>
|
18
|
+
</article>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<% content_for :meta_title, t('.title', id: @entity.id) %>
|
2
|
+
<% content_for :options do %>
|
3
|
+
<ul>
|
4
|
+
<li><%= link_to t(:list), admin_comments_path %></li>
|
5
|
+
<li><%= link_to t(:edit), edit_comment_path(@entity) %></li>
|
6
|
+
</ul>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<article class="comment">
|
10
|
+
<h1><%= t('.title', id: @entity.id) %></h1>
|
11
|
+
|
12
|
+
<div class="comment">
|
13
|
+
<div class="title">
|
14
|
+
<%= @entity.commentable.model_name.human %>
|
15
|
+
<cite><%= link_to @entity.commentable.title, @entity.commentable %></cite>
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<div class="author">
|
19
|
+
<%= user_link @entity.user %>
|
20
|
+
<%= time_tag @entity.created_at %>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<div class="body">
|
24
|
+
<%= prepare_comment_text(@entity) %>
|
25
|
+
</div>
|
26
|
+
</div>
|
27
|
+
</article>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Biovision comment</title>
|
5
|
+
<%= stylesheet_link_tag "biovision/comment/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "biovision/comment/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,65 @@
|
|
1
|
+
ru:
|
2
|
+
comment_count:
|
3
|
+
zero: "комментариев нет"
|
4
|
+
one: "%{count} комментарий"
|
5
|
+
few: "%{count} комментария"
|
6
|
+
many: "%{count} комментариев"
|
7
|
+
other: "%{count} комментариев"
|
8
|
+
comment:
|
9
|
+
zero: "комментариев нет"
|
10
|
+
one: "%{count} комментарий"
|
11
|
+
few: "%{count} комментария"
|
12
|
+
many: "%{count} комментариев"
|
13
|
+
other: "%{count} комментариев"
|
14
|
+
add_comment: "Добавить комментарий"
|
15
|
+
comments_list: "Комментарии"
|
16
|
+
activerecord:
|
17
|
+
models:
|
18
|
+
comment: "Комментарий"
|
19
|
+
errors:
|
20
|
+
models:
|
21
|
+
comment:
|
22
|
+
attributes:
|
23
|
+
commentable:
|
24
|
+
not_commentable: "недоступен вам для комментирования"
|
25
|
+
attributes:
|
26
|
+
comment:
|
27
|
+
commentable: "Комментируемый объект" # Comment validates_presence_of :commentable
|
28
|
+
commentable_id: "Комментируемый объект"
|
29
|
+
commentable_type: "Тип комментируемого объекта"
|
30
|
+
user_id: "Автор"
|
31
|
+
deleted: "Комментарий удалён"
|
32
|
+
body: "Текст"
|
33
|
+
admin:
|
34
|
+
comments:
|
35
|
+
nav_item:
|
36
|
+
text: "Комментарии"
|
37
|
+
description: "Модерация комментариев"
|
38
|
+
index:
|
39
|
+
title: "Комментарии, страница %{page}"
|
40
|
+
heading: "Комментарии"
|
41
|
+
show:
|
42
|
+
title: "Комментарий №%{id}"
|
43
|
+
my:
|
44
|
+
comments:
|
45
|
+
index:
|
46
|
+
title: "Мои комментарии, страница %{page}"
|
47
|
+
heading: "Мои комментарии"
|
48
|
+
description: "Оставленные вами комментарии"
|
49
|
+
comments:
|
50
|
+
create:
|
51
|
+
success: "Комментарий добавлен"
|
52
|
+
update:
|
53
|
+
success: "Комментарий изменён"
|
54
|
+
destroy:
|
55
|
+
success: "Комментарий удалён"
|
56
|
+
new:
|
57
|
+
title: "Добавление комментария"
|
58
|
+
edit:
|
59
|
+
title: "Редактирование комментария"
|
60
|
+
show:
|
61
|
+
title: "Комментарий №%{id}"
|
62
|
+
entry_reply:
|
63
|
+
subject: "Новый комментарий к вашей записи"
|
64
|
+
comment:
|
65
|
+
deleted: "Комментарий удалён"
|
data/config/routes.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
resources :comments, except: [:index, :new]
|
3
|
+
|
4
|
+
namespace :admin do
|
5
|
+
resources :comments, only: [:index, :show] do
|
6
|
+
member do
|
7
|
+
post 'toggle', defaults: { format: :json }
|
8
|
+
put 'lock', defaults: { format: :json }
|
9
|
+
delete 'lock', action: :unlock, defaults: { format: :json }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
namespace :my do
|
15
|
+
resources :comments, only: [:index]
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class CreateComments < ActiveRecord::Migration[5.0]
|
2
|
+
def up
|
3
|
+
unless Comment.table_exists?
|
4
|
+
create_table :comments do |t|
|
5
|
+
t.timestamps
|
6
|
+
t.integer :parent_id
|
7
|
+
t.references :user, foreign_key: true, on_update: :cascade, on_delete: :cascade
|
8
|
+
t.references :agent, foreign_key: true, on_update: :cascade, on_delete: :nullify
|
9
|
+
t.inet :ip
|
10
|
+
t.boolean :visible, default: true, null: false
|
11
|
+
t.boolean :locked, default: false, null: false
|
12
|
+
t.boolean :deleted, default: false, null: false
|
13
|
+
t.integer :upvote_count, default: 0, null: false
|
14
|
+
t.integer :downvote_count, default: 0, null: false
|
15
|
+
t.integer :vote_result, default: 0, null: false
|
16
|
+
t.integer :commentable_id, null: false
|
17
|
+
t.string :commentable_type, null: false
|
18
|
+
t.text :body, null: false
|
19
|
+
end
|
20
|
+
|
21
|
+
add_index :comments, [:commentable_id, :commentable_type]
|
22
|
+
add_foreign_key :comments, :comments, column: :parent_id, on_update: :cascade, on_delete: :cascade
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def down
|
27
|
+
if Comment.table_exists?
|
28
|
+
drop_table :comments
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: biovision-comment
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.170914
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maxim Khan-Magomedov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails-i18n
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: biovision-base
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: kaminari
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: database_cleaner
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: factory_girl_rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pg
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec-rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Commenting for biovision-based applications
|
126
|
+
email:
|
127
|
+
- maxim.km@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- MIT-LICENSE
|
133
|
+
- README.md
|
134
|
+
- Rakefile
|
135
|
+
- app/assets/config/biovision_comment_manifest.js
|
136
|
+
- app/assets/javascripts/biovision/comment/application.js
|
137
|
+
- app/assets/stylesheets/biovision/comment/comments.scss
|
138
|
+
- app/controllers/admin/comments_controller.rb
|
139
|
+
- app/controllers/biovision/comment/application_controller.rb
|
140
|
+
- app/controllers/comments_controller.rb
|
141
|
+
- app/controllers/my/comments_controller.rb
|
142
|
+
- app/helpers/biovision/comment/application_helper.rb
|
143
|
+
- app/jobs/biovision/comment/application_job.rb
|
144
|
+
- app/mailers/biovision/comment/application_mailer.rb
|
145
|
+
- app/mailers/comment_mailer.rb
|
146
|
+
- app/models/biovision/comment/application_record.rb
|
147
|
+
- app/models/comment.rb
|
148
|
+
- app/views/admin/comments/_comment.html.erb
|
149
|
+
- app/views/admin/comments/_nav_item.html.erb
|
150
|
+
- app/views/admin/comments/entity/_in_list.html.erb
|
151
|
+
- app/views/admin/comments/index.html.erb
|
152
|
+
- app/views/admin/comments/show.html.erb
|
153
|
+
- app/views/comment_mailer/entry_reply.text.erb
|
154
|
+
- app/views/comments/_comment.html.erb
|
155
|
+
- app/views/comments/_form.html.erb
|
156
|
+
- app/views/comments/_list.html.erb
|
157
|
+
- app/views/comments/edit.html.erb
|
158
|
+
- app/views/comments/new.html.erb
|
159
|
+
- app/views/comments/show.html.erb
|
160
|
+
- app/views/layouts/biovision/comment/application.html.erb
|
161
|
+
- config/locales/comments-ru.yml
|
162
|
+
- config/routes.rb
|
163
|
+
- db/migrate/20170914000001_create_comments.rb
|
164
|
+
- lib/biovision/comment.rb
|
165
|
+
- lib/biovision/comment/engine.rb
|
166
|
+
- lib/biovision/comment/version.rb
|
167
|
+
- lib/tasks/biovision/comment_tasks.rake
|
168
|
+
homepage: https://github.com/Biovision/biovision-comment
|
169
|
+
licenses:
|
170
|
+
- MIT
|
171
|
+
metadata: {}
|
172
|
+
post_install_message:
|
173
|
+
rdoc_options: []
|
174
|
+
require_paths:
|
175
|
+
- lib
|
176
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
requirements: []
|
187
|
+
rubyforge_project:
|
188
|
+
rubygems_version: 2.6.11
|
189
|
+
signing_key:
|
190
|
+
specification_version: 4
|
191
|
+
summary: Commenting for biovision-based applications
|
192
|
+
test_files: []
|