加入了对赞功能模块,同时预留了踩功能,但暂时不使用。

exceptionHandle
william 12 years ago
parent 4676eed9a3
commit 0b5ea87f11

@ -7,6 +7,7 @@ gem "coderay", "~> 1.0.6"
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"
gem 'acts-as-taggable-on'
gem 'seems_rateable'
# Optional gem for LDAP authentication
group :ldap do
gem "net-ldap", "~> 0.3.1"

@ -98,6 +98,9 @@ GEM
rmagick (2.13.2)
ruby-openid (2.1.8)
rubyzip (0.9.9)
seems_rateable (1.0.9)
jquery-rails
rails
selenium-webdriver (2.33.0)
childprocess (>= 0.2.5)
multi_json (~> 1.0)
@ -150,6 +153,7 @@ DEPENDENCIES
rdoc (>= 2.4.2)
rmagick (>= 2.0.0)
ruby-openid (~> 2.1.4)
seems_rateable
shoulda (~> 3.3.2)
sqlite3
yard

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

@ -0,0 +1,225 @@
/************************************************************************
*************************************************************************
@Name : jRating - jQuery Plugin
@Revison : 3.0
@Date : 28/01/2013
@Author: ALPIXEL - (www.myjqueryplugins.com - www.alpixel.fr)
@License : Open Source - MIT License : http://www.opensource.org/licenses/mit-license.php
**************************************************************************
*************************************************************************/
(function($) {
$.fn.jRating = function(op) {
var defaults = {
/** String vars **/
bigStarsPath : '<%= image_path "seems_rateable/stars.png" %>', // path of the icon stars.png
smallStarsPath : '<%= image_path "seems_rateable/small.png" %>', // path of the icon small.png
path : '<%= SeemsRateable::Engine.routes.url_helpers.ratings_path %>',
type : 'big', // can be set to 'small' or 'big'
/** Boolean vars **/
step:false, // if true, mouseover binded star by star,
isDisabled:false,
showRateInfo: false,
canRateAgain : false,
/** Integer vars **/
length:5, // number of star to display
decimalLength : 0, // number of decimals.. Max 3, but you can complete the function 'getNote'
rateMax : 20, // maximal rate - integer from 0 to 9999 (or more)
rateInfosX : -45, // relative position in X axis of the info box when mouseover
rateInfosY : 5, // relative position in Y axis of the info box when mouseover
nbRates : 1,
/** Functions **/
onSuccess : null,
onError : null
};
if(this.length>0)
return this.each(function() {
/*vars*/
var opts = $.extend(defaults, op),
newWidth = 0,
starWidth = 0,
starHeight = 0,
bgPath = '',
hasRated = false,
globalWidth = 0,
nbOfRates = opts.nbRates;
if($(this).hasClass('jDisabled') || opts.isDisabled)
var jDisabled = true;
else
var jDisabled = false;
getStarWidth();
$(this).height(starHeight);
var average = parseFloat($(this).attr('data-average')), // get the average of all rates
idBox = parseInt($(this).attr('data-id')), // get the id of the box
kls = $(this).attr('data-kls'),
dimension = $(this).attr('data-dimension'),
widthRatingContainer = starWidth*opts.length, // Width of the Container
widthColor = average/opts.rateMax*widthRatingContainer, // Width of the color Container
quotient =
$('<div>',
{
'class' : 'jRatingColor',
css:{
width:widthColor
}
}).appendTo($(this)),
average =
$('<div>',
{
'class' : 'jRatingAverage',
css:{
width:0,
top:- starHeight
}
}).appendTo($(this)),
jstar =
$('<div>',
{
'class' : 'jStar',
css:{
width:widthRatingContainer,
height:starHeight,
top:- (starHeight*2),
background: 'url('+bgPath+') repeat-x'
}
}).appendTo($(this));
$(this).css({width: widthRatingContainer,overflow:'hidden',zIndex:1,position:'relative'});
if(!jDisabled)
$(this).unbind().bind({
mouseenter : function(e){
var realOffsetLeft = findRealLeft(this);
var relativeX = e.pageX - realOffsetLeft;
if (opts.showRateInfo)
var tooltip =
$('<p>',{
'class' : 'jRatingInfos',
html : getNote(relativeX)+' <span class="maxRate">/ '+opts.rateMax+'</span>',
css : {
top: (e.pageY + opts.rateInfosY),
left: (e.pageX + opts.rateInfosX)
}
}).appendTo('body').show();
},
mouseover : function(e){
$(this).css('cursor','pointer');
},
mouseout : function(){
$(this).css('cursor','default');
if(hasRated) average.width(globalWidth);
else average.width(0);
},
mousemove : function(e){
var realOffsetLeft = findRealLeft(this);
var relativeX = e.pageX - realOffsetLeft;
if(opts.step) newWidth = Math.floor(relativeX/starWidth)*starWidth + starWidth;
else newWidth = relativeX;
average.width(newWidth);
if (opts.showRateInfo)
$("p.jRatingInfos")
.css({
left: (e.pageX + opts.rateInfosX)
})
.html(getNote(newWidth) +' <span class="maxRate">/ '+opts.rateMax+'</span>');
},
mouseleave : function(){
$("p.jRatingInfos").remove();
},
click : function(e){
var element = this;
/*set vars*/
hasRated = true;
globalWidth = newWidth;
nbOfRates--;
if(!opts.canRateAgain || parseInt(nbOfRates) <= 0) $(this).unbind().css('cursor','default').addClass('jDisabled');
if (opts.showRateInfo) $("p.jRatingInfos").fadeOut('fast',function(){$(this).remove();});
e.preventDefault();
var rate = getNote(newWidth);
average.width(newWidth);
$.post(defaults.path,
{
idBox : idBox,
rate : rate,
kls : kls,
dimension : dimension
/** action : 'rating' **/
},
function(data) {
if(!data.error)
{
/** Here you can display an alert box,
or use the jNotify Plugin :) http://www.myqjqueryplugins.com/jNotify
exemple : */
if(opts.onSuccess) opts.onSuccess( element, rate );
}
else
{
/** Here you can display an alert box,
or use the jNotify Plugin :) http://www.myqjqueryplugins.com/jNotify
exemple : */
if(opts.onError) opts.onError( element, rate );
}
},
'json'
);
}
});
function getNote(relativeX) {
var noteBrut = parseFloat((relativeX*100/widthRatingContainer)*opts.rateMax/100);
switch(opts.decimalLength) {
case 1 :
var note = Math.round(noteBrut*10)/10;
break;
case 2 :
var note = Math.round(noteBrut*100)/100;
break;
case 3 :
var note = Math.round(noteBrut*1000)/1000;
break;
default :
var note = Math.round(noteBrut*1)/1;
}
return note;
};
function getStarWidth(){
switch(opts.type) {
case 'small' :
starWidth = 12; // width of the picture small.png
starHeight = 10; // height of the picture small.png
bgPath = opts.smallStarsPath;
break;
default :
starWidth = 23; // width of the picture stars.png
starHeight = 20; // height of the picture stars.png
bgPath = opts.bigStarsPath;
}
};
function findRealLeft(obj) {
if( !obj ) return 0;
return obj.offsetLeft + findRealLeft( obj.offsetParent );
};
});
}
})(jQuery);

