@@ -38,7 +49,6 @@
<%= call_hook :view_layouts_base_content %>
- <%= render :partial => 'layouts/base_footer'%>
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index b3624b14d..6a0b351ba 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -386,14 +386,16 @@ class IssuesController < ApplicationController end def add_journal - jour = Journal.new - jour.user_id = User.current.id - jour.notes = params[:notes] - jour.journalized = @issue - jour.save - @user_activity_id = params[:user_activity_id] - respond_to do |format| - format.js + if User.current.logged? + jour = Journal.new + jour.user_id = User.current.id + jour.notes = params[:notes] + jour.journalized = @issue + jour.save + @user_activity_id = params[:user_activity_id] + respond_to do |format| + format.js + end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e3480b238..859f19f19 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -102,22 +102,22 @@ class UsersController < ApplicationController # issue:问题;journal:缺陷状态更新; forum:公共贴吧: user_feedback: 用户留言; new_reply:新闻回复(comment) def user_messages unless User.current.logged? - render_403 + redirect_to signin_url return end # 当前用户查看消息,则设置消息为已读 - #if params[:viewed] == "all" - # course_querys = @user.course_messages - # forge_querys = @user.forge_messages - # user_querys = @user.user_feedback_messages - # forum_querys = @user.memo_messages - # if User.current.id == @user.id - # course_querys.update_all(:viewed => true) - # forge_querys.update_all(:viewed => true) - # user_querys.update_all(:viewed => true) - # forum_querys.update_all(:viewed => true) - # end - #end + if params[:viewed] == "all" + course_querys = @user.course_messages + forge_querys = @user.forge_messages + user_querys = @user.user_feedback_messages + forum_querys = @user.memo_messages + if User.current.id == @user.id + course_querys.update_all(:viewed => true) + forge_querys.update_all(:viewed => true) + user_querys.update_all(:viewed => true) + forum_querys.update_all(:viewed => true) + end + end # @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count case params[:type] when nil @@ -296,12 +296,16 @@ class UsersController < ApplicationController #用户作业列表 def user_homeworks - @page = params[:page] ? params[:page].to_i + 1 : 0 - user_course_ids = "(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" - @homework_commons = HomeworkCommon.where("course_id in #{user_course_ids}").order("created_at desc").limit(10).offset(@page * 10) - respond_to do |format| - format.js - format.html {render :layout => 'new_base_user'} + if User.current == @user + @page = params[:page] ? params[:page].to_i + 1 : 0 + user_course_ids = "(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" + @homework_commons = HomeworkCommon.where("course_id in #{user_course_ids}").order("created_at desc").limit(10).offset(@page * 10) + respond_to do |format| + format.js + format.html {render :layout => 'new_base_user'} + end + else + render_403 end end @@ -345,16 +349,20 @@ class UsersController < ApplicationController end def new_user_commit_homework - @user = User.current - @homework = HomeworkCommon.find(params[:homework_id]) - @is_test = params[:is_test] == 'true' - @student_work = @homework.student_works.where(user_id: User.current.id).first - if @student_work.nil? - @student_work = StudentWork.new - end - respond_to do |format| - format.js - format.html {render :layout => 'new_base_user'} + if User.current.logged? + @user = User.current + @homework = HomeworkCommon.find(params[:homework_id]) + @is_test = params[:is_test] == 'true' + @student_work = @homework.student_works.where(user_id: User.current.id).first + if @student_work.nil? + @student_work = StudentWork.new + end + respond_to do |format| + format.js + format.html {render :layout => 'new_base_user'} + end + else + render_403 end end @@ -364,53 +372,57 @@ class UsersController < ApplicationController end def user_new_homework - if params[:homework_common] - homework = HomeworkCommon.new - homework.name = params[:homework_common][:name] - homework.description = params[:homework_common][:description] - homework.end_time = params[:homework_common][:end_time] || Time.now - homework.publish_time = Time.now - homework.homework_type = params[:homework_type].to_i || 1 - homework.late_penalty = 2 - homework.user_id = User.current.id - homework.course_id = params[:course_id] + if User.current.logged? + if params[:homework_common] + homework = HomeworkCommon.new + homework.name = params[:homework_common][:name] + homework.description = params[:homework_common][:description] + homework.end_time = params[:homework_common][:end_time] || Time.now + homework.publish_time = Time.now + homework.homework_type = params[:homework_type].to_i || 1 + homework.late_penalty = 2 + homework.user_id = User.current.id + homework.course_id = params[:course_id] - homework.save_attachments(params[:attachments]) - render_attachment_warning_if_needed(homework) + homework.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(homework) - #匿评作业相关属性 - if homework.homework_type == 1 - homework_detail_manual = HomeworkDetailManual.new - homework_detail_manual.ta_proportion = params[:ta_proportion] || 0.6 - homework_detail_manual.comment_status = 1 - homework_detail_manual.evaluation_start = Time.now - homework_detail_manual.evaluation_end = Time.now - homework_detail_manual.evaluation_num = params[:evaluation_num] || 3 - homework_detail_manual.absence_penalty = 2 - homework.homework_detail_manual = homework_detail_manual - else - homework_detail_programing = HomeworkDetailPrograming.new - homework.homework_detail_programing = homework_detail_programing - homework_detail_programing.ta_proportion = params[:ta_proportion] || 0.6 - homework_detail_programing.language = params[:program][:language].to_i + #匿评作业相关属性 + if homework.homework_type == 1 + homework_detail_manual = HomeworkDetailManual.new + homework_detail_manual.ta_proportion = params[:ta_proportion] || 0.6 + homework_detail_manual.comment_status = 1 + homework_detail_manual.evaluation_start = Time.now + homework_detail_manual.evaluation_end = Time.now + homework_detail_manual.evaluation_num = params[:evaluation_num] || 3 + homework_detail_manual.absence_penalty = 2 + homework.homework_detail_manual = homework_detail_manual + else + homework_detail_programing = HomeworkDetailPrograming.new + homework.homework_detail_programing = homework_detail_programing + homework_detail_programing.ta_proportion = params[:ta_proportion] || 0.6 + homework_detail_programing.language = params[:program][:language].to_i - inputs = params[:program][:input] - if Array === inputs - inputs.each_with_index do |val, i| - homework.homework_tests << HomeworkTest.new( - input: val, - output: params[:program][:output][i] - ) + inputs = params[:program][:input] + if Array === inputs + inputs.each_with_index do |val, i| + homework.homework_tests << HomeworkTest.new( + input: val, + output: params[:program][:output][i] + ) + end end - end - - end - if homework.save - homework_detail_manual.save if homework_detail_manual - homework_detail_programing.save if homework_detail_programing - redirect_to user_homeworks_user_path(User.current.id) + end + + if homework.save + homework_detail_manual.save if homework_detail_manual + homework_detail_programing.save if homework_detail_programing + redirect_to user_homeworks_user_path(User.current.id) + end end + else + render_403 end end @@ -507,6 +519,7 @@ class UsersController < ApplicationController att_copy = atta.copy att_copy.container_id = nil att_copy.container_type = nil + att_copy.author_id = User.current.id att_copy.copy_from = atta.id att_copy.save @attachments << att_copy @@ -540,6 +553,10 @@ class UsersController < ApplicationController # modified by fq def user_newfeedback + unless User.current.logged? + redirect_to signin_url + return + end # 更新用户留言消息状态 @user.journals_for_messages.each do |jour_message| jour_message.user_feedback_messages.each do |userfeedback_message| @@ -767,7 +784,7 @@ class UsersController < ApplicationController @page = params[:page] ? params[:page].to_i + 1 : 0 user_project_ids = @user.projects.visible.empty? ? "(-1)" : "(" + @user.projects.visible.map{|project| project.id}.join(",") + ")" user_course_ids = @user.courses.visible.empty? ? "(-1)" : "(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" - course_types = "('Message','News','HomeworkCommon','poll')" + course_types = "('Message','News','HomeworkCommon','Poll')" project_types = "('Message','Issue')" if params[:type].present? case params[:type] diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index c94763e31..c82255d00 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -27,7 +27,7 @@ module UserScoreHelper issue_c = issue_c + Journal.where("user_id = ?", user.id).count ############################ memos = Memo.where('author_id = ? AND parent_id IS NOT NULL', user.id) - + memos.each do |m| if Memo.find(m.parent_id).author.id != user.id issue_c = issue_c + 1 @@ -35,18 +35,18 @@ module UserScoreHelper issue_c = issue_c - 1 end end - - + + pmemos = Memo.where('author_id = ? AND parent_id IS NULL', user.id) pmemos.each do |pm| issue_c = issue_c + pm.replies_count end ############################ - + issue_c = issue_c + JournalsForMessage.where('user_id = ? AND reply_id IS NOT NULL AND reply_id <> ?', user.id, user.id).count + JournalsForMessage.where('reply_id = ? AND user_id <> ?', user.id, user.id).count - - - + + + return issue_c end @@ -58,14 +58,14 @@ module UserScoreHelper def calculate_skill_count(user) - + praise_count_l0 = 0 praise_count_l1 = 0 praise_count_l2 = 0 tread_count_l0 = 0 tread_count_l1 = 0 tread_count_l2 = 0 - issues = Issue.where('author_id = ?', user.id) + issues = Issue.where('author_id = ?', user.id) issues.each do |i| pts = PraiseTread.where('praise_tread_object_id = ?', i.id) pts.each do |p| @@ -75,7 +75,7 @@ module UserScoreHelper if p.praise_or_tread == 1 praise_count_l0 = praise_count_l0 + 1 else - tread_count_l0 = tread_count_l0 + 1 + tread_count_l0 = tread_count_l0 + 1 end end if templevel.to_i == 1 @@ -97,7 +97,7 @@ module UserScoreHelper - + bids = Bid.where('author_id = ?', user.id) bids.each do |b| ptcs = PraiseTread.where('praise_tread_object_id = ?', b.id) @@ -108,7 +108,7 @@ module UserScoreHelper if p.praise_or_tread == 1 praise_count_l0 = praise_count_l0 + 1 else - tread_count_l0 = tread_count_l0 + 1 + tread_count_l0 = tread_count_l0 + 1 end end if templevel.to_i == 1 @@ -127,7 +127,7 @@ module UserScoreHelper end end end - + contests = Contest.where('author_id = ?', user.id) contests.each do |c| ptcs = PraiseTread.where('praise_tread_object_id = ?', c.id) @@ -138,7 +138,7 @@ module UserScoreHelper if p.praise_or_tread == 1 praise_count_l0 = praise_count_l0 + 1 else - tread_count_l0 = tread_count_l0 + 1 + tread_count_l0 = tread_count_l0 + 1 end end if templevel.to_i == 1 @@ -154,12 +154,12 @@ module UserScoreHelper else tread_count_l2 + tread_count_l2 + 1 end - end - end + end + end end - - - + + + # case level # when 0 skill_score = praise_count - 0.5 * tread_count # when 1 skill_score = 2 * praise_count - 1.5 * tread_count @@ -170,9 +170,9 @@ module UserScoreHelper skill_score = 2 * praise_count_l0.to_f + 3 * praise_count_l1.to_f + 4 * praise_count_l2.to_f - 1 * tread_count_l0.to_f - 1.5 * tread_count_l1.to_f - 2 * tread_count_l2.to_f - + tread_user_count = PraiseTread.where('praise_or_tread = ? AND user_id = ?', 0, user.id).count - + skill_score = skill_score.to_f - tread_user_count.to_f @@ -182,17 +182,17 @@ module UserScoreHelper return skill_score - - - + + + end - + def calculate_level(user) commit_count = user.changesets.count max_praise_num = 0 - - - issues = Issue.where('author_id = ?', user.id) + + + issues = Issue.where('author_id = ?', user.id) issues.each do |i| ptcs = PraiseTreadCache.where('object_id = ?', i.id) ptcs.each do |p| @@ -201,7 +201,7 @@ module UserScoreHelper end end end - + bids = Bid.where('author_id = ?', user.id) bids.each do |b| ptcs = PraiseTreadCache.where('object_id = ?', b.id) @@ -211,7 +211,7 @@ module UserScoreHelper end end end - + contests = Contest.where('author_id = ?', user.id) contests.each do |c| ptcs = PraiseTreadCache.where('object_id = ?', c.id) @@ -219,12 +219,12 @@ module UserScoreHelper if p.praise_num.to_i > max_praise_num.to_i max_praise_num = p.praise_num end - end + end end - - + + best_answer_num = 0 - + isManager = 0 members = Member.where('user_id = ?', user.id) members.each do |m| @@ -238,21 +238,21 @@ module UserScoreHelper end - + level = 0 - + if max_praise_num > 4 level = 1 end if commit_count > 0 and commit_count < 101 level = 1 - end + end if commit_count > 100 or isManager == 1 level = 2 end - + return level - + end def calculate_activity_count(user) @@ -282,23 +282,23 @@ module UserScoreHelper def calculate_issue(user) commit_count = user.changesets.count - + issue_details_count = 0 issues = Issue.where('assigned_to_id = ?', user.id) - + change_count = 0 issues.each do |issue| js = issue.journals js.each do |j| change_count = change_count + j.details.where("prop_key = ?", "done_ratio").count end - - + + issue_details_count = change_count + issue_details_count end - + return (commit_count + issue_details_count) - + end @@ -306,9 +306,9 @@ module UserScoreHelper attachments = Attachment.where("container_type IS NOT NULL AND container_type <> 'Issue' AND author_id = ?", user.id).count return attachments - + end - + def calculate_user_score(user) collaboration = calculate_collaboration_count(user) influence = calculate_influence_count(user) @@ -322,7 +322,7 @@ module UserScoreHelper UserScore.new(:collaboration => collaboration, :influence => influence, :skill => skill, :activity => activity, :file => file, :issue => issue, :level => level) end - + def update_user_score(user) collaboration = calculate_collaboration_count(user) influence = calculate_influence_count(user) @@ -331,7 +331,7 @@ module UserScoreHelper issue = calculate_issue(user) ##activity = calculate_activity_count(user) - + level = calculate_level(user) user.user_score.update_attributes(:collaboration => collaboration, :influence => influence, :skill => skill, :activity => activity, :file => file, :issue => issue, :level => level) @@ -423,7 +423,7 @@ module UserScoreHelper #更新分数 def update_score(option_number) - option_number.total_score = collaboration(option_number) + influence(option_number) + skill(option_number) + active(option_number) + option_number.total_score = collaboration(option_number) + influence(option_number) + skill(option_number) + project_active(option_number) if option_number.total_score < 0 option_number.total_score = 0 end @@ -444,7 +444,7 @@ module UserScoreHelper 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) + def project_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 diff --git a/app/models/query.rb b/app/models/query.rb index 7f51aa53c..65c78e71f 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -493,26 +493,27 @@ class Query < ActiveRecord::Base def project_statement project_clauses = [] # unless project.descendants.blank? - if project && project.descendants && project.descendants.active && !project.descendants.active.empty? - ids = [project.id] - if has_filter?("subproject_id") - case operator_for("subproject_id") - when '=' - # include the selected subprojects - ids += values_for("subproject_id").each(&:to_i) - when '!*' - # main project only - else - # all subprojects - ids += project.descendants.collect(&:id) - end - elsif Setting.display_subprojects_issues? - ids += project.descendants.collect(&:id) - end - project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',') - elsif project + # if project && project.descendants && project.descendants.active && !project.descendants.active.empty? + # ids = [project.id] + # if has_filter?("subproject_id") + # case operator_for("subproject_id") + # when '=' + # # include the selected subprojects + # ids += values_for("subproject_id").each(&:to_i) + # when '!*' + # # main project only + # else + # # all subprojects + # ids += project.descendants.collect(&:id) + # end + # elsif Setting.display_subprojects_issues? + # ids += project.descendants.collect(&:id) + # end + # project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',') + # elsif project + if project project_clauses << "#{Project.table_name}.id = %d" % project.id - end + end # end project_clauses.any? ? project_clauses.join(' AND ') : nil end diff --git a/app/views/layouts/base_tags.html.erb b/app/views/layouts/base_tags.html.erb index 6a5b490d1..3fd00e042 100644 --- a/app/views/layouts/base_tags.html.erb +++ b/app/views/layouts/base_tags.html.erb @@ -19,12 +19,23 @@ <%= call_hook :view_layouts_base_html_head %> <%= yield :header_tags -%> + <%= stylesheet_link_tag 'base','header', :media => 'all'%>
+ + + + +