个人主页->访客

This commit is contained in:
yutao 2015-07-14 15:16:15 +08:00
parent b7c4449f4b
commit 00c50d8114
7 changed files with 134 additions and 79 deletions

View File

@ -26,10 +26,10 @@ class UsersController < ApplicationController
menu_item :user_homework, :only => :user_homeworks
menu_item :user_project, :only => [:user_projects, :watch_projects]
# menu_item :requirement_focus, :only => :watch_bids
menu_item :requirement_focus, :only => :watch_contests
menu_item :requirement_focus, :only => :watch_contests
menu_item :user_newfeedback, :only => :user_newfeedback
#Ended by young
# edit
@ -40,24 +40,27 @@ class UsersController < ApplicationController
:user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :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,:update_score,:user_activities,:user_projects_index,
:user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show]
:user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist]
#edit has been deleted by huang, 2013-9-23
before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses,
:user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses,
: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,
:user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show]
: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
#before_filter :select_entry, only: :user_projects
accept_api_auth :index, :show, :create, :update, :destroy,:tag_save , :tag_saveEx
#william
before_filter :require_login, :only => [:tag_save,:tag_saveEx]
#before_filter :refresh_changests, :only =>[:user_activities,:user_courses,:user_projects,:user_newfeedback]
#visitor
before_filter :recorded_visitor, :only => [:show,:user_fanslist,:user_watchlist,:user_visitorlist]
helper :sort
include SortHelper
helper :custom_fields
@ -179,21 +182,21 @@ class UsersController < ApplicationController
# format.api
# end
end
#new add by linchun
def watch_contests
@bids = Contest.watched_by(@user)
def watch_contests
@bids = Contest.watched_by(@user)
@offset, @limit = api_offset_and_limit({:limit => 10})
@contest_count = @contests.count
@contest_pages = Paginator.new @contest_count, @limit, params['page']
@offset ||= @contest_pages.reverse_offset
@offset ||= @contest_pages.reverse_offset
unless @offset == 0
@contest = @contests.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
@contest = @contests.offset(@offset).limit(limit).all.reverse
end
respond_to do |format|
format.html {
render :layout => 'base_users'
@ -230,9 +233,9 @@ class UsersController < ApplicationController
end
end
# end
# added by huang
def user_homeworks
def user_homeworks
# @membership = @user.memberships.all(:conditions => Project.visible_condition(User.current))
# @memberships = []
# @membership.each do |membership|
@ -251,9 +254,9 @@ class UsersController < ApplicationController
# return
# end
# end
end
end
include CoursesHelper
def user_courses
@ -334,7 +337,7 @@ class UsersController < ApplicationController
#end
def index
@status = params[:status] || 1
sort_init 'login', 'asc'
sort_update %w(login firstname lastname mail admin created_on last_login_on)
@ -350,7 +353,7 @@ class UsersController < ApplicationController
# 先内连一下statuses 保证排序之后数量一致
scope = User.visible.
joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id")
# unknow
scope = scope.in_group(params[:group_id]) if params[:group_id].present?
@ -387,7 +390,7 @@ class UsersController < ApplicationController
# limit and offset
@users = @users.limit(@user_pages.per_page).offset(@user_pages.offset)
@user_base_tag = params[:id] ? 'base_users':'users_base'
respond_to do |format|
format.html {
@ -397,7 +400,7 @@ class UsersController < ApplicationController
format.api
end
end
def search
sort_init 'login', 'asc'
sort_update %w(login firstname lastname mail admin created_on last_login_on)
@ -601,9 +604,9 @@ class UsersController < ApplicationController
end
when "2"
message = []
if @user == User.current
if @user == User.current
message = JournalsForMessage.reference_message(@user.id)
message += Journal.reference_message(@user.id)
message += Journal.reference_message(@user.id)
end
@activity_count = message.size
@info_pages = Paginator.new @activity_count, pre_count, params['page']
@ -634,7 +637,7 @@ class UsersController < ApplicationController
p_ids = []
Project.where(id: project_ids).each do |x|
p_ids << x.id unless x.visible?(User.current)
end
end
ids = []
ids << Issue.where(id: act_ids, project_id: p_ids).map{|x| x.id}
@ -653,7 +656,7 @@ class UsersController < ApplicationController
p_ids = []
Project.where(id: project_ids).each do |x|
p_ids << x.id unless x.visible?(User.current)
end
end
ids << Journal.where(id: act_ids, journalized_id: p_ids, journalized_type: 'Project').map{|x| x.id}
#News
@ -662,16 +665,16 @@ class UsersController < ApplicationController
p_ids = []
Project.where(id: project_ids).each do |x|
p_ids << x.id unless x.visible?(User.current)
end
end
ids << News.where(id: act_ids, project_id: p_ids).map{|x| x.id}
project_ids = News.where(id: act_ids).select('distinct course_id').map{|x| x.course_id}
c_ids = []
Course.where(id: project_ids).each do |x|
c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x)
end
end
ids << News.where(id: act_ids, course_id: p_ids).map{|x| x.id}
#Message
act_ids = activity.where(act_type: 'Message').select('act_id').map{|x| x.act_id}
board_ids = Message.where(id: act_ids).select('distinct board_id').map{|x| x.board_id}
@ -679,14 +682,14 @@ class UsersController < ApplicationController
p_ids = []
Project.where(id: project_ids).each do |x|
p_ids << x.id unless x.visible?(User.current)
end
end
ids << Message.where(id: act_ids, board_id: p_ids).map{|x| x.id}
project_ids = Board.where(id: board_ids).select('distinct course_id').map{|x| x.course_id}
c_ids = []
Course.where(id: project_ids).each do |x|
c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x)
end
end
ids << Message.where(id: act_ids, board_id: c_ids).map{|x| x.id}
logger.debug "filter ids #{ids}"
@ -704,33 +707,33 @@ class UsersController < ApplicationController
# (e.act_type == "Message" && !e.act.board.nil? && ((!e.act.board.project.nil? && !e.act.board.project.visible?(User.current)) || (!e.act.board.course.nil? && e.act.board.course.is_public == 0 && !User.current.member_of_course?(e.act.board.course))))))
# }
#
@activity_count = activity.count
@activity_pages = Paginator.new @activity_count, pre_count, params['page']
@activity = activity.slice(@activity_pages.offset,@activity_pages.per_page)
@state = 0
end
if params[:user].present?
user_temp = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:user]}%' or lastname like '%#{params[:user]}%'")
if user_temp.size > 1
activity = Activity.where('user_id in (?)', user_temp).where('user_id in (?)', watcher).order('id desc')
activity = Activity.where('user_id in (?)', user_temp).where('user_id in (?)', watcher).order('id desc')
elsif user_temp.size == 1
activity = Activity.where('user_id = ?', user_temp).where('user_id in (?)', watcher).order('id desc')
activity = Activity.where('user_id = ?', user_temp).where('user_id in (?)', watcher).order('id desc')
else
activity = Activity.where("1 = 0")
end
@offset, @limit = api_offset_and_limit({:limit => 10})
@activity_count = activity.count
@activity_count = activity.count
@activity_pages = Paginator.new @activity_count, @limit, params['page']
@offset ||= @activity_pages.offset
@activity = activity.offset(@offset).limit(@limit)
@activity = activity.offset(@offset).limit(@limit)
@state = 0
end
#Modified by nie
unless User.current.admin?
if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?)
@ -752,17 +755,17 @@ class UsersController < ApplicationController
def info
message = []
if @user == User.current
if @user == User.current
message = JournalsForMessage.reference_message(@user.id)
message += Journal.reference_message(@user.id)
message += Journal.reference_message(@user.id)
end
@offset, @limit = api_offset_and_limit({:limit => 10})
@info_count = message.size
@info_pages = Paginator.new @info_count, @limit, params['page']
@offset ||= @info_pages.offset
messages = message.sort {|x,y| y.created_on <=> x.created_on }
@message = messages[@offset, @limit]
unless User.current.admin?
@ -778,7 +781,7 @@ class UsersController < ApplicationController
end
end
#### end
def new
@user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
@ -836,7 +839,7 @@ class UsersController < ApplicationController
@auth_sources = AuthSource.all
@membership ||= Member.new
end
def watch_projects
@watch_projects = Project.joins(:watchers).where("project_type <>? and watchable_type = ? and `watchers`.user_id = ?", '1','Project', @user.id)
@state = 1
@ -1025,36 +1028,47 @@ class UsersController < ApplicationController
@action = 'fans'
render :layout=>'base_users_new'
end
def user_visitorlist
limit = 10;
#query = @user.watcher_users;
query = User.joins("join visitors v on #{User.table_name}.id=v.user_id")
query = query.where("v.master_id=?",@user.id)
@obj_count = query.count();
@obj_pages = Paginator.new @obj_count,limit,params['page']
@list = query.order("v.updated_on desc").limit(limit).offset(@obj_pages.offset).all();
@action = 'visitor'
render :template=>'users/user_fanslist',:layout=>'base_users_new'
end
#william
def update_extensions(user_extensions)
user_extensions = params[:user_extensions]
unless user_extensions.nil?
user_extensions = UserExtensions.find_by_id(user_extensions.user_id)
# user_extensions.
end
end
# added by bai
def topic_score_index
end
def project_score_index
end
def activity_score_index
end
def influence_score_index
end
def score_index
end
# end
def topic_new_score_index
@ -1100,7 +1114,7 @@ class UsersController < ApplicationController
# 必填自己的工作单位,其实就是学校
def auth_user_extension
if @user == User.current && @user.user_extensions.nil?
if @user == User.current && @user.user_extensions.nil?
flash[:error] = l(:error_complete_occupation)
redirect_to my_account_url
end
@ -1128,4 +1142,20 @@ class UsersController < ApplicationController
render_404
end
end
def recorded_visitor
if(User.current.logged? && User.current != @user)
#impl = Visitor.where('user_id=? and master_id=?',User.current.id,@user.id).find;
# impl = Visitor.find_by_sql('user_id=? and master_id=?',[User.current.id,@user.id]);
impl = Visitor.find_by_user_id_and_master_id(User.current.id,@user.id);
if(impl.nil?)
impl = Visitor.new
impl.user_id = User.current.id
impl.master_id = @user.id
else
impl.updated_on = Time.now
end
impl.save
end
end
end

