From 89b9a5c09dbc269981b9ea5fc094d78cefd2d93a Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Sat, 15 Aug 2015 17:06:41 +0800 Subject: [PATCH 01/27] =?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 | 77 +++++++++++++++++- app/helpers/application_helper.rb | 3 +- app/helpers/users_helper.rb | 23 ++++++ app/models/user.rb | 9 ++- app/views/layouts/base_users_new.html.erb | 12 +++ config/routes.rb | 7 ++ db/schema.rb | 10 +++ public/stylesheets/public.css | 65 ++++++++++++++++ public/stylesheets/public_new.css | 95 +++++++++++++++++++++++ 9 files changed, 297 insertions(+), 4 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 39a467d53..0b3302fae 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -46,7 +46,7 @@ class UsersController < ApplicationController :user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index, :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index, - :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index, + :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource, :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show @@ -807,6 +807,27 @@ class UsersController < ApplicationController end end + # 上传用户资源 + def user_resource_create + @user = User.find(params[:id]) + #@user.save_attachments(params[:attachments],User.current) + # Container_type为Principal + Attachment.attach_filesex(@user, params[:attachments], params[:attachment_type]) + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") + respond_to do |format| + format.js + end + end + + # 删除用户资源 + def user_resource_delete + Attachment.delete(params[:resource_id]) + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") + respond_to do |format| + format.js + end + end + def destroy @user.destroy respond_to do |format| @@ -1008,6 +1029,55 @@ class UsersController < ApplicationController @user = User.find(params[:id]) end + # 资源库 分为全部 课程资源 项目资源 附件 + def user_resource + #确定container_type + # @user = User.find(params[:id]) + if(params[:type].nil? || params[:type] == "1") #全部 + if User.current.id == params[:id] + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") + else + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") + end + elsif params[:type] == "2" #课程资源 + if User.current.id == params[:id] + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Course'").order("created_on desc") + else + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Course' ").order("created_on desc") + end + elsif params[:type] == "3" #项目资源 + if User.current.id == params[:id] + @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 + elsif params[:type] == "4" #附件 + if User.current.id == params[:id] + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon')").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')").order("created_on desc") + end + end + @type = params[:type] + respond_to do |format| + format.js + format.html {render :layout => 'base_users_new'} + end + end + + # 根据资源关键字进行搜索 + def resource_search + search = params[:search].to_s.strip.downcase + if User.current.id == params[:id] + @attachments = Attachment.where("author_id = #{params[:id]} and container_type not in ('Version','PhoneAppVersion','StudentWork') and (filename like '%#{search}%') ").order("created_on desc") + else + @attachments = Attachment.where("author_id = #{params[:id]} and container_type not in ('Version','PhoneAppVersion','StudentWork') and is_public = 1 and (filename like '%#{search}%') ").order("created_on desc") + end + respond_to do |format| + format.js + end + end + private def find_user @@ -1021,7 +1091,7 @@ class UsersController < ApplicationController render_404 end - def setting_layout(default_base='base_users') + def setting_layout(default_base='base_users_new') User.current.admin? ? default_base : default_base end @@ -1071,4 +1141,7 @@ class UsersController < ApplicationController impl.save end end + + + end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6ac3c234a..cdcb6fc4d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1852,7 +1852,8 @@ module ApplicationHelper candown = true elsif attachment.container.class.to_s=="StudentWork" candown = true - + elsif attachment.container.class.to_s == "User" + candown = (attachment.is_public == 1 || attachment.is_public == true || attachment.author_id == User.current.id) elsif attachment.container_type == "Bid" && attachment.container && attachment.container.courses course = attachment.container.courses.first candown = User.current.member_of_course?(attachment.container.courses.first) || (course.is_public == 1 && attachment.is_public == 1) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 49865d335..41458bc90 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -29,6 +29,29 @@ module UsersHelper ["#{l(:status_locked)} (#{user_count_by_status[3].to_i})", '3']], selected.to_s) end + def get_resource_type type + case type + when 'Course' + '课程资源' + when 'Project' + '项目资源' + when 'Issue' + '缺陷附件' + when 'Message' + '讨论区附件' + when 'Document' + '文档附件' + when 'News' + '通知附件' + when 'HomewCommon' + '作业附件' + when 'StudentWorkScore' + '批改附件' + when 'Principal' + '用户资源' + end + end + def user_mail_notification_options(user) user.valid_notification_options.collect {|o| [l(o.last), o.first]} end diff --git a/app/models/user.rb b/app/models/user.rb index 1cd0675c8..4fae33185 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -150,7 +150,8 @@ class User < Principal nil } - + acts_as_attachable :view_permission => :view_files, + :delete_permission => :manage_files acts_as_customizable ############################added by william acts_as_taggable @@ -239,6 +240,12 @@ class User < Principal self.user_extensions ||= UserExtensions.new end + # User现在可以作为一个Container_type,而Attachment的Container方法会有一个Container.try(:project), + # 所以这里定义一个空方法,保证不报错 + def project + + end + def user_score_attr self.user_score ||= UserScore.new end diff --git a/app/views/layouts/base_users_new.html.erb b/app/views/layouts/base_users_new.html.erb index 09d437da4..f9f065e2a 100644 --- a/app/views/layouts/base_users_new.html.erb +++ b/app/views/layouts/base_users_new.html.erb @@ -146,6 +146,12 @@ (<%=@user.projects.count%>) + <% else%> + <% end %>
From 375c016783b00bbbae617181011af267593b797c Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Tue, 18 Aug 2015 15:42:36 +0800 Subject: [PATCH 07/27] =?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/views/users/user_resource.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/user_resource.html.erb b/app/views/users/user_resource.html.erb index 98984b3f9..f5a6c57f0 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -199,7 +199,7 @@ $(".resourcesList").click(function(e) { '"/> '+ '<% end %>'); $("#res_name").focus(); - document.getElementById('res_name').scrollIntoView() + $("html,body").animate({scrollTop:$("#res_name").offset().top},1000) } String.prototype.trim = function() { var str = this, From ae6260571b4d4321cf68d433f8d0c793dd9d0c94 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Tue, 18 Aug 2015 16:57:41 +0800 Subject: [PATCH 08/27] =?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 | 8 ++++---- app/views/users/user_resource.html.erb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6bbfbd12b..c3c5da9cf 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1106,25 +1106,25 @@ class UsersController < ApplicationController #确定container_type # @user = User.find(params[:id]) if(params[:type].nil? || params[:type] == "1") #全部 - if User.current.id == params[:id] + if User.current.id.to_i == params[:id].to_i @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") else @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") end elsif params[:type] == "2" #课程资源 - if User.current.id == params[:id] + if User.current.id.to_i == params[:id].to_i @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Course'").order("created_on desc") else @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Course' ").order("created_on desc") end elsif params[:type] == "3" #项目资源 - if User.current.id == params[:id] + 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 elsif params[:type] == "4" #附件 - if User.current.id == params[:id] + if User.current.id.to_i == params[:id].to_i @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon')").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')").order("created_on desc") diff --git a/app/views/users/user_resource.html.erb b/app/views/users/user_resource.html.erb index f5a6c57f0..09bee5ac6 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -199,7 +199,7 @@ $(".resourcesList").click(function(e) { '"/> '+ '<% end %>'); $("#res_name").focus(); - $("html,body").animate({scrollTop:$("#res_name").offset().top},1000) + $("html,body").animate({scrollTop:$("#res_name").offset().top},1000) } String.prototype.trim = function() { var str = this, From 43d57074e51277b505fc7d7f7ed781c2a81cb2a8 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Tue, 18 Aug 2015 17:26:39 +0800 Subject: [PATCH 09/27] =?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 | 2 +- app/views/users/user_resource.html.erb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c3c5da9cf..2caae19e1 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -894,7 +894,7 @@ class UsersController < ApplicationController # format.js # end if @flag - render :text=>'sucess' + render :text=> download_named_attachment_path(@attachment.id, @attachment.filename) else render :text=>'fail' end diff --git a/app/views/users/user_resource.html.erb b/app/views/users/user_resource.html.erb index 09bee5ac6..1cad8f2de 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -158,7 +158,7 @@ $(".resourcesList").click(function(e) { //将当前行改变为白色 line.children().css("background-color", 'white'); //当前行恢复编辑状态到链接状态 - if(ele.nodeName != 'INPUT') { + if(ele && ele.nodeName != 'INPUT') { restore(); } line = null; @@ -224,9 +224,10 @@ $(".resourcesList").click(function(e) { '<%=rename_resource_user_path(@user) %>', $("#res_name_form").serialize(), function (data){ - if(data =='sucess'){//修改成功,那么将链接恢复,并且将链接的显示内容改变。链接可以不变 + if(data != 'fail'){//修改成功,那么将链接恢复,并且将链接的显示内容改变。链接可以不变 last_line.children().first().html(res_link); last_line.children().first().children().attr('title',name); + last_line.children().first().children().attr('href',data); last_line.children().first().children().html(name.length > 17? name.substring(0,17)+'...' : name); }else{ last_line.children().first().html(res_link); From 3836cfb40ba4bcd3b07b3a8dfb7698f24dddb3d6 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Tue, 18 Aug 2015 17:45:14 +0800 Subject: [PATCH 10/27] =?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/views/users/_resource_search_form.html.erb | 2 +- app/views/users/user_resource.html.erb | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/users/_resource_search_form.html.erb b/app/views/users/_resource_search_form.html.erb index 0c48514b3..725167b65 100644 --- a/app/views/users/_resource_search_form.html.erb +++ b/app/views/users/_resource_search_form.html.erb @@ -1,6 +1,6 @@ <%= form_tag( url_for(:controller => 'users',:action => 'resource_search',:id=>user.id), :remote=>true ,:method => 'post',:class=>'resourcesSearchloadBox',:id=>'resource_search_form') do %> - + <%= hidden_field_tag(:type,type) %> <%= submit_tag '',:class=>'searchIcon',:style=>'border-style:none' %> diff --git a/app/views/users/user_resource.html.erb b/app/views/users/user_resource.html.erb index 1cad8f2de..621b0c17d 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -216,7 +216,10 @@ $(".resourcesList").click(function(e) { function restore(){ //上一行不为空 且链接不为空 if( last_line != null && res_link != null && res_link != '') { - name = $("#res_name") ? $("#res_name").val().trim() : $("#res_name") ; + name = $("#res_name").lenght != 0 && $("#res_name").val() != undefined ? $("#res_name").val().trim() : undefined ; + if (name == undefined || name === 'undefined' ){ //只要res_name没有值,那么就不是编辑状态 + return; + } if( name && name != res_name.trim()){ if(confirm('确定修改为 '+name)){ From e7f818deb9e62b599ab126b781eedbeef148a4bb Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Wed, 19 Aug 2015 09:20:39 +0800 Subject: [PATCH 11/27] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=BA=93=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 2caae19e1..bc9394716 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1146,25 +1146,25 @@ class UsersController < ApplicationController # @attachments = Attachment.where("author_id = #{params[:id]} and container_type not in ('Version','PhoneAppVersion','StudentWork') and is_public = 1 and (filename like '%#{search}%') ").order("created_on desc") # end if(params[:type].nil? || params[:type] == "1") #全部 - if User.current.id == params[:id] + if User.current.id.to_i == params[:id].to_i @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '%#{search}%') ").order("created_on desc") else @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '%#{search}%') ").order("created_on desc") end elsif params[:type] == "2" #课程资源 - if User.current.id == params[:id] + if User.current.id.to_i == params[:id].to_i @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Course' and (filename like '%#{search}%')").order("created_on desc") else @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Course' and (filename like '%#{search}%') ").order("created_on desc") end elsif params[:type] == "3" #项目资源 - if User.current.id == params[:id] + if User.current.id.to_i == params[:id].to_i @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project' and (filename like '%#{search}%')").order("created_on desc") else @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' and (filename like '%#{search}%') ").order("created_on desc") end elsif params[:type] == "4" #附件 - if User.current.id == params[:id] + if User.current.id.to_i == params[:id].to_i @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") else @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '%#{search}%')").order("created_on desc") From 0ef7d5f0fa23ac6f4e099770c8197242a4fc2228 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Wed, 19 Aug 2015 12:04:06 +0800 Subject: [PATCH 12/27] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=BA=93=E5=8F=AF?= =?UTF-8?q?=E8=A7=81=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index bc9394716..c523bbb3d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,3 +1,4 @@ +#encoding: utf-8 # Redmine - project management software # Copyright (C) 2006-2013 Jean-Philippe Lang # @@ -14,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + class UsersController < ApplicationController layout :setting_layout @@ -1109,13 +1111,18 @@ class UsersController < ApplicationController if User.current.id.to_i == params[:id].to_i @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") + 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 in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " + + "or (container_type = 'Course' and is_public <> -1 and container_id in (#{user_course_ids.join(',')}))").order("created_on desc") end elsif params[:type] == "2" #课程资源 if User.current.id.to_i == params[:id].to_i @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Course'").order("created_on desc") else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Course' ").order("created_on desc") + 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')"+ + "or (container_type = 'Course' and is_public <> -1 and container_id in (#{user_course_ids.join(',')}))").order("created_on desc") end elsif params[:type] == "3" #项目资源 if User.current.id.to_i == params[:id].to_i @@ -1140,22 +1147,24 @@ class UsersController < ApplicationController # 根据资源关键字进行搜索 def resource_search search = params[:search].to_s.strip.downcase - # if User.current.id == params[:id] - # @attachments = Attachment.where("author_id = #{params[:id]} and container_type not in ('Version','PhoneAppVersion','StudentWork') and (filename like '%#{search}%') ").order("created_on desc") - # else - # @attachments = Attachment.where("author_id = #{params[:id]} and container_type not in ('Version','PhoneAppVersion','StudentWork') and is_public = 1 and (filename like '%#{search}%') ").order("created_on desc") - # end if(params[:type].nil? || params[:type] == "1") #全部 if User.current.id.to_i == params[:id].to_i @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '%#{search}%') ").order("created_on desc") else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '%#{search}%') ").order("created_on desc") + 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 in" + + " ('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon'))"+ + " or (container_type = 'Course' and is_public <> -1 and container_id in (#{user_course_ids.join(',')})) )" + + " and (filename like '%#{search}%') ").order("created_on desc") end elsif params[:type] == "2" #课程资源 if User.current.id.to_i == params[:id].to_i @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Course' and (filename like '%#{search}%')").order("created_on desc") else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Course' and (filename like '%#{search}%') ").order("created_on desc") + 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') "+ + "or (container_type = 'Course' and is_public <> -1 and container_id in (#{user_course_ids.join(',')})) )"+ + " and (filename like '%#{search}%') ").order("created_on desc") end elsif params[:type] == "3" #项目资源 if User.current.id.to_i == params[:id].to_i From 929da7512da5d1c17d8e913b7e7937424faabead Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Wed, 19 Aug 2015 17:13:57 +0800 Subject: [PATCH 13/27] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=BA=93=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E7=95=8C=E9=9D=A2=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 33 ++++++++- .../users/_resource_search_form.html.erb | 2 +- .../users/_resource_share_popup.html.erb | 15 +++- app/views/users/_resources_list.html.erb | 5 +- app/views/users/user_resource.html.erb | 58 +++++++++------- public/stylesheets/images/homepage_icon.png | Bin 0 -> 6829 bytes public/stylesheets/images/nav_icon.png | Bin 0 -> 3204 bytes public/stylesheets/public_new.css | 65 ++++++++++++++---- 8 files changed, 133 insertions(+), 45 deletions(-) create mode 100644 public/stylesheets/images/homepage_icon.png create mode 100644 public/stylesheets/images/nav_icon.png diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c523bbb3d..e4109e5bb 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -825,7 +825,38 @@ class UsersController < ApplicationController # 删除用户资源 def user_resource_delete Attachment.delete(params[:resource_id]) - @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") + #@attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") + if(params[:type].nil? || params[:type] == "1") #全部 + if User.current.id.to_i == params[:id].to_i + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").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 in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " + + "or (container_type = 'Course' and is_public <> -1 and container_id in (#{user_course_ids.join(',')}))").order("created_on desc") + end + elsif params[:type] == "2" #课程资源 + if User.current.id.to_i == params[:id].to_i + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Course'").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')"+ + "or (container_type = 'Course' and is_public <> -1 and container_id in (#{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 + 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('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon')").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')").order("created_on desc") + end + end + @type = params[:type] respond_to do |format| format.js end diff --git a/app/views/users/_resource_search_form.html.erb b/app/views/users/_resource_search_form.html.erb index 725167b65..5f854cba0 100644 --- a/app/views/users/_resource_search_form.html.erb +++ b/app/views/users/_resource_search_form.html.erb @@ -2,6 +2,6 @@ :remote=>true ,:method => 'post',:class=>'resourcesSearchloadBox',:id=>'resource_search_form') do %> <%= hidden_field_tag(:type,type) %> - <%= submit_tag '',:class=>'searchIcon',: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/_resource_share_popup.html.erb b/app/views/users/_resource_share_popup.html.erb index 01ac79075..cad94056c 100644 --- a/app/views/users/_resource_share_popup.html.erb +++ b/app/views/users/_resource_share_popup.html.erb @@ -1,8 +1,17 @@ -
将资源移动至 -
+
+
将资源发送至
+
+ +
+
+
+
<%= form_tag search_user_course_user_path(user),:method => 'get', :remote=>true,:id=>'search_user_course_form',:class=>'resourcesSearchBox' do %> <%= hidden_field_tag(:send_id, @send_id) %> @@ -17,7 +26,7 @@ <%= hidden_field_tag(:send_id, @send_id) %> <% if !courses.empty? %> <% courses.each do |course| %> -
    +
    • diff --git a/app/views/users/_resources_list.html.erb b/app/views/users/_resources_list.html.erb index 6f9ba0fee..b344c737d 100644 --- a/app/views/users/_resources_list.html.erb +++ b/app/views/users/_resources_list.html.erb @@ -1,7 +1,10 @@ <% if attachments.nil? || attachments.empty? %> <% else %> <% attachments.each do |attach| %> -
        +
          +
        • + +
        • <%= link_to truncate(attach.filename,:length=>18), download_named_attachment_path(attach.id, attach.filename), diff --git a/app/views/users/user_resource.html.erb b/app/views/users/user_resource.html.erb index 621b0c17d..5867c463f 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -40,22 +40,22 @@ }
          -
          -
          资源
          +
          +
          资源库
            • - <%= link_to '全部' ,user_resource_user_path(:id=>@user.id,:type=>1),:remote=>true,:method => 'get',:class=>'resourcesGrey' %> + <%= link_to '全部' ,user_resource_user_path(:id=>@user.id,:type=>1),:remote=>true,:method => 'get',:class=>'resourcesTypeAll resourcesGrey' %>
            • - <%= link_to '课程资源' ,user_resource_user_path(:id=>@user.id,:type=>2),:remote=>true,:method => 'get',:class=>'resourcesGrey' %> + <%= link_to '课程资源' ,user_resource_user_path(:id=>@user.id,:type=>2),:remote=>true,:method => 'get',:class=>'homepagePostTypeAssignment postTypeGrey' %>
            • - <%= link_to '项目资源' ,user_resource_user_path(:id=>@user.id,:type=>3),:remote=>true,:method => 'get',:class=>'resourcesGrey' %> + <%= link_to '项目资源' ,user_resource_user_path(:id=>@user.id,:type=>3),:remote=>true,:method => 'get',:class=>'homepagePostTypeQuiz postTypeGrey' %>
            • - <%= link_to '附件' ,user_resource_user_path(:id=>@user.id,:type=>4),:remote=>true,:method => 'get',:class=>'resourcesGrey' %> + <%= link_to '附件' ,user_resource_user_path(:id=>@user.id,:type=>4),:remote=>true,:method => 'get',:class=>'resourcesTypeAtt resourcesGrey' %>
          • @@ -63,14 +63,14 @@
          <%= render :partial => 'resource_search_form',:locals => {:user=>@user,:type=>@type} %>
            +
          • 资源名称
          • 大小
          • 类别
          • @@ -78,11 +78,21 @@
          • 上传时间
          -
          -
            - +
            <%= render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments} %> -
          +
          +
          +
          + +
          + 全选 + 删除 +
          +
          选择 10 个资源
          +
          + 发送 +
          +
        • -
        • <%= course.name%>
        • +
        • <%= truncate(course.name,:length=>18)%>
        <% end %> diff --git a/app/views/users/add_exist_file_to_course.js.erb b/app/views/users/add_exist_file_to_course.js.erb index 903212798..c5b9f8fbe 100644 --- a/app/views/users/add_exist_file_to_course.js.erb +++ b/app/views/users/add_exist_file_to_course.js.erb @@ -1 +1,2 @@ +alert('发送成功') closeModal(); \ No newline at end of file diff --git a/app/views/users/add_exist_file_to_project.js.erb b/app/views/users/add_exist_file_to_project.js.erb new file mode 100644 index 000000000..6ed846821 --- /dev/null +++ b/app/views/users/add_exist_file_to_project.js.erb @@ -0,0 +1,2 @@ +alert('发送成功'); +closeModal(); \ No newline at end of file diff --git a/app/views/users/search_user_project.js.erb b/app/views/users/search_user_project.js.erb new file mode 100644 index 000000000..c22e4ad6d --- /dev/null +++ b/app/views/users/search_user_project.js.erb @@ -0,0 +1,11 @@ +var screenWidth = $(window).width(); +var screenHeight = $(window).height(); //当前浏览器窗口的 宽高 +var scrolltop = $(document).scrollTop();//获取当前窗口距离页面顶部高度 +var objLeft = (screenWidth - 2)/2.5 ; //2 可以根据需要修改 +var objTop = (screenHeight - 100)/2 + scrolltop; //100可以根据需要修改 +var popupHeight = $(".resourceSharePopup").outerHeight(true); +$(".resourceSharePopup").css("marginTop",-popupHeight/2); + +$("#upload_box").css('left',objLeft).css('top',objTop); +$("#upload_box").html('<%= escape_javascript( render :partial => "resource_share_for_project_popup" ,:locals => {:projects=>@projects,:user=>@user})%>'); +$("#upload_box").css('display','block'); \ No newline at end of file diff --git a/app/views/users/user_resource.html.erb b/app/views/users/user_resource.html.erb index 5867c463f..6938e389e 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -3,7 +3,11 @@ <%= stylesheet_link_tag 'project' %> <%= stylesheet_link_tag 'leftside' %> <%= javascript_include_tag 'attachments'%> - + + + + + diff --git a/config/routes.rb b/config/routes.rb index c77a1e892..1318a495e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -350,8 +350,10 @@ RedmineApp::Application.routes.draw do post "user_resource_delete" get "search_user_course" post "add_exist_file_to_course" + post "add_exist_file_to_project" get 'resource_preview' post 'rename_resource' + get 'search_user_project' # end end end From 107a5686d1cb522ea149f1ca4df8d4f6af4f400c Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Thu, 20 Aug 2015 11:37:32 +0800 Subject: [PATCH 15/27] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=BA=93=20=E5=85=A8?= =?UTF-8?q?=E9=80=89=E5=8F=8D=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_resources_list.html.erb | 2 +- app/views/users/user_resource.html.erb | 70 +++++++++++++++++++++++- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/app/views/users/_resources_list.html.erb b/app/views/users/_resources_list.html.erb index b344c737d..7a18a037b 100644 --- a/app/views/users/_resources_list.html.erb +++ b/app/views/users/_resources_list.html.erb @@ -3,7 +3,7 @@ <% attachments.each do |attach| %>
        • - +
        • diff --git a/app/views/users/user_resource.html.erb b/app/views/users/user_resource.html.erb index 6938e389e..1ead2447c 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -87,12 +87,12 @@
