biovision-vote 0.1.1.170713

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +54 -0
  4. data/Rakefile +24 -0
  5. data/app/assets/config/biovision_vote_manifest.js +2 -0
  6. data/app/assets/images/biovision/vote/icons/downvote-active.svg +3 -0
  7. data/app/assets/images/biovision/vote/icons/downvote-error.svg +3 -0
  8. data/app/assets/images/biovision/vote/icons/downvote-switch.svg +3 -0
  9. data/app/assets/images/biovision/vote/icons/downvote.svg +3 -0
  10. data/app/assets/images/biovision/vote/icons/upvote-active.svg +3 -0
  11. data/app/assets/images/biovision/vote/icons/upvote-error.svg +3 -0
  12. data/app/assets/images/biovision/vote/icons/upvote-switch.svg +3 -0
  13. data/app/assets/images/biovision/vote/icons/upvote.svg +3 -0
  14. data/app/assets/javascripts/biovision/vote/application.js +13 -0
  15. data/app/assets/javascripts/biovision/vote/biovision-vote.js +36 -0
  16. data/app/assets/stylesheets/biovision/vote/vote.scss +85 -0
  17. data/app/controllers/admin/votes_controller.rb +12 -0
  18. data/app/controllers/biovision/vote/application_controller.rb +7 -0
  19. data/app/controllers/votes_controller.rb +50 -0
  20. data/app/helpers/biovision/vote/application_helper.rb +14 -0
  21. data/app/jobs/biovision/vote/application_job.rb +6 -0
  22. data/app/mailers/biovision/vote/application_mailer.rb +8 -0
  23. data/app/models/application_record.rb +3 -0
  24. data/app/models/biovision/vote/application_record.rb +7 -0
  25. data/app/models/concerns/votable_item.rb +30 -0
  26. data/app/models/vote.rb +74 -0
  27. data/app/views/admin/votes/_nav_item.html.erb +6 -0
  28. data/app/views/admin/votes/entity/_in_list.html.erb +15 -0
  29. data/app/views/admin/votes/index.html.erb +12 -0
  30. data/app/views/layouts/biovision/vote/application.html.erb +14 -0
  31. data/app/views/votes/_vote_block.html.erb +14 -0
  32. data/app/views/votes/result.jbuilder +1 -0
  33. data/config/locales/votes-ru.yml +31 -0
  34. data/config/routes.rb +7 -0
  35. data/db/migrate/20170330000001_create_votes.rb +13 -0
  36. data/lib/biovision/vote.rb +7 -0
  37. data/lib/biovision/vote/engine.rb +6 -0
  38. data/lib/biovision/vote/version.rb +5 -0
  39. data/lib/tasks/biovision/vote_tasks.rake +4 -0
  40. metadata +194 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4d1fceb881320631d5c9d0a3808fb2d333e8a50f
4
+ data.tar.gz: 6779b532195a2a5b6388a49a03b82a04eb718514
5
+ SHA512:
6
+ metadata.gz: 7fa528b1e84ff60e750cf4988fa2759307d91013b68109aeb622b73c5cd098a80791babbb2e85f065eea455f02e12247b07c5f64541eb1b8a5f9a507366924f7
7
+ data.tar.gz: ef480eada0e9169f2024415c6c8886524b44fe5d06e041106b96acf72e60fd17c16be489bfa43fc8ca8da4a6184154311a3df50715427f535cb9b6ca7bcda038
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,54 @@
1
+ Biovision::Vote
2
+ ===============
3
+
4
+ Модуль голосования для приложений на базе `biovision-base`.
5
+
6
+ Используйте на свой страх и риск без каких-либо гарантий.
7
+
8
+ Использование
9
+ -------------
10
+
11
+ Для возможности голосовать за модель у неё должны быть поля такого вида:
12
+
13
+ ```ruby
14
+ class AddVotableToModels < ActiveRecord::Migration[5.0]
15
+ def change
16
+ add_column :posts, :upvote_count, :integer, default: 0, null: false
17
+ add_column :posts, :downvote_count, :integer, default: 0, null: false
18
+ add_column :posts, :vote_result, :integer, default: 0, null: false
19
+ end
20
+ end
21
+ ```
22
+
23
+ Функционал примешивается через `include VotableItem`.
24
+
25
+ По умолчанию голосовать за сущности могут только авторизованные пользователи.
26
+ Допустимость голосования определяется методом `VotableItem#votable_by?`, который
27
+ можно переопределить в моделях, если требуется.
28
+
29
+ Для ссылки на голосуемый объект в админке и за её пределами нужно в какой-нибудь
30
+ помощник добавить методы `votable_item_link(entity)`
31
+ и `admin_votable_item_link(entity)`.
32
+
33
+ ## Installation
34
+ Add this line to your application's Gemfile:
35
+
36
+ ```ruby
37
+ gem 'biovision-vote'
38
+ ```
39
+
40
+ And then execute:
41
+ ```bash
42
+ $ bundle
43
+ ```
44
+
45
+ Or install it yourself as:
46
+ ```bash
47
+ $ gem install biovision-vote
48
+ ```
49
+
50
+ ## Contributing
51
+ Contribution directions go here.
52
+
53
+ ## License
54
+ 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,24 @@
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::Vote'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ require 'bundler/gem_tasks'
24
+
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/biovision/vote .js
2
+ //= link_directory ../stylesheets/biovision/vote .css
@@ -0,0 +1,3 @@
1
+ <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
+ <polyline points="9 2, 9 12, 4 12, 11 21, 13 21, 20 12, 15 12, 15 2, 9 2" fill="#822" stroke="#844" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
+ <polyline points="9 2, 9 12, 4 12, 11 21, 13 21, 20 12, 15 12, 15 2, 9 2" fill="#888" stroke="#444" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
+ <polyline points="9 2, 9 12, 4 12, 11 21, 13 21, 20 12, 15 12, 15 2, 9 2" fill="#ff4" stroke="#884" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
+ <polyline points="9 2, 9 12, 4 12, 11 21, 13 21, 20 12, 15 12, 15 2, 9 2" fill="none" stroke="#844" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
+ <polyline points="9 21, 9 11, 4 11, 11 2, 13 2, 20 11, 15 11, 15 21, 9 21" fill="#282" stroke="#484" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
+ <polyline points="9 21, 9 11, 4 11, 11 2, 13 2, 20 11, 15 11, 15 21, 9 21" fill="#888" stroke="#444" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
+ <polyline points="9 21, 9 11, 4 11, 11 2, 13 2, 20 11, 15 11, 15 21, 9 21" fill="#ff4" stroke="#884" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
+ <polyline points="9 21, 9 11, 4 11, 11 2, 13 2, 20 11, 15 11, 15 21, 9 21" fill="none" stroke="#484" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
3
+ </svg>
@@ -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,36 @@
1
+ 'use strict';
2
+
3
+ $(function () {
4
+ $('.vote-block.active .vote').on('click', function () {
5
+ var $button = $(this);
6
+ var $container = $(this).closest('.vote-block');
7
+ var votable_id = $container.data('id');
8
+ var upvote = $(this).hasClass('upvote');
9
+ var $form = $container.find('form');
10
+
11
+ $('#vote_delta_' + votable_id).val(upvote ? '1' : '-1');
12
+
13
+ if ($container.hasClass('active')) {
14
+ $button.addClass('switch');
15
+
16
+ $.post($form.attr('action'), $form.serialize(), function (result) {
17
+ console.log(result);
18
+ $button.removeClass('switch');
19
+ if (result.hasOwnProperty('data')) {
20
+ var vote_type = result['data']['vote_type'];
21
+ var vote_result = result['data']['vote_result'];
22
+
23
+ $container.removeClass('voted-none');
24
+ $container.addClass('voted-' + vote_type);
25
+ $container.find('.result').html(vote_result);
26
+ }
27
+ }).fail(function(result) {
28
+ $button.removeClass('switch');
29
+ $button.addClass('error');
30
+ handle_ajax_failure(result);
31
+ });
32
+ }
33
+
34
+ $container.removeClass('active');
35
+ });
36
+ });
@@ -0,0 +1,85 @@
1
+ $font-size-decreased: 1.2rem !default;
2
+
3
+ .vote-block {
4
+ align-items: center;
5
+ display: flex;
6
+ padding: 0 .8rem;
7
+
8
+ .vote {
9
+ background: no-repeat center / cover;
10
+ height: 1.2rem;
11
+ width: 1.2rem;
12
+ }
13
+
14
+ &.active {
15
+ .vote {
16
+ cursor: pointer;
17
+ }
18
+
19
+ &.voted-none {
20
+ .upvote:hover {
21
+ background-image: image_url('biovision/vote/icons/upvote-active.svg');
22
+ }
23
+
24
+ .downvote:hover {
25
+ background-image: image_url('biovision/vote/icons/downvote-active.svg');
26
+ }
27
+ }
28
+ }
29
+
30
+ &.voted-upvote {
31
+ .upvote {
32
+ background-image: image_url('biovision/vote/icons/upvote-active.svg');
33
+ }
34
+
35
+ .downvote {
36
+ background-image: image_url('biovision/vote/icons/downvote.svg');
37
+ }
38
+ }
39
+
40
+ &.voted-downvote {
41
+ .upvote {
42
+ background-image: image_url('biovision/vote/icons/upvote.svg');
43
+ }
44
+
45
+ .downvote {
46
+ background-image: image_url('biovision/vote/icons/downvote-active.svg');
47
+ }
48
+ }
49
+
50
+ &.voted-none {
51
+ .upvote {
52
+ background-image: image_url('biovision/vote/icons/upvote.svg');
53
+ }
54
+
55
+ .downvote {
56
+ background-image: image_url('biovision/vote/icons/downvote.svg');
57
+ }
58
+ }
59
+
60
+ .upvote {
61
+ &.switch {
62
+ background-image: image_url('biovision/vote/icons/upvote-switch.svg');
63
+ }
64
+
65
+ &.error {
66
+ background-image: image_url('biovision/vote/icons/upvote-error.svg');
67
+ }
68
+ }
69
+
70
+ .downvote {
71
+ &.switch {
72
+ background-image: image_url('biovision/vote/icons/downvote-switch.svg');
73
+ }
74
+
75
+ &.error {
76
+ background-image: image_url('biovision/vote/icons/downvote-error.svg');
77
+ }
78
+ }
79
+
80
+ .result {
81
+ font-size: $font-size-decreased;
82
+ padding: 0 .8rem;
83
+ text-align: center;
84
+ }
85
+ }
@@ -0,0 +1,12 @@
1
+ class Admin::VotesController < AdminController
2
+ # get /admin/votes
3
+ def index
4
+ @collection = Vote.page_for_administration(current_page)
5
+ end
6
+
7
+ private
8
+
9
+ def restrict_access
10
+ require_privilege :moderator
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ module Biovision
2
+ module Vote
3
+ class ApplicationController < ActionController::Base
4
+ protect_from_forgery with: :exception
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,50 @@
1
+ class VotesController < ApplicationController
2
+ before_action :set_entity, only: [:destroy]
3
+
4
+ # post /votes
5
+ def create
6
+ @entity = Vote.new(creation_parameters)
7
+ if @entity.votable.votable_by?(current_user)
8
+ process_vote
9
+ else
10
+ render :result, status: :unauthorized
11
+ end
12
+ end
13
+
14
+ # delete /votes/:id
15
+ def destroy
16
+ @entity.destroy
17
+ render :result
18
+ end
19
+
20
+ private
21
+
22
+ def set_entity
23
+ @entity = Vote.find_by(id: params[:id])
24
+ if @entity.nil? || !@entity.editable_by?(current_user)
25
+ handle_http_404('Cannot find vote')
26
+ end
27
+ end
28
+
29
+ def creation_parameters
30
+ parameters = params.require(:vote).permit(Vote.creation_parameters)
31
+ parameters.merge(owner_for_entity(true))
32
+ end
33
+
34
+ def process_vote
35
+ if Vote.voted?(current_user, @entity.votable)
36
+ render :result, status: :conflict
37
+ else
38
+ count_vote
39
+ end
40
+ end
41
+
42
+ def count_vote
43
+ @entity.save
44
+ name = @entity.upvote? ? Vote::METRIC_UPVOTE_HIT : Vote::METRIC_DOWNVOTE_HIT
45
+ Metric.register(name)
46
+ Metric.register(Vote::METRIC_VOTE_HIT)
47
+
48
+ render :result, status: :created
49
+ end
50
+ end
@@ -0,0 +1,14 @@
1
+ module Biovision
2
+ module Vote
3
+ module ApplicationHelper
4
+ # @param [Vote] vote
5
+ def vote_image(vote)
6
+ if vote.upvote?
7
+ image_tag('biovision/vote/icons/upvote-active.svg', alt: '⇧')
8
+ else
9
+ image_tag('biovision/vote/icons/downvote-active.svg', alt: '⇩')
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ module Biovision
2
+ module Vote
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module Biovision
2
+ module Vote
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: 'from@example.com'
5
+ layout 'mailer'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,7 @@
1
+ module Biovision
2
+ module Vote
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ module VotableItem
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ has_many :votes, as: :votable, dependent: :destroy
6
+ end
7
+
8
+ # @param [User] user
9
+ def votable_by?(user)
10
+ return false if user.nil?
11
+ !Vote.voted?(user, self)
12
+ end
13
+
14
+ # @param [User] user
15
+ def vote_data(user = nil)
16
+ {
17
+ upvote_count: upvote_count,
18
+ downvote_count: downvote_count,
19
+ vote_result: vote_result,
20
+ vote_type: voted(user)
21
+ }
22
+ end
23
+
24
+ # @param [User] user
25
+ def voted(user)
26
+ vote = votes.find_by(user: user)
27
+ return :none if vote.nil?
28
+ vote.upvote? ? :upvote : :downvote
29
+ end
30
+ end
@@ -0,0 +1,74 @@
1
+ class Vote < ApplicationRecord
2
+ include HasOwner
3
+
4
+ PER_PAGE = 20
5
+
6
+ METRIC_VOTE_HIT = 'votes.any.hit'
7
+ METRIC_UPVOTE_HIT = 'votes.upvote.hit'
8
+ METRIC_DOWNVOTE_HIT = 'votes.downvote.hit'
9
+
10
+ belongs_to :user, optional: true
11
+ belongs_to :agent, optional: true
12
+ belongs_to :votable, polymorphic: true
13
+
14
+ before_validation { self.delta = (delta.to_i > 0 ? 1 : -1) }
15
+ validates_uniqueness_of :votable_id, scope: [:user_id, :votable_type]
16
+
17
+ after_create :add_vote_result
18
+ after_destroy :discard_vote_result
19
+
20
+ scope :recent, -> { order('id desc') }
21
+
22
+ # @param [Integer] page
23
+ def self.page_for_administration(page = 1)
24
+ recent.page(page).per(PER_PAGE)
25
+ end
26
+
27
+ # @param [User] user
28
+ # @param [ApplicationRecord] votable
29
+ def self.voted?(user, votable)
30
+ exists?(user: user, votable: votable)
31
+ end
32
+
33
+ # @param [User] user
34
+ # @param [ApplicationRecord] votable
35
+ # @param [Integer] delta
36
+ def self.count_vote(user, votable, delta = 1)
37
+ create(user: user, votable: votable, delta: delta) unless voted?
38
+ votable.reload
39
+ votable.vote_result
40
+ end
41
+
42
+ def self.creation_parameters
43
+ %i(votable_id votable_type delta)
44
+ end
45
+
46
+ def upvote?
47
+ delta >= 0
48
+ end
49
+
50
+ def downvote?
51
+ delta < 0
52
+ end
53
+
54
+ # @param [User] user
55
+ def editable_by?(user)
56
+ owned_by?(user) || UserPrivilege.user_has_privilege?(:user, :moderator)
57
+ end
58
+
59
+ private
60
+
61
+ def add_vote_result
62
+ votable.vote_result = votable.vote_result + delta
63
+ votable.upvote_count = votable.upvote_count + 1 if upvote?
64
+ votable.downvote_count = votable.downvote_count + 1 if downvote?
65
+ votable.save
66
+ end
67
+
68
+ def discard_vote_result
69
+ votable.vote_result = votable.vote_result - delta
70
+ votable.upvote_count = votable.upvote_count - 1 if upvote?
71
+ votable.downvote_count = votable.downvote_count - 1 if downvote?
72
+ votable.save
73
+ end
74
+ end
@@ -0,0 +1,6 @@
1
+ <div>
2
+ <%= link_to t('.text'), admin_votes_path %>
3
+ </div>
4
+ <div class="description">
5
+ <%= t('.description') %>
6
+ </div>
@@ -0,0 +1,15 @@
1
+ <div class="image">
2
+ <%= vote_image(entity) %>
3
+ </div>
4
+ <div class="data">
5
+ <div>
6
+ <%= entity.votable.model_name.human %>
7
+ <cite><%= admin_votable_link(entity.votable) %></cite>
8
+ </div>
9
+ <div class="info">
10
+ <%= admin_user_link(votable.user) %>
11
+ </div>
12
+ <div class="secondary info">
13
+ <%= time_tag(entity.created_at) %>
14
+ </div>
15
+ </div>
@@ -0,0 +1,12 @@
1
+ <% content_for :meta_title, t('.title') %>
2
+
3
+ <article class="entity-page">
4
+ <h1><%= t('.heading') %></h1>
5
+ <ul class="actions">
6
+ <li><%= back_icon(admin_path) %></li>
7
+ </ul>
8
+
9
+ <%= paginate @collection %>
10
+ <%= render partial: 'shared/admin/list', locals: { collection: @collection } %>
11
+ <%= paginate @collection %>
12
+ </article>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Biovision vote</title>
5
+ <%= stylesheet_link_tag "biovision/vote/application", media: "all" %>
6
+ <%= javascript_include_tag "biovision/vote/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,14 @@
1
+ <% block_class = votable.votable_by?(current_user) ? 'active' : '' %>
2
+ <div class="vote-block <%= block_class %> voted-<%= votable.voted(current_user) %>" data-id="<%= votable.id %>">
3
+ <div class="vote upvote"></div>
4
+ <div class="result"><%= votable.vote_result %></div>
5
+ <div class="vote downvote"></div>
6
+ <% unless block_class.blank? %>
7
+ <% entity = Vote.new(votable: votable) %>
8
+ <%= form_tag votes_path, method: :post do %>
9
+ <%= hidden_field_tag 'vote[votable_id]', entity.votable_id, id: "vote_votable_id_#{votable.id}" %>
10
+ <%= hidden_field_tag 'vote[votable_type]', entity.votable_type, id: "vote_votable_type_#{votable.id}" %>
11
+ <%= hidden_field_tag 'vote[delta]', '0', id: "vote_delta_#{votable.id}" %>
12
+ <% end %>
13
+ <% end %>
14
+ </div>
@@ -0,0 +1 @@
1
+ json.data @entity.votable.vote_data(current_user)
@@ -0,0 +1,31 @@
1
+ ru:
2
+ upvote_count:
3
+ zero: "голосов «за» нет"
4
+ one: "%{count} голос «за»"
5
+ few: "%{count} голоса «за»"
6
+ many: "%{count} голосов «за»"
7
+ other: "%{count} голосов «за»"
8
+ downvote_count:
9
+ zero: "голосов «против» нет"
10
+ one: "%{count} голос «против»"
11
+ few: "%{count} голоса «против»"
12
+ many: "%{count} голосов «против»"
13
+ other: "%{count} голосов «против»"
14
+ activerecord:
15
+ models:
16
+ vote: "Голос"
17
+ attributes:
18
+ vote:
19
+ user: "Пользователь"
20
+ votable: "Объект голосования"
21
+ agent: "Агент пользователя"
22
+ ip: "IP-адрес"
23
+ delta: "Изменение"
24
+ admin:
25
+ votes:
26
+ nav_item:
27
+ text: "Голоса пользователей"
28
+ description: "Просмотр голосов пользователей"
29
+ index:
30
+ title: "Голоса, страница %{page}"
31
+ heading: "Голоса пользователей"
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Rails.application.routes.draw do
2
+ resources :votes, only: [:create, :destroy], defaults: { format: :json }
3
+
4
+ namespace :admin do
5
+ resources :votes, only: [:index]
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ class CreateVotes < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :votes do |t|
4
+ t.timestamps
5
+ t.references :user, foreign_key: true, on_update: :cascade, on_delete: :cascade
6
+ t.references :agent, foreign_key: true, on_update: :cascade, on_delete: :nullify
7
+ t.inet :ip
8
+ t.integer :delta, limit: 2, default: 0, null: false
9
+ t.integer :votable_id, null: false
10
+ t.string :votable_type, null: false
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ require "biovision/vote/engine"
2
+
3
+ module Biovision
4
+ module Vote
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module Biovision
2
+ module Vote
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Biovision
2
+ module Vote
3
+ VERSION = '0.1.1.170713'
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :biovision_vote do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: biovision-vote
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1.170713
5
+ platform: ruby
6
+ authors:
7
+ - Maxim Khan-Magomedov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-13 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: pg
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: rspec-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: database_cleaner
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: factory_girl_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: Voting functionality 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_vote_manifest.js
136
+ - app/assets/images/biovision/vote/icons/downvote-active.svg
137
+ - app/assets/images/biovision/vote/icons/downvote-error.svg
138
+ - app/assets/images/biovision/vote/icons/downvote-switch.svg
139
+ - app/assets/images/biovision/vote/icons/downvote.svg
140
+ - app/assets/images/biovision/vote/icons/upvote-active.svg
141
+ - app/assets/images/biovision/vote/icons/upvote-error.svg
142
+ - app/assets/images/biovision/vote/icons/upvote-switch.svg
143
+ - app/assets/images/biovision/vote/icons/upvote.svg
144
+ - app/assets/javascripts/biovision/vote/application.js
145
+ - app/assets/javascripts/biovision/vote/biovision-vote.js
146
+ - app/assets/stylesheets/biovision/vote/vote.scss
147
+ - app/controllers/admin/votes_controller.rb
148
+ - app/controllers/biovision/vote/application_controller.rb
149
+ - app/controllers/votes_controller.rb
150
+ - app/helpers/biovision/vote/application_helper.rb
151
+ - app/jobs/biovision/vote/application_job.rb
152
+ - app/mailers/biovision/vote/application_mailer.rb
153
+ - app/models/application_record.rb
154
+ - app/models/biovision/vote/application_record.rb
155
+ - app/models/concerns/votable_item.rb
156
+ - app/models/vote.rb
157
+ - app/views/admin/votes/_nav_item.html.erb
158
+ - app/views/admin/votes/entity/_in_list.html.erb
159
+ - app/views/admin/votes/index.html.erb
160
+ - app/views/layouts/biovision/vote/application.html.erb
161
+ - app/views/votes/_vote_block.html.erb
162
+ - app/views/votes/result.jbuilder
163
+ - config/locales/votes-ru.yml
164
+ - config/routes.rb
165
+ - db/migrate/20170330000001_create_votes.rb
166
+ - lib/biovision/vote.rb
167
+ - lib/biovision/vote/engine.rb
168
+ - lib/biovision/vote/version.rb
169
+ - lib/tasks/biovision/vote_tasks.rake
170
+ homepage: https://github.com/Biovision/biovision-vote
171
+ licenses:
172
+ - MIT
173
+ metadata: {}
174
+ post_install_message:
175
+ rdoc_options: []
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubyforge_project:
190
+ rubygems_version: 2.6.11
191
+ signing_key:
192
+ specification_version: 4
193
+ summary: Voting functionality for biovision-based applications
194
+ test_files: []