From f3f75a57bdad2096e33b521479061efd4b31b39f Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 18 May 2016 17:37:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B3=E8=AF=B7=E8=B5=84=E6=BA=90=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E8=B5=84=E6=BA=90=E5=8F=91=E5=B8=83=E8=BF=99=E6=94=B6?= =?UTF-8?q?=E5=88=B0=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 101 ++++++++++++++++-- app/models/apply_resource.rb | 3 +- .../_apply_resource_course_message.html.erb | 29 +++++ app/views/users/_resources_list.html.erb | 10 +- app/views/users/_user_message_course.html.erb | 6 ++ .../users/_user_resource_type_filter.html.erb | 2 +- app/views/users/apply_for_resource.js.erb | 2 +- 7 files changed, 136 insertions(+), 17 deletions(-) create mode 100644 app/views/users/_apply_resource_course_message.html.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index dd1d8f876..b6fed88af 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -311,6 +311,30 @@ class UsersController < ApplicationController end end + # 处理资源引用请求 + # status + def deal_with_apply_resource + @msg = CourseMessage.find(params[:msg_id]) + ah = ApplyHomework.where("user_id = ? and homework_common_id = ?",@msg.apply_user_id, @msg.course_message_id) + case params[:agree] + when 'Y' + unless ah.empty? + ah.first.update_column('status', 2) + CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>1) + @msg.update_attributes(:apply_result=>1,:viewed=>1) + end + when 'N' + unless ah.empty? + ah.first.update_column('status', 3) + CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>2) + @msg.update_attributes(:apply_result=>2,:viewed=>1) + end + end + respond_to do |format| + format.js + end + end + #处理引用作业的请求 #status 1 同意 2 拒绝 def dealwith_apply_homework @@ -419,6 +443,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 +469,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? @@ -2608,7 +2666,7 @@ 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 # 获取公共资源搜索 @@ -2637,6 +2695,17 @@ 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_course_private_resources author_id, user_course_ids, order, score + apply_id = ApplyResource.where("user_id =?", author_id).map{|ar| ar.attachment_id} + attachments = Attachment.where("user_id =? and attachment_id =?") + 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 +2715,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 +2739,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 +2762,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 +2783,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 # 资源库 分为全部 课程资源 项目资源 附件 @@ -2761,6 +2830,20 @@ 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} + # apply_id = ApplyResource.where("user_id =?", author_id).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] diff --git a/app/models/apply_resource.rb b/app/models/apply_resource.rb index 50fdeebcb..ac65c0e3d 100644 --- a/app/models/apply_resource.rb +++ b/app/models/apply_resource.rb @@ -1,4 +1,5 @@ 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 @@ -6,7 +7,7 @@ class ApplyResource < ActiveRecord::Base after_create :act_as_apply_resource_message def act_as_apply_resource_message - self.course_messages << CourseMessage.new(:user_id => self.user_id, :course_id => self.container_id, :viewed => false, :status => 5) + self.course_messages << CourseMessage.new(:user_id => self.apply_user_id, :course_id => self.container_id, :viewed => false, :status => 5) # REDO:发送邮件 # Mailer.run.apply_for_resource_request(self.container_id, User.current) end 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..154ae3172 --- /dev/null +++ b/app/views/users/_apply_resource_course_message.html.erb @@ -0,0 +1,29 @@ +
  • + +
  • +
  • + <%= 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 %> + " class = "<%= ma.viewed == 0 ? "newsBlack" : "newsGrey "%>"> + <%= ma.course_message.user.show_name + "申请引用资源\""+"#{ma.course_message.attachment.try(:name)}"+"\"#{content}" %> + +
  • + +
  • + + <% if ma.apply_result == 0 || ma.apply_result.nil?%> + <%= link_to '同意', dealwith_apply_homework_user_path(User.current,:agree => 'Y', :msg_id => ma.id), :remote => 'true' %> | + <%= link_to '拒绝', dealwith_apply_homework_user_path(User.current, :agree => 'N', :msg_id => ma.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/_resources_list.html.erb b/app/views/users/_resources_list.html.erb index 720fed133..18d20cd60 100644 --- a/app/views/users/_resources_list.html.erb +++ b/app/views/users/_resources_list.html.erb @@ -15,16 +15,16 @@ 私有 <% end %> -
  • +
  • <% if attach.is_public == 0 && @type == "6" && attach.author != User.current %> - <% ah = attach.get_status_by_attach(attach.author_id) %> + <% ah = attach.get_status_by_attach(User.current.id) %> <% if ah.nil? %> <%= link_to("请求分享", apply_resource_user_path(User.current.id, :attachment_id => attach.id), :class => 'green_btn_share c_white', :remote => true) %> - <% elsif ah.status == 1 %> + <% elsif ah == 1 %> 等待回复 - <% elsif ah.status == 2 %> + <% elsif ah == 2 %> 可引用 - <% elsif ah.status == 3 %> + <% elsif ah == 3 %> 已拒绝 <% end %> <% else %> diff --git a/app/views/users/_user_message_course.html.erb b/app/views/users/_user_message_course.html.erb index d278c7d74..9befe2b0b 100644 --- a/app/views/users/_user_message_course.html.erb +++ b/app/views/users/_user_message_course.html.erb @@ -234,6 +234,12 @@ <%= render :partial => 'apply_homework_course_message', :locals => {:ma => ma} %> <% end %> + + <% if ma.course_message_type == "ApplyResource" %> + + <% end %> <% if ma.course_message_type == "HomeworkCommon" && ma.status == 6 %>