View File

@ -321,6 +321,15 @@ module UsersHelper
list = obj.watcher_users.order("#{Watcher.table_name}.id desc").limit(10).all
return [count,list];
end
def get_visitor_users(obj)
query = Visitor.where("master_id=?",obj.id)
count = query.count
if count == 0
return [0,[]]
end
list = query.order("updated_on desc").limit(10).all
return [count,list];
end
def get_create_course_count(user)
return Course.where("tea_id = ?",user.id).count()

3
app/models/visitor.rb Normal file
View File

@ -0,0 +1,3 @@
class Visitor < ActiveRecord::Base
belongs_to :user
end

View File

@ -253,23 +253,18 @@ $(".subNav").click(function(){
<%= render :partial => 'layouts/user_watch_list', :locals => {:user => @user} %>
<%= render :partial => 'layouts/user_fans_list', :locals => {:user => @user} %>
<!--<div class="leftbox mt10" >-->
<!--<h4 class="fl">访客</h4><a href="javascirpt:void();" class="more fr mr10">更多</a>-->
<!--<div class="cl"></div>-->
<!--<div class="mt5">-->
<!--<a href="javascirpt:void();" class="pic_members"><img src="images/pic_users.jpg" width="38" height="38" alt="头像" /></a>-->
<!--<a href="javascirpt:void();" class="pic_members"><img src="images/pic_users.jpg" width="38" height="38" alt="头像" /></a>-->
<!--<a href="javascirpt:void();" class="pic_members"><img src="images/pic_users.jpg" width="38" height="38" alt="头像" /></a>-->
<!--<a href="javascirpt:void();" class="pic_members"><img src="images/pic_users.jpg" width="38" height="38" alt="头像" /></a>-->
<!--<a href="javascirpt:void();" class="pic_members"><img src="images/pic_users.jpg" width="38" height="38" alt="头像" /></a>-->
<!--<a href="javascirpt:void();" class="pic_members"><img src="images/pic_users.jpg" width="38" height="38" alt="头像" /></a>-->
<!--<a href="javascirpt:void();" class="pic_members"><img src="images/pic_users.jpg" width="38" height="38" alt="头像" /></a>-->
<!--<a href="javascirpt:void();" class="pic_members"><img src="images/pic_users.jpg" width="38" height="38" alt="头像" /></a>-->
<!--<a href="javascirpt:void();" class="pic_members"><img src="images/pic_users.jpg" width="38" height="38" alt="头像" /></a>-->
<!--<a href="javascirpt:void();" class="pic_members"><img src="images/pic_users.jpg" width="38" height="38" alt="头像" /></a>-->
<!--<div class="cl"></div>-->
<!--</div>-->
<!--</div>&lt;!&ndash;leftbox end&ndash;&gt;-->
<% visitor_count,visitor_list = get_visitor_users(@user) %>
<div class="leftbox mt10" style="display:<%= visitor_count==0 ? 'none' : 'block' %>">
<h4 class="fl">访客</h4><a href="<%=url_for(:controller => 'users', :action => 'user_visitorlist', :id=>@user.id)%>" data-count="<%= visitor_count %>" style="display:<%= visitor_count>10 ? 'block' : 'block' %>" class="more fr mr10">更多</a>
<div class="cl"></div>
<div class="mt5">
<% for visitor in visitor_list %>
<%= link_to image_tag(url_to_avatar(visitor.user), :style => "width:38px;height:38px;"), user_path(visitor.user), :class => "pic_members", :title => "#{visitor.user.name}" %>
<% end %>
<div class="cl"></div>
</div>
</div>
</div><!--LSide end-->
<%= yield %>

View File

@ -1,9 +1,12 @@
<div id="RSide" class="fl">
<div class="courses_box">
<div class="courses_top mb10" id="<%= @action == 'fans' ? 'nh_fans_list' : 'nh_wacth_list' %>">
<% if @action == 'fans'%>
<div class="courses_top mb10" id="<%= (@action == 'fans' || @action == 'visitor' ) ? 'nh_fans_list' : 'nh_wacth_list' %>">
<% if @action == 'fans' %>
<h2 class="courses_h2 fl">粉丝</h2>
<div class="courses_select fr">共有<span class="c_orange" nh_name="fans_count"><%=@obj_count%></span>名粉丝</div>
<% elsif @action == 'visitor' %>
<h2 class="courses_h2 fl">访客</h2>
<div class="courses_select fr">共有<span class="c_orange"><%=@obj_count%></span>访客</div>
<% else %>
<h2 class="courses_h2 fl">关注</h2>
<div class="courses_select fr">一共关注<span class="c_orange" nh_name="watcher_count"><%=@obj_count%></span>人</div>

View File

@ -302,6 +302,7 @@ RedmineApp::Application.routes.draw do
match 'user_course_activities', :to => 'users#user_course_activities', :via => :get
match 'user_project_activities', :to => 'users#user_project_activities', :via => :get
match 'user_feedback4show', :to => 'users#user_feedback4show', :via => :get
match 'user_visitorlist', :to => 'users#user_visitorlist', :via => :get
match 'user_homeworks', :to => 'users#user_homeworks', :via => :get
match 'watch_projects', :to => 'users#watch_projects', :via => :get
# added by bai

View File

@ -0,0 +1,14 @@
class CreateVisitors < ActiveRecord::Migration
def change
create_table :visitors do |t|
t.integer :user_id
t.integer :master_id
t.datetime :updated_on
t.datetime :created_on
end
add_index "visitors", ["user_id"], :name => "index_visitors_user_id"
add_index "visitors", ["master_id"], :name => "index_visitors_master_id"
add_index "visitors", ["updated_on"], :name => "index_visitors_updated_on"
end
end