This commit is contained in:
sw 2014-06-11 15:54:40 +08:00
commit 872b7efb84
18 changed files with 1056 additions and 2147 deletions

View File

@ -62,6 +62,7 @@ class DocumentsController < ApplicationController
def create
@document = @project.documents.build
@document.safe_attributes = params[:document]
@document.user = User.current
@document.save_attachments(params[:attachments])
if @document.save
render_attachment_warning_if_needed(@document)

View File

@ -122,7 +122,9 @@ class WatchersController < ApplicationController
end
def find_watchables
#根据参数获取关注对象的类型user、project
klass = Object.const_get(params[:object_type].camelcase) rescue nil
#判断获取的对象能否响应watched_by方法
if klass && klass.respond_to?('watched_by')
@watchables = klass.find_all_by_id(Array.wrap(params[:object_id]))
raise Unauthorized if @watchables.any? {|w| w.respond_to?(:visible?) && !w.visible?}

View File

@ -18,6 +18,7 @@
class Document < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :project
belongs_to :user
belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
before_save :be_user_score # user_score
@ -62,7 +63,7 @@ class Document < ActiveRecord::Base
# update user score
def be_user_score
if self.new_record?
UserScore.project(:push_document, User.current, { document_id: self.id })
UserScore.project(:push_document, self.user, { document_id: self.id })
end
end
end

View File

@ -1493,7 +1493,10 @@ class Issue < ActiveRecord::Base
UserScore.project(:post_issue, User.current, { issue_id: self.id })
elsif self.done_ratio_changed?
UserScore.project(:update_issue_ratio, User.current, { issue_id: self.id })
#缺陷状态更改
elsif self.status_id_changed?
#协同得分
UserScore.joint(:change_issue_status, User.current,nil, {issue_id: self.id})
end
end
end

View File

