新版首页架构

This commit is contained in:
cxt 2016-12-07 15:15:00 +08:00
parent 35fdf9a8a7
commit 27d800a94a
9 changed files with 254 additions and 86 deletions

View File

@ -50,10 +50,10 @@ gem 'elasticsearch-model'
gem 'elasticsearch-rails' gem 'elasticsearch-rails'
#rails 3.2.22.2 bug #rails 3.2.22.2 bug
# gem "test-unit", "~>3.0" gem "test-unit", "~>3.0"
### profile ### profile
# gem 'oneapm_rpm' gem 'oneapm_rpm'
group :development do group :development do
gem 'grape-swagger' gem 'grape-swagger'

View File

@ -42,7 +42,7 @@ class UsersController < ApplicationController
:activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource, :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,:user_messages,:edit_brief_introduction, :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction,
:user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list, :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list,
:sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses,:homepage, :user_issues] :sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses,:homepage, :user_issues, :course_community, :project_community]
before_filter :auth_user_extension, only: :show before_filter :auth_user_extension, only: :show
#before_filter :rest_user_score, only: :show #before_filter :rest_user_score, only: :show
#before_filter :select_entry, only: :user_projects #before_filter :select_entry, only: :user_projects
@ -1812,96 +1812,119 @@ class UsersController < ApplicationController
params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false) params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false)
join_course_messages.update_all(:viewed => true) join_course_messages.update_all(:viewed => true)
end end
shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id)
shield_course_ids = ShieldActivity.select("shield_id").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.favorite_projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
user_course_ids = (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')"
project_types = "('Message','Issue','Project')"
principal_types = "JournalsForMessage"
container_type = ''
act_type = ''
# 用户项目数 # 访问自己的主页
@my_project_count = user_project_count #if @user == User.current
# 用户的课程数
@my_course_count = user_course_count
# 用户发布的issue数
@issues_author_is_self_count = issues_author_is_self_count
# 用户收到的issue数
@issues_assigned_is_self_count = issues_assigned_is_self_count
if params[:type].present? #else
case params[:type] # 访问他人主页 显示对当前用户可见的动态
when "course_homework" shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id)
container_type = 'Course' shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id)
act_type = 'HomeworkCommon' @page = params[:page] ? params[:page].to_i + 1 : 0
when "course_news" user_project_ids = (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
container_type = 'Course' user_course_ids = (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")"
act_type = 'News' course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')"
when "course_message" project_types = "('Message','Issue','Project')"
container_type = 'Course' principal_types = "JournalsForMessage"
act_type = 'Message' container_type = ''
when "course_poll" act_type = ''
container_type = 'Course'
act_type = 'Poll' # 用户项目数
when "course_journals" @my_project_count = user_project_count
container_type = 'Course' # 用户的课程数
act_type = 'JournalsForMessage' @my_course_count = user_course_count
when "project_issue" # 用户发布的issue数
container_type = 'Project' @issues_author_is_self_count = issues_author_is_self_count
act_type = 'Issue' # 用户收到的issue数
when "project_message" @issues_assigned_is_self_count = issues_assigned_is_self_count
container_type = 'Project'
act_type = 'Message' if params[:type].present?
when "user_journals" case params[:type]
container_type = 'Principal' when "course_homework"
act_type = 'JournalsForMessage' container_type = 'Course'
when "current_user" act_type = 'HomeworkCommon'
container_type = 'Principal' when "course_news"
act_type = 'Principal' container_type = 'Course'
when "all" act_type = 'News'
container_type = 'all' when "course_message"
act_type = 'all' container_type = 'Course'
act_type = 'Message'
when "course_poll"
container_type = 'Course'
act_type = 'Poll'
when "course_journals"
container_type = 'Course'
act_type = 'JournalsForMessage'
when "project_issue"
container_type = 'Project'
act_type = 'Issue'
when "project_message"
container_type = 'Project'
act_type = 'Message'
when "user_journals"
container_type = 'Principal'
act_type = 'JournalsForMessage'
when "current_user"
container_type = 'Principal'
act_type = 'Principal'
when "all"
container_type = 'all'
act_type = 'all'
end
end end
end if container_type != '' && container_type != 'all'
if container_type != '' && container_type != 'all' if container_type == 'Course'
if container_type == 'Course' sql = "container_type = '#{container_type}' and container_id in #{user_course_ids} and act_type = '#{act_type}'"
sql = "container_type = '#{container_type}' and container_id in #{user_course_ids} and act_type = '#{act_type}'" elsif container_type == 'Project'
elsif container_type == 'Project' sql = "container_type = '#{container_type}' and container_id in #{user_project_ids} and act_type = '#{act_type}'"
sql = "container_type = '#{container_type}' and container_id in #{user_project_ids} and act_type = '#{act_type}'" elsif container_type == 'Principal' && act_type == 'JournalsForMessage'
elsif container_type == 'Principal' && act_type == 'JournalsForMessage' sql = "container_type = '#{container_type}' and act_type= '#{act_type}' and container_id = #{@user.id}"
sql = "container_type = '#{container_type}' and act_type= '#{act_type}' and container_id = #{@user.id}" elsif container_type == 'Principal' && act_type == 'Principal'
elsif container_type == 'Principal' && act_type == 'Principal' sql = "user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))"
sql = "user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))" end
end if User.current != @user
if User.current != @user sql += " and user_id = #{@user.id}"
sql += " and user_id = #{@user.id}" end
end
else
if User.current != @user
blog_ids = "("+@user.blog.id.to_s+")"
else else
blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" if User.current != @user
blog_ids = "("+@user.blog.id.to_s+")"
else
blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")"
end
sql = "(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " +
"or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})"
if container_type != 'all' && User.current != @user
sql = "user_id = #{@user.id} and(" + sql + ")"
end
end end
sql = "(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10)
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + @type = params[:type]
"or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})" #end
if container_type != 'all' && User.current != @user
sql = "user_id = #{@user.id} and(" + sql + ")"
end
end
@user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10)
@type = params[:type]
respond_to do |format| respond_to do |format|
format.js format.js
format.html {render :layout => 'new_base_user'} format.html {render :layout => 'new_base_user'}
end end
end end
# 课程社区
def course_community
respond_to do |format|
format.js
format.html {render :layout => 'base_course_community'}
end
end
# 项目社区
def project_community
respond_to do |format|
format.js
format.html {render :layout => 'base_project_community'}
end
end
def show_old def show_old
pre_count = 10 #limit pre_count = 10 #limit
# Time 2015-02-04 11:46:34 # Time 2015-02-04 11:46:34

View File

@ -11,10 +11,10 @@
<%#= link_to "资源库", user_resource_user_path(User.current, :type => 1), :class => "c_white f16 db p10" %> <%#= link_to "资源库", user_resource_user_path(User.current, :type => 1), :class => "c_white f16 db p10" %>
</li>--> </li>-->
<li class="navHomepageMenu fl"> <li class="navHomepageMenu fl">
<a href="javascript:void(0);" title="" class="c_white f16 db p10">课程</a> <%= link_to "课程", user_course_community_path(User.current), :class => "c_white f16 db p10" %>
</li> </li>
<li class="navHomepageMenu fl"> <li class="navHomepageMenu fl">
<a href="javascript:void(0);" title="" class="c_white f16 db p10">项目</a> <%= link_to "项目", user_project_community_path(User.current), :class => "c_white f16 db p10" %>
</li> </li>
<% if hidden_unproject_infos %> <% if hidden_unproject_infos %>
<!-- <li class="navHomepageMenu fl"> <!-- <li class="navHomepageMenu fl">

View File

@ -0,0 +1,69 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title><%= h html_title %></title>
<meta name="description" content="<%= Redmine::Info.app_name %>" />
<meta name="keywords" content="issue,bug,tracker" />
<%= csrf_meta_tag %>
<%= favicon %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/common', 'css/structure','css/public', 'prettify','css/project','css/courses','css/popup','syllabus','css/moduel', 'css/user', :media => 'all' %>
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
<%= javascript_heads %>
<%= javascript_include_tag "bootstrap","avatars","new_user",'attachments','prettify'%>
<%= heads_for_theme %>
<%= call_hook :view_layouts_base_html_head %>
<%= yield :header_tags -%>
<!-- MathJax的配置 -->
<script type="text/javascript"
src="/javascripts/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- 配置 在生成的公式图片上去掉Math定义的右键菜单$$ $$ \( \) \[ \] 中的公式给予显示-->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
showMathMenu: false,
showMathMenuMSIE: false,
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
</head>
<body onload="prettyPrint();">
<div class="navContainer">
<% is_current_user = User.current.logged? && User.current == @user%>
<% if User.current.logged? %>
<%= render :partial => 'layouts/logined_header' %>
<% else%>
<%= render :partial => 'layouts/unlogin_header' %>
<% end%>
</div>
<div class="cl"></div>
<div class="homepageContentContainer">
<!--div class="homepageRightBannerImg"></div-->
<div class="cl"></div>
<div class="homepageContent">
<div class="homepageLeft mt10" id="LSide">
<%# 更新访问数,刷新的时候更新访问次数 %>
<% update_visiti_count @user %>
<div class="fontGrey5 mt10 ml20">访问计数 <%= @user.visits.to_i %> 自2016年5月</div>
</div>
<div class="homepageRight">
<%= yield %>
</div>
</div>
</div>
<div class="cl"></div>
<%= render :partial => 'layouts/footer' %>
<div class="cl"></div>
<div id="ajax-modal" style="display:none;"></div>
<div id="ajax-indicator" style="display:none;">
<span><%= l(:label_loading) %></span>
</div>
<div id="nh_tx_dialog_html" class="white_content" style="display:none;">
<%=render :partial => 'layouts/upload_avatar', :locals => {:source => @user} %>
</div>
</body>
</html>

View File

@ -0,0 +1,69 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title><%= h html_title %></title>
<meta name="description" content="<%= Redmine::Info.app_name %>" />
<meta name="keywords" content="issue,bug,tracker" />
<%= csrf_meta_tag %>
<%= favicon %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/common', 'css/structure','css/public', 'prettify','css/project','css/courses','css/popup','syllabus','css/moduel', 'css/user', :media => 'all' %>
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
<%= javascript_heads %>
<%= javascript_include_tag "bootstrap","avatars","new_user",'attachments','prettify'%>
<%= heads_for_theme %>
<%= call_hook :view_layouts_base_html_head %>
<%= yield :header_tags -%>
<!-- MathJax的配置 -->
<script type="text/javascript"
src="/javascripts/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- 配置 在生成的公式图片上去掉Math定义的右键菜单$$ $$ \( \) \[ \] 中的公式给予显示-->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
showMathMenu: false,
showMathMenuMSIE: false,
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
</head>
<body onload="prettyPrint();">
<div class="navContainer">
<% is_current_user = User.current.logged? && User.current == @user%>
<% if User.current.logged? %>
<%= render :partial => 'layouts/logined_header' %>
<% else%>
<%= render :partial => 'layouts/unlogin_header' %>
<% end%>
</div>
<div class="cl"></div>
<div class="homepageContentContainer">
<!--div class="homepageRightBannerImg"></div-->
<div class="cl"></div>
<div class="homepageContent">
<div class="homepageLeft mt10" id="LSide">
<%# 更新访问数,刷新的时候更新访问次数 %>
<% update_visiti_count @user %>
<div class="fontGrey5 mt10 ml20">访问计数 <%= @user.visits.to_i %> 自2016年5月</div>
</div>
<div class="homepageRight">
<%= yield %>
</div>
</div>
</div>
<div class="cl"></div>
<%= render :partial => 'layouts/footer' %>
<div class="cl"></div>
<div id="ajax-modal" style="display:none;"></div>
<div id="ajax-indicator" style="display:none;">
<span><%= l(:label_loading) %></span>
</div>
<div id="nh_tx_dialog_html" class="white_content" style="display:none;">
<%=render :partial => 'layouts/upload_avatar', :locals => {:source => @user} %>
</div>
</body>
</html>

View File

@ -160,7 +160,9 @@
</div> </div>
<div class="home-user-leftnav"> <div class="home-user-leftnav">
<h3 >课程社区</h3> <h3>
<%= link_to "课程社区", user_course_community_path(User.current), :class => "fl" %>
</h3>
<% if hidden_unproject_infos %> <% if hidden_unproject_infos %>
<ul> <ul>
<li class="home-user-leftnav-li icons-class clear"> <li class="home-user-leftnav-li icons-class clear">
@ -200,7 +202,9 @@
</div> </div>
<% end %> <% end %>
<div class="home-user-leftnav"> <div class="home-user-leftnav">
<h3 >项目社区</h3> <h3 >
<%= link_to "项目社区", user_project_community_path(User.current), :class => "fl" %>
</h3>
<ul> <ul>
<li class="home-user-leftnav-li icons-project clear"> <li class="home-user-leftnav-li icons-project clear">
<%= link_to "项目<span class='issues_nav_tag ml140'>#{@my_project_count}</span>".html_safe, {:controller => "users", :action => "user_projectlist", :id => @user}, :id => 'user_project_list', :class => "fl" %> <%= link_to "项目<span class='issues_nav_tag ml140'>#{@my_project_count}</span>".html_safe, {:controller => "users", :action => "user_projectlist", :id => @user}, :id => 'user_project_list', :class => "fl" %>

View File

@ -564,6 +564,9 @@ RedmineApp::Application.routes.draw do
match 'courses/:course_id/news/new', :to => 'news#new', :via => [:get, :post] match 'courses/:course_id/news/new', :to => 'news#new', :via => [:get, :post]
match 'users/:user_id/homepage/articles/:id', :to => 'article_homepages#show', :as => "user_homepage_show" match 'users/:user_id/homepage/articles/:id', :to => 'article_homepages#show', :as => "user_homepage_show"
match 'users/:id/courses', :to => 'users#course_community', :as => "user_course_community"
match 'users/:id/projects', :to => 'users#project_community', :as => "user_project_community"
scope ":username" do scope ":username" do
resources :posts resources :posts
end end