like_dislike 2.0 → 2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e5e0aa180cb46f6fb8a17422ac0c25f9fae259e
4
- data.tar.gz: 3c3e95c0726bd7eab49967e9155ff4edc512cdf9
3
+ metadata.gz: 5a7a60d81f4400e3a111e6bf71b136428c9a20ef
4
+ data.tar.gz: dd8066e46f97e0512ea7bda3401e23169fa21a18
5
5
  SHA512:
6
- metadata.gz: 42c19dbda0c05f21095ea4c7568f27327152536de27156ce715923e47c4c805ea08fd71cd0741a2f4ca6f42aef3dd3432d9af366ac9776233ec8109900e07aac
7
- data.tar.gz: 8a4537f362fba125672b6710180b2e22792d3a53f953258fccbd0e7309c2cdfa200d75e8cdd6b2ddf90fd1e7f2ac60174932c292c91d5b2d2f898ac1c1b7025f
6
+ metadata.gz: 83b0bc792da3f322295a6494511a33554cca3205e6af3aa18b8d469fecbed2012295906b14542db9b8aaff93c5d45f4489a3cc8a762486e8ad0c02c73a697789
7
+ data.tar.gz: 474aa6e74999e1b136f77355eec87a57d8544c7a8e5ae9576a153321f98601cbd84f9d54f7de0165471c4add88cf849dcc663d187a7c5bba897533dd8efb175c
@@ -1,29 +1,30 @@
1
1
  //= require jquery.turbolinks
2
2
  $(document).on('ready page:load', function () {
3
- $(".voting_wrapper .voting_btn").click(function (e) {
4
- var clicked_button = $(this).children().attr('class');
5
- var unique_id = $(this).parent().attr("id");
6
- var like_state,msg;
7
- if(clicked_button==='down_button')
8
- {
9
- like_state = 'down';
10
- msg = 'Please login to UnLike';
11
- }
12
- else if(clicked_button==='up_button')
13
- {
14
- like_state = 'up';
15
- msg = 'Please login to Like';
16
- }
3
+ $(".voting_wrapper .voting_btn").click(function (e) {
4
+ var clicked_button = $(this).children().attr('class');
5
+ var unique_id = $(this).parent().attr("id");
6
+ var likeable_type = $(this).parent().attr("data-info");
7
+ var like_state,msg;
8
+ if(clicked_button==='down_button')
9
+ {
10
+ msg = 'Please login to UnLike';
11
+ action = 'downvote'
12
+ }
13
+ else if(clicked_button==='up_button')
14
+ {
15
+ msg = 'Please login to Like';
16
+ action = 'upvote'
17
+ }
17
18
 
18
- post_data = {'id':unique_id, 'vote':like_state};
19
- $.post('vote_items', post_data, function(data) {
20
- getData = data.toString().split(",")
21
- $('#'+unique_id+' .up_votes').text(getData[0]);
22
- $('#'+unique_id+' .down_votes').text(getData[1]);
23
- }).fail(function(err) {
24
- if (err.statusText == "Unauthorized"){
25
- alert(msg)
26
- }
27
- });
28
- });
19
+ post_data = {'likeable_id':unique_id, 'likeable_type':likeable_type};
20
+ $.post(action, post_data, function(data) {
21
+ getData = data.toString().split(",")
22
+ $('#'+unique_id+' .up_votes').text(getData[0]);
23
+ $('#'+unique_id+' .down_votes').text(getData[1]);
24
+ }).fail(function(err) {
25
+ if (err.statusText == "Unauthorized"){
26
+ alert(msg)
27
+ }
28
+ });
29
+ });
29
30
  });
