From 66bf50098a3038f897ad8fd4026028a6a2895c04 Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Fri, 8 Jan 2016 14:12:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=84=E7=BB=87/=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E5=B1=8F=E8=94=BD=E9=A1=B9=E7=9B=AE/=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E5=8A=A8=E6=80=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../javascripts/shield_activities.js.coffee | 3 ++ .../stylesheets/shield_activities.css.scss | 3 ++ app/controllers/organizations_controller.rb | 6 ++- .../shield_activities_controller.rb | 43 +++++++++++++++++++ app/controllers/users_controller.rb | 6 ++- app/helpers/shield_activities_helper.rb | 2 + app/models/shield_activity.rb | 3 ++ app/views/blogs/_homepage.html.erb | 8 ++-- app/views/layouts/_org_courses.html.erb | 8 +++- app/views/layouts/_org_projects.html.erb | 8 +++- app/views/layouts/_user_courses.html.erb | 8 +++- app/views/layouts/_user_projects.html.erb | 8 +++- app/views/shield_activities/create.js.erb | 1 + app/views/shield_activities/destroy.js.erb | 1 + app/views/users/_show_detail_info.html.erb | 43 +++++++++++-------- app/views/users/user_newfeedback.html.erb | 6 ++- config/locales/zh.yml | 2 + config/routes.rb | 1 + ...20160108024752_create_shield_activities.rb | 15 +++++++ db/schema.rb | 11 ++++- .../shield_activities_controller_spec.rb | 5 +++ 21 files changed, 158 insertions(+), 33 deletions(-) create mode 100644 app/assets/javascripts/shield_activities.js.coffee create mode 100644 app/assets/stylesheets/shield_activities.css.scss create mode 100644 app/controllers/shield_activities_controller.rb create mode 100644 app/helpers/shield_activities_helper.rb create mode 100644 app/models/shield_activity.rb create mode 100644 app/views/shield_activities/create.js.erb create mode 100644 app/views/shield_activities/destroy.js.erb create mode 100644 db/migrate/20160108024752_create_shield_activities.rb create mode 100644 spec/controllers/shield_activities_controller_spec.rb diff --git a/app/assets/javascripts/shield_activities.js.coffee b/app/assets/javascripts/shield_activities.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/shield_activities.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/shield_activities.css.scss b/app/assets/stylesheets/shield_activities.css.scss new file mode 100644 index 000000000..9ac6bff3e --- /dev/null +++ b/app/assets/stylesheets/shield_activities.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the shield_activities controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index ba017579f..d428a5814 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -73,8 +73,10 @@ class OrganizationsController < ApplicationController @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0 @org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10) else - project_ids = @organization.projects.map(&:id) << 0 - course_ids = @organization.courses.map(&:id) << 0 + shield_project_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Project'").map(&:shield_id) + shield_course_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Course'").map(&:shield_id) + project_ids = (@organization.projects.map(&:id)-shield_project_ids) << 0 + course_ids = (@organization.courses.map(&:id)-shield_course_ids) << 0 course_types = "('Message','News','HomeworkCommon','Poll','Course')" case params[:type] when nil diff --git a/app/controllers/shield_activities_controller.rb b/app/controllers/shield_activities_controller.rb new file mode 100644 index 000000000..7f4f4eebf --- /dev/null +++ b/app/controllers/shield_activities_controller.rb @@ -0,0 +1,43 @@ +class ShieldActivitiesController < ApplicationController + def create + if params[:org_id] + if params[:project_id] + ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i) + elsif params[:course_id] + ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Course', :shield_id => params[:course_id].to_i) + end + elsif params[:user_id] + if params[:project_id] + ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i) + elsif params[:course_id] + ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Course', :shield_id => params[:course_id].to_i) + end + end + end + + def destroy + if params[:org_id] + if params[:project_id] + ShieldActivity.where("container_type='Organization' and container_id=#{params[:org_id].to_i} and shield_type='Project' and shield_id=#{params[:project_id]}").each do |act| + act.destroy + end + # ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i) + elsif params[:course_id] + ShieldActivity.where("container_type='Organization' and container_id=#{params[:org_id].to_i} and shield_type='Course' and shield_id=#{params[:course_id]}").each do |act| + act.destroy + end + end + elsif params[:user_id] + if params[:project_id] + ShieldActivity.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Project' and shield_id=#{params[:project_id]}").each do |act| + act.destroy + end + # ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i) + elsif params[:course_id] + ShieldActivity.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Course' and shield_id=#{params[:course_id]}").each do |act| + act.destroy + end + end + end + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d28837858..1e0a833d9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -965,9 +965,11 @@ class UsersController < ApplicationController params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false) join_course_messages.update_all(:viewed => true) end + shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id) + shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id) @page = params[:page] ? params[:page].to_i + 1 : 0 - user_project_ids = @user.projects.visible.empty? ? "(-1)" : "(" + @user.projects.visible.map{|project| project.id}.join(",") + ")" - user_course_ids = @user.courses.visible.empty? ? "(-1)" : "(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" + user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" + user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")" course_types = "('Message','News','HomeworkCommon','Poll','Course')" project_types = "('Message','Issue','ProjectCreateInfo')" principal_types = "JournalsForMessage" diff --git a/app/helpers/shield_activities_helper.rb b/app/helpers/shield_activities_helper.rb new file mode 100644 index 000000000..5dcbcca33 --- /dev/null +++ b/app/helpers/shield_activities_helper.rb @@ -0,0 +1,2 @@ +module ShieldActivitiesHelper +end diff --git a/app/models/shield_activity.rb b/app/models/shield_activity.rb new file mode 100644 index 000000000..8f8447dcf --- /dev/null +++ b/app/models/shield_activity.rb @@ -0,0 +1,3 @@ +class ShieldActivity < ActiveRecord::Base + +end \ No newline at end of file diff --git a/app/views/blogs/_homepage.html.erb b/app/views/blogs/_homepage.html.erb index a4059fc33..a7fe42a75 100644 --- a/app/views/blogs/_homepage.html.erb +++ b/app/views/blogs/_homepage.html.erb @@ -1,21 +1,21 @@
-
+
<% if activity.author.id == User.current.id%> -