竞赛首页定制中添加编辑通知通告的编辑框并存入数据库

添加新的表记录个人得分相关细节,及各种得分更新方法
This commit is contained in:
z9hang 2014-07-23 17:56:15 +08:00
parent fb6cd2e9d8
commit 80b5871756
5 changed files with 119 additions and 5 deletions

View File

@ -220,7 +220,10 @@ class AdminController < ApplicationController
@contest_page.web_title = params[:web_title]
@contest_page.title = params[:contest_title]
@contest_page.description = params[:contest_description]
if @first_page.save && @contest_page.save
@notification.title = params[:contest_notification_title]
@notification.content = params[:contest_notification][:content]
if @first_page.save && @contest_page.save && @notification.save
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_update)

View File

@ -337,7 +337,80 @@ module UserScoreHelper
:activity => activity, :file => file, :issue => issue, :level => level)
end
#====================================================================================================
def get_option_number(user,type)
option_number = OptionNumber.where("user_id = '#{user.id}' and score_type = '#{type}'");
if option_number.nil?
option_number = OptionNumber.new
option_number.user_id = user.id
option_number.score_type =type
end
option_number
end
#更新分数
def update_score(option_number)
option_number.total_score = collaboration(option_number) + influence(option_number) + skill(option_number) + active(option_number)
option_number.save
end
#协同得分
def collaboration(option_number)
option_number.memo * 2 + option_number.messages_for_issues + option_number.issues_status + option_number.replay_for_message + option_number.replay_for_memo
end
#影响力得分
def influence(option_number)
option_number.follow * 2
end
#技术得分
def skill(option_number)
option_number.praise_by_one * 4 + option_number.praise_by_two * 6 + option_number.praise_by_three * 8 - option_number.tread * 2 - option_number.tread_by_one * 2 - option_number.tread_by_two * 4 - option_number.tread_by_three * 6
end
#项目贡献得分
def active(option_number)
option_number.changeset * 4 + option_number.document * 4 + option_number.attachment * 4 + option_number.issue_done_ratio * 2 + option_number.post_issue * 4
end
#更新发帖数
def update_memo_number(user,type)
option_number = get_option_number(user,type)
option_number.memo = Message.includes(:author).where("parent_id IS NULL and author_id = '#{user.id}'").all.count
update_score(option_number)
end
#更新对缺陷留言数
def update_messges_for_issue(user,type)
option_number = get_option_number(user,type)
option_number.messages_for_issues = Journal.includes(:user).where("user_id = '#{user.id}'").all.count
update_score(option_number)
end
#更新更改缺陷状态状态次数
def update_issues_status(user,type)
option_number = get_option_number(user,type)
option_number.issues_status = Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count
update_score(option_number)
end
#更新对留言的回复数量
def update_replay_for_message(user,type)
option_number = get_option_number(user,type)
option_number.replay_for_message = JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL and user_id = #{user.id}").count
update_score(option_number)
end
#更新对帖子的回复数量
def update_replay_for_memo(user,type)
option_number = get_option_number(user,type)
option_number.replay_for_memo = Message.includes(:author).where("parent_id IS NOT NULL and author_id = #{user.id}").count
update_score(option_number)
end
#更新被关注的人数
def update_follow(user,type)
option_number = get_option_number(user,type)
option_number.follow = Watcher.includes(:watchable).where("watchable_type = 'Principal' and watchable_id = '#{user.id}'").count
update_score(option_number)
end
#更新踩别人帖子的数量
end

View File

@ -35,9 +35,19 @@
</p>
<div style="margin-left:60px;padding-right: 20px;" id="notification">
<label for='contest_description' style="vertical-align: top">&nbsp;&nbsp;&nbsp;</label>
<label for='contest_notification_title'>&nbsp;&nbsp;&nbsp;<%= l(:label_contest_notification_title) %>:</label>
<p style="margin-left:70px;padding-right: 20px;">
<%= text_field_tag 'contest_notification_title', params[:label_contest_notification_title], :value => @notification.title,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>
</p>
<label for='contest_notification' style="vertical-align: top">&nbsp;&nbsp;&nbsp;<%= l(:label_contest_notification_content)%>:</label>
<%= text_area 'contest_notification', 'content', :value => @notification.content,:cols => 80, :rows => 15, :class => 'wiki-edit' %>
<%= wikitoolbar_for 'contest_notification_content' %>
<!-- <script src="/javascripts/ckeditor/ckeditor.js?1404953555" type="text/javascript"></script>
<p><#%= text_area 'contest_notification', 'content', :value => @notification.content,:required => true, :size => 80,:class => 'wiki-edit', id: 'editor01' %></p>
<script type="text/javascript">var ckeditor=CKEDITOR.replace('editor01');</script> -->
</div>
<%= submit_tag l(:button_save), :class => "small", :name => nil %>
<% end %>

View File

@ -573,6 +573,8 @@ zh:
label_site_description: 网站简介
label_site_image: 简介图片
label_sort_type: 热门项目排序方式
label_contest_notification_title: 竞赛通知标题
label_contest_notification_content: 竞赛通知内容
#by young
label_requirement: 需求
label_new_course: 课程列表

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140722080924) do
ActiveRecord::Schema.define(:version => 20140723082637) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -716,6 +716,32 @@ ActiveRecord::Schema.define(:version => 20140722080924) do
t.datetime "updated_at", :null => false
end
create_table "option_numbers", :force => true do |t|
t.string "user_id"
t.integer "memo"
t.integer "messages_for_issues"
t.integer "issues_status"
t.integer "replay_for_message"
t.integer "replay_for_memo"
t.integer "follow"
t.integer "tread"
t.integer "praise_by_one"
t.integer "praise_by_two"
t.integer "praise_by_three"
t.integer "tread_by_one"
t.integer "tread_by_two"
t.integer "tread_by_three"
t.integer "changeset"
t.integer "document"
t.integer "attachment"
t.integer "issue_done_ratio"
t.integer "post_issue"
t.integer "score_type"
t.integer "total_score"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "praise_tread_caches", :force => true do |t|
t.integer "object_id", :null => false
t.string "object_type"