@ -46,6 +46,7 @@ class Journal < ActiveRecord::Base
# fq
after_create :act_as_activity
before_save :be_user_score
# end
scope :visible, lambda {|*args|
@ -151,4 +152,13 @@ class Journal < ActiveRecord::Base
self.acts << Activity.new(:user_id => self.user_id)
end
# end
# 更新用户分数 -by zjc
def be_user_score
#新建了留言且留言不为空,不为空白
if self.new_record? && !self.notes.nil? && self.notes.gsub(' ','') != ''
#协同得分加分
UserScore.joint(:post_issue, User.current,self.issue.author, { message_id: self.id })
end
end
end

View File

@ -42,6 +42,7 @@ class JournalsForMessage < ActiveRecord::Base
after_create :act_as_activity #huang
after_create :reset_counters!
after_destroy :reset_counters!
before_save :be_user_score
# default_scope { where('m_parent_id IS NULL') }
@ -99,4 +100,13 @@ class JournalsForMessage < ActiveRecord::Base
count = find_all_by_m_parent_id(journals_for_messages.m_parent_id).count #(SELECT COUNT(*) FROM #{JournalsForMessage.table_name} WHERE m_parent_id = #{jfm_id} )
update_all("m_reply_count = #{count.to_i}", ["id = ?", journals_for_messages.m_parent_id])
end
# 更新用户分数 -by zjc
def be_user_score
#新建了留言且留言不为空,不为空白
if self.new_record?
#协同得分加分
UserScore.joint(:reply_message, User.current,User.find(self.reply_id), { journals_for_messages_id: self.id })
end
end
end

View File

@ -123,10 +123,14 @@ class Message < ActiveRecord::Base
end
# end
# update user score
#更新用户分数 -by zjc
def be_user_score
if self.new_record?
#新建message且无parent的为发帖
if self.new_record? && self.parent_id.nil?
UserScore.joint(:post_message, User.current,nil, { message_id: self.id })
#新建message且有parent的为回帖
elsif self.new_record? && !self.parent_id.nil?
UserScore.joint(:reply_posting, User.current,self.parent.author, { message_id: self.id })
end
end
end

View File

@ -113,6 +113,7 @@ class User < Principal
has_many :journals
has_many :messages, :foreign_key => 'author_id'
has_one :user_score, :dependent => :destroy
has_many :documents # 项目中关联的文档再次与人关联
# end
######added by nie

View File

@ -18,6 +18,8 @@
class UserScore < ActiveRecord::Base
belongs_to :user
before_save :correct_score
def self.find_max_file
self.maximum(:file)
end
@ -50,23 +52,23 @@ class UserScore < ActiveRecord::Base
current_user, target_user = get_users(current_user, target_user)
user_score = current_user.user_score_attr
case operate
when :post_message # current_user 发帖了
when :post_message # current_user 发帖了 Add Message
user_score.collaboration = user_score.collaboration.to_i + 2
user_score.save
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a message. options => (#{options.to_s})"
when :post_issue # current_user 对 target_user 的缺陷留言了
when :post_issue # current_user 对 target_user 的缺陷留言了 Add Journal
user_score.collaboration = user_score.collaboration.to_i + 1
user_score.save
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a issue. options => (#{options.to_s})"
when :change_issue_status # current_user 更改了缺陷的状态
when :change_issue_status # current_user 更改了缺陷的状态 Changed Issue
user_score.collaboration = user_score.collaboration.to_i + 1
user_score.save
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} change issue status. options => (#{options.to_s})"
when :reply_message # current_user 对 target_user 留言的回复
when :reply_message # current_user 对 target_user 留言的回复 Add Journals_for_messages
user_score.collaboration = user_score.collaboration.to_i + 1
user_score.save
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply message. options => (#{options.to_s})"
when :reply_posting # current_user 对 target_user 帖子的回复
when :reply_posting # current_user 对 target_user 帖子的回复 Add Message
user_score.collaboration = user_score.collaboration.to_i + 1
user_score.save
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply posting. options => (#{options.to_s})"
@ -90,12 +92,16 @@ class UserScore < ActiveRecord::Base
# Returns boolean. 返回积分保存结果
def self.influence(operate, current_user, target_user, options={})
current_user, target_user = get_users(current_user, target_user)
user_score = current_user.user_score_attr
user_score = target_user.user_score_attr
case operate
when :followed_by # current_user 关注了target_user
user_score.active = user_score.influence.to_i + 2
user_score.save
Rails.logger.info "[UserScore#influence] ===> User: #{current_user} be followed. options => (#{options.to_s})"
when :cancel_followed # current_uer 取消了对 target_user的关注
user_score.active = user_score.influence.to_i - 2
user_score.save
Rails.logger.info "[UserScore#influence] ===> User: #{current_user} canceled followed. options => (#{options.to_s})"
else
Rails.logger.error "[UserScore#influence] ===> #{operate} is not define."
return false
@ -183,4 +189,22 @@ class UserScore < ActiveRecord::Base
[cUser, tUser]
end
#修正分数
#分数小于0时修正为0
#分数大于等于0时不修正 -by zjc
def correct_score
if self.collaboration < 0
self.collaboration = 0
end
if self.active < 0
self.active = 0
end
if self.influence < 0
self.influence = 0
end
if self.skill < 0
self.skill = 0
end
end
end

View File

@ -1,3 +1,5 @@
<div class="frame-wiki">
<div class="contextual">
<% if User.current.allowed_to?(:edit_documents, @project) %>
<%= link_to l(:button_edit), edit_document_path(@document), :class => 'icon icon-edit', :accesskey => accesskey(:edit) %>
@ -7,26 +9,15 @@
<% end %>
</div>
<!-- <h3><%=h @document.title %></h3>
<h2><%=h @document.title %></h2>
<p><em><%=h @document.category.name %><br />
<%= format_date @document.created_on %></em></p>
<div class="wiki">
<%= textilizable @document.description, :attachments => @document.attachments %>
</div> -->
<!--add by huang-->
<table width="660px" align="center">
<tr><td><h3><strong><%=h @document.title %></strong></h3></td></tr>
<tr><td>
<div class="font_description">
<%= textilizable @document.description, :attachments => @document.attachments %>
</div>
</td></tr>
<tr><td align="right"><p class="font_lighter"><%= format_date @document.created_on %></p></td></tr>
<tr><td class="line_under"></td></tr>
</table>
<%= textilizable @document, :description, :attachments => @document.attachments %>
</div>
<div style="border-top:solid 1px #C6E9F1;"></div>
<h3><%= l(:label_attachment_plural) %></h3>
<%= link_to_attachments @document %>
@ -42,3 +33,4 @@
<% end %>
<% html_title @document.title -%>
</div>

View File

@ -46,7 +46,6 @@
<div class="memo-title <%= @memo.sticky ? 'sticky' : '' %> <%= @memo.locked? ? 'locked' : '' %>"><%= label_tag l(:field_subject) %>: <%=h @memo.subject %></div>
<div class="memo-content">
<!-- < %= textilizable(@memo, :content) %> -->
<%= raw @memo.content %>
<p>
<% if @memo.attachments.any?%>

View File

@ -0,0 +1,5 @@
class AddUserIdToDocuments < ActiveRecord::Migration
def change
add_column :documents, :user_id, :integer, default: 0
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140605025247) do
ActiveRecord::Schema.define(:version => 20140609061903) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -288,6 +288,7 @@ ActiveRecord::Schema.define(:version => 20140605025247) do
t.string "title", :limit => 60, :default => "", :null => false
t.text "description"
t.datetime "created_on"
t.integer "user_id", :default => 0
end
add_index "documents", ["category_id"], :name => "index_documents_on_category_id"

File diff suppressed because it is too large Load Diff

72
lib/tasks/userscore.rake Normal file
View File

@ -0,0 +1,72 @@
desc "User Score description"
task :user_score do
puts "user_score sync."
end
namespace :user_score do
desc "calculating user score"
# Rails.env = 'production'
task :calculate => :environment do
puts "loading..."
# collaboration 协同得分
users = {}
# 发帖
Message.includes(:author).where("parent_id IS NULL").all.each do |m|
users[m.author.id] = users[m.author.id].to_i + 2
end
puts ":post_message calculate Completed. users count: #{users.count}"
# 对缺陷的留言
Journal.includes(:user).all.each do |j|
users[j.user.id] = users[j.user.id].to_i + 1
end
puts ":post_issue calculate Completed. users count: #{users.count}"
# 更改一次缺陷状态
Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id'").each do |j|
users[j.user.id] = users[j.user.id].to_i + 1
end
puts ":change_issue_status calculate Completed. users count: #{users.count}"
# 对留言的回复
JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL").each do |jfm|
users[jfm.user.id] = users[jfm.user.id].to_i + 1
end
puts ":reply_message calculate Completed. users count: #{users.count}"
# 对帖子的回复
Message.includes(:author).where("parent_id IS NOT NULL").each do |m|
users[m.author.id] = users[m.author.id].to_i + 1
end
puts ":reply_posting calculate Completed. users count: #{users.count}"
users.each do |user_id, score|
UserScore.find_or_create_by_user_id(user_id).update_attribute(:collaboration, score)
end
puts "=== UserScore#collaboration calculate Completed. users count: #{users.count}"
users.clear
# influence 影响力得分
# ...
# skill 技术得分
# ...
# active 项目贡献得分
# ...
end
end
desc "create tmp file, to test"
file 'tmp/test.yml' do
require 'yaml'
var = {
:name => "name",
:age => "age",
:agent => "agent"
}
File.open('tmp/test.yml', 'w') do |f|
f.write YAML.dump({'conf' => var })
end
end

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,9 @@
/* Temporary
*******************************************************************************/
.frame-wiki {
padding: 0 10px;
}
/* TODO: base/common/page 准备封装一些基本样式组合调用 参考YUI
*******************************************************************************/
* {

View File

@ -524,19 +524,8 @@ ul.projects li.root
margin:4px 20px 20px;
padding-bottom:15px;
text-align:left
/*font-size: 18px;*/
}
#footer a:hover
{
/*background:#666 none repeat scroll 0 0;*/
/*color:#FFF!important*/
}
#footer a:link,#footer a:visited
{
/*color:#666*/
}
#footer .bgr:after
{
@ -544,60 +533,6 @@ ul.projects li.root
float:right
}
h1,h2,h3,h4
{
font-family:'微软雅黑',"PT Sans","Lucida Grande",arial,sans-serif /*modify by men*/
}
h1
{
font-size:24px; /*工作台界面框框大小*/
font-weight:400;
margin:0 0 0 .25em;
padding:0 0 10px;
text-align:left
}
h2,h3,h4,.wiki h1,.wiki h2,.wiki h3
{
border-bottom:0
}
h2,.wiki h1
{
background-color:#e0e0e0; /*第三层背景非导航条*/
margin:-6px -10px 10px;
padding:10px 20px;
font-size:14px;
color:#fff;
border-top:1px #ddd solid
}
.wiki h1
{
font-family:"PT Sans","Trebuchet MS",Helvetica,sans-serif;
font-weight:700
}
.wiki h2
{
background-color:transparent
}
div.issue div.wiki h3
{
text-decoration:underline
}
h3,h4
{
font-weight:400
}
div.wiki h3,div.wiki h4
{
font-weight:700
}
#sidebar h3
{
@ -2077,20 +2012,11 @@ div.avatar_user{
* *
*Designed for message.
*/
li {
list-style-type: none;
}
.avatar-3{
width: 35px;
height: 35px;
}
.inner-right{
float: left;
}
.messages-for-user-reply{
margin-top: 10px;
padding-left: 60px;
}
ul.message-for-user {
list-style-type: none;