diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 25cc85ae2..3f49abb23 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -599,8 +599,19 @@ class AdminController < ApplicationController #学校列表 def schools - + @order = "" + @sort = "" @schools = School.find_by_sql("SELECT * FROM schools ORDER BY created_at DESC") + if params[:sort] && (params[:order] == 'num') + @order = params[:order] + @sort = params[:sort] + @schools.each do |school| + count = UserExtensions.where("school_id = #{school.id} or occupation = '#{school.name}'").count + school[:infocount] = count.to_i + end + @sort == 'asc' ? (@schools = @schools.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@schools = @schools.sort{|x,y| y[:infocount] <=> x[:infocount]}) + end + @school_count = @schools.count @school_pages = Paginator.new @school_count, 30, params['page'] || 1 @@ -777,8 +788,15 @@ class AdminController < ApplicationController #留言列表 def leave_messages + notes1, notes2, notes3 = '', '', '' + begin + notes1 = Message.find(19292).content + notes2 = Message.find(19291).content + notes3 = Message.find(19504).content + rescue => e + end @jour = JournalsForMessage.find_by_sql("SELECT * FROM journals_for_messages AS j1 - WHERE j1.jour_type IN ('Course','Principal') AND (j1.m_parent_id IS NULL OR (j1.m_parent_id IN (SELECT id FROM journals_for_messages WHERE jour_type IN ('Course','Principal')))) order by created_on desc") + WHERE j1.jour_type IN ('Course','Principal') AND (j1.m_parent_id IS NULL OR (j1.m_parent_id IN (SELECT id FROM journals_for_messages WHERE jour_type IN ('Course','Principal')))) AND j1.notes !='#{notes1}' AND j1.notes !='#{notes2}' AND j1.notes !='#{notes3}' order by created_on desc") @jour = paginateHelper @jour,30 @page = (params['page'] || 1).to_i - 1 respond_to do |format| diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 7ec532d79..5d1345f24 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -1,3 +1,4 @@ +#encoding: utf-8 # Redmine - project management software # Copyright (C) 2006-2013 Jean-Philippe Lang # @@ -203,16 +204,51 @@ class AttachmentsController < ApplicationController @attachment.save @newfiledense = filedense end - if @project - - elsif @course - + if @attachment.container_type == "Project" || @attachment.container_type == "Course" + tip_attachment_update end + respond_to do |format| format.js end end + def tip_attachment_update + if params[:course_id] + @tip_all_attachments = Attachment.where(:container_type => "Course", :container_id => params[:course_id]) + @tip_all_public_attachments = Attachment.where(:container_type => "Course", :container_id => params[:course_id], :is_public => 1) + @tip_all_private_attachments = Attachment.where(:container_type => "Course", :container_id => params[:course_id], :is_public => 0) + @course = Course.find(params[:course_id]) + elsif params[:project_id] + @tip_all_attachments = Attachment.where(:container_type => "Project", :container_id => params[:project_id]) + @tip_all_public_attachments = Attachment.where(:container_type => "Project", :container_id => params[:project_id], :is_public => 1) + @tip_all_private_attachments = Attachment.where(:container_type => "Project", :container_id => params[:project_id], :is_public => 0) + @project = Project.find(params[:project_id]) + end + @tag_name = params[:tag_name] + @other = params[:other] + unless @tag_name.blank? + if @other + if @project + @tip_all_attachments = @tip_all_attachments.select{|attachment| !attachment.tag_list.include?('软件版本') && !attachment.tag_list.include?('文档') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('论文') } + @tip_all_public_attachments = @tip_all_public_attachments.select{|attachment| !attachment.tag_list.include?('软件版本') && !attachment.tag_list.include?('文档') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('论文') } + @tip_all_private_attachments = @tip_all_private_attachments.select{|attachment| !attachment.tag_list.include?('软件版本') && !attachment.tag_list.include?('文档') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('论文') } + elsif @course + @tip_all_attachments = @tip_all_attachments.select{|attachment| !attachment.tag_list.include?('课件') && !attachment.tag_list.include?('软件') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('论文') } + @tip_all_public_attachments = @tip_all_public_attachments.select{|attachment| !attachment.tag_list.include?('课件') && !attachment.tag_list.include?('软件') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('论文') } + @tip_all_private_attachments = @tip_all_private_attachments.select{|attachment| !attachment.tag_list.include?('课件') && !attachment.tag_list.include?('软件') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('论文') } + end + else + @tip_all_attachments = @tip_all_attachments.select{|attachment| attachment.tag_list.include?(@tag_name)} + @tip_all_public_attachments = @tip_all_public_attachments.select{|attachment| attachment.tag_list.include?(@tag_name)} + @tip_all_private_attachments = @tip_all_private_attachments.select{|attachment| attachment.tag_list.include?(@tag_name)} + end + end + @tip_all_attachments = @tip_all_attachments.count + @tip_all_public_attachments = @tip_all_public_attachments.count + @tip_all_private_attachments = @tip_all_private_attachments.count + end + def thumbnail if @attachment.thumbnailable? && thumbnail = @attachment.thumbnail(:size => params[:size]) if stale?(:etag => thumbnail) @@ -281,6 +317,7 @@ class AttachmentsController < ApplicationController @attachment.delete @flag = true end + # tip_attachment_update respond_to do |format| format.js diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index 9d90cb9f2..e80c56e49 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -40,7 +40,7 @@ class AvatarController < ApplicationController @urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file)) # 用户头像上传时进行特别处理 - if @is_direct == '1' && (@source_type == 'User' || @source_type == 'Course' || @source_type == 'Project') + if @is_direct == '1' && (@source_type == 'User' || @source_type == 'Course' || @source_type == 'Project' || @source_type == 'Organization') diskfile += "temp" @urlfile += "temp" end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2614b6271..e542d1e1d 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -331,7 +331,7 @@ class CoursesController < ApplicationController @all_members = searchTeacherAndAssistant(@course) @members = @all_members when '2' - if @course.open_student == 1 || User.current.member_of_course?(@course) + if @course.open_student == 1 || User.current.member_of_course?(@course) || User.current.admin? @subPage_title = l :label_student_list page = params[:page].nil? ? 0 : (params['page'].to_i - 1) @all_members = student_homework_score(0,page, 10,@score_sort_by,@sort_type) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 988768414..7318a4dc2 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -86,19 +86,20 @@ class FilesController < ApplicationController else @result = find_course_attache q,@course,sort @result = visable_attachemnts @result - # @searched_attach = paginateHelper @result,10 + # @searched_attach = paginateHelper @result,10 @tag_list = get_course_tag_list @course end @all_attachments = @result + get_attachment_for_tip(@all_attachments) @limit = 10 @feedback_count = @all_attachments.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @offset ||= @feedback_pages.offset #@curse_attachments_all = @all_attachments[@offset, @limit] @obj_attachments = paginateHelper @all_attachments,10 - #rescue Exception => e - # #render 'stores' - # redirect_to search_course_files_url + #rescue Exception => e + # #render 'stores' + # redirect_to search_course_files_url end end @@ -164,6 +165,7 @@ class FilesController < ApplicationController end @all_attachments = @project_attachment_result + get_attachment_for_tip(@all_attachments) @limit = 10 @feedback_count = @all_attachments.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @@ -176,52 +178,52 @@ class FilesController < ApplicationController end end - def search_files_in_subfield - sort = "" - @sort = "" - @order = "" - @is_remote = true - @q = params[:name].strip - if params[:sort] - order_by = params[:sort].split(":") - @sort = order_by[0] - if order_by.count > 1 - @order = order_by[1] - end - sort = "#{@sort} #{@order}" + def search_files_in_subfield + sort = "" + @sort = "" + @order = "" + @is_remote = true + @q = params[:name].strip + if params[:sort] + order_by = params[:sort].split(":") + @sort = order_by[0] + if order_by.count > 1 + @order = order_by[1] end - # show_attachments [@course] - begin - q = "%#{params[:name].strip}%" - #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? - if params[:insite] - if q == "%%" - @result = [] - @searched_attach = paginateHelper @result,10 - else - @result = find_public_attache q,sort - @result = visable_attachemnts_insite @result,@org_subfield - @searched_attach = paginateHelper @result,10 - end + sort = "#{@sort} #{@order}" + end + # show_attachments [@course] + begin + q = "%#{params[:name].strip}%" + #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? + if params[:insite] + if q == "%%" + @result = [] + @searched_attach = paginateHelper @result,10 else - @result = find_org_subfield_attache q,@org_subfield,sort - @result = visable_attachemnts @result + @result = find_public_attache q,sort + @result = visable_attachemnts_insite @result,@org_subfield @searched_attach = paginateHelper @result,10 - @tag_list = attachment_tag_list @result end - #rescue Exception => e - # #render 'stores' - # redirect_to search_course_files_url + else + @result = find_org_subfield_attache q,@org_subfield,sort + @result = visable_attachemnts @result + @searched_attach = paginateHelper @result,10 + @tag_list = attachment_tag_list @result end - @page = params[:page] || 1 + #rescue Exception => e + # #render 'stores' + # redirect_to search_course_files_url end + @page = params[:page] || 1 + end def find_course_attache keywords,course,sort = "" if sort == "" sort = "created_on DESC" end if keywords != "%%" - resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ", like: "%#{keywords}%").reorder(sort) + resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ", like: "%#{keywords}%").reorder(sort) else resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' "). reorder(sort) end @@ -250,7 +252,7 @@ class FilesController < ApplicationController else resultSet = Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' "). reorder(sort) end - end + end def find_public_attache keywords,sort = "" # StoresController#search 将每条文件都查出来,再次进行判断过滤。---> resultSet.to_a.map @@ -260,7 +262,7 @@ class FilesController < ApplicationController sort = "created_on DESC" end resultSet = Attachment.where("attachments.container_type IS NOT NULL AND attachments.copy_from IS NULL AND filename LIKE :like ", like: "%#{keywords}%"). - reorder(sort) + reorder(sort) end def index @@ -325,7 +327,7 @@ class FilesController < ApplicationController @containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)] show_attachments @containers - # get_attachment_for_tip(@all_attachments) + get_attachment_for_tip(@all_attachments) @tag_list = attachment_tag_list @all_attachments @@ -355,7 +357,7 @@ class FilesController < ApplicationController when "quotes" attribute = "quotes" else - attribute = "created_on" + attribute = "created_on" end @sort = order_by[0] @order = order_by[1] @@ -378,7 +380,7 @@ class FilesController < ApplicationController @containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)] show_attachments @containers - # get_attachment_for_tip(@all_attachments) + get_attachment_for_tip(@all_attachments) @tag_list = attachment_tag_list @all_attachments @@ -501,228 +503,228 @@ class FilesController < ApplicationController end def create - if params[:add_tag] - @addTag=true - #render :back + if params[:add_tag] + @addTag=true + #render :back tag_saveEx #render :text =>"success" respond_to do |format| - format.js - end - else - #modify by nwb - if @project - @addTag=false - if params[:in_project_toolbar] - @in_project_toolbar = params[:in_project_toolbar] - end - attachments = Attachment.attach_filesex(@project, params[:attachments], params[:attachment_type]) - if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') - # 发送邮件 - Mailer.run.attachments_added(attachments[:files]) - # 生成动态 - attachments[:files].each do |file| - ForgeActivity.create(:user_id => User.current.id, :project_id => @project.id, :forge_act_id => file.id, :forge_act_type => "Attachment") - end - # 更新资源总数, 根据上传的附件数累加 - @project.project_score.update_attribute(:attach_num, @project.project_score.attach_num + attachments[:files].count) unless @project.project_score.nil? - end - # end - if params[:project_attachment_type] && params[:project_attachment_type].is_a?(Array) - params[:project_attachment_type].each do |type| - tag_name = get_project_tag_name_by_type_nmuber type - if !attachments.empty? && attachments[:files] && tag_name != "" - attachments[:files].each do |attachment| - attachment.tag_list.add(tag_name) - attachment.description = params[:description] - attachment.save - end - end - end - else - if params[:project_attachment_type] && params[:project_attachment_type] != "6" - tag_name = get_project_tag_name_by_type_nmuber params[:project_attachment_type] - if !attachments.empty? && attachments[:files] && tag_name != "" - attachments[:files].each do |attachment| - attachment.tag_list.add(tag_name) - attachment.description = params[:description] - attachment.save - end - end - end - end - # TODO: 临时用 nyan - sort_init 'created_on', 'desc' - sort_update 'created_on' => "#{Attachment.table_name}.created_on", - 'filename' => "#{Attachment.table_name}.filename", - 'size' => "#{Attachment.table_name}.filesize", - 'downloads' => "#{Attachment.table_name}.downloads" - - @containers = [Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] - show_attachments @containers - @tag_list = attachment_tag_list @all_attachments - @attachtype = 0 - @contenttype = 0 - respond_to do |format| - format.js - format.html { - redirect_to project_files_url(@project) - } - end - elsif @course - @addTag=false - if params[:in_course_toolbar] - @in_course_toolbar = params[:in_course_toolbar] - end - attachments = Attachment.attach_filesex(@course, params[:attachments], params[:attachment_type]) - - if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') - Mailer.run.attachments_added(attachments[:files]) - end - if !attachments.empty? && attachments[:files] - attachments[:files].each do |attachment| - if params[:publish_time] - if params[:publish_time] == "" - attachment.publish_time = Date.today - else - attachment.publish_time = params[:publish_time] - end - else - attachment.publish_time = Date.today - end - if attachment.publish_time > Date.today - attachment.is_publish = 0 - end - attachment.description = params[:description] - attachment.save - end - end - if params[:course_attachment_type] && params[:course_attachment_type].is_a?(Array) - params[:course_attachment_type].each do |type| - tag_name = get_tag_name_by_type_number type - if !attachments.empty? && attachments[:files] && tag_name != "" - attachments[:files].each do |attachment| - attachment.tag_list.add(tag_name) - attachment.save - end - end - end - else - if params[:course_attachment_type] && params[:course_attachment_type] != "5" - tag_name = get_tag_name_by_type_number params[:course_attachment_type] - if !attachments.empty? && attachments[:files] && tag_name != "" - attachments[:files].each do |attachment| - attachment.tag_list.add(tag_name) - attachment.save - end - end - end - end - # 更新课程英雄榜得分 - course_member_score(@course.id, attachments[:files].first.author_id, "Attachment") - # end - # end - # TODO: 临时用 nyan - sort_init 'created_on', 'desc' - sort_update 'created_on' => "#{Attachment.table_name}.created_on", - 'filename' => "#{Attachment.table_name}.filename", - 'size' => "#{Attachment.table_name}.filesize", - 'downloads' => "#{Attachment.table_name}.downloads" - - @containers = [Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)] - - show_attachments @containers - @tag_list = attachment_tag_list @all_attachments - - @attachtype = 0 - @contenttype = 0 - - respond_to do |format| - format.js - format.html { - redirect_to course_files_url(@course) - } - end - elsif @org_subfield - @addTag=false - attachments = Attachment.attach_filesex(@org_subfield, params[:attachments], params[:org_subfield_attachment_type]) - - if params[:org_subfield_attachment_type] && params[:org_subfield_attachment_type].is_a?(Array) - params[:org_subfield_attachment_type].each do |type| - tag_name = get_tag_name_by_type_number type - if !attachments.empty? && attachments[:files] && tag_name != "" - attachments[:files].each do |attachment| - attachment.tag_list.add(tag_name) - attachment.description = params[:description] - attachment.save - end - end - end - else - if params[:org_subfield_attachment_type] && params[:org_subfield_attachment_type] != "5" - tag_name = get_tag_name_by_type_number params[:org_subfield_attachment_type] - if !attachments.empty? && attachments[:files] && tag_name != "" - attachments[:files].each do |attachment| - attachment.tag_list.add(tag_name) - attachment.description = params[:description] - attachment.save - end - end - end - end - - # TODO: 临时用 nyan - sort_init 'created_on', 'desc' - sort_update 'created_on' => "#{Attachment.table_name}.created_on", - 'filename' => "#{Attachment.table_name}.filename", - 'size' => "#{Attachment.table_name}.filesize", - 'downloads' => "#{Attachment.table_name}.downloads" - - @containers = [OrgSubfield.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@org_subfield.id)] - - show_attachments @containers - @tag_list = attachment_tag_list @all_attachments - @attachtype = 0 - @contenttype = 0 - - respond_to do |format| - format.js - # format.html { - # redirect_to org_subfield_files_url(@org_subfield) - # } - end - # 组织添加附件,为了修改图片 - elsif params[:organization_id] - @organization = Organization.find(params[:organization_id]) - @addTag=false - # atttchment_type = 0为logo 1为banner - if params[:logo] - attachments = Attachment.attach_filesex(@organization, params[:attachments], false) - else - attachments = Attachment.attach_filesex(@organization, params[:attachments], true) - end - # TODO: 临时用 nyan - sort_init 'created_on', 'desc' - sort_update 'created_on' => "#{Attachment.table_name}.created_on", - 'filename' => "#{Attachment.table_name}.filename", - 'size' => "#{Attachment.table_name}.filesize", - 'downloads' => "#{Attachment.table_name}.downloads" - - @containers = [Organization.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@organization.id)] - - show_attachments @containers - @tag_list = attachment_tag_list @all_attachments - @attachtype = 0 - @contenttype = 0 - - respond_to do |format| - format.js - # format.html { - # redirect_to org_subfield_files_url(@org_subfield) - # } - end - end - end + format.js + end + else + #modify by nwb + if @project + @addTag=false + if params[:in_project_toolbar] + @in_project_toolbar = params[:in_project_toolbar] + end + attachments = Attachment.attach_filesex(@project, params[:attachments], params[:attachment_type]) + if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') + # 发送邮件 + Mailer.run.attachments_added(attachments[:files]) + # 生成动态 + attachments[:files].each do |file| + ForgeActivity.create(:user_id => User.current.id, :project_id => @project.id, :forge_act_id => file.id, :forge_act_type => "Attachment") + end + # 更新资源总数, 根据上传的附件数累加 + @project.project_score.update_attribute(:attach_num, @project.project_score.attach_num + attachments[:files].count) unless @project.project_score.nil? + end + # end + if params[:project_attachment_type] && params[:project_attachment_type].is_a?(Array) + params[:project_attachment_type].each do |type| + tag_name = get_project_tag_name_by_type_nmuber type + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.description = params[:description] + attachment.save + end + end + end + else + if params[:project_attachment_type] && params[:project_attachment_type] != "6" + tag_name = get_project_tag_name_by_type_nmuber params[:project_attachment_type] + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.description = params[:description] + attachment.save + end + end + end + end + # TODO: 临时用 nyan + sort_init 'created_on', 'desc' + sort_update 'created_on' => "#{Attachment.table_name}.created_on", + 'filename' => "#{Attachment.table_name}.filename", + 'size' => "#{Attachment.table_name}.filesize", + 'downloads' => "#{Attachment.table_name}.downloads" + + @containers = [Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] + show_attachments @containers + @tag_list = attachment_tag_list @all_attachments + @attachtype = 0 + @contenttype = 0 + respond_to do |format| + format.js + format.html { + redirect_to project_files_url(@project) + } + end + elsif @course + @addTag=false + if params[:in_course_toolbar] + @in_course_toolbar = params[:in_course_toolbar] + end + attachments = Attachment.attach_filesex(@course, params[:attachments], params[:attachment_type]) + + if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') + Mailer.run.attachments_added(attachments[:files]) + end + if !attachments.empty? && attachments[:files] + attachments[:files].each do |attachment| + if params[:publish_time] + if params[:publish_time] == "" + attachment.publish_time = Date.today + else + attachment.publish_time = params[:publish_time] + end + else + attachment.publish_time = Date.today + end + if attachment.publish_time > Date.today + attachment.is_publish = 0 + end + attachment.description = params[:description] + attachment.save + end + end + if params[:course_attachment_type] && params[:course_attachment_type].is_a?(Array) + params[:course_attachment_type].each do |type| + tag_name = get_tag_name_by_type_number type + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.save + end + end + end + else + if params[:course_attachment_type] && params[:course_attachment_type] != "5" + tag_name = get_tag_name_by_type_number params[:course_attachment_type] + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.save + end + end + end + end + # 更新课程英雄榜得分 + course_member_score(@course.id, attachments[:files].first.author_id, "Attachment") + # end + # end + # TODO: 临时用 nyan + sort_init 'created_on', 'desc' + sort_update 'created_on' => "#{Attachment.table_name}.created_on", + 'filename' => "#{Attachment.table_name}.filename", + 'size' => "#{Attachment.table_name}.filesize", + 'downloads' => "#{Attachment.table_name}.downloads" + + @containers = [Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)] + + show_attachments @containers + @tag_list = attachment_tag_list @all_attachments + + @attachtype = 0 + @contenttype = 0 + + respond_to do |format| + format.js + format.html { + redirect_to course_files_url(@course) + } + end + elsif @org_subfield + @addTag=false + attachments = Attachment.attach_filesex(@org_subfield, params[:attachments], params[:org_subfield_attachment_type]) + + if params[:org_subfield_attachment_type] && params[:org_subfield_attachment_type].is_a?(Array) + params[:org_subfield_attachment_type].each do |type| + tag_name = get_tag_name_by_type_number type + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.description = params[:description] + attachment.save + end + end + end + else + if params[:org_subfield_attachment_type] && params[:org_subfield_attachment_type] != "5" + tag_name = get_tag_name_by_type_number params[:org_subfield_attachment_type] + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.description = params[:description] + attachment.save + end + end + end + end + + # TODO: 临时用 nyan + sort_init 'created_on', 'desc' + sort_update 'created_on' => "#{Attachment.table_name}.created_on", + 'filename' => "#{Attachment.table_name}.filename", + 'size' => "#{Attachment.table_name}.filesize", + 'downloads' => "#{Attachment.table_name}.downloads" + + @containers = [OrgSubfield.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@org_subfield.id)] + + show_attachments @containers + @tag_list = attachment_tag_list @all_attachments + @attachtype = 0 + @contenttype = 0 + + respond_to do |format| + format.js + # format.html { + # redirect_to org_subfield_files_url(@org_subfield) + # } + end + # 组织添加附件,为了修改图片 + elsif params[:organization_id] + @organization = Organization.find(params[:organization_id]) + @addTag=false + # atttchment_type = 0为logo 1为banner + if params[:logo] + attachments = Attachment.attach_filesex(@organization, params[:attachments], false) + else + attachments = Attachment.attach_filesex(@organization, params[:attachments], true) + end + # TODO: 临时用 nyan + sort_init 'created_on', 'desc' + sort_update 'created_on' => "#{Attachment.table_name}.created_on", + 'filename' => "#{Attachment.table_name}.filename", + 'size' => "#{Attachment.table_name}.filesize", + 'downloads' => "#{Attachment.table_name}.downloads" + + @containers = [Organization.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@organization.id)] + + show_attachments @containers + @tag_list = attachment_tag_list @all_attachments + @attachtype = 0 + @contenttype = 0 + + respond_to do |format| + format.js + # format.html { + # redirect_to org_subfield_files_url(@org_subfield) + # } + end + end + end end def get_project_tag_name_by_type_nmuber type @@ -798,13 +800,13 @@ class FilesController < ApplicationController else #捕获异常 end - end + end # 返回指定资源类型的资源列表 # added by nwb def getattachtype - sort_init 'created_on', 'desc' - sort_update 'created_on' => "#{Attachment.table_name}.created_on", + sort_init 'created_on', 'desc' + sort_update 'created_on' => "#{Attachment.table_name}.created_on", 'filename' => "#{Attachment.table_name}.filename", 'size' => "#{Attachment.table_name}.filesize", 'downloads' => "#{Attachment.table_name}.downloads" @@ -842,27 +844,27 @@ class FilesController < ApplicationController end end - if @project - @isproject = true - @containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] - @containers += @project.versions.includes(:attachments).reorder(sort).all - show_attachments @containers - @attachtype = params[:type].to_i - @contenttype = params[:contentType].to_s + if @project + @isproject = true + @containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] + @containers += @project.versions.includes(:attachments).reorder(sort).all + show_attachments @containers + @attachtype = params[:type].to_i + @contenttype = params[:contentType].to_s respond_to do |format| format.js - format.html { - render :layout => 'base_projects' - } + format.html { + render :layout => 'base_projects' + } end - elsif @course + elsif @course @isproject = false @containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)] show_attachments @containers @attachtype = params[:type].to_i @contenttype = params[:contentType].to_s - # render layout: 'base_courses' + # render layout: 'base_courses' @left_nav_type = 5 respond_to do |format| format.js @@ -870,19 +872,19 @@ class FilesController < ApplicationController render :layout => 'base_courses' } end - else - show_attachments @containers - @attachtype = params[:type].to_i - @contenttype = params[:contentType].to_s + else + show_attachments @containers + @attachtype = params[:type].to_i + @contenttype = params[:contentType].to_s - respond_to do |format| + respond_to do |format| format.js format.html - end - end + end + end end - #查找指定TAG的按条件过滤的资源列表,只有课程内搜索有此功能 + #查找指定TAG的按条件过滤的资源列表,只有课程内搜索有此功能 def search_tag_attachment @q,@tag_name,@order = params[:q],params[:tag_name] @is_remote = true diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index c4935a1af..ca6484e49 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -96,6 +96,9 @@ class MyController < ApplicationController elsif params[:project] @project = Project.find params[:project] diskfile = disk_filename('Project', @project.id) + elsif params[:organization] + @organization = Organization.find params[:organization] + diskfile = disk_filename('Organization', @organization.id) else @user = User.current diskfile = disk_filename('User', @user.id) @@ -116,6 +119,9 @@ class MyController < ApplicationController when 'Project' @project = Project.find params[:source_id] diskfile = disk_filename('Project', @project.id) + when 'Organization' + @organization = Organization.find params[:source_id] + diskfile = disk_filename('Organization', @organization.id) end end diskfile1 = diskfile + 'temp' diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index 3a9eff0ce..365889640 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -16,8 +16,8 @@ class QualityAnalysisController < ApplicationController end # params 说明:{identifier:版本库名} + # type: 1 新的分析 2 重新分析 def create - logger.info("11111111111111111111111111111") begin user_name = User.find(params[:user_id]).try(:login) identifier = params[:identifier] @@ -30,98 +30,98 @@ class QualityAnalysisController < ApplicationController # 考虑到历史数据:有些用户创建类job但是build失败,即sonar没有结果,这个时候需要把job删除,并且删掉quality_analyses表数据 # 如果不要这句则需要迁移数据 @sonar_address = Redmine::Configuration['sonar_address'] - projects_date = open(@sonar_address + "/api/projects/index").read - arr = JSON.parse(projects_date).map {|m| m["nm"]} # eg: ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"] - quality_an = QualityAnalysis.where(:sonar_name => sonar_name).first - if @client_jenkins.job.exists?(job_name) && QualityAnalysis.where(:sonar_name => sonar_name).select{|qa| arr.include?(qa.sonar_name)}.blank? - aa = @client_jenkins.job.delete("#{job_name}") - quality_an.delete unless quality_an.blank? - end + # projects_date = open(@sonar_address + "/api/projects/index").read + # arr = JSON.parse(projects_date).map {|m| m["nm"]} # eg: ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"] + quality_an = QualityAnalysis.where(:sonar_name => sonar_name) + # if @client_jenkins.job.exists?(job_name) && QualityAnalysis.where(:sonar_name => sonar_name).select{|qa| arr.include?(qa.sonar_name)}.blank? + # aa = @client_jenkins.job.delete("#{job_name}") + # quality_an.delete unless quality_an.blank? + # end + + # type 1的时候之所以判断job是否存在,为了防止特殊情况,正常情况是不会出现的 + # 重新分析的时候需要删除以前的分析结果 + @client_jenkins.job.delete("#{job_name}") if @client_jenkins.job.exists?(job_name) + quality_an.delete_all unless quality_an.blank? # Checks if the given job exists in Jenkins. - unless @client_jenkins.job.exists?(job_name) - @g = Gitlab.client - branch = params[:branch] - language = swith_language_type(params[:language]) - path = params[:path].blank? ? "./" : params[:path] - # qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first - version = quality_an.nil? ? 1 : quality_an.sonar_version + 1 - properties = "sonar.projectKey=#{sonar_name} + @g = Gitlab.client + branch = params[:branch] + language = swith_language_type(params[:language]) + path = params[:path].blank? ? "./" : params[:path] + # qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first + version = 1 + properties = "sonar.projectKey=#{sonar_name} sonar.projectName=#{sonar_name} sonar.projectVersion=#{version} sonar.sources=#{path} sonar.language=#{language.downcase} sonar.sourceEncoding=utf-8" - git_url = @gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git" - - # 替换配置文件 - @doc = Nokogiri::XML(File.open(File.join(Rails.root, 'tmp', 'config.xml'))) - @doc.at_xpath("//hudson.plugins.git.UserRemoteConfig/url").content = git_url - @doc.at_xpath("//hudson.plugins.git.BranchSpec/name").content = "*/#{branch}" - @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties # sonar-properties - - # jenkins job创建 - jenkins_job = @client_jenkins.job.create("#{job_name}", @doc.to_xml) - logger.info("Jenkins status of create ==> #{jenkins_job}") - - # 将地址作为hook值添加到gitlab - @g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{job_name}") - # job创建完成后自动运行job,如果运行成功则返回‘200’ - code = @client_jenkins.job.build("#{job_name}") - logger.error("build result ==> #{code}") - - # 判断调用sonar分析是否成功 - # 等待启动时间处理, 最长时间为30分钟 - for i in 0..360 do - sleep(5) - @current_build_status = @client_jenkins.job.get_current_build_status("#{job_name}") - if (@current_build_status == "success" || @current_build_status == "failure") + git_url = @gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git" + + # 替换配置文件 + @doc = Nokogiri::XML(File.open(File.join(Rails.root, 'tmp', 'config.xml'))) + @doc.at_xpath("//hudson.plugins.git.UserRemoteConfig/url").content = git_url + @doc.at_xpath("//hudson.plugins.git.BranchSpec/name").content = "*/#{branch}" + @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties # sonar-properties + + # jenkins job创建 + jenkins_job = @client_jenkins.job.create("#{job_name}", @doc.to_xml) + + # 将地址作为hook值添加到gitlab + # @g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{job_name}") + # job创建完成后自动运行job,如果运行成功则返回‘200’ + code = @client_jenkins.job.build("#{job_name}") + + # 判断调用sonar分析是否成功 + # 等待启动时间处理, 最长时间为30分钟 + for i in 0..360 do + sleep(5) + @current_build_status = @client_jenkins.job.get_current_build_status("#{job_name}") + if (@current_build_status == "success" || @current_build_status == "failure") + break + if i == 360 + @build_console_result = false break - if i == 360 - @build_console_result = false - break - end end end + end - # sonar 缓冲,sonar生成数据 - sleep(10) + # sonar 缓冲,sonar生成数据 + sleep(10) - # 获取sonar output结果 - console_build = @client_jenkins.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')["output"] - logger.info("@current_build_status is ==> #{@current_build_status}") + # 获取sonar output结果 + console_build = @client_jenkins.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')["output"] + logger.info("@current_build_status is ==> #{@current_build_status}") - # 两种情况需要删除job: - # 1/创建成功但是build失败则删除job - # 2/creat和build成功,调用sonar启动失败则删除job - # 错误信息存储需存到Trustie数据库,否则一旦job删除则无法获取这些信息 - if jenkins_job == '200' && code != '201' + # 两种情况需要删除job: + # 1/创建成功但是build失败则删除job + # 2/creat和build成功,调用sonar启动失败则删除job + # 错误信息存储需存到Trustie数据库,否则一旦job删除则无法获取这些信息 + if jenkins_job == '200' && code != '201' + @client_jenkins.job.delete("#{job_name}") + else + if @current_build_status == "failure" + reg_console = /Exception:.*?\r/.match(console_build) + output = reg_console[0].gsub("\r", "") unless reg_console.nil? + se = SonarError.where(:jenkins_job_name => job_name).first + se.nil? ? SonarError.create(:project_id => @project.id, :jenkins_job_name => job_name, :output => output) : se.update_column(:output, output) @client_jenkins.job.delete("#{job_name}") - else - if @current_build_status == "failure" - reg_console = /Exception:.*?\r/.match(console_build) - output = reg_console[0].gsub("\r", "") unless reg_console.nil? - se = SonarError.where(:jenkins_job_name => job_name).first - se.nil? ? SonarError.create(:project_id => @project.id, :jenkins_job_name => job_name, :output => output) : se.update_column(:output, output) - @client_jenkins.job.delete("#{job_name}") - elsif @current_build_status == "success" - if quality_an.blank? - QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, - :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => "#{user_name}:#{rep_id}") - else - qa.update_attribute(:sonar_version, version) - end + elsif @current_build_status == "success" + if quality_an.blank? + QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, + :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => "#{user_name}:#{rep_id}") end end + end - respond_to do |format| - if @current_build_status == "success" - format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch, :current_build_status => @current_build_status, :job_name => job_name)} - elsif @current_build_status == "failure" - format.html{redirect_to error_list_project_quality_analysi_path(:project_id => @project.id, :job_name => job_name)} - end + respond_to do |format| + if @current_build_status == "success" + format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch, :current_build_status => @current_build_status, :job_name => job_name)} + elsif @current_build_status == "failure" + format.html{redirect_to error_list_project_quality_analysi_path(:project_id => @project.id, :job_name => job_name)} end end + rescue => e @message = e.message logger.error("######################====>#{e.message}") @@ -302,10 +302,8 @@ class QualityAnalysisController < ApplicationController @jenkins_address = Redmine::Configuration['jenkins_address'] jenkins_username = Redmine::Configuration['jenkins_username'] jenkins_password = Redmine::Configuration['jenkins_password'] - logger.info("22222222222222222222222222222222") # connect jenkins @client_jenkins = JenkinsApi::Client.new(:server_url => @jenkins_address, :username => jenkins_username, :password => jenkins_password) - logger.info("333333333333333333333333333333") rescue => e logger.error("failed to connect Jenkins ==> #{e}") end diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 5e13149df..64f85b5db 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -1402,7 +1402,7 @@ class StudentWorkController < ApplicationController end def find_or_save_student_work(is_test) - student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first + student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id, is_test: is_test).first if student_work.nil? @homework.student_works.build( name: params[:title], @@ -1413,7 +1413,7 @@ class StudentWorkController < ApplicationController unless @homework.save logger.debug @homework.errors.full_messages else - student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first + student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id, is_test: is_test).first end end student_work diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b385fe610..8e729b083 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -983,7 +983,7 @@ class UsersController < ApplicationController @user = User.current @homework = HomeworkCommon.find(params[:homework_id]) @is_test = params[:is_test] == 'true' - @student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first + @student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id, is_test: @is_test).first if @student_work.nil? @student_work = StudentWork.new end @@ -1660,55 +1660,117 @@ class UsersController < ApplicationController course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')" project_types = "('Message','Issue','Project')" principal_types = "JournalsForMessage" + container_type = '' + act_type = '' if params[:type].present? case params[:type] when "course_homework" - @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'HomeworkCommon'").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Course' + act_type = 'HomeworkCommon' when "course_news" - @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'News'").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Course' + act_type = 'News' when "course_message" - @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Course' + act_type = 'Message' when "course_poll" - @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Poll'").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Course' + act_type = 'Poll' when "course_journals" - @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'JournalsForMessage'").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Course' + act_type = 'JournalsForMessage' when "project_issue" - @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Project' + act_type = 'Issue' when "project_message" - @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Course' + act_type = 'Message' when "user_journals" - @user_activities = UserActivity.where("container_type = 'Principal' and act_type= 'JournalsForMessage' and container_id = #{@user.id}").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Principal' + act_type = 'JournalsForMessage' when "current_user" - @user_activities = UserActivity.where("user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))").order('updated_at desc').limit(10).offset(@page * 10) - else - if @user == User.current - blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" - else - blog_ids = "("+@user.blog.id.to_s+")" - end - @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ - "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) + container_type = 'Principal' + act_type = 'Principal' + end + end + if container_type != '' && act_type != '' + if container_type == 'Course' + sql = "container_type = '#{container_type}' and container_id in #{user_course_ids} and act_type = '#{act_type}'" + elsif container_type == 'Project' + sql = "container_type = '#{container_type}' and container_id in #{user_project_ids} and act_type = '#{act_type}'" + elsif container_type == 'Principal' && act_type == 'JournalsForMessage' + sql = "container_type = '#{container_type}' and act_type= '#{act_type}' and container_id = #{@user.id}" + elsif container_type == 'Principal' && act_type == 'Principal' + sql = "user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))" + end + if User.current != @user + sql += "and user_id = #{@user.id}" end else - # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) - # blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" - # 减少数据库交互 - if @user == User.current - watched_user_ids = User.watched_by(@user.id).count == 0 ? " " : ("," + User.watched_by(@user.id).map{|u| u.id.to_s }.join(',')) - user_ids = "(" + @user.id.to_s + watched_user_ids + ")" + if User.current != @user + blog_ids = "("+@user.blog.id.to_s+")" + sql = "user_id = #{@user.id} and((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids}))" else - user_ids = "(" + @user.id.to_s + ")" - end - watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}") - blog_ids = watched_user_blog_ids.empty? ? "(-1)" : "(" + watched_user_blog_ids.map { |blog| blog.id}.join(",") + ")" - - @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ - "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) - end + blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" + sql = "(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})" + end + end + @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) + # if params[:type].present? + # case params[:type] + # when "course_homework" + # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'HomeworkCommon'").order('updated_at desc').limit(10).offset(@page * 10) + # when "course_news" + # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'News'").order('updated_at desc').limit(10).offset(@page * 10) + # when "course_message" + # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) + # when "course_poll" + # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Poll'").order('updated_at desc').limit(10).offset(@page * 10) + # when "course_journals" + # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'JournalsForMessage'").order('updated_at desc').limit(10).offset(@page * 10) + # when "project_issue" + # @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('updated_at desc').limit(10).offset(@page * 10) + # when "project_message" + # @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) + # when "user_journals" + # @user_activities = UserActivity.where("container_type = 'Principal' and act_type= 'JournalsForMessage' and container_id = #{@user.id}").order('updated_at desc').limit(10).offset(@page * 10) + # when "current_user" + # @user_activities = UserActivity.where("user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))").order('updated_at desc').limit(10).offset(@page * 10) + # else + # if @user == User.current + # blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" + # else + # blog_ids = "("+@user.blog.id.to_s+")" + # end + # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + # "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + # "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + + # "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) + # end + # else + # # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) + # # blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" + # # 减少数据库交互 + # if @user == User.current + # watched_user_ids = User.watched_by(@user.id).count == 0 ? " " : ("," + User.watched_by(@user.id).map{|u| u.id.to_s }.join(',')) + # user_ids = "(" + @user.id.to_s + watched_user_ids + ")" + # else + # user_ids = "(" + @user.id.to_s + ")" + # end + # watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}") + # blog_ids = watched_user_blog_ids.empty? ? "(-1)" : "(" + watched_user_blog_ids.map { |blog| blog.id}.join(",") + ")" + # + # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + # "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + # "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + + # "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) + # end # @user_activities = paginateHelper @user_activities,500 @type = params[:type] respond_to do |format| diff --git a/app/helpers/school_helper.rb b/app/helpers/school_helper.rb index 075d2b039..daa0550ef 100644 --- a/app/helpers/school_helper.rb +++ b/app/helpers/school_helper.rb @@ -1,6 +1,6 @@ module SchoolHelper def schoolMember_num school - count = student_num(school) + teacher_num(school) + count = UserExtensions.where("school_id = #{school.id} or occupation = '#{school.name}'").count count.to_s end diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index 4f0a2ca6d..2ecb5516f 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -22,8 +22,12 @@ module StudentWorkHelper end #获取指定用户对某一作业的评分结果 - def student_work_score work,user - StudentWorksScore.where(:user_id => user.id,:student_work_id => work.id).last + def student_work_score work,user,reviewer_role=0 + if reviewer_role != 0 + StudentWorksScore.where(:user_id => user.id,:student_work_id => work.id,:reviewer_role => reviewer_role).last + else + StudentWorksScore.where(:user_id => user.id,:student_work_id => work.id).last + end end #获取指定评分的角色 diff --git a/app/models/at_message.rb b/app/models/at_message.rb index 4c3ca9b74..5a175fe76 100644 --- a/app/models/at_message.rb +++ b/app/models/at_message.rb @@ -184,8 +184,10 @@ class AtMessage < ActiveRecord::Base when 'JournalsForMessage' if at_message.jour_type == 'Principal' {controller: :users, action: :user_messages, id: at_message.at_user} - else + elsif at_message.jour_type == 'HomeworkCommon' {controller: :homework_common, action: :index, course: at_message.jour.course_id} + elsif at_message.jour_type == 'Course' + {controller: :courses, action: :feedback, id: at_message.jour_id} end else diff --git a/app/views/admin/schools.html.erb b/app/views/admin/schools.html.erb index f52d1f060..42bec6551 100644 --- a/app/views/admin/schools.html.erb +++ b/app/views/admin/schools.html.erb @@ -20,8 +20,8 @@