@ -0,0 +1,25 @@
$(document).ready(function(){
$(".rateable").jRating({
//default options displayed below ->
rateMax: 5, //Maximal rate
length : 5, //Number of stars
//decimalLength : 0, //Number of decimals in the rate
//type : 'big', //Big or small
//step : true, //If set to true, filling of the stars is done star by star (step by step).
//isDisabled: false, //Set true to display static rating
//showRateInfo:false, //Rate info panel, set true to display
//rateInfosX : 45, //In pixel - Absolute left position of the information box during mousemove.
//rateInfosY : 5, //In pixel - Absolute top position of the information box during mousemove.
path : '<%= SeemsRateable::Engine.routes.url_helpers.ratings_path %>',
onSuccess : function(element, rate){
//something like ->
//alert('success');
$('<span class="text-success"><small style="display:inline-block;">Thanks for rating!</small></span>').insertAfter(element)
},
onError : function(element, rate) {
$('<span class="text-error"><small style="display:inline-block;">You have already rated!</small></span>').insertAfter(element)
}
});
});

@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

@ -95,6 +95,9 @@ class ApplicationController < ActionController::Base
# Returns the current user or nil if no user is logged in
# and starts a session if needed
def current_user
find_current_user
end
def find_current_user
user = nil
unless api_request?

