diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 1478bceae..374e26431 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1177,7 +1177,7 @@ class CoursesController < ApplicationController AND homework_commons.course_id = #{@course.id} AND student_works.user_id = members.user_id ) AS score,(SELECT (message_num*2 + message_reply_num*1 + news_reply_num*1 + news_num*1 + - resource_num*5 + journal_num*1 + homework_journal_num*1 ) FROM `course_contributor_scores` AS ccs WHERE ccs.course_id = 577 AND ccs.user_id = members.user_id + resource_num*5 + journal_num*1 + homework_journal_num*1 ) FROM `course_contributor_scores` AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id ) AS act_score FROM members JOIN students_for_courses @@ -1191,7 +1191,7 @@ class CoursesController < ApplicationController AND homework_commons.course_id = #{@course.id} AND student_works.user_id = members.user_id ) AS score,(SELECT (message_num*2 + message_reply_num*1 + news_reply_num*1 + news_num*1 + - resource_num*5 + journal_num*1 + homework_journal_num*1 ) FROM `course_contributor_scores` AS ccs WHERE ccs.course_id = 577 AND ccs.user_id = members.user_id + resource_num*5 + journal_num*1 + homework_journal_num*1 ) FROM `course_contributor_scores` AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id ) AS act_score FROM members JOIN students_for_courses diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index cf94da8d9..7ec796b61 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -256,6 +256,13 @@ class FilesController < ApplicationController @order = "" @is_remote = false if params[:project_id] + # 更新资源申请消息为已读 + # ar_ids = ApplyResource.where("user_id =? and container_id =? and container_type =?", User.current.id, params[:project_id].to_i, "Project").map{|ar| ar.id} + # cms = CourseMessage.where("course_message_type =? and user_id =? and course_message_id in (#{ar_ids.empty? ? '0': ar_ids.join(',')})", "ApplyResource", User.current.id) + # cms.each do |cm| + # cm.update_column(:viewed, true) + # end + # over @page = params[:page] ? params[:page].to_i + 1 : 2 @container_type = 0 if params[:sort] diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 1946378ef..3ab62bbea 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -164,7 +164,7 @@ class OrganizationsController < ApplicationController return end q = params[:search].nil? ? "" : "#{params[:search].strip}" - @field = OrgSubfield.find(params[:org_subfield_id]) + @field = params[:org_subfield_id].nil? ? OrgSubfield.where("organization_id =? and field_type =?", params[:id].to_i, "Comptec").first : OrgSubfield.find(params[:org_subfield_id]) @type = params[:type] if @type == "courses" || @type.nil? @org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 1d7b4117d..e4cf31f55 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -423,9 +423,13 @@ class PollController < ApplicationController # 将其他地方的问卷导出来 def other_poll # 查作者是我,或者作者是当前课程的老师,且不在当前课程内的问卷 进行导入 - tea_ids = '(' - tea_ids << Course.find(params[:polls_group_id]).tea_id.to_s << ','<< User.current.id.to_s << ')' - @polls = Poll.where("user_id in #{tea_ids} and polls_type = 'course' and polls_group_id != #{params[:polls_group_id]}") + courses = User.current.courses.select { |course| User.current.allowed_to?(:as_teacher,course)} + course_ids = courses.empty? ? "(-1)" : "(" + courses.map { |course| course.id}.join(',') + ")" + none_courses = User.current.courses.where("is_delete = 1 or #{Course.table_name}.id = #{params[:polls_group_id].to_i}") + none_course_ids = none_courses.empty? ? "(-1)" : "(" + none_courses.map { |course| course.id}.join(',') + ")" + #tea_ids = '(' + #tea_ids << Course.find(params[:polls_group_id]).tea_id.to_s << ','<< User.current.id.to_s << ')' + @polls = Poll.where("(user_id = #{User.current.id} or polls_group_id in #{course_ids}) and polls_type = 'course' and polls_group_id not in #{none_course_ids}") @polls_group_id = params[:polls_group_id] respond_to do |format| format.js diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 4a148bb8b..531f0cb90 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -362,6 +362,8 @@ update # project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT # ip = RepositoriesHelper::REPO_IP_ADDRESS gitlab_address = Redmine::Configuration['gitlab_address'] + # REDO:需优化,仅测试用 + @zip_path = gitlab_address.to_s + "/api/v3/projects/" + @project.gpid.to_s + "/repository/archive?&private_token=YTyCv4978MXmdL2B9C62" if @repository.type.to_s == "Repository::Gitlab" @repos_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+@repository.identifier+"."+"git" else diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 7da42bd24..f518f81da 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -376,6 +376,7 @@ class StudentWorkController < ApplicationController ################################################################################################################## @order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name] || "",params[:group] @homework_commons = @course.homework_commons.where("publish_time <= ?",Time.now.strftime("%Y-%m-%d")).order("created_at desc") + @all_homework_commons = @course.homework_commons.order("created_at desc") @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? @is_evaluation = @homework.homework_detail_manual && @homework.homework_detail_manual.comment_status == 2 && !@is_teacher #是不是匿评 @show_all = false diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f3e0908ba..52fdad2e7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -311,6 +311,28 @@ class UsersController < ApplicationController end end + # 处理资源引用请求 + # status + def deal_with_apply_resource + @msg = CourseMessage.find(params[:msg_id]) + ar = ApplyResource.where("id = ?", @msg.course_message_id).first + unless ar.nil? + case params[:agree] + when 'Y' + ar.update_column('status', 2) + @msg.update_attributes(:apply_result => 1, :viewed => 1) + ar.course_messages << CourseMessage.new(:user_id => ar.user_id, :course_id => -1, :viewed => false, :apply_result => 2, :status => 1) + when 'N' + ar.update_column('status', 3) + @msg.update_attributes(:apply_result => 2, :viewed => 1) + ar.course_messages << CourseMessage.new(:user_id => ar.user_id, :course_id => -1, :viewed => false, :apply_result => 3, :status => 1) + end + end + respond_to do |format| + format.js + end + end + #处理引用作业的请求 #status 1 同意 2 拒绝 def dealwith_apply_homework @@ -419,6 +441,19 @@ class UsersController < ApplicationController end # end + # 资源分享请求弹框 + def apply_resource + if User.current.logged? + @attachment = Attachment.find params[:attachment_id] + @state = 2 + else + @state = 1 + end + respond_to do |format| + format.js + end + end + #引用作业请求弹框 def apply_homework if User.current.logged? @@ -432,6 +467,27 @@ class UsersController < ApplicationController end end + # 申请引用资源 + def apply_for_resource + if User.current.logged? + @attachment = Attachment.where("id =?", params[:attachment_id].to_i).first + unless @attachment.nil? + ar = ApplyResource.where("user_id = ? and attachment_id = ?", User.current.id, params[:attacment_id].to_i) + if ar.empty? + ApplyResource.create(:user_id => params[:id].to_i, :attachment_id => params[:attachment_id].to_i, :status => true, :container_id => @attachment.container_id, :container_type => @attachment.container_type, :content => params[:content], :apply_user_id => @attachment.author_id) + @state = 2 + else + @state = 3 + end + end + else + @state = 1 + end + respond_to do |format| + format.js + end + end + #申请引用非公开作业 def apply_for_homework if User.current.logged? @@ -1886,7 +1942,7 @@ class UsersController < ApplicationController # 将资源发送到对应的课程,分为发送单个,或者批量发送 def add_exist_file_to_course @flag = true - if params[:send_id].present? + if params[:send_id].present? send_id = params[:send_id] @ori = Attachment.find_by_id(send_id) course_ids = params[:course_ids] @@ -1933,14 +1989,14 @@ class UsersController < ApplicationController end send_ids.each do |send_id| quotes = 0 - ori = Attachment.find_by_id(send_id) + @ori = Attachment.find_by_id(send_id) unless course_ids.nil? course_ids.each do |id| quotes = 0 - next if ori.blank? + next if @ori.blank? @exist = false Course.find(id).attachments.each do |att| #如果课程中包含该资源 - if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + if att.id == @ori.id || (!att.copy_from.nil? && !@ori.copy_from.nil? && att.copy_from == @ori.copy_from) || att.copy_from == @ori.id || att.id == @ori.copy_from att.created_on = Time.now att.save @exist = true @@ -1948,21 +2004,21 @@ class UsersController < ApplicationController end end next if @exist - attach_copied_obj = ori.copy - attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj = @ori.copy + attach_copied_obj.tag_list.add(@ori.tag_list) # tag关联 attach_copied_obj.container = Course.find(id) attach_copied_obj.created_on = Time.now attach_copied_obj.author_id = User.current.id attach_copied_obj.is_public = 0 - attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from + attach_copied_obj.copy_from = @ori.copy_from.nil? ? @ori.id : @ori.copy_from #发送要添加copy_from if attach_copied_obj.attachtype == nil attach_copied_obj.attachtype = 4 end if attach_copied_obj.save # 更新引用次数 - quotes = ori.quotes.to_i + 1 - ori.update_attribute(:quotes, quotes) unless ori.nil? - ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + quotes = @ori.quotes.to_i + 1 + @ori.update_attribute(:quotes, quotes) unless @ori.nil? + @ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) end @save_message = attach_copied_obj.errors.full_messages end @@ -2002,6 +2058,18 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end + elsif params[:type] == "2" + apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + if params[:status] == "2" + resource_type = "'Course'" + elsif params[:status] == "3" + resource_type = "'Project'" + elsif params[:status] == "5" + resource_type = "'Principal'" + else + resource_type = "'Project','OrgSubfield','Principal','Course'" + end + @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) end @type = params[:type] @limit = 25 @@ -2143,6 +2211,18 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end + elsif params[:type] == "2" + apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + if params[:status] == "2" + resource_type = "'Course'" + elsif params[:status] == "3" + resource_type = "'Project'" + elsif params[:status] == "5" + resource_type = "'Principal'" + else + resource_type = "'Project','OrgSubfield','Principal','Course'" + end + @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) end @status = params[:status] @type = params[:type] @@ -2272,6 +2352,18 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end + elsif params[:type] == "2" + apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + if params[:status] == "2" + resource_type = "'Course'" + elsif params[:status] == "3" + resource_type = "'Project'" + elsif params[:status] == "5" + resource_type = "'Principal'" + else + resource_type = "'Project','OrgSubfield','Principal','Course'" + end + @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) end @type = params[:type] @limit = 25 @@ -2608,12 +2700,12 @@ class UsersController < ApplicationController # 获取公共资源 def get_public_resources user_course_ids, user_project_ids, order, score - attachments = Attachment.where("(is_publish = 1 and is_public =1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("#{order.nil? ? 'created_on' : order} #{score}") + attachments = Attachment.where("(is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取公共资源搜索 def get_public_resources_search user_course_ids, user_project_ids, order, score, search - attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)" ,:p => search).order("#{order.nil? ? 'created_on' : order} #{score}") + attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的资源 @@ -2637,6 +2729,16 @@ class UsersController < ApplicationController and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}") end + # 获取我的私有资源分享结果 + def get_my_private_resources apply_ids, resource_type, order, score + attachments = Attachment.where("id in (#{apply_ids.empty? ? '0': apply_ids.join(',')}) and container_type in(#{resource_type})").order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取我的私有资源分享搜索结果 + def get_my_private_resources_search apply_ids, resource_type, order, score, search + attachments = Attachment.where("id in (#{apply_ids.empty? ? '0': apply_ids.join(',')}) and container_type in(#{resource_type}) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") + end + # 获取我的课程资源中搜索结果 def get_course_resources_search author_id, user_course_ids, order, score, search attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+ @@ -2646,12 +2748,12 @@ class UsersController < ApplicationController # 获取公共资源中课程资源 def get_course_resources_public user_course_ids, order, score - attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1)").order("#{order.nil? ? 'created_on' : order} #{score}") + attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1)").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取公共资源中课程资源搜索结果 def get_course_resources_public_search user_course_ids, order, score, search - attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") + attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的项目资源 @@ -2670,12 +2772,12 @@ class UsersController < ApplicationController # 获取公共资源的项目资源 def get_project_resources_public user_project_ids, order, score - attchments = Attachment.where("container_type = 'Project' and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") + attchments = Attachment.where("container_type = 'Project' and container_id is not null").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取公共资源的项目资源搜索 def get_project_resources_public_search user_project_ids, order, score, search - attchments = Attachment.where("(container_type = 'Project' and container_id is not null and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") + attchments = Attachment.where("(container_type = 'Project' and container_id is not null) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我上传的附件 @@ -2693,13 +2795,13 @@ class UsersController < ApplicationController # 获取公共资源中我上传的附件 def get_attch_resources_public order, score attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') - and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") + and container_id is not null").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取公共资源中我上传的附件 def get_attch_resources_public_search order, score, search attchments = Attachment.where("(container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') - and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") + and container_id is not null) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的用户类型资源 @@ -2714,12 +2816,12 @@ class UsersController < ApplicationController # 获取我的用户类型资源 def get_principal_resources_public order, score - attchments = Attachment.where("container_type = 'Principal'and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") + attchments = Attachment.where("container_type = 'Principal' and container_id is not null").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的用户类型资源 def get_principal_resources_public_search order, score, search - attchments = Attachment.where("(container_type = 'Principal'and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") + attchments = Attachment.where("(container_type = 'Principal'and container_id is not null) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 资源库 分为全部 课程资源 项目资源 附件 @@ -2734,7 +2836,7 @@ class UsersController < ApplicationController user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} - if(params[:type].blank? || params[:type] == "1") # 我的资源 + if( params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) @@ -2748,7 +2850,7 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) end - elsif params[:type] == "6" # 公共资源 + elsif (params[:type].blank? || params[:type] == "6") # 公共资源 if params[:status] == "2" @attachments = get_course_resources_public( user_course_ids, @order, @score) elsif params[:status] == "3" @@ -2761,6 +2863,18 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end + elsif params[:type] == "2" # 私有资源 + apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + if params[:status] == "2" + resource_type = "'Course'" + elsif params[:status] == "3" + resource_type = "'Project'" + elsif params[:status] == "5" + resource_type = "'Principal'" + else + resource_type = "'Project','OrgSubfield','Principal','Course'" + end + @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) end @status = params[:status] @type = params[:type] @@ -2780,8 +2894,7 @@ class UsersController < ApplicationController # 导入资源 def import_resources # 别人的资源库是没有权限去看的 - @user = User.find_by_login(params[:id]) - if User.current != @user + if User.current.id != params[:id].to_i render_403 return end @@ -2941,6 +3054,19 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search) end + elsif params[:type] == "2" # 私有资源 + apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + if params[:status] == "2" + resource_type = "'Course'" + elsif params[:status] == "3" + resource_type = "'Project'" + elsif params[:status] == "5" + resource_type = "'Principal'" + else + resource_type = "'Project','OrgSubfield','Principal','Course'" + end + @attachments = get_my_private_resources_search(apply_ids, resource_type, @order, @score, search) + @attachments end @status = params[:status] @type = params[:type] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c8a3bca0c..8d9c9733e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -49,6 +49,21 @@ module ApplicationHelper return result end + # 判断某个资源是否可以申请 + def attach_show_allow attach_id + attachment = Attachment.find(attach_id) + case attachment.container_type + when "Project" + User.current.member_of?(attachment.container) ? true : false + when "Course" + User.current.member_of_course?(attachment.container) ? true : false + when "OrgSubfield" + User.current.member_of_org?(attachment.container) ? true : false + when "Principal" + User.current.id == attachment.author_id ? true : false + end + end + # Time 2015-03-24 15:27:29 # Author lizanle # Description 从硬盘上删除对应的资源文件 @@ -3237,6 +3252,7 @@ def strip_html(text,len=0,endss="...") ss = "" if text.length>0 ss=text.gsub(/<\/?.*?>/, '').strip + ss = ss.gsub(/ /, ' ') if len > 0 && ss.length > len ss = ss[0, len] + endss diff --git a/app/models/apply_resource.rb b/app/models/apply_resource.rb new file mode 100644 index 000000000..df646166c --- /dev/null +++ b/app/models/apply_resource.rb @@ -0,0 +1,19 @@ +class ApplyResource < ActiveRecord::Base + # status:1. 等待回复 2.审核通过 3.已拒绝 + attr_accessible :attachment_id, :status, :user_id, :container_type, :container_id, :apply_user_id, :content + belongs_to :user + belongs_to :attachment + has_many :course_messages, :class_name => 'CourseMessage', :as => :course_message, :dependent => :destroy + after_create :act_as_apply_resource_message + + def act_as_apply_resource_message + self.course_messages << CourseMessage.new(:user_id => self.apply_user_id, :course_id => -1, :viewed => false, :status => 0, ) + # REDO:发送邮件 + # Mailer.run.apply_for_resource_request(self.container_id, User.current) + end + + def find_attachment attachment_id + Attachment.find(attachment_id) + end + +end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index b3f5ce4ed..b7ec264fd 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -35,6 +35,7 @@ class Attachment < ActiveRecord::Base # end include UserScoreHelper has_many :attachment_histories + has_many :apply_resources, :dependent => :destroy validates :filename, presence: true, length: {maximum: 254} validates :author, presence: true @@ -139,6 +140,11 @@ class Attachment < ActiveRecord::Base } ) end + + def get_apply_resource_status attachment_id, author_id + ApplyResource.where("attachment_id =? and apply_user_id =?", attachment_id, author_id).first.try(:status) + end + # add by nwb # 公开的项目id列表 def self.public_project_id @@ -536,6 +542,11 @@ class Attachment < ActiveRecord::Base end end + # 获取资源申请状态 + def get_status_by_attach user_id + ApplyResource.where("user_id =? and attachment_id =?", user_id, self.id).first.try(:status) + end + private # Physically deletes the file from the file system diff --git a/app/models/course_message.rb b/app/models/course_message.rb index 703da936b..59fcfe456 100644 --- a/app/models/course_message.rb +++ b/app/models/course_message.rb @@ -1,5 +1,7 @@ class CourseMessage < ActiveRecord::Base # status说明: status在课程不同的类型,区分不同的功能 status = 9 作品的提交记录 + # ApplyResource status: + # 0: 发送申请 1:回复允许申请 2:拒绝申请消息 # HomeworkCommon:status: # nil:发布了作业; 1:作业截止时间到了提醒!;2:开启匿评; 3:关闭匿评; 4:匿评开始失败; 5:申请引用作业, 6:申请结果 # apply_user_id: 申请者的用户id diff --git a/app/models/journal.rb b/app/models/journal.rb index 02086fa62..eeaa17dd6 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -239,8 +239,10 @@ class Journal < ActiveRecord::Base #缺陷回复微信模板消息 def issue_wechat_message - ws = WechatService.new - content = strip_html self.notes.html_safe, 200 - ws.comment_template self.issue.author_id, "issues", self.journalized_id, "#{l(:label_issue_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + if !self.notes.nil? && self.notes.gsub(' ','') != '' + ws = WechatService.new + content = strip_html self.notes.html_safe, 200 + ws.comment_template self.issue.author_id, "issues", self.journalized_id, "#{l(:label_issue_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + end end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 68b747ab9..d0113744c 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -259,19 +259,26 @@ class JournalsForMessage < ActiveRecord::Base if self.m_parent_id.nil? if self.user_id != self.jour.user_id self.course_messages << CourseMessage.new(:user_id => self.jour.user_id,:course_id => self.jour.course.id, :viewed => false) + count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.jour.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count + if count == 0 + ws = WechatService.new + #content = truncate(strip_tags(self.notes.to_s), length: 200) + content = strip_html self.notes.html_safe, 200 + ws.comment_template self.jour.user_id, "homework", self.jour_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + end end else if self.user_id != self.parent.user_id self.course_messages << CourseMessage.new(:user_id => self.parent.user_id,:course_id => self.jour.course.id, :viewed => false) + count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.parent.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count + if count == 0 + ws = WechatService.new + #content = truncate(strip_tags(self.notes.to_s), length: 200) + content = strip_html self.notes.html_safe, 200 + ws.comment_template self.parent.user_id, "homework", self.jour_id, "#{l(:label_new_second_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + end end end - count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.jour.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count - if count == 0 - ws = WechatService.new - #content = truncate(strip_tags(self.notes.to_s), length: 200) - content = strip_html self.notes.html_safe, 200 - ws.comment_template self.jour.user_id, "homework", self.jour_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), content - end end end diff --git a/app/models/user.rb b/app/models/user.rb index 3956d936e..44ef54c95 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -109,6 +109,7 @@ class User < Principal has_many :student_works_scores, :dependent => :destroy has_many :student_work_projects, :dependent => :destroy has_many :apply_homeworks, :dependent => :destroy + has_many :apply_resources, :dependent => :destroy #end has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, diff --git a/app/views/exercise/_student_exercise.html.erb b/app/views/exercise/_student_exercise.html.erb index d7a1b85bb..f9fd114dd 100644 --- a/app/views/exercise/_student_exercise.html.erb +++ b/app/views/exercise/_student_exercise.html.erb @@ -22,60 +22,6 @@
- <%= render :partial => "student_table"%> + <%= render :partial => "student_table" %>
-
- -<% @exercise_users_list.each do |exercise|%> - - - -
-<% end%> \ No newline at end of file +
\ No newline at end of file diff --git a/app/views/exercise/_student_exercise_archive.html.erb b/app/views/exercise/_student_exercise_archive.html.erb new file mode 100644 index 000000000..abc604b73 --- /dev/null +++ b/app/views/exercise/_student_exercise_archive.html.erb @@ -0,0 +1,81 @@ +
+ + 测验 + + (<%= @exercise_count%>人已交) + + <% if !@is_teacher && @exercise_users_list.empty?%> + 您尚未提交 + <% elsif !@is_teacher && !@exercise_users_list.empty?%> + 您已提交 + <% end %> + + <%#if @is_teacher || @exercise.exercise_status == 3%> + + <%#= select_tag(:student_work_in_group,options_for_select(course_group_list(@course),@group), {:class => "classSplit"}) unless course_group_list(@course).empty? %> + <%# end%> + +
+
+ +
+ <%= render :partial => "student_table"%> +
+
+ +<% @exercise_users_list.each do |exercise|%> + + + +
+<% end%> \ No newline at end of file diff --git a/app/views/exercise/_student_table.html.erb b/app/views/exercise/_student_table.html.erb index 8957c5048..5a93c352a 100644 --- a/app/views/exercise/_student_table.html.erb +++ b/app/views/exercise/_student_table.html.erb @@ -1,23 +1,71 @@ - + + 点击查看详情 + \ No newline at end of file diff --git a/app/views/users/_apply_resource_course_message.html.erb b/app/views/users/_apply_resource_course_message.html.erb new file mode 100644 index 000000000..fd493daf2 --- /dev/null +++ b/app/views/users/_apply_resource_course_message.html.erb @@ -0,0 +1,38 @@ +
  • + +
  • +
  • + <%= link_to ma.course_message.user.show_name, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %> + ">申请引用资源: +
  • +
  • + <% content = ma.course_message.content.nil? ? '' : ':'+ ma.course_message.content.to_s %> + <% show_content = ma.course_message.user.show_name + "申请引用资源\""+"#{ma.course_message.find_attachment(ma.course_message.attachment_id).try(:filename)}"+"\"#{content}" %> + <% if ma.course_message.container_type == "Course" %> + <%= link_to show_content, course_files_path(ma.course_message.container_id), :title => show_content, :class => " #{ma.viewed == 0 ? "newsBlack" : "newsGrey "}" %> + <% elsif ma.course_message.container_type == "Project" %> + <%= link_to show_content, project_files_path(ma.course_message.container_id), :title => show_content, :class => " #{ma.viewed == 0 ? "newsBlack" : "newsGrey "}" %> + <% elsif ma.course_message.container_type == "OrgSubfield" %> + <%= link_to show_content, org_subfield_files_path(ma.course_message.container_id), :title => show_content, :class => " #{ma.viewed == 0 ? "newsBlack" : "newsGrey "}" %> + <% else %> + "> + <%= show_content %> + + <% end %> +
  • + +
  • + + <% if ma.apply_result == 0 || ma.apply_result.nil? %> + <%= link_to '同意', deal_with_apply_resource_user_path(User.current, :agree => 'Y', :msg_id => ma.id, :apply_user_id => ma.course_message.apply_user_id), :remote => 'true' %> | + <%= link_to '拒绝', deal_with_apply_resource_user_path(User.current, :agree => 'N', :msg_id => ma.id, :apply_user_id => ma.course_message.apply_user_id), :remote => 'true' %> + <% elsif ma.apply_result == 1 %> + 您已经同意了该申请 + <% elsif ma.apply_result == 2 %> + 您已经拒绝了该申请 + <%end %> + +
  • +
  • <%= time_tag(ma.created_at).html_safe %>
  • \ No newline at end of file diff --git a/app/views/users/_apply_resource_course_message_reply.html.erb b/app/views/users/_apply_resource_course_message_reply.html.erb new file mode 100644 index 000000000..2aff99c17 --- /dev/null +++ b/app/views/users/_apply_resource_course_message_reply.html.erb @@ -0,0 +1,34 @@ + \ No newline at end of file diff --git a/app/views/users/_resources_list.html.erb b/app/views/users/_resources_list.html.erb index b8551f7c5..7d510d977 100644 --- a/app/views/users/_resources_list.html.erb +++ b/app/views/users/_resources_list.html.erb @@ -6,11 +6,38 @@ <% attachments.each do |attach| %>
    @@ -68,19 +97,27 @@ document.oncontextmenu = function() {return true;} line.children().css("background-color",'white'); id = line.children().last().html(); - if (lastSendType === '2'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。 - $.ajax({ - type: 'get', - url: '<%= search_user_project_user_path(User.current.id) %>' + "?send_id=" + id + "&type=<%= @type %>", - data:{send_type:'file'} - }); + is_public = line.children().eq(11).html(); + user_id = line.children().eq(6).html(); + apply_status = line.children().eq(12).html(); + if(is_public == 0 && user_id != '<%= User.current.id %>' && apply_status != 2){ + alert('您无权发送私有资源') }else{ - $.ajax({ - type: 'get', - url: '<%= search_user_course_user_path(User.current.id)%>' + "?send_id=" + id + "&type=<%= @type %>", - data:{send_type:'file'} - }); + if (lastSendType === '2'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。 + $.ajax({ + type: 'get', + url: '<%= search_user_project_user_path(User.current.id) %>' + "?send_id=" + id + "&type=<%= @type %>", + data:{send_type:'file'} + }); + }else{ + $.ajax({ + type: 'get', + url: '<%= search_user_course_user_path(User.current.id)%>' + "?send_id=" + id + "&type=<%= @type %>", + data:{send_type:'file'} + }); + } } + } function batch_send(){ @@ -176,7 +213,7 @@ } line.children().css("background-color", 'white'); id = line.children().last().html(); - user_id = line.children().eq(5).html(); + user_id = line.children().eq(6).html(); if(line.children().first().children().data('hasHistory') == 'Y'){ alert('该资源存在历史版本,不能删除'); return; diff --git a/app/views/users/_show_new_upload.html.erb b/app/views/users/_show_new_upload.html.erb new file mode 100644 index 000000000..b343aeae1 --- /dev/null +++ b/app/views/users/_show_new_upload.html.erb @@ -0,0 +1,3 @@ +<% if @type != "2" %> +
    上传资源
    +<% end %> diff --git a/app/views/users/_user_message_course.html.erb b/app/views/users/_user_message_course.html.erb index d46c45593..60d5b6ed8 100644 --- a/app/views/users/_user_message_course.html.erb +++ b/app/views/users/_user_message_course.html.erb @@ -234,6 +234,18 @@ <%= render :partial => 'apply_homework_course_message', :locals => {:ma => ma} %> <% end %> + + <% if ma.course_message_type == "ApplyResource" && ma.status == 0 %> + + <% end %> + + <% if ma.course_message_type == "ApplyResource" && ma.status == 1 %> + + <% end %> <% if ma.course_message_type == "HomeworkCommon" && ma.status == 6 %>