增加组织/个人屏蔽项目/课程动态功能

This commit is contained in:
ouyangxuhua 2016-01-08 14:12:55 +08:00
parent 9e286ef8a5
commit 66bf50098a
21 changed files with 158 additions and 33 deletions

View File

@ -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/

View File

@ -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/

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -0,0 +1,2 @@
module ShieldActivitiesHelper
end

View File

@ -0,0 +1,3 @@
class ShieldActivity < ActiveRecord::Base
end

View File

@ -1,21 +1,21 @@
<div class="resources mt10" id="user_activity_<%= user_activity_id%>" >
<div class="homepagePostBrief" onmouseover="$('#message_setting_<%=activity.id%>').show();" onmouseout="$('#message_setting_<%= activity.id%>').hide();">
<div class="homepagePostBrief" onmouseover="$('#homepage_message_setting_<%=activity.id%>').show();" onmouseout="$('#homepage_message_setting_<%= activity.id%>').hide();">
<div class="homepagePostDes">
<% if activity.author.id == User.current.id%>
<div class="homepagePostSetting" id="message_setting_<%= activity.id%>" style="display: none">
<div class="homepagePostSetting" id="homepage_message_setting_<%= activity.id%>" style="display: none">
<ul>
<li class="homepagePostSettingIcon">
<ul class="homepagePostSettiongText">
<li>
<%= link_to(
l(:button_edit),
l(:button_edit_homepage),
{:controller => 'blog_comments',:action => 'edit',:user_id=>activity.author_id,:blog_id=>activity.blog_id, :id => activity.id},
:class => 'postOptionLink'
) if User.current && User.current.id == activity.author.id %>
</li>
<li>
<%= link_to(
l(:button_delete),
l(:button_delete_homepage),
{:controller => 'blog_comments',:action => 'destroy',:user_id=>activity.author_id,:blog_id=>activity.blog_id, :id => activity.id},
:method => :delete,
:data => {:confirm => l(:text_are_you_sure)},

View File

@ -10,7 +10,13 @@
<li><%= link_to "发布通知", new_course_news_path(course), :class => 'postOptionLink' %></li>
<li><%= link_to "上传资源",upload_files_menu_path(:course_id => course.id), :remote => true, :class => 'postOptionLink' %></li>
<li><%= link_to "发布新帖",course_boards_path( course, :flag => true, :is_new => 1), :class => 'postOptionLink' %></li>
<li><a href="javascript:void(0);" class="postOptionLink">屏蔽动态</a></li>
<li>
<% if ShieldActivity.where("container_type='Organization' and container_id=#{org_id} and shield_type='Course' and shield_id=#{course.id}").count == 0 %>
<%= link_to "屏蔽动态", shield_activities_path(:org_id => org_id, :course_id => course.id), :method => 'post',:class => 'postOptionLink',:remote => true %>
<% else %>
<%= link_to "显示动态", {:controller => 'shield_activities', :action => 'destroy', :org_id => org_id, :course_id => course.id}, :method => 'delete',:class => 'postOptionLink',:remote => true %>
<% end %>
</li>
</ul>
</li>
</ul>

View File

@ -9,7 +9,13 @@
<li><%=link_to "发布问题", new_project_issue_path(project), :class => 'postOptionLink', :target => '_blank' %></li>
<li><%=link_to "发布新帖",project_boards_path(project, :flag => true), :class => 'postOptionLink',:target => '_blank' %></li>
<li><%= link_to "上传资源",upload_files_menu_path(:project_id => project.id), :remote => true, :class => 'postOptionLink' %></li>
<li><a href="javascript:void(0);" class="postOptionLink">屏蔽动态</a></li>
<li>
<% if ShieldActivity.where("container_type='Organization' and container_id=#{org_id} and shield_type='Project' and shield_id=#{project.id}").count == 0 %>
<%= link_to "屏蔽动态", shield_activities_path(:org_id => org_id, :project_id => project.id), :method => 'post',:class => 'postOptionLink',:remote => true %>
<% else %>
<%= link_to "显示动态", {:controller => 'shield_activities', :action => 'destroy', :org_id => org_id, :project_id => project.id},:method => 'delete',:class => 'postOptionLink',:remote => true %>
<% end %>
</li>
</ul>
</li>
</ul>

View File

@ -9,7 +9,13 @@
<li><%= link_to "发布通知", new_course_news_path(course), :class => 'postOptionLink' %></li>
<li><%= link_to "上传资源",upload_files_menu_path(:course_id => course.id), :remote => true, :class => 'postOptionLink' %></li>
<li><%= link_to "发布新帖",course_boards_path( course, :flag => true, :is_new => 1), :class => 'postOptionLink' %></li>
<li><a href="javascript:void(0);" class="postOptionLink">屏蔽动态</a></li>
<li>
<% if ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Course' and shield_id=#{course.id}").count == 0 %>
<%= link_to "屏蔽动态", shield_activities_path(:user_id => user.id, :course_id => course.id), :method => 'post',:class => 'postOptionLink',:remote => true %>
<% else %>
<%= link_to "显示动态", {:controller => 'shield_activities', :action => 'destroy', :user_id => user.id, :course_id => course.id},:method => 'delete',:class => 'postOptionLink',:remote => true %>
<% end %>
</li>
</ul>
</li>
</ul>

View File

@ -8,7 +8,13 @@
<li><%=link_to "发布问题", new_project_issue_path(project), :class => 'postOptionLink', :target => '_blank' %></li>
<li><%=link_to "发布新帖",project_boards_path(project, :flag => true), :class => 'postOptionLink',:target => '_blank' %></li>
<li><%= link_to "上传资源",upload_files_menu_path(:project_id => project.id), :remote => true, :class => 'postOptionLink' %></li>
<li><a href="javascript:void(0);" class="postOptionLink">屏蔽动态</a></li>
<li>
<% if ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Project' and shield_id=#{project.id}").count == 0 %>
<%= link_to "屏蔽动态", shield_activities_path(:user_id => user.id, :project_id => project.id), :method => 'post',:class => 'postOptionLink',:remote => true %>
<% else %>
<%= link_to "显示动态", {:controller => 'shield_activities', :action => 'destroy', :user_id => user.id, :project_id => project.id},:method => 'delete',:class => 'postOptionLink',:remote => true %>
<% end %>
</li>
</ul>
</li>
</ul>

View File

@ -0,0 +1 @@
location.reload();

View File

@ -0,0 +1 @@
location.reload();

View File

@ -1,38 +1,45 @@
<div class="userCard boxShadow">
<div class="userCard boxShadow" style="<%= User.current == user ? 'top:-153px;':'' %>">
<div class="userAvatarWrap fl">
<%= image_tag(url_to_avatar(user), :width => "50", :height => "50") %>
<%= link_to image_tag(url_to_avatar(user), :width => "50", :height => "50"), user_path(user), :alt => "用户头像", :target => '_blank' %>
<%#= image_tag(url_to_avatar(user), :width => "50", :height => "50") %>
<!--<img src="images/homepageImage.jpg" width="50" height="50" alt="个人头像" />-->
</div>
<div class="fl ml15">
<p class="homepageImageName mb5" style="max-width:88px;"><%= user %></p><span class="fb f14"><%= user.show_name %></span>
<div class="fl">
<p class="homepageImageName mb5" style="max-width:88px;"><%= user %></p>
<span class="homepageImageSex"></span>
<div class="cl"></div>
<p class="mb8 c_dark f14"><%= user.user_extensions.technical_title %></p>
<p class="mb8 c_dark f14">
<span class="mr15 hidden fl ml15" style="max-width:90px;"><%= user.show_name %></span>
<%= user.user_extensions.technical_title %>
</p>
</div>
<div class="cl"></div>
<div>
<div class="homepageImageBlock mb10">
<div><a href="javascript:void(0);" class="homepageImageNumber"><%= User.watched_by(user.id).count %></a></div>
<div class="homepageImageText">关注</div>
<div><%= link_to User.watched_by(user.id).count, {:controller=>"users", :action=>"user_watchlist",:id=>user.id}, :class => 'homepageImageNumber',:target => "_blank" %></div>
<div class="homepageImageText"><%= link_to '关注',{:controller=>"users", :action=>"user_watchlist",:id=>user.id},:target => "_blank" %></div>
</div>
<div class="homepageVerDiv"></div>
<div class="homepageImageBlock">
<div><a href="javascript:void(0);" class="homepageImageNumber fans_count_<%= user.id %>"><%= user.watcher_users.count %></a></div>
<div class="homepageImageText">粉丝</div>
<div><%= link_to user.watcher_users.count,{:controller=>"users", :action=>"user_fanslist",:id=>user.id}, :class => 'homepageImageNumber', :id => "fans_count_#{user.id}",:target => "_blank" %></div>
<div class="homepageImageText"><%= link_to '粉丝', {:controller=>"users", :action=>"user_fanslist",:id=>user.id},:target => "_blank" %></div>
</div>
<div class="homepageVerDiv"></div>
<div class="homepageImageBlock">
<div><a href="javascript:void(0);" class="homepageImageNumber"><%= user.blog.blog_comments.where("#{BlogComment.table_name}.parent_id is null").count %></a></div>
<div class="homepageImageText">博客</div>
<div><%= link_to user.blog.blog_comments.where("#{BlogComment.table_name}.parent_id is null").count, user_blogs_path(user), :class => 'homepageImageNumber',:target => "_blank" %></div>
<div class="homepageImageText"><%= link_to '博客', user_blogs_path(user),:target => "_blank" %></div>
</div>
<div class="cl"></div>
<div class="add_cancel_watch_<%= user.id %>">
<%= render :partial => 'users/watch_btn_for_picture', :locals => {:user => user} %>
</div>
<!--<a href="javascript:void(0);" class="userFollow mr27 fl">添加关注</a> <a href="javascript:void(0);" class="userCancel mr27 fl" style="display:none;">取消关注</a>-->
<%= link_to "留言", feedback_path(user), :class => 'greyBtn fr', :target => "_blank" %>
<%= link_to "私信", feedback_path(user), :class => 'greyBtn fr', :style => 'margin-right:20px;', :target => "_blank" %>
<!--<a href="javascript:void(0);" class="greyBtn fl">私信</a><a href="javascript:void(0);" class="greyBtn fr">留言</a> -->
<% if User.current != user %>
<div class="add_cancel_watch_<%= user.id %>">
<%= render :partial => 'users/watch_btn_for_picture', :locals => {:user => user} %>
</div>
<!--<a href="javascript:void(0);" class="userFollow mr27 fl">添加关注</a> <a href="javascript:void(0);" class="userCancel mr27 fl" style="display:none;">取消关注</a>-->
<%= link_to "留言", feedback_path(user), :class => 'greyBtn fr', :target => "_blank" %>
<%= link_to "私信", feedback_path(user), :class => 'greyBtn fr', :style => 'margin-right:20px;', :target => "_blank" %>
<!--<a href="javascript:void(0);" class="greyBtn fl">私信</a><a href="javascript:void(0);" class="greyBtn fr">留言</a> -->
<% end %>
</div>
<em></em>
<font></font>
</div>

View File

@ -21,7 +21,7 @@
<div class="cl"></div>
<div class="message_box mb10" id="users_setting">
<div class="message_box mb10" id="users_setting" >
<div nhname='new_message' style="display:none;">
<%= form_for('new_form',:url => leave_user_message_path(@user.id), :html =>{:id => "user_feedback_new"}, :method => "post") do |f|%>
<textarea placeholder="有问题或有建议,请直接给我留言吧!" style="display: none" nhname='new_message_textarea' name="new_form[user_message]"></textarea>
@ -38,7 +38,9 @@
<div class="message_list_box " id="user_jour_list" style="padding: <%= @jour && @jour.count > 0 ? '10' : '0'%>px;">
<%if @jour%>
<% @jour.each do |jour|%>
<%= render :partial => 'user_jours_new', :locals => {:jour => jour} %>
<% unless jour.private == 1 && (!User.current || (User.current && jour.jour_id != User.current.id && jour.user_id != User.current.id)) %>
<%= render :partial => 'user_jours_new', :locals => {:jour => jour} %>
<% end %>
<%end%>
<% end%>

View File

@ -903,6 +903,8 @@ zh:
button_delete: 删除
button_set_homepage: 设为首页
button_cancel_homepage: 取消首页
button_edit_homepage: 编辑首页
button_delete_homepage: 删除首页
button_edit_associated_wikipage: "编辑相关wiki页面: %{page_title}"
button_add: 新增
button_change: 修改

View File

@ -31,6 +31,7 @@ RedmineApp::Application.routes.draw do
# Enable Grack support
# mount Trustie::Grack.new, at: '/', constraints: lambda { |request| /[-\/\w\.]+\.git\//.match(request.path_info) }, via: [:get, :post]
resources :shield_activities
resources :organizations do
member do
get 'setting'#, :action => 'settings', :as => 'settings'

View File

@ -0,0 +1,15 @@
class CreateShieldActivities < ActiveRecord::Migration
def up
create_table :shield_activities do |t|
t.string :container_type
t.integer :container_id
t.string :shield_type
t.integer :shield_id
t.timestamps
end
end
def down
drop_table :shield_activities
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20160107050736) do
ActiveRecord::Schema.define(:version => 20160108024752) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -1556,6 +1556,15 @@ ActiveRecord::Schema.define(:version => 20160107050736) do
t.string "description"
end
create_table "shield_activities", :force => true do |t|
t.string "container_type"
t.integer "container_id"
t.string "shield_type"
t.integer "shield_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "softapplications", :force => true do |t|
t.string "name"
t.text "description"

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ShieldActivitiesController, :type => :controller do
end