@ -0,0 +1,68 @@
class PraiseTreadController < ApplicationController
def praise_plus
@obj = nil
if request.get?
@obj = params[:obj] # 传的是对象最后变成id了
#首先创建或更新praise_tread 表
@pt = PraiseTread.find_by_user_id_and_praise_tread_object_id(User.current.id,@obj)
@pt = @pt.nil? ? PraiseTread.new : @pt
@pt.user_id = User.current.id
@pt.praise_tread_object_id = @obj.to_i
@pt.praise_tread_object_type = User.find_by_id(@obj).class.name.underscore
@pt.praise_or_tread = 1
@pt.save
#再创建或更新praise_tread_cache表
@ptc = PraiseTreadCache.find_by_object_id(@obj)
@ptc = @ptc.nil? ? PraiseTreadCache.new : @ptc
@ptc.object_id = @obj.to_i
@ptc.object_type = User.find_by_id(@obj).class.name.underscore
@ptc.plus(1)
@ptc.save
end
@obj = User.find_by_id(@obj)
respond_to do |format|
format.html
format.js
end
end
def praise_minus
@obj = nil
if request.get?
@obj = params[:obj] # 传的是对象最后变成id了
#首先更新praise_tread 表 删除关注记录
@pt = PraiseTread.find_by_user_id_and_praise_tread_object_id_and_praise_tread_object_type(User.current.id,@obj,"user")
@pt.delete
#再更新praise_tread_cache表 使相应的记录减1 当为0时删除
@ptc = PraiseTreadCache.find_by_object_id(@obj)
@ptc.minus(1)
if @ptc.praise_num == 0
@ptc.delete
end
end
@obj = User.find_by_id(@obj)
respond_to do |format|
format.html
format.js
end
end
def tread_plus
end
def tread_minus
respond_to do |format|
format.html
format.js
end
end
end

@ -26,12 +26,8 @@ module ApplicationHelper
include GravatarHelper::PublicMethods
include Redmine::Pagination::Helper
include AvatarHelper
### added by william
include ActsAsTaggableOn::TagsHelper
# include WatchersHelper
include PraiseTreadHelper
extend Forwardable
def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter

@ -0,0 +1,23 @@
module PraiseTreadHelper
#added by william
def is_praise_or_tread(object,user_id)
@obj_type = object.class.name.underscore
@obj_id = object.id
@is_praise = PraiseTread.find_by_sql("select * from praise_treads where user_id=#{user_id} and " +
"praise_tread_object_type='#{@obj_type}' and praise_tread_object_id=#{@obj_id} ")
return @is_praise
end
#end
def get_praise_num(object)
@obj_type = object.class.name.underscore
@obj_id = object.id
@record = PraiseTreadCache.find_by_object_id_and_object_type(@obj_id,@obj_type)
if @record
return @record.praise_num
else
return 0
end
end
end

@ -0,0 +1,4 @@
class PraiseTread < ActiveRecord::Base
attr_accessible :user_id,:praise_tread_object_id,:praise_tread_object_type,:praise_or_tread
end

@ -0,0 +1,11 @@
class PraiseTreadCache < ActiveRecord::Base
attr_accessible :object_id,:object_type,:praise_num,:tread_num
def plus(num)
self.update_attribute(:praise_num, self.praise_num.to_i + num)
end
def minus(num)
self.update_attribute(:praise_num, self.praise_num.to_i - num)
end
end

@ -103,7 +103,7 @@ class User < Principal
acts_as_customizable
############################added by william
acts_as_taggable
seems_rateable
############################# added by liuping 关注
acts_as_watchable

@ -9,7 +9,11 @@
<%= favicon %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'application', :media => 'all' %>
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
<!-- added by william -->
<%= seems_rateable_stylesheet %>
<!-- end -->
<%= javascript_heads %>
<%= heads_for_theme %>
<%= call_hook :view_layouts_base_html_head %>
<!-- page specific tags -->
@ -44,6 +48,11 @@
</table></td>
</tr>
</table>
<div id="praise_tread">
<%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => @user,:show_flag => false,:user_id => User.current.id}%>
</div>
<div>
<%= l(:label_user_watcher) %> (<strong class="font_small_watch"><%= User.watched_by(@user.id).count %></strong>) &nbsp;
<%= l(:label_user_fans) %> (<strong class="font_small_watch"><%= @user.watcher_users.count %></strong>)