@@ -0,0 +1,29 @@
1
+ module LikeDislike
2
+ class VotesController < ActionController::Base
3
+ before_action :find_likeable
4
+ before_action :authenticate_user!
5
+ respond_to :js
6
+
7
+ def create
8
+ @likeable.liked_by current_user
9
+ render json: render_votes
10
+ end
11
+
12
+ def destroy
13
+ @likeable.disliked_by current_user
14
+ render json: render_votes
15
+ end
16
+
17
+ private
18
+
19
+ def render_votes
20
+ [@likeable.cached_votes_up, @likeable.cached_votes_down]
21
+ end
22
+
23
+ def find_likeable
24
+ @likeable_type = params[:likeable_type].classify
25
+ @likeable = @likeable_type.constantize.find(params[:likeable_id])
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,4 @@
1
+ LikeDislike::Engine.routes.draw do
2
+ match :upvote, to: 'votes#create', as: :upvote, via: :post
3
+ match :downvote, to: 'votes#destroy', as: :downvote, via: :post
4
+ end
@@ -0,0 +1,25 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module LikeDislike
4
+ module Generators
5
+ # Migration generator that creates migration file from template
6
+ class MigrationGenerator < ActiveRecord::Generators::Base
7
+ source_root File.expand_path("../templates", __FILE__)
8
+
9
+ argument :name, :type => :string, :default => 'create_votes'
10
+
11
+ def copy_cache_vote_migration
12
+ if name == "create_votes"
13
+ migration_template "migration_vote_table.rb", "db/migrate/create_votes.rb"
14
+ else
15
+ migration_template "migration_cache_vote.rb", "db/migrate/add_column_to_#{name.downcase}.rb"
16
+ end
17
+ end
18
+
19
+ def add_like_dislike_routes
20
+ route "mount LikeDislike::Engine, at: '/'"
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ class AddColumnTo<%= name %> < ActiveRecord::Migration
2
+ def change
3
+ <% table_name = name.downcase.pluralize.to_sym %>
4
+ add_column :<%= table_name %>, :cached_votes_up, :integer, :default => 0
5
+ add_column :<%= table_name %>, :cached_votes_down, :integer, :default => 0
6
+ add_column :<%= table_name %>, :cached_votes_score, :integer, :default => 0
7
+ add_index :<%= table_name %>, :cached_votes_up
8
+ add_index :<%= table_name %>, :cached_votes_down
9
+ add_index :<%= table_name %>, :cached_votes_score
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ class CreateVotes < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :votes do |t|
4
+
5
+ t.references :votable, :polymorphic => true
6
+ t.references :voter, :polymorphic => true
7
+
8
+ t.boolean :vote_flag
9
+ t.string :vote_scope
10
+ t.integer :vote_weight
11
+
12
+ t.timestamps
13
+ end
14
+
15
+ if ActiveRecord::VERSION::MAJOR < 4
16
+ add_index :votes, [:votable_id, :votable_type]
17
+ add_index :votes, [:voter_id, :voter_type]
18
+ end
19
+
20
+ add_index :votes, [:voter_id, :voter_type, :vote_scope]
21
+ add_index :votes, [:votable_id, :votable_type, :vote_scope]
22
+ end
23
+
24
+ def self.down
25
+ drop_table :votes
26
+ end
27
+ end
@@ -3,8 +3,7 @@ require 'acts_as_votable'
3
3
  require 'jquery-turbolinks'
4
4
 
5
5
  module LikeDislike
6
- module Rails
7
- class Engine < ::Rails::Engine
8
- end
6
+ class Engine < ::Rails::Engine
7
+ isolate_namespace LikeDislike
9
8
  end
10
9
  end
@@ -1,19 +1,21 @@
1
1
  module LikeDislike
2
- module Helper
3
- def like_unlike_button(votable_object)
4
- html = []
5
- html << "<div class='voting_wrapper' id=#{votable_object.id}>
6
- <div class='voting_wrapper' id=#{votable_object.id}>
7
- <div class='voting_btn'>
8
- <div class='up_button'></div>
9
- <span class='up_votes'>#{votable_object.get_upvotes.size}</span>
10
- </div>
11
- <div class='voting_btn'>
12
- <div class='down_button'></div>
13
- <span class='down_votes'>#{votable_object.get_downvotes.size}</span>
14
- </div>
15
- </div>"
16
- raw html.join("\n")
17
- end
18
- end
2
+ module Helper
3
+ def like_unlike_button(votable_object)
4
+ if current_user
5
+ html = []
6
+ html << "<div class='voting_wrapper' id=#{votable_object.id} >
7
+ <div class='voting_wrapper' data-info=#{votable_object.class.to_s} id=#{votable_object.id} >
8
+ <div class='voting_btn'>
9
+ <div class='up_button'></div>
10
+ <span class='up_votes'>#{votable_object.get_upvotes.size}</span>
11
+ </div>
12
+ <div class='voting_btn'>
13
+ <div class='down_button'></div>
14
+ <span class='down_votes'>#{votable_object.get_downvotes.size}</span>
15
+ </div>
16
+ </div>"
17
+ raw html.join("\n")
18
+ end
19
+ end
20
+ end
19
21
  end
@@ -1,3 +1,3 @@
1
1
  module LikeDislike
2
- VERSION = "2.0"
2
+ VERSION = "2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: like_dislike
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.0'
4
+ version: '2.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - kishore-mohan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-04 00:00:00.000000000 Z
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_votable
@@ -45,8 +45,14 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - app/assets/images/thumbs.png
48
49
  - app/assets/javascripts/like_dislike.js
49
50
  - app/assets/stylesheets/like_dislike.css.erb
51
+ - app/controllers/like_dislike/votes_controller.rb
52
+ - config/routes.rb
53
+ - lib/generators/like_dislike/migration/migration_generator.rb
54
+ - lib/generators/like_dislike/migration/templates/migration_cache_vote.rb
55
+ - lib/generators/like_dislike/migration/templates/migration_vote_table.rb
50
56
  - lib/like_dislike.rb
51
57
  - lib/like_dislike/engine.rb
52
58
  - lib/like_dislike/helper.rb
@@ -72,9 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
78
  version: '0'
73
79
  requirements: []
74
80
  rubyforge_project:
75
- rubygems_version: 2.2.2
81
+ rubygems_version: 2.4.8
76
82
  signing_key:
77
83
  specification_version: 4
78
84
  summary: Like Dislike by user and Vote and Unvote by user
79
85
  test_files: []
80
- has_rdoc: