diff --git a/1234567 b/1234567 index dc8696854..f21c6a454 100644 --- a/1234567 +++ b/1234567 @@ -1 +1 @@ -{"access_token":"03kBJXYaoncSoMkMC_GyNNhKmx6rzK3DbzN0_VxgOJO9_Xtp2F5pSYw0X2HdTWg5sUf0zw3oY1O8ZPVF3TbLGwYP5-kj9AlpS4F2fqEY03BE95y5hPRlVv3g_VegHP25VINhAJAIVA","expires_in":7200,"got_token_at":1461306222} \ No newline at end of file +{"access_token":"GrEg56Sg5QRM7IXghWlaDzNd-7iaQsqX2acszXkSTFwOh_OxtN_UNIJsj9rlSZeSkZSofQwd0KvFGv_StzARHeLw81JllcI3a3VuXgZ_cjbQnM3m00g0HiLtTniQFsEIUVIdABAPQD","expires_in":7200,"got_token_at":1461314104} diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index e6e0ec087..8ae20972c 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -610,15 +610,33 @@ class AdminController < ApplicationController tStart = @page*30 @code_work_tests = CodeTests.find_by_sql("select * from code_tests order by id desc limit #{tStart},30 ") - #取出各个作业是否是模拟答题的 + #取出各个作品是否是模拟答题的 is_test = {} + #作品是否存在 + link_swork = {} + #作业是否存在 + link_hwork = {} @code_work_tests.each do |test| + #作品是否存在 if is_test[test['student_work_id']] != nil + test['link_swork'] = link_swork[test['student_work_id']] test['is_test'] = is_test[test['student_work_id']] else - test['is_test'] = StudentWork.find(test['student_work_id']).is_test + work = StudentWork.where("id=?",test['student_work_id']).first + test['link_swork'] = !work.nil? + test['is_test'] = work.nil? ? false : work.is_test #test['is_test'] = CodeTests.find_by_sql("select is_test from student_works where id = #{test['student_work_id']}").first['is_test'] is_test[test['student_work_id']] = test['is_test'] + link_swork[test['student_work_id']] = test['link_swork'] + end + + #作业是否存在 + if link_hwork[test['homework_id']] != nil + test['link_hwork'] = link_hwork[test['homework_id']] + else + hwork = HomeworkCommon.where("id=?",test['homework_id']).first + test['link_hwork'] = !hwork.nil? + link_hwork[test['homework_id']] = test['link_hwork'] end end diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 49e6ec290..d8188ca74 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -73,11 +73,18 @@ class HomeworkCommonController < ApplicationController else @homework.publish_time = params[:homework_common][:publish_time] end + homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new @homework.end_time = params[:homework_common][:end_time] || Time.now @homework.course_id = params[:course_id] - @homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0 + anonymous = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment].to_i : 0 + if anonymous != @homework.anonymous_comment + if anonymous == 1 + homework_detail_manual.ta_proportion = @homework.homework_type == 1 ? 1.0 : 0.4 + else + homework_detail_manual.ta_proportion = @homework.homework_type == 1 ? 0.6 : 0.3 + end + end - homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 homework_detail_manual.comment_status = 1 end @@ -94,6 +101,13 @@ class HomeworkCommonController < ApplicationController @homework.homework_detail_programing ||= HomeworkDetailPrograming.new @homework_detail_programing = @homework.homework_detail_programing @homework_detail_programing.language = params[:language_type].to_i + if anonymous != @homework.anonymous_comment + if anonymous == 1 + @homework_detail_programing.ta_proportion = 0.6 + else + @homework_detail_programing.ta_proportion = 0.5 + end + end @homework.homework_tests.delete_all inputs = params[:program][:input] @@ -116,8 +130,9 @@ class HomeworkCommonController < ApplicationController @homework_detail_group.base_on_project = params[:base_on_project].to_i end + @homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment].to_i : 0 if @homework.save - @homework_detail_manual.save if @homework_detail_manual + homework_detail_manual.save if homework_detail_manual @homework_detail_programing.save if @homework_detail_programing @homework_detail_group.save if @homework_detail_group diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index e1d623d5a..f3c01f21e 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -84,9 +84,6 @@ class OrganizationsController < ApplicationController @subfield_content = @organization.org_subfields.order("priority") @organization = Organization.find(params[:id]) - # 统计访问量 - @organization.update_column(:visits, @organization.visits.to_i + 1) - # @org_subfield = OrgSubfield.find(params[:org_subfield_id]) # @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0 # @org_acts = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10) @@ -123,8 +120,6 @@ class OrganizationsController < ApplicationController else if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) @organization = Organization.find(params[:id]) - # 统计访问量 - @organization.update_column(:visits, @organization.visits.to_i + 1) if params[:org_subfield_id] @org_subfield = OrgSubfield.find(params[:org_subfield_id]) @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0 diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 380e880ad..b73ecf9b9 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -325,27 +325,11 @@ update end end - # unless @repository.gitlab? - # # redirect_to to_gitlab_project_repository_path(@project, @repository) - # render :to_gitlab - # return - # end - - #if( !User.current.member_of?(@project) || @project.hidden_repo) - # @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty? - - # :name, :path, :kind, :size, :lastrev, :changeset @entries = @repository.entries(@path, @rev) - # @trees = g.trees(project, @path) @changeset = @repository.find_changeset_by_name(@rev) - #@project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT - #@ip = RepositoriesHelper::REPO_IP_ADDRESS - if request.xhr? @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) else - #Modified by young - # (show_error_not_found; return) unless @entries g = Gitlab.client @changesets = g.commits(@project.gpid, :ref_name => @rev) g_project = g.project(@project.gpid) @@ -360,17 +344,16 @@ update if @changesets_all_count != @project.project_score.changeset_num && @changesets_all_count != 0 update_commits_count(@project, @changesets_all_count) end - # end # 最近一次提交 @changesets_latest_coimmit = @changesets[0] unless @changesets[0].blank? update_commits_date(@project, @changesets_latest_coimmit) end @creator = User.where("id =?", @project.user_id).first.try(:login) - @properties = @repository.properties(@path, @rev) - @repositories = @project.repositories - project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT - ip = RepositoriesHelper::REPO_IP_ADDRESS + # @properties = @repository.properties(@path, @rev) + # @repositories = @project.repositories + # project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT + # ip = RepositoriesHelper::REPO_IP_ADDRESS gitlab_address = Redmine::Configuration['gitlab_address'] if @repository.type.to_s == "Repository::Gitlab" @repos_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+@repository.identifier+"."+"git" @@ -586,8 +569,6 @@ update end end end - # @static_month__per_user = g.rep_stats(project_id, :rev => rev, :creator => creator, :period => 2) - # @static_week_per_user = g.rep_stats(project_id, :rev => rev, :creator => creator, :period => 3) rescue render_404 return diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 9d2548a36..42236f2d2 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -504,6 +504,7 @@ class StudentWorkController < ApplicationController end @score = @b_sort == "desc" ? "asc" : "desc" + @is_focus = params[:is_focus] ? params[:is_focus].to_i : 0 # 消息传过来的ID @message_student_work_id = params[:student_work_id] respond_to do |format| @@ -920,8 +921,6 @@ class StudentWorkController < ApplicationController student_work.late_penalty = @homework.late_penalty student_work.save end - - @homework.save end if params[:absence_penalty] && homework_detail_manual.absence_penalty.to_s != params[:absence_penalty].to_s @@ -944,7 +943,6 @@ class StudentWorkController < ApplicationController homework_detail_programing.ta_proportion = params[:sy_proportion] if homework_detail_programing @homework.teacher_priority = teacher_priority - @homework.save homework_detail_manual.save if homework_detail_manual homework_detail_programing.save if homework_detail_programing @@ -953,6 +951,8 @@ class StudentWorkController < ApplicationController student_work.save end end + + @homework.save if params[:student_path] redirect_to student_work_index_url(:homework => @homework.id) else diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a15f37274..7392ed8ff 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -750,7 +750,11 @@ class UsersController < ApplicationController render_attachment_warning_if_needed(homework) homework_detail_manual = HomeworkDetailManual.new - homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 0.6 : 0.3 + if homework.anonymous_comment == 1 + homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 1.0 : 0.4 + else + homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 0.6 : 0.3 + end if homework.publish_time > Date.today homework_detail_manual.comment_status = 0 else @@ -766,7 +770,11 @@ class UsersController < ApplicationController if homework.homework_type == 2 homework_detail_programing = HomeworkDetailPrograming.new homework.homework_detail_programing = homework_detail_programing - homework_detail_programing.ta_proportion = 0.5 + if homework.anonymous_comment == 1 + homework_detail_programing.ta_proportion = 0.6 + else + homework_detail_programing.ta_proportion = 0.5 + end homework_detail_programing.language = params[:language_type].to_i inputs = params[:program][:input] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 606c9b5fd..163e76999 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -123,7 +123,7 @@ module ApplicationHelper CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :homework_journal_num => 1) else score = course_contributor_score.homework_journal_num.to_i + 1 - course_contributor_score.update_attributes(:homework_journal_num => score) + course_contributor_score.update_column(:homework_journal_num, score) end # 课程留言 when "Course" @@ -131,42 +131,42 @@ module ApplicationHelper CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :journal_num => 1) else score = course_contributor_score.journal_num.to_i + 1 - course_contributor_score.update_attributes(:journal_num => score) + course_contributor_score.update_column(:journal_num, score) end when "Message" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1) else score = course_contributor_score.message_num.to_i + 1 - course_contributor_score.update_attributes(:message_num => score) + course_contributor_score.update_column(:message_num, score) end when "MessageReply" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_reply_num => 1) else score = course_contributor_score.message_reply_num.to_i + 1 - course_contributor_score.update_attributes(:message_reply_num => score) + course_contributor_score.update_column(:message_reply_num, score) end when "NewReply" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_reply_num => 1) else score = course_contributor_score.news_reply_num.to_i + 1 - course_contributor_score.update_attributes(:news_reply_num => score) + course_contributor_score.update_column(:news_reply_num, score) end when "News" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_num => 1) else score = course_contributor_score.news_num.to_i + 1 - course_contributor_score.update_attributes(:news_num => score) + course_contributor_score.update_column(:news_num, score) end when "Attachment" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :resource_num => 1) else score = course_contributor_score.resource_num.to_i + 1 - course_contributor_score.update_attributes(:resource_num => score) + course_contributor_score.update_column(:resource_num, score) end end end @@ -178,38 +178,38 @@ module ApplicationHelper when "HomeworkCommon" unless course_contributor_score.nil? score = course_contributor_score.homework_journal_num.to_i - 1 - course_contributor_score.update_attribute(:homework_journal_num, score < 0 ? 0 : score) + course_contributor_score.update_column(:homework_journal_num, score < 0 ? 0 : score) end # 课程留言 when "Course" unless course_contributor_score.nil? score = course_contributor_score.journal_num.to_i - 1 - course_contributor_score.update_attribute(:journal_num, score < 0 ? 0 : score) + course_contributor_score.update_column(:journal_num, score < 0 ? 0 : score) end when "Message" unless course_contributor_score.nil? score = course_contributor_score.message_num.to_i - 1 - course_contributor_score.update_attribute(:message_num, score < 0 ? 0 : score) + course_contributor_score.update_column(:message_num, score < 0 ? 0 : score) end when "MessageReply" unless course_contributor_score.nil? score = course_contributor_score.message_reply_num.to_i - 1 - course_contributor_score.update_attribute(:message_reply_num, score < 0 ? 0 : score) + course_contributor_score.update_column(:message_reply_num, score < 0 ? 0 : score) end when "NewReply" unless course_contributor_score.nil? score = course_contributor_score.news_reply_num.to_i - 1 - course_contributor_score.update_attribute(:news_reply_num, score < 0 ? 0 : score) + course_contributor_score.update_column(:news_reply_num, score < 0 ? 0 : score) end when "News" unless course_contributor_score.nil? score = course_contributor_score.news_num.to_i - 1 - course_contributor_score.update_attribute(:news_num, score < 0 ? 0 : score) + course_contributor_score.update_column(:news_num, score < 0 ? 0 : score) end when "Attachment" unless course_contributor_score.nil? score = course_contributor_score.resource_num.to_i - 1 - course_contributor_score.update_attribute(:resource_num, score < 0 ? 0 : score) + course_contributor_score.update_column(:resource_num, score < 0 ? 0 : score) end end end @@ -2983,8 +2983,12 @@ def homework_common_index_url_in_org(course_id) Setting.protocol + "://" + Setting.host_name + "/homework_common?course=" + course_id.to_s end -def student_work_index_url_in_org(homework_id) - Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s +def student_work_index_url_in_org(homework_id, is_focus = '') + if is_focus != '' + Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s + "&is_focus=" + is_focus.to_s + else + Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s + end end def course_url_in_org(course_id) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 36187b460..3cf781f76 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -41,6 +41,23 @@ module RepositoriesHelper identifiers.include?(iden) ? false :true end + # 获取文件目录的最新动态 + def get_trees_last_changes(project_id, rev, ent_name) + g = Gitlab.client + begin + tree_changes = g.rep_last_changes(project_id, :rev => rev, :path => ent_name) + tree_changes + rescue + logger.error("faile to get tress activities!") + end + end + + def translate_time time + case time + when time.include("") + end + end + # 获取diff内容行号 def diff_line_num content content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.join("").to_i diff --git a/app/models/message.rb b/app/models/message.rb index e6df9493b..9a32dc590 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -261,7 +261,7 @@ class Message < ActiveRecord::Base ws = WechatService.new if self.course if self.parent_id.nil? # 主贴 - self.course.members.each do |m| + self.course.members.includes(:user).each do |m| if self.author.allowed_to?(:as_teacher, self.course) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息 self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) content = strip_html self.subject, 200 @@ -269,7 +269,7 @@ class Message < ActiveRecord::Base end end else # 回帖 - self.course.members.each do |m| + self.course.members.includes(:user).each do |m| if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) content = strip_html self.content.html_safe, 200 @@ -279,7 +279,7 @@ class Message < ActiveRecord::Base end elsif self.project # 项目相关 if self.parent_id.nil? # 主贴 - self.project.members.each do |m| + self.project.members.includes(:user).each do |m| if m.user_id != self.author_id self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false) content = strip_html self.subject, 200 @@ -287,7 +287,7 @@ class Message < ActiveRecord::Base end end else # 回帖 - self.project.members.each do |m| + self.project.members.includes(:user).each do |m| if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false) content = strip_html self.content.html_safe, 200 diff --git a/app/models/repository.rb b/app/models/repository.rb index 571bba1b9..305c82f97 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -44,7 +44,7 @@ class Repository < ActiveRecord::Base # validates_uniqueness_of :identifier, :allow_blank => true validates_exclusion_of :identifier, :in => %w(show entry raw changes annotate diff show stats graph) # donwcase letters, digits, dashes, underscores but not digits only - validates_format_of :identifier, :with => /^[a-z0-9_\-]+$/, :allow_blank => true + validates_format_of :identifier, :with => /^[a-zA-Z0-9_\-]*[a-zA-Z_\-]+[a-zA-Z0-9_\-]*$/, :allow_blank => true # Checks if the SCM is enabled when creating a repository validate :repo_create_validation, :on => :create diff --git a/app/views/admin/code_work_tests.html.erb b/app/views/admin/code_work_tests.html.erb index cb113f1e6..64c3a41e1 100644 --- a/app/views/admin/code_work_tests.html.erb +++ b/app/views/admin/code_work_tests.html.erb @@ -37,13 +37,21 @@ <% if test['homework_id'] != nil %> "> '> - <%=link_to(test['homework_id'], student_work_index_path(:homework => test['homework_id']))%> + <% if test['link_hwork'] %> + <%=link_to(test['homework_id'], student_work_index_path(:homework => test['homework_id']))%> + <% else %> + <%= test['homework_id'] %> + <% end %> '> - <% if !test['is_test'] %> - <%=link_to(test['student_work_id'], student_work_index_path(:homework => test['homework_id'],:student_work_id=>test['student_work_id']))%> + <% if test['link_swork'] && test['link_hwork'] %> + <% if !test['is_test'] %> + <%=link_to(test['student_work_id'], student_work_index_path(:homework => test['homework_id'],:student_work_id=>test['student_work_id']))%> + <% else %> + <%=link_to(test['student_work_id'], new_user_commit_homework_users_path(homework_id: test['homework_id'], is_test: true))%> + <% end %> <% else %> - <%=link_to(test['student_work_id'], new_user_commit_homework_users_path(homework_id: test['homework_id'], is_test: true))%> + <%= test['student_work_id'] %> <% end %> diff --git a/app/views/layouts/base_org.html.erb b/app/views/layouts/base_org.html.erb index faf141600..b2cfa9877 100644 --- a/app/views/layouts/base_org.html.erb +++ b/app/views/layouts/base_org.html.erb @@ -113,6 +113,9 @@ + <%# 更新访问数,刷新的时候更新访问次数 %> + <% update_visiti_count @organization %> + <%# over %>
diff --git a/app/views/layouts/base_org_newstyle.html.erb b/app/views/layouts/base_org_newstyle.html.erb index 64da94ebf..1fcf60d20 100644 --- a/app/views/layouts/base_org_newstyle.html.erb +++ b/app/views/layouts/base_org_newstyle.html.erb @@ -397,6 +397,9 @@ <% end %> <% end %> + <%# 更新访问数,刷新的时候更新访问次数 %> + <% update_visiti_count @organization %> + <%# over %>