@ -0,0 +1,17 @@
<div id="praise">
<% if is_praise_or_tread(obj,user_id).size > 0 %>
<%= image_tag("/images/praise.png") %>
<%= link_to "取消贊",:controller=>"praise_tread",:action=>"praise_minus",:remote=>true,:obj => obj %>
(<%= get_praise_num(obj)%>)
<% else %>
<%= image_tag("/images/tread.png") %>
<%= link_to "贊",:controller=>"praise_tread",:action=>"praise_plus",:remote=>true,:obj => obj %>
(<%= get_praise_num(obj)%>)
<% end %>
</div>
<% if show_flag %>
<div id="tread">
<%= link_to image_tag("/images/tread.png"),:controller=>"praise_tread",
:action=>"tread_minus",:remote=>true,:obj => obj %>踩
</div>
<% end %>

@ -0,0 +1,3 @@
$('#praise_tread').html('<%= j(
render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:show_flag => false,:user_id => User.current.id}
)%>');

@ -0,0 +1,3 @@
$('#praise_tread').html('<%= j(
render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:show_flag => false,:user_id => User.current.id}
)%>');

@ -0,0 +1,4 @@
#SeemsRateable engine Initializer
#Configure owner class of the given ratings
SeemsRateable::Engine.config.owner_class = "User"

@ -17,11 +17,13 @@
RedmineApp::Application.routes.draw do
resources :shares
get "tags/index"
get "tags/show"
get "praise_tread/praise_plus"
get "praise_tread/praise_minus"
get "praise_tread/tread_minus"
root :to => 'welcome#index', :as => 'home'
@ -95,7 +97,7 @@ RedmineApp::Application.routes.draw do
match 'users/:id/memberships/:membership_id', :to => 'users#edit_membership', :via => :put, :as => 'user_membership'
match 'users/:id/memberships/:membership_id', :to => 'users#destroy_membership', :via => :delete
match 'users/:id/memberships', :to => 'users#edit_membership', :via => :post, :as => 'user_memberships'
################# added by william
################# added by william
match 'users/tag_save', :to => 'users#tag_save', :via => :post, :as => 'tag'
post 'watchers/watch', :to => 'watchers#watch', :as => 'watch'
@ -422,8 +424,12 @@ RedmineApp::Application.routes.draw do
match 'bids/:id', :controller => 'bids', :action => 'show', :as => 'respond'
########### added by liuping
match 'tags/add_tag',:to => 'tags#add_tag',:as=>"add_tag"
match 'tags/delete_tag',:to => 'tags#delete_tag',:as=>"add_tag"
match 'parise_tread/praise_plus',:to => 'parise_tread#praise_plus',:as=>"praise"
match 'parise_tread/tread_minus',:to => 'parise_tread#tread_minus',:as=>"tread"
end

@ -0,0 +1,18 @@
class CreateSeemsRateableRates < ActiveRecord::Migration
def self.up
create_table :seems_rateable_rates do |t|
t.belongs_to :rater
t.belongs_to :rateable, :polymorphic => true
t.float :stars, :null => false
t.integer :rater_id, :limit => 8
t.integer :rateable_id
t.string :rateable_type
t.string :dimension
t.timestamps
end
end
def self.down
drop_table :rates
end
end

@ -0,0 +1,17 @@
class CreateSeemsRateableCachedRatings < ActiveRecord::Migration
def self.up
create_table :seems_rateable_cached_ratings do |t|
t.belongs_to :cacheable, :polymorphic => true
t.float :avg, :null => false
t.integer :cnt, :null => false
t.string :dimension
t.integer :cacheable_id, :limit => 8
t.string :cacheable_type
t.timestamps
end
end
def self.down
drop_table :cached_ratings
end
end

@ -0,0 +1,15 @@
class CreatePraiseTreads < ActiveRecord::Migration
def self.up
create_table :praise_treads do |t|
t.column :user_id,:integer,:null => false
t.column :praise_tread_object_id,:integer
t.column :praise_tread_object_type,:string
t.column :praise_or_tread,:integer
t.timestamps
end
end
def self.down
drop_table :praise_treads
end
end

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save