Merge branch 'szzh' of http://repository.trustie.net/xianbo/trustie2 into szzh
This commit is contained in:
commit
8e9b939038
|
@ -44,4 +44,10 @@ app\controller\welcome_controller.rb
|
|||
return 0
|
||||
end
|
||||
end
|
||||
================================================================================
|
||||
================================================================================
|
||||
|
||||
================================================================================
|
||||
0606:新坑
|
||||
user_scores表结构有问题,需要运行
|
||||
bundle exec rake db:migrate:down VERSION=20140410021724
|
||||
bundle exec rake db:migrate:up VERSION=20140410021724
|
|
@ -137,7 +137,7 @@ class User < Principal
|
|||
has_one :user_extensions,:dependent => :destroy
|
||||
## end
|
||||
|
||||
default_scope -> { includes(:user_extensions, :user_score) }
|
||||
# default_scope -> { includes(:user_extensions, :user_score) }
|
||||
scope :teacher, -> {
|
||||
joins(:user_extensions).where('user_extensions.identity = ?', UserExtensions::TEACHER)
|
||||
}
|
||||
|
@ -201,6 +201,7 @@ class User < Principal
|
|||
|
||||
# ======================================================================
|
||||
# 集中处理 User 扩展表为空的问题
|
||||
# 合并 user_score 属性
|
||||
validate :valid_user_extensions
|
||||
after_save :save_user_extensions
|
||||
|
||||
|
@ -208,21 +209,32 @@ class User < Principal
|
|||
self.user_extensions ||= UserExtensions.new
|
||||
end
|
||||
|
||||
def user_score_attr
|
||||
self.user_score ||= UserScore.new
|
||||
end
|
||||
|
||||
alias_method :ori_respond_to?, :respond_to?
|
||||
def respond_to?(m, include_private = false)
|
||||
flag = UserExtensions.instance_methods.include? m.to_sym
|
||||
if flag
|
||||
flag
|
||||
else
|
||||
super
|
||||
end
|
||||
flag = false
|
||||
flag = ori_respond_to? m.to_sym unless flag
|
||||
flag = UserExtensions.new.respond_to? m.to_sym unless flag
|
||||
flag = UserScore.new.respond_to? m.to_sym unless flag
|
||||
|
||||
flag
|
||||
end
|
||||
|
||||
def method_missing m, *args, &block
|
||||
if extensions.respond_to? m.to_sym
|
||||
self.class.send :define_method, m.to_sym, *args do
|
||||
self.class.send(:define_method, "_meta_#{m}".to_sym) do |*args, &block|
|
||||
self.extensions.__send__ m.to_sym, *args
|
||||
end
|
||||
__send__ m.to_sym, *args, &block
|
||||
__send__ "_meta_#{m}".to_sym, *args, &block
|
||||
|
||||
elsif user_score_attr.respond_to? m.to_sym
|
||||
self.class.send(:define_method, "_meta_#{m}".to_sym) do |*args, &block|
|
||||
self.user_score_attr.__send__ m.to_sym, *args
|
||||
end
|
||||
__send__ "_meta_#{m}".to_sym, *args, &block
|
||||
|
||||
else
|
||||
super
|
||||
|
@ -241,6 +253,7 @@ class User < Principal
|
|||
|
||||
def save_user_extensions
|
||||
self.extensions.save
|
||||
self.user_score_attr.save
|
||||
end
|
||||
# 集中处理 User 扩展表为空的问题 < end
|
||||
# ======================================================================
|
||||
|
|
|
@ -33,4 +33,101 @@ class UserScore < ActiveRecord::Base
|
|||
def self.find_min_issue
|
||||
self.minimum(:file)
|
||||
end
|
||||
# 以上类方法目测没用,反正也报错
|
||||
# ===============================================================================
|
||||
|
||||
# 前略·协同得分
|
||||
# operate - 更新操作 类型 symbol
|
||||
# user - 计分用户
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# UserScore.joint(:post_message, User.current, nil)
|
||||
# # => true #当前用户发帖计分操作成功
|
||||
#
|
||||
# Returns boolean. 返回积分保存结果
|
||||
def self.joint(operate, current_user, target_user, options={})
|
||||
case operate
|
||||
when :post_message # current_user 发帖了
|
||||
when :post_issue # current_user 对 target_user 的缺陷留言了
|
||||
when :change_issue_status # current_user 更改了缺陷的状态
|
||||
when :reply_message # current_user 对 target_user 留言的回复
|
||||
when :reply_posting # current_user 对 target_user 帖子的回复
|
||||
else
|
||||
Rails.logger.error "[UserScore#joint] ===> #{operate} is not define."
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
# 前略·影响力得分
|
||||
# operate - 更新操作 类型 symbol
|
||||
# user - 计分用户
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# UserScore.influence(:followed_by, user)
|
||||
# # => true #当前被关注用户记分成功
|
||||
#
|
||||
# Returns boolean. 返回积分保存结果
|
||||
def self.influence(operate, current_user, target_user, options={})
|
||||
case operate
|
||||
when :followed_by # current_user 关注了target_user
|
||||
else
|
||||
Rails.logger.error "[UserScore#influence] ===> #{operate} is not define."
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
# 前略·技术得分
|
||||
# operate - 更新操作 类型 symbol
|
||||
# user - 计分用户
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# UserScore.skill(:followed_by, current_user, target_user)
|
||||
# # => true #当前current_user对target_user用户帖子的记分成功
|
||||
#
|
||||
# Returns boolean. 返回积分保存结果
|
||||
def self.skill(operate, current_user, target_user, options={})
|
||||
case operate
|
||||
when :treading # current_user 踩了 target_user 的帖子
|
||||
when :treaded_by_user # current_user 踩了 target_user 的帖子
|
||||
when :praise_by_user # current_user 顶了 target_user 的帖子
|
||||
else
|
||||
Rails.logger.error "[UserScore#skill] ===> #{operate} is not define."
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
# 前略·项目得分
|
||||
# operate - 更新操作 类型 symbol
|
||||
# user - 计分用户
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# UserScore.project(:pull_code, current_user)
|
||||
# # => true #当前current_user对项目贡献积分成功
|
||||
#
|
||||
# Returns boolean. 返回积分保存结果
|
||||
def self.project(operate, current_user, options={})
|
||||
case operate
|
||||
when :push_code # current_user 提交了代码
|
||||
when :push_document # current_user
|
||||
when :push_file # current_user
|
||||
when :update_issue # current_user
|
||||
when :post_issue # current_user
|
||||
else
|
||||
Rails.logger.error "[UserScore#project] ===> #{operate} is not define."
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_users(current_user, target_user)
|
||||
cUser = (current_user.kind_of?User) ? user : User.find_by_id(user)
|
||||
tUser = (target_user.kind_of?User) ? user : User.find_by_id(user)
|
||||
|
||||
@current_user, @target_user = cUser, tUser
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
<!-- added by bai -->
|
||||
<% unless @user.id == 1%>
|
||||
<% messages_count = @user.messages.count %>
|
||||
<% messages_score = messages_count * 0.05%>
|
||||
<% finall_messages_score = messages_score %>
|
||||
<% end %>
|
||||
|
||||
<% journals_count = @user.journals.count %>
|
||||
<% journals_score = journals_count * 0.1 %>
|
||||
|
@ -73,31 +71,6 @@
|
|||
|
||||
</div>
|
||||
|
||||
<!-- <div class="inf_user_image">
|
||||
<ul>
|
||||
<li>
|
||||
<%= link_to l(:label_user_score), {:controller => 'users', :action => 'score_index', :remote => true} %> :
|
||||
<%= format("%.2f" , finall_user_score).to_f %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to l(:label_user_score_of_topic), {:controller => 'users', :action => 'topic_score_index', :remote => true} %> :
|
||||
<%= format("%.2f" , finall_messages_score).to_f %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to l(:label_user_score_of_project), {:controller => 'users', :action => 'project_score_index', :remote => true} %> :
|
||||
<%= format("%.2f" , finall_user_project_score).to_f %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to l(:label_user_score_of_activity), {:controller => 'users', :action => 'activity_score_index', :remote => true} %> :
|
||||
<%= format("%.2f" , finall_activity_score).to_f %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to l(:label_user_score_of_influence), {:controller => 'users', :action => 'influence_score_index', :remote => true} %> :
|
||||
<%= format("%.2f" , finall_influence_score).to_f %>
|
||||
</li>
|
||||
</ul>
|
||||
</div> -->
|
||||
<div id="show_score_detail", style="padding-left: 6px">
|
||||
<%= render :partial => 'users/score_index', :locals => {:index => 0 } %>
|
||||
</div>
|
||||
<!-- end -->
|
|
@ -1,5 +1,3 @@
|
|||
<!-- added by bai -->
|
||||
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'users/show_score') %>');
|
||||
showModal('ajax-modal', '400px');
|
||||
$('#ajax-modal').addClass('new-watcher');
|
||||
<!-- end -->
|
12
db/schema.rb
12
db/schema.rb
|
@ -923,11 +923,13 @@ ActiveRecord::Schema.define(:version => 20140605025247) do
|
|||
add_index "user_preferences", ["user_id"], :name => "index_user_preferences_on_user_id"
|
||||
|
||||
create_table "user_scores", :force => true do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "collaboration"
|
||||
t.integer "influence"
|
||||
t.integer "skill"
|
||||
t.integer "activity"
|
||||
t.integer "user_id", :null => false
|
||||
t.integer "collaboration"
|
||||
t.integer "influence"
|
||||
t.integer "skill"
|
||||
t.integer "active"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "user_statuses", :force => true do |t|
|
||||
|
|
Loading…
Reference in New Issue