-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
152 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
= redmine_vote | ||
|
||
Description goes here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class VoteController < ApplicationController | ||
unloadable | ||
|
||
before_filter :require_login | ||
before_filter :find_user, :find_board_and_topic#, :authorize | ||
|
||
def submit | ||
votes = Votes.new() | ||
votes.submit(@message.id, @user.id, params[:point]) | ||
end | ||
|
||
def point | ||
votes = Votes.new() | ||
@point = votes.point(@message.id) | ||
end | ||
|
||
private | ||
def find_user | ||
@user = User.current | ||
end | ||
|
||
def find_board_and_topic | ||
begin | ||
@board = Board.find(params[:board_id]) | ||
@message = @board.topics.find(params[:message_id]) | ||
|
||
rescue ActiveRecord::RecordNotFound | ||
render_404 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module VoteHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Votes < ActiveRecord::Base | ||
unloadable | ||
|
||
def submit(message_id, user_id, point = 0) | ||
votes = Votes.find(:first, :conditions => ['message_id = ? and user_id = ?', message_id, user_id]) | ||
unless votes | ||
votes = Votes.new | ||
votes.message_id = message_id | ||
votes.user_id = user_id | ||
votes.point = point.nil? ? 0 : point | ||
votes.save! | ||
end | ||
end | ||
|
||
def point(message_id) | ||
return Votes.sum(:point, :conditions => ['message_id = ?', message_id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<% | ||
unless User.current.login == '' | ||
%> | ||
|
||
<div id="vote"> | ||
<a class="vote-point" id="vote-point1" href="#" data-point="1">▲</a> | ||
<a class="vote-point" id="vote-point-1" href="#" data-point="-1">▼</a> | ||
<span>Vote</span> | ||
</div> | ||
|
||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h2>VoteController#count</h2> | ||
|
||
<%= @point %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h2>VoteController#vote</h2> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
$(document).ready(function() { | ||
if($(".controller-messages").length) { | ||
//console.log(document.URL); | ||
$("#vote").show(); | ||
$(".vote-point").bind("click", function(event) { | ||
event.preventDefault(); | ||
var point = $(this).data("point"); | ||
$.ajax({ | ||
type: "POST", | ||
url: document.URL + "/vote?p=1", | ||
success: function(data, textStatus, jqXHR) { | ||
console.log(data); | ||
} | ||
}); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#vote { | ||
display:none; | ||
margin: 20px auto; | ||
text-align:center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# English strings go here for Rails i18n | ||
en: | ||
# my_label: "My label" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Plugin's routes | ||
# See: http://guides.rubyonrails.org/routing.html | ||
|
||
Rails.application.routes.draw do | ||
get 'boards/:board_id/topics/:message_id/vote', :to => 'vote#point' | ||
post 'boards/:board_id/topics/:message_id/vote', :to => 'vote#submit' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateVotes < ActiveRecord::Migration | ||
def change | ||
create_table :votes do |t| | ||
t.integer :message_id | ||
t.integer :user_id | ||
t.integer :point | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'redmine' | ||
require 'vote_application_hooks' | ||
|
||
Redmine::Plugin.register :redmine_vote do | ||
name 'Redmine Vote plugin' | ||
author 'Jong-Ha Ahn' | ||
description 'This is a plugin for Redmine' | ||
version '0.0.1' | ||
url 'http://github.com/jongha/redmine_vote' | ||
author_url 'http://www.mrlatte.net' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class VoteHeaderHooks < Redmine::Hook::ViewListener | ||
|
||
def view_layouts_base_html_head(context = {}) | ||
o = stylesheet_link_tag('vote', :plugin => 'redmine_vote') | ||
o << javascript_include_tag('vote', :plugin => 'redmine_vote') | ||
return o | ||
end | ||
end | ||
|
||
class VoteLayoutBaseContentHooks < Redmine::Hook::ViewListener | ||
render_on :view_layouts_base_content, :partial => 'vote/view_layouts_base_content' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require File.expand_path('../../test_helper', __FILE__) | ||
|
||
class VoteControllerTest < ActionController::TestCase | ||
# Replace this with your real tests. | ||
def test_truth | ||
assert true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Load the Redmine helper | ||
require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require File.expand_path('../../test_helper', __FILE__) | ||
|
||
class VotesTest < ActiveSupport::TestCase | ||
|
||
# Replace this with your real tests. | ||
def test_truth | ||
assert true | ||
end | ||
end |