biovision-vote 0.1.1.170713 → 0.1.2.170925

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d1fceb881320631d5c9d0a3808fb2d333e8a50f
4
- data.tar.gz: 6779b532195a2a5b6388a49a03b82a04eb718514
3
+ metadata.gz: 2896e74fd3e5c25c96555df47134054a1dd6f590
4
+ data.tar.gz: 9864256f76fcc4c69b4a8e3a051f92ec7a1278f0
5
5
  SHA512:
6
- metadata.gz: 7fa528b1e84ff60e750cf4988fa2759307d91013b68109aeb622b73c5cd098a80791babbb2e85f065eea455f02e12247b07c5f64541eb1b8a5f9a507366924f7
7
- data.tar.gz: ef480eada0e9169f2024415c6c8886524b44fe5d06e041106b96acf72e60fd17c16be489bfa43fc8ca8da4a6184154311a3df50715427f535cb9b6ca7bcda038
6
+ metadata.gz: 2e04835cfee1d598a18143385563b64aaa394368bf5cf419cff484e45265579d8a1823ce1f5413827cb7b7bb76801e8ab612d20fd8083dd6cfd1ea60f9f3ad97
7
+ data.tar.gz: d34535db6f6717c29c73268052f0f578713bc1da3ec0c26a9af184f0a72345daab2054b57727d970f8aa8d116bc78d8775ab53e818c1c07efdca5a1bca61f60a
data/README.md CHANGED
@@ -11,7 +11,7 @@ Biovision::Vote
11
11
  Для возможности голосовать за модель у неё должны быть поля такого вида:
12
12
 
13
13
  ```ruby
14
- class AddVotableToModels < ActiveRecord::Migration[5.0]
14
+ class AddVotableToModels < ActiveRecord::Migration[5.1]
15
15
  def change
16
16
  add_column :posts, :upvote_count, :integer, default: 0, null: false
17
17
  add_column :posts, :downvote_count, :integer, default: 0, null: false
@@ -26,9 +26,11 @@ end
26
26
  Допустимость голосования определяется методом `VotableItem#votable_by?`, который
27
27
  можно переопределить в моделях, если требуется.
28
28
 
29
- Для ссылки на голосуемый объект в админке и за её пределами нужно в какой-нибудь
30
- помощник добавить методы `votable_item_link(entity)`
31
- и `admin_votable_item_link(entity)`.
29
+ Чтобы заработал фронт, нужно в `application.js` добавить это:
30
+
31
+ ```javascript
32
+ //= require biovision/vote/biovision-vote.js
33
+ ```
32
34
 
33
35
  ## Installation
34
36
  Add this line to your application's Gemfile:
@@ -1,3 +1,3 @@
1
- <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
1
+ <svg version="1.1" baseProfile="full" viewBox="0 0 24 24" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
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
3
  </svg>
@@ -1,3 +1,3 @@
1
- <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
1
+ <svg version="1.1" baseProfile="full" viewBox="0 0 24 24" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
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
3
  </svg>
@@ -1,3 +1,3 @@
1
- <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
1
+ <svg version="1.1" baseProfile="full" viewBox="0 0 24 24" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
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
3
  </svg>
@@ -1,3 +1,3 @@
1
- <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
1
+ <svg version="1.1" baseProfile="full" viewBox="0 0 24 24" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
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
3
  </svg>
@@ -1,3 +1,3 @@
1
- <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
1
+ <svg version="1.1" baseProfile="full" viewBox="0 0 24 24" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
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
3
  </svg>
@@ -1,3 +1,3 @@
1
- <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
1
+ <svg version="1.1" baseProfile="full" viewBox="0 0 24 24" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
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
3
  </svg>
@@ -1,3 +1,3 @@
1
- <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
1
+ <svg version="1.1" baseProfile="full" viewBox="0 0 24 24" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
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
3
  </svg>
@@ -1,3 +1,3 @@
1
- <svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
1
+ <svg version="1.1" baseProfile="full" viewBox="0 0 24 24" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
2
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
3
  </svg>
@@ -1,36 +1,45 @@
1
1
  'use strict';