- +
全选 删除
-
选择 10 个资源
+
选择 0 个资源
@@ -179,6 +179,72 @@ $(".resourcesList").click(function(e) { } line = null; }); + //只要有一个选中了就是true + function checkboxSelected(){ + selected = false; + $("#resources_list").find("input[name='checkbox1']").each(function(){ + if($(this).attr('checked') == true){ + selected = true; + } + }); + return selected; + } + //只有全选才是true + function checkboxAllSelected(){ + allSelected = true; + $("#resources_list").find("input[name='checkbox1']").each(function(){ + if($(this).attr('checked') == undefined){ + allSelected = false; + } + }); + return allSelected; + } + //只有全部不选才是true + function checkboxAllDeselected(){ + allDeselected = true; + $("#resources_list").find("input[name='checkbox1']").each(function(){ + if($(this).attr('checked') == 'checked'){ + allDeselected = false; + } + }); + return allDeselected; + } + //查看所有的checkbox状态,并且按情况更改$("#checkboxAll")的状态 + function checkAllBox(checkbox){ + //只有选中当前checkbox且这个时候所有的checkbox都被选中了,$("#checkboxAll")才是被选中状态,其余都是非选中状态 + if(checkbox.attr('checked') == 'checked' && checkboxAllSelected()){ + $("#checkboxAll").attr('checked',true); + }else{ + $("#checkboxAll").attr('checked',false); + } + $("#res_count").html(getCheckBoxSeletedCount()); + + } + //获取当前checkbox选中的数目 + function getCheckBoxSeletedCount(){ + var i = 0; + $("#resources_list").find("input[name='checkbox1']").each(function(){ + if($(this).attr('checked') == 'checked'){ + i ++; + } + }); + return i; + } + $("#checkboxAll").click(function(e){ + + if($(this).attr('checked')){ + $("#resources_list").find("input[name='checkbox1']").each(function(){ + $(this).attr('checked',true); + }); + $("#res_count").html('<%= @attachments.size%>'); + }else{ + $("#resources_list").find("input[name='checkbox1']").each(function(){ + $(this).attr('checked',false); + }); + $("#res_count").html(0); + } + }); + function show_send(){ $("#contextMenu").hide(); document.oncontextmenu = function() {return true;} From f97a55e16438e0408b2b5939fcc03b7bb42e97d2 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Thu, 20 Aug 2015 14:01:33 +0800 Subject: [PATCH 16/27] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=BA=93=20=E5=88=A0?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 9 ++++- app/views/users/_resources_list.html.erb | 2 +- app/views/users/user_resource.html.erb | 47 +++++++++++++++++------- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 76ce9efaf..f62286973 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -823,9 +823,16 @@ class UsersController < ApplicationController end end - # 删除用户资源 + # 删除用户资源,分为批量删除 和 单个删除 def user_resource_delete + if params[:resource_id].present? Attachment.delete(params[:resource_id]) + elsif params[:checkbox1].present? + params[:checkbox1].each do |id| + Attachment.delete(id) + end + end + #@attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") if(params[:type].nil? || params[:type] == "1") #全部 if User.current.id.to_i == params[:id].to_i diff --git a/app/views/users/_resources_list.html.erb b/app/views/users/_resources_list.html.erb index 7a18a037b..62e819b43 100644 --- a/app/views/users/_resources_list.html.erb +++ b/app/views/users/_resources_list.html.erb @@ -3,7 +3,7 @@ <% attachments.each do |attach| %>
  • - +
  • diff --git a/app/views/users/user_resource.html.erb b/app/views/users/user_resource.html.erb index 1ead2447c..7b173409a 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -82,22 +82,26 @@
  • 上传时间
+
+ <%= render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments} %> +
- +
- 全选 - 删除 + 全选 + 删除
选择 0 个资源
+