From f6d09e055495bd08854d627840ded36356fd6f7d Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Sun, 24 Apr 2016 14:23:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=B8=AD=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=B8=80=E4=B8=AA=20=E9=9A=90=E8=97=8F=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E4=BF=A1=E6=81=AF=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/settings_controller.rb | 22 ++++++ app/views/layouts/new_base_user.html.erb | 81 ++++++++++++----------- app/views/settings/edit.html.erb | 1 + app/views/settings/hidden_courses.js.erb | 5 ++ app/views/users/_user_activities.html.erb | 6 +- app/views/users/show.html.erb | 32 +++++---- config/locales/zh.yml | 6 +- config/routes.rb | 1 + config/settings.yml | 2 + 9 files changed, 100 insertions(+), 56 deletions(-) create mode 100644 app/views/settings/hidden_courses.js.erb diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 93e0e9c4b..c22f9e4ab 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -32,6 +32,10 @@ class SettingsController < ApplicationController hidden_non_project = Setting.find_by_name("hidden_non_project") @text = (hidden_non_project && hidden_non_project.value == "0") ? l(:label_show_non_project) : l(:label_hidden_non_project) + #1隐藏了课程信息 0显示了课程信息 + hidden_courses = Setting.find_by_name("hidden_courses") + @text_1 = (hidden_courses && hidden_courses.value == "1") ? l(:label_show_courses) : l(:label_hidden_courses) + @notifiables = Redmine::Notifiable.all if request.post? && params[:settings] && params[:settings].is_a?(Hash) settings = (params[:settings] || {}).dup.symbolize_keys @@ -89,4 +93,22 @@ class SettingsController < ApplicationController redirect_to settings_url end + + #隐藏/显示课程信息 + def hidden_courses + @notifiable = Setting.find_by_name("hidden_courses") + if @notifiable + @notifiable.value == "1" ? @notifiable.value = 0 : @notifiable.value = 1 + @notifiable.save + else + @notifiable = Setting.new() + @notifiable.name = "hidden_courses" + @notifiable.value = 1 + @notifiable.save + end + + redirect_to settings_url + end end + + diff --git a/app/views/layouts/new_base_user.html.erb b/app/views/layouts/new_base_user.html.erb index 4e1064b7f..0d40bb946 100644 --- a/app/views/layouts/new_base_user.html.erb +++ b/app/views/layouts/new_base_user.html.erb @@ -185,48 +185,53 @@
<%= link_to "动态",user_activities_path(@user.id),:class => "homepageMenuText"%>
-
- 课程 - <% if is_current_user%> - <% if User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true)%> -
-
- <% else%> - <%=link_to "", join_private_courses_courses_path, :class => "homepageMenuSetting fr",:style => "margin-right:10px;", :remote => true, :title => "加入课程"%> +
+ <% else%> + <%=link_to "", join_private_courses_courses_path, :class => "homepageMenuSetting fr",:style => "margin-right:10px;", :remote => true, :title => "加入课程"%> + <% end%> <% end%> - <% end%> - - <% if @user.courses.visible.count > 0 - course_order_ids = "(" + - CourseActivity.find_by_sql("SELECT c.course_id, updated_at FROM - (SELECT ca.course_id, MAX(ca.updated_at) AS updated_at FROM course_activities ca WHERE ca.course_id IN (" + @user.courses.visible.select('courses.id').map{|c| c.id}.join(',') + ") - GROUP BY ca.course_id) AS c - ORDER BY c.updated_at DESC limit 5").map {|c| c.course_id}.join(",") + ")" - courses = Course.where("id in #{course_order_ids}") - else - courses = [] + + <% if @user.courses.visible.count > 0 + course_order_ids = "(" + + CourseActivity.find_by_sql("SELECT c.course_id, updated_at FROM + (SELECT ca.course_id, MAX(ca.updated_at) AS updated_at FROM course_activities ca WHERE ca.course_id IN (" + @user.courses.visible.select('courses.id').map{|c| c.id}.join(',') + ") + GROUP BY ca.course_id) AS c + ORDER BY c.updated_at DESC limit 5").map {|c| c.course_id}.join(",") + ")" + courses = Course.where("id in #{course_order_ids}") + else + courses = [] + + end + %> + <%# courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5) %> +
+ +
+ <% end %> - end - %> - <%# courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5) %> -
- -
项目 diff --git a/app/views/settings/edit.html.erb b/app/views/settings/edit.html.erb index 798db291b..32e95db57 100644 --- a/app/views/settings/edit.html.erb +++ b/app/views/settings/edit.html.erb @@ -1,5 +1,6 @@

<%=l(:label_settings)%>

<%= link_to @text,settings_hidden_non_project_path,:id => "hidden_non_project",:style => "float: right;margin-right: 60px;margin-top: 9px;"%> +<%= link_to @text_1,settings_hidden_courses_path,:id => "hidden_courses",:style => "float: right;margin-right: 60px;margin-top: 9px;"%>
<%= render_tabs administration_settings_tabs %> diff --git a/app/views/settings/hidden_courses.js.erb b/app/views/settings/hidden_courses.js.erb new file mode 100644 index 000000000..b4d344a6c --- /dev/null +++ b/app/views/settings/hidden_courses.js.erb @@ -0,0 +1,5 @@ +<% if @notifiable.value == "0"%> +$("#hidden_courses").replaceWith("<%= escape_javascript(link_to '隐藏课程信息',settings_hidden_courses_path,:id => 'hidden_courses',:style => 'float: right;margin-right: 60px;margin-top: 9px;', :remote => true)%>"); +<% else%> +$("#hidden_courses").replaceWith("<%= escape_javascript(link_to '显示课程信息',settings_hidden_courses_path,:id => 'hidden_courses',:style => 'float: right;margin-right: 60px;margin-top: 9px;', :remote => true)%>"); +<% end%> \ No newline at end of file diff --git a/app/views/users/_user_activities.html.erb b/app/views/users/_user_activities.html.erb index 69d209df9..b7df824a4 100644 --- a/app/views/users/_user_activities.html.erb +++ b/app/views/users/_user_activities.html.erb @@ -65,7 +65,11 @@ <% case user_activity.act_type.to_s %> <% when 'HomeworkCommon' %> <%# cache (act) do %> - <%= render :partial => 'course_homework', :locals => {:activity => act,:user_activity_id =>user_activity.id,:course_activity => 0} %> + <% hidden_courses = Setting.find_by_name("hidden_courses") %> + <% unvisiable = hidden_courses && hidden_courses.value == "1"%> + <% if !unvisiable %> + <%= render :partial => 'course_homework', :locals => {:activity => act,:user_activity_id =>user_activity.id,:course_activity => 0} %> + <% end %> <%# end %> <% when 'News' %> <%# cache [act, act.comments.count] do %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 2fe9ab079..5470d2bf3 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -5,20 +5,24 @@