2
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');
3
+ document.addEventListener('DOMContentLoaded', function () {
4
+ document.querySelectorAll('.vote-block.active .vote').forEach(function (element) {
5
+ element.addEventListener('click', function () {
6
+ const $button = this;
7
+ const $container = $button.closest('.vote-block');
8
+ const votable_id = $container.getAttribute('data-id');
9
+ const upvote = $button.classList.contains('upvote');
10
+
11
+ document.getElementById('vote_delta_' + votable_id).value = upvote ? '1' : '-1';
12
+
13
+ if ($container.classList.contains('active')) {
14
+ const $form = $container.querySelector('form');
15
+ const on_success = function () {
16
+ const result = JSON.parse(this.responseText);
17
+
18
+ $button.classList.remove('switch');
19
+ if (result.hasOwnProperty('data')) {
20
+ const vote_type = result['data']['vote_type'];
21
+ const vote_result = result['data']['vote_result'];
22
+
23
+ $container.classList.remove('voted-none');
24
+ $container.classList.add('voted-' + vote_type);
25
+ $container.querySelector('.result').innerHTML = vote_result;
26
+ }
27
+ };
28
+
29
+ const on_failure = function(result) {
30
+ $button.classList.remove('switch');
31
+ $button.classList.add('error');
32
+ handle_ajax_failure(result);
33
+ };
34
+
35
+ const request = Biovision.new_ajax_request('POST', $form.getAttribute('action'), on_success, on_failure);
36
+
37
+ $button.classList.add('switch');
38
+
39
+ request.send(new FormData($form));
40
+ }
41
+
42
+ $container.classList.remove('active');
43
+ });
35
44
  });
36
45
  });
@@ -1,5 +1,3 @@
1
- $font-size-decreased: 1.2rem !default;
2
-
3
1
  .vote-block {
4
2
  align-items: center;
5
3
  display: flex;
@@ -78,8 +76,9 @@ $font-size-decreased: 1.2rem !default;
78
76
  }
79
77
 
80
78
  .result {
81
- font-size: $font-size-decreased;
79
+ font-size: 1.2rem;
80
+ line-height: 1.2rem;
82
81
  padding: 0 .8rem;
83
82
  text-align: center;
84
83
  }
85
- }
84
+ }
@@ -9,6 +9,19 @@ module Biovision
9
9
  image_tag('biovision/vote/icons/downvote-active.svg', alt: '⇩')
10
10
  end
11
11
  end
12
+
13
+ # @param [ApplicationRecord] entity
14
+ def biovision_votable_link(entity)
15
+ text = entity.model_name.human
16
+ if entity.respond_to?(:title)
17
+ text << " «#{entity.title}»"
18
+ elsif entity.respond_to?(:name)
19
+ text << " «#{entity.name}»"
20
+ else
21
+ text << " №#{entity.id}"
22
+ end
23
+ link_to(text, entity)
24
+ end
12
25
  end
13
26
  end
14
27
  end
@@ -3,11 +3,10 @@
3
3
  </div>
4
4
  <div class="data">
5
5
  <div>
6
- <%= entity.votable.model_name.human %>
7
- <cite><%= admin_votable_link(entity.votable) %></cite>
6
+ <%= biovision_votable_link(entity.votable) %>
8
7
  </div>
9
8
  <div class="info">
10
- <%= admin_user_link(votable.user) %>
9
+ <%= admin_user_link(entity.user) %>
11
10
  </div>
12
11
  <div class="secondary info">
13
12
  <%= time_tag(entity.created_at) %>
@@ -1,6 +1,9 @@
1
- <% content_for :meta_title, t('.title') %>
1
+ <% content_for :meta_title, t('.title', page: current_page) %>
2
+ <% content_for :breadcrumbs do %>
3
+ <span><%= t('admin.votes.nav_item.text') %></span>
4
+ <% end %>
2
5
 
3
- <article class="entity-page">
6
+ <article>
4
7
  <h1><%= t('.heading') %></h1>
5
8
  <ul class="actions">
6
9
  <li><%= back_icon(admin_path) %></li>
@@ -1,6 +1,14 @@
1
1
  module Biovision
2
2
  module Vote
3
+ require 'biovision/base'
4
+
3
5
  class Engine < ::Rails::Engine
6
+ config.assets.precompile << %w(biovision/vote/**/*)
7
+
8
+ config.generators do |g|
9
+ g.test_framework :rspec
10
+ g.fixture_replacement :factory_girl, :dir => 'spec/factories'
11
+ end
4
12
  end
5
13
  end
6
14
  end
@@ -1,5 +1,5 @@
1
1
  module Biovision
2
2
  module Vote
3
- VERSION = '0.1.1.170713'
3
+ VERSION = '0.1.2.170925'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biovision-vote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.170713
4
+ version: 0.1.2.170925
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxim Khan-Magomedov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-13 00:00:00.000000000 Z
11
+ date: 2017-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  version: '0'
188
188
  requirements: []
189
189
  rubyforge_project:
190
- rubygems_version: 2.6.11
190
+ rubygems_version: 2.6.13
191
191
  signing_key:
192
192
  specification_version: 4
193
193
  summary: Voting functionality for biovision-based applications