From 8edaa9d2bddcecf7daf84923feb804b0d2cae9a0 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 1 Mar 2016 17:33:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 67 +++---- app/helpers/users_helper.rb | 53 ++++++ app/views/layouts/_logined_header.html.erb | 2 +- .../users/_resource_search_form.html.erb | 6 +- app/views/users/_resources_list.html.erb | 27 +-- app/views/users/user_resource.html.erb | 171 +++++++++--------- public/stylesheets/public.css | 21 +++ 7 files changed, 210 insertions(+), 137 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e6b2a2036..ddb650193 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -697,6 +697,8 @@ class UsersController < ApplicationController @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") elsif params[:type] == "5" #用户资源 @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal'").order("created_on desc") + elsif params[:type] == "6" #公共资源 + Attachment.where("(is_public =1 and is_publish = 1 and container_id is not null)" + "or (author_id = #{params[:id]} and is_publish = 0)").order("created_on desc") end @type = params[:type] @limit = 7 @@ -729,6 +731,8 @@ class UsersController < ApplicationController @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '%#{search}%')").order("created_on desc") elsif params[:type] == "5" #用户资源 @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal' and (filename like '%#{search}%')").order("created_on desc") + elsif params[:type] == "6" #公共资源 + @attachments = Attachment.where("(is_public =1 and is_publish = 1 and container_id is not null)" + "or (author_id = #{params[:id]} and is_publish = 0)").order("created_on desc") end @type = params[:type] @limit = 7 @@ -1445,6 +1449,8 @@ class UsersController < ApplicationController else @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type ='Principal'").order("created_on desc") end + elsif params[:type] == "6" # 公共资源 + @attachments = Attachment.where("(is_public =1 and is_publish = 1 and container_id is not null)" + "or (author_id = #{params[:id]} and is_publish = 0)").order("created_on desc") end @type = params[:type] || 1 @limit = 25 @@ -2171,51 +2177,30 @@ class UsersController < ApplicationController # 资源库 分为全部 课程资源 项目资源 附件 def user_resource - #确定container_type - # @user = User.find(params[:id]) # 别人的资源库是没有权限去看的 if User.current.id.to_i != params[:id].to_i render_403 return end - if(params[:type].blank? || params[:type] == "1") #全部 - if User.current.id.to_i == params[:id].to_i - user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - @attachments = Attachment.where("(author_id = #{params[:id]} and is_publish = 1 and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ - "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1)").order("created_on desc") - else - user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #Ta的资源库的话,应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源 - @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 and is_publish = 1 " + - "and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " + - "or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1)").order("created_on desc") - end - elsif params[:type] == "2" #课程资源 - if User.current.id.to_i == params[:id].to_i - user_course_ids = User.current.courses.map { |c| c.id} - @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("created_on desc") - else - user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中 - @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 and container_type = 'Course' and is_publish = 1)"+ - "or (container_type = 'Course' and is_public = 1 and is_publish = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc") - end - elsif params[:type] == "3" #项目资源 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project'").order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' ").order("created_on desc") - end + user_course_ids = User.current.courses.map { |c| c.id} + user_project_ids = User.current.projects.map {|p| p.id} + # user_org_ids = User.current.projects.map {|p| p.id} + if(params[:type].blank? || params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + @attachments = Attachment.where("(author_id = #{params[:id]} and is_publish = 1 and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ + "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1)" + + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1)" ).order("created_on desc") + elsif params[:type] == "2" # 课程资源 + @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("created_on desc") + elsif params[:type] == "3" # 项目资源 + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project'").order("created_on desc") elsif params[:type] == "4" #附件 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") - end + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") elsif params[:type] == "5" #用户资源 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal'").order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Principal'").order("created_on desc") - end + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal'").order("created_on desc") + elsif params[:type] == "6" # 公共资源 + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = Attachment.where(" ").order("created_on desc") end @type = params[:type] @limit = 25 @@ -2227,7 +2212,7 @@ class UsersController < ApplicationController @attachments = paginateHelper @attachments,25 respond_to do |format| format.js - format.html {render :layout => 'new_base_user'} + format.html {render :layout => 'new_base'} end end @@ -2274,6 +2259,10 @@ class UsersController < ApplicationController else @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Principal' and (filename like :p)",:p=>search).order("created_on desc") end + elsif params[:type] == "6" #全部资源 + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = Attachment.where("((is_public =1 and is_publish = 1 and container_id is not null)" + + "or (author_id = #{params[:id]} and is_publish = 0)) and (filename like :p) ", :p => search).order("created_on desc") end @type = params[:type] @limit = 25 diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index efb67a2ac..1e924cefa 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -54,6 +54,59 @@ module UsersHelper end end + def get_resource_origin attach + type = attach.container_type + content = attach.container + case type + when 'Course' + result = current_time_and_term_resource content + when 'Project' + result = content.name + when 'Issue' + result = content.subject + when 'Message' + result = content.subject + when 'News' + result = content.title + when 'HomewCommon' + result = content.name + when 'StudentWorkScore' + result = content.name + when 'Principal' + result = content.name + when 'OrgSubfield' + result = content.name + end + end + + def current_time_and_term_resource course + str = "" + term = cur_course_term_resource + name = course.name + if (course.time == course.end_time && course.term == course.end_term) || (course.end_term.nil? && course.end_time.nil?) || course.time > Time.now.year + str = name + "(" + course.time.to_s + course.term.to_s + ")" + elsif course.time == Time.now.year && set_term_value(cur_course_term) <= set_term_value(course.term) + str = name + "(" + course.time.to_s + course.term.to_s + ")" + elsif course.end_time < Time.now.year || (course.end_time == Time.now.year && set_term_value(cur_course_term) >= set_term_value(course.term)) + str = name + "(" + course.end_time.to_s + course.end_term.to_s + ")" + else + str = name + "(" + Time.now.year.to_s + cur_course_term_resource.to_s + ")" + end + str + end + + def cur_course_term_resource + month = Time.now.month + if month >= 9 || month < 2 + term = "秋" + elsif (month >= 7 && Time.now.day >= 15) || month == 8 + term = "夏" + else + term = "春" + end + term + end + def title_for_message type case type when nil diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index 2fa627c73..0ab5c2876 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -8,7 +8,7 @@ <%= link_to "首页",user_activities_path(User.current.id), :class => "c_white f16 db p10", :title => "回到个人首页"%> + 资源库 diff --git a/app/views/users/_resource_search_form.html.erb b/app/views/users/_resource_search_form.html.erb index c629f9f32..f52fbe4df 100644 --- a/app/views/users/_resource_search_form.html.erb +++ b/app/views/users/_resource_search_form.html.erb @@ -1,7 +1,7 @@ -<%= form_tag( url_for(:controller => 'users',:action => 'resource_search',:id=>user.id), - :remote=>true ,:method => 'get',:class=>'resourcesSearchloadBox',:id=>'resource_search_form') do %> +<%= form_tag( url_for(:controller => 'users', :action => 'resource_search', :id => user.id), + :remote => true , :method => 'get', :class => 'resourcesSearchloadBox mt10', :id => 'resource_search_form') do %> <%= hidden_field_tag(:type,type.nil? ? 1 : type) %> - <%= submit_tag '',:class=>'homepageSearchIcon',:onfocus=>'this.blur();',:style=>'border-style:none' %> + <%= submit_tag '', :class => 'homepageSearchIcon', :onfocus => 'this.blur();', :style => 'border-style:none' %> <% end %> \ 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 a0a1377f1..cb845e0ed 100644 --- a/app/views/users/_resources_list.html.erb +++ b/app/views/users/_resources_list.html.erb @@ -1,27 +1,28 @@ - <% if attachments.nil? || attachments.empty? %> <% else %> <% attachments.each do |attach| %> -