diff --git a/ReadMe.txt b/ReadMe.txt index c373119fb..35e56515d 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -62,4 +62,4 @@ kw: 首页, 定制, forge, course, contest, 排序 如果运行迁移文件有报错与‘sort_type’相关 先运行 bundle exec rake db:migrate:down version=20140716021202 bundle exec rake db:migrate:up version=20140716021202 在按如下步骤执行,未报与之相关的则直接按如下步骤执行 1.运行 bundle exec rake db:migrate:down version=20140719080032 -2.运行 bundle exec rake db:migrate:up version=20140719080032 \ No newline at end of file +2.运行 bundle exec rake db:migrate:up version=20140719080032 diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 781d07d58..a76a78dcb 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -148,8 +148,8 @@ class AdminController < ApplicationController elsif request.post? @first_page = FirstPage.where("page_type = 'project'").first @first_page.web_title = params[:web_title] - @first_page.description = params[:description] - @first_page.title = params[:title] + @first_page.description = params[:first_page][:description] + #@first_page.title = params[:title] @first_page.sort_type = params[:sort_type] if @first_page.save respond_to do |format| diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e6efca1e8..110974b77 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -482,14 +482,19 @@ class ApplicationController < ActionController::Base # Renders an error response def render_error(arg) arg = {:message => arg} unless arg.is_a?(Hash) - @message = arg[:message] + @lay = arg[:layout] @message = l(@message) if @message.is_a?(Symbol) @status = arg[:status] || 500 respond_to do |format| format.html { - render :template => 'common/error', :layout => use_layout, :status => @status + if @lay + render :template => 'common/error', :layout => @lay,:status => @status + else + render :template => 'common/error', :layout => use_layout, :status => @status + end + } format.any { head @status } end diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 6c22d8de2..a0da2d025 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -286,7 +286,7 @@ private raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename if @attachment.container_type == 'Course' @course = @attachment.course - elsif @attachment.container.course + elsif @attachment.container.has_attribute?(:course) && @attachment.container.course @course = @attachment.container.course else unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 9c41f91d6..d3de11177 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -1,5 +1,7 @@ # added by fq class ForumsController < ApplicationController + layout "users_base" + # GET /forums # GET /forums.json before_filter :find_forum_if_available @@ -143,9 +145,10 @@ class ForumsController < ApplicationController respond_to do |format| if @forum.update_attributes(params[:forum]) - format.html { redirect_to @forum, notice: 'Forum was successfully updated.' } + format.html { redirect_to @forum, notice: l(:label_forum_update_succ) } format.json { head :no_content } else + flash.now[:error] = "#{l :label_forum_update_fail}: #{@forum.errors.full_messages[0]}" format.html { render action: "edit" } format.json { render json: @forum.errors, status: :unprocessable_entity } end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 516b88310..7109a5460 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -24,24 +24,19 @@ class WelcomeController < ApplicationController def index @first_page = FirstPage.where("page_type = 'project'").first - @hot_projects = find_miracle_project(10, 3) - @hot_projects_ids = [] - @hot_projects.each do |p| - @hot_projects_ids << p - end - @projects_all = Project.active.visible. - joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id"). - where("#{Project.table_name}.project_type = ? and #{Project.table_name}.id in (?)", Project::ProjectType_project,@hot_projects_ids) if @first_page.nil? || @first_page.sort_type.nil? - @projects = @projects_all.order("grade desc") + @projects = find_miracle_project(10, 3,"grade desc") else case @first_page.sort_type when 0 - @projects = @projects_all.order("created_on desc") + @projects = find_miracle_project(10, 3,"created_on desc") + #@projects = @projects_all.order("created_on desc") when 1 - @projects = @projects_all.order("grade desc") + @projects = find_miracle_project(10, 3,"grade desc") + #@projects = @projects_all.order("grade desc") when 2 - @projects = @projects_all.order("watchers_count desc") + @projects = find_miracle_project(10, 3,"watchers_count desc") + #@projects = @projects_all.order("watchers_count desc") #gcm #when '3' diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index a4f53c100..110f81537 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -216,7 +216,7 @@ class WordsController < ApplicationController elsif ( referer.match(/homework_attach/) || referer.match(/homework_attach/) ) #new added obj = HomeworkAttach.find_by_id(obj_id) else - raise 'create reply obj unknow type.' + raise "create reply obj unknow type.#{referer}" end obj end @@ -240,8 +240,8 @@ class WordsController < ApplicationController elsif obj.kind_of? HomeworkAttach obj.add_jour(nil, nil, obj.id, options) #new added else - raise 'create reply obj unknow type.' + raise "create reply obj unknow type.#{obj.class}" end end #######end of message -end \ No newline at end of file +end diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 9e1676474..a5506be93 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -1,4 +1,5 @@ class ZipdownController < ApplicationController + #查找项目(课程) before_filter :find_project_by_bid_id, :only => [:assort] #检查权限 @@ -43,16 +44,17 @@ class ZipdownController < ApplicationController zipfile = zip_homework_by_user homework send_file zipfile, :filename => homework.name+".zip", :type => detect_content_type(zipfile) if(zipfile) else - render file: 'zipdown/no_file_dowmload.js.erb' + render_403 :message => :no_file_dowmload ,:layout => "course_base" end else - render_403 :message =>:notice_file_not_found + render_403 :message =>:notice_file_not_found ,:layout => "course_base" end else - render_403 :message => :notice_not_authorized + render_403 :message => :notice_not_authorized ,:layout => "course_base" end + rescue => e - render file: 'zipdown/file_not_fond.js.erb' + render file: 'public/file_not_found.html' end private diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index ede00b694..720919369 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -338,14 +338,44 @@ module UserScoreHelper 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 + def get_option_number(user,type,project_id=nil) + if project_id.nil? + option_number = OptionNumber.where("user_id = '#{user.id}' and score_type = '#{type}'"); + else + option_number = OptionNumber.where("user_id = '#{user.id}' and score_type = '#{type}' and project_id = '#{project_id}'"); + end + + result = nil + if option_number.nil? || option_number.count == 0 + result = OptionNumber.new + result.user_id = user.id + result.memo = 0 + result.messages_for_issues = 0 + result.issues_status = 0 + result.replay_for_message = 0 + result.replay_for_memo = 0 + result.follow = 0 + result.tread = 0 + result.praise_by_one = 0 + result.praise_by_two = 0 + result.praise_by_three = 0 + result.tread_by_one = 0 + result.tread_by_two = 0 + result.tread_by_three = 0 + result.changeset = 0 + result.document = 0 + result.attachment = 0 + result.issue_done_ratio = 0 + result.post_issue = 0 + result.total_score = 0 + result.score_type =type + unless project_id.nil? + result.project_id = project_id + end + else + result = option_number.first end - option_number + result end #更新分数 @@ -374,7 +404,7 @@ module UserScoreHelper #更新发帖数 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 + option_number.memo = Message.includes(:author).where("parent_id IS NULL and author_id = '#{user.id}'").all.count + Memo.includes(:author).where("parent_id IS NULL and author_id = '#{user.id}'").all.count update_score(option_number) end @@ -401,7 +431,7 @@ module UserScoreHelper #更新对帖子的回复数量 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 + option_number.replay_for_memo = Message.includes(:author).where("parent_id IS NOT NULL and author_id = #{user.id}").all.count + Memo.includes(:author).where("parent_id IS NOT NULL and author_id = #{user.id}").all.count update_score(option_number) end @@ -412,5 +442,97 @@ module UserScoreHelper update_score(option_number) end - #更新踩别人帖子的数量 + #更新帖子踩各项数量 + def update_tread(user,type) + option_number = get_option_number(user,type) + option_number.tread = PraiseTread.where("praise_tread_object_type = 'Memo' || praise_tread_object_type = 'Message' and praise_or_tread = 0 and user_id = '#{user.id}'").all.count + pts = PraiseTread.where("praise_tread_object_type = 'Memo' || praise_tread_object_type = 'Message' and praise_or_tread = 0").all + result = [] + result1 = [] + result2 = [] + pts.each do |pt| + obj = PraiseTread.find_object_by_type_and_id(pt.praise_tread_object_type, pt.praise_tread_object_id) + if obj.nil? + next + end + target_user = obj.author + level = UserLevels.get_level(pt.user)#pt.user.get_level + project = pt.project + if level == 1 && target_user.id = user.id + result << pt + elsif level == 2 && target_user.id = user.id + result1 << pt + elsif level == 3 && target_user.id = user.id + result2 << pt + end + end + option_number.tread_by_one = result.count + option_number.tread_by_two = result1.count + option_number.tread_by_three = result2.count + update_score(option_number) + end + + #更新帖子顶数量 + def update_praise(user,type) + option_number = get_option_number(user,type) + pts = PraiseTread.where("praise_tread_object_type = 'Memo' || praise_tread_object_type = 'Message' and praise_or_tread = 1").all + result = [] + result1 = [] + result2 = [] + pts.each do |pt| + obj = PraiseTread.find_object_by_type_and_id(pt.praise_tread_object_type, pt.praise_tread_object_id) + if obj.nil? + next + end + target_user = obj.author + level = UserLevels.get_level(pt.user)#pt.user.get_level + project = pt.project + if level == 1 && target_user.id = user.id + result << pt + elsif level == 2 && target_user.id = user.id + result1 << pt + elsif level == 3 && target_user.id = user.id + result2 << pt + end + end + option_number.praise_by_one = result.count + option_number.praise_by_two = result1.count + option_number.praise_by_three = result2.count + update_score(option_number) + end + + #更新提交代码次数 + def update_changeset(user,type) + option_number = get_option_number(user,type) + option_number.changeset = Changeset.includes(:user).where("user_id = '#{user.id}'").all.count + update_score(option_number) + end + + #更新文档提交次数 + def update_document(user,type) + option_number = get_option_number(user,type) + option_number.document = Document.includes(:user).where("user_id = '#{user.id}'").all.count + update_score(option_number) + end + + #更新附件提交数量 + def update_attachment(user,type) + option_number = get_option_number(user,type) + option_number.attachment = Attachment.includes(:author).where("author_id = '#{user.id}'").all.count + update_score(option_number) + end + + #更新缺陷完成度次数 + def update_issue_done_ratio(user,type) + option_number = get_option_number(user,type) + option_number.issue_done_ratio = Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'done_ratio' and #{User.table_name}.id = '#{user.id}'").count + update_score(option_number) + end + + #更新发布缺陷次数 + def update_post_issue(user,type) + option_number = get_option_number(user,type) + option_number.post_issue = Issue.includes(:author).where("author_id = '#{user.id}'").all.count + update_score(option_number) + end end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 99357a3d0..8ee7f42d8 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -203,12 +203,12 @@ module WelcomeHelper #end end - def find_miracle_project(sum, max_rate) + def find_miracle_project(sum, max_rate,order) #max = sum*(max_rate.to_f/10) #c1 = find_new_project(sum).to_a.dup #c2 = find_all_hot_project(sum).to_a.dup #(c2.take(sum-max)+c1.take(max)).take(sum) - find_all_hot_project(sum).dup#.to_a.dup + find_all_hot_project(sum,order).to_a.dup end def find_new_course limit=15 @@ -220,8 +220,8 @@ module WelcomeHelper end - def find_all_hot_project limit=15 - sort_project_by_hot limit + def find_all_hot_project limit=15,order + sort_project_by_hot limit,order end def find_all_hot_course limit=15 @@ -366,8 +366,9 @@ module WelcomeHelper private - def sort_project_by_hot limit=15 - sort_project_by_hot_rails 0, 'grade DESC', limit + def sort_project_by_hot limit=15,order + #'grade DESC' + sort_project_by_hot_rails 0,order , limit end def sort_course_by_hot limit=15 @@ -433,7 +434,7 @@ module WelcomeHelper # FROM projects AS p LEFT OUTER JOIN ( # SELECT project_id,grade FROM project_statuses # WHERE project_type = #{project_type} ORDER BY #{order_by} LIMIT #{limit} ) AS t ON p.id = t.project_id ") - Project.visible.joins(:project_status).where("#{Project.table_name}.project_type = ?", project_type).order(order_by).limit(limit)#.all + Project.visible.joins(:project_status).where("#{Project.table_name}.project_type = ?", project_type).order(order_by).limit(limit).all end def sort_bid_by_hot_rails reward_type, limit = 10 diff --git a/app/models/first_page.rb b/app/models/first_page.rb index 52c6e204d..58d20901e 100644 --- a/app/models/first_page.rb +++ b/app/models/first_page.rb @@ -2,5 +2,5 @@ class FirstPage < ActiveRecord::Base attr_accessible :description, :title, :web_title,:page_type,:sort_type validates_presence_of :web_title, :title, :description,:page_type validates_length_of :web_title,:title, maximum: 30 - validates_length_of :description, maximum: 100 + #validates_length_of :description, maximum: 100 end diff --git a/app/models/issue.rb b/app/models/issue.rb index f47e1c6f9..83e7f8479 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -18,6 +18,7 @@ class Issue < ActiveRecord::Base include Redmine::SafeAttributes include Redmine::Utils::DateCalculation + include UserScoreHelper belongs_to :project belongs_to :tracker @@ -1507,17 +1508,20 @@ class Issue < ActiveRecord::Base #缺陷完成度更新 if self.done_ratio_changed? UserScore.project(:update_issue_ratio, User.current,self,{ issue_id: self.id }) + #update_issue_done_ratio(User.current,1) end #缺陷状态更改 if self.status_id_changed? #协同得分 UserScore.joint(:change_issue_status, User.current,nil,self, {issue_id: self.id}) + #update_issues_status(self.author , 1) end end #发布缺陷 def be_user_score_new_issue UserScore.project(:post_issue, User.current,self, { issue_id: self.id }) + update_post_issue(self.author,1) end diff --git a/app/models/journal.rb b/app/models/journal.rb index 2e9363dd7..8d03f2325 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -16,6 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class Journal < ActiveRecord::Base + include UserScoreHelper belongs_to :journalized, :polymorphic => true # added as a quick fix to allow eager loading of the polymorphic association # since always associated to an issue, for now @@ -161,6 +162,7 @@ class Journal < ActiveRecord::Base if !self.notes.nil? && self.notes.gsub(' ','') != '' #协同得分加分 UserScore.joint(:post_issue_message, User.current,self.issue.author,self, { message_id: self.id }) + update_messges_for_issue(User.current,1) end end # 减少用户分数 -by zjc diff --git a/app/models/journal_detail.rb b/app/models/journal_detail.rb index 1ec195733..4100a5b1c 100644 --- a/app/models/journal_detail.rb +++ b/app/models/journal_detail.rb @@ -16,9 +16,10 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class JournalDetail < ActiveRecord::Base + include UserScoreHelper belongs_to :journal before_save :normalize_values - + after_create :be_user_score private def normalize_values @@ -38,4 +39,15 @@ class JournalDetail < ActiveRecord::Base v end end + + def be_user_score + #更新缺陷完成度 + if self.prop_key = 'done_ratio' + update_issue_done_ratio(User.current,1) + #更新缺陷状态 + elsif self.prop_key = 'status_id' + update_issues_status(User.current , 1) + end + end + end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 9551ff28b..4debe668f 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -3,6 +3,7 @@ # 注意reply_id 是提到人的id,不是留言id, Base中叫做 at_user class JournalsForMessage < ActiveRecord::Base include Redmine::SafeAttributes + include UserScoreHelper safe_attributes "jour_type", # 留言所属类型 "jour_id", # 留言所属类型的id "notes", # 留言内容 @@ -132,6 +133,7 @@ class JournalsForMessage < ActiveRecord::Base if self.reply_id != 0 #协同得分加分 UserScore.joint(:reply_message, User.current,User.find(self.reply_id),self, { journals_for_messages_id: self.id }) + update_replay_for_message(User.current,1) end end # 更新用户分数 -by zjc diff --git a/app/models/memo.rb b/app/models/memo.rb index feb10dec9..6370065ba 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -1,5 +1,6 @@ class Memo < ActiveRecord::Base include Redmine::SafeAttributes + include UserScoreHelper belongs_to :forum belongs_to :author, :class_name => "User", :foreign_key => 'author_id' @@ -148,9 +149,11 @@ class Memo < ActiveRecord::Base #新建memo且无parent的为发帖 if self.parent_id.nil? UserScore.joint(:post_message, User.current,nil,self ,{ memo_id: self.id }) + update_memo_number(User.current,1) #新建memo且有parent的为回帖 elsif !self.parent_id.nil? UserScore.joint(:reply_posting, User.current,self.parent.author,self, { memo_id: self.id }) + update_replay_for_memo(User.current,1) end end diff --git a/app/models/message.rb b/app/models/message.rb index faf7e5bdf..2c183dc59 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -17,6 +17,8 @@ class Message < ActiveRecord::Base include Redmine::SafeAttributes + include UserScoreHelper + belongs_to :board belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC" @@ -149,9 +151,11 @@ class Message < ActiveRecord::Base #新建message且无parent的为发帖 if self.parent_id.nil? UserScore.joint(:post_message, User.current,nil,self, { message_id: self.id }) + update_memo_number(User.current,1) #新建message且有parent的为回帖 elsif !self.parent_id.nil? UserScore.joint(:reply_posting, User.current,self.parent.author,self, { message_id: self.id }) + update_replay_for_memo(User.current,1) end end #减少用户分数 diff --git a/app/models/option_number.rb b/app/models/option_number.rb new file mode 100644 index 000000000..8ba32a575 --- /dev/null +++ b/app/models/option_number.rb @@ -0,0 +1,4 @@ +class OptionNumber < ActiveRecord::Base + attr_accessible :attachment, :changeset, :document, :follow, :issue_done_ratio, :issues_status, :memo, :messages_for_issues, :post_issue, :praise_by_one, :praise_by_three, :praise_by_two, :replay_for_memo, :replay_for_message, :score_type, :total_score, :tread, :tread_by_one, :tread_by_three, :tread_by_two, :user_id + +end diff --git a/app/views/admin/first_page_made.html.erb b/app/views/admin/first_page_made.html.erb index 242b7c689..e4a5119d3 100644 --- a/app/views/admin/first_page_made.html.erb +++ b/app/views/admin/first_page_made.html.erb @@ -20,13 +20,15 @@ <%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source:@first_page} %> -

- - <%= text_field_tag 'title', params[:label_site_title], :value => @first_page.title,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> -

+

- <%= text_area_tag 'description',@first_page.description,:rows => 8, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> + + <%= text_area 'first_page', 'description', :value => @first_page.description,:cols => 80, :rows => 15, :class => 'wiki-edit' %> + <%= wikitoolbar_for 'first_page_description' %>

diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index dbd841159..b68bf5773 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -45,7 +45,8 @@

<% unless @first_page.nil? %> - <%= @first_page.title %> , <%= @first_page.description %> + + <%= @first_page.description.html_safe %> <% end %>