From b94553edcd334a8a107766d0c52a8c1f25553bda Mon Sep 17 00:00:00 2001
From: yuanke <249218296@qq.com>
Date: Mon, 10 Oct 2016 09:38:21 +0800
Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E4=BF=AE=E6=94=B9=E5=8F=8A?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/models/user.rb | 6 ++++
.../welcome/_search_all_results.html.erb | 29 +++++++++++--------
.../_search_attachment_results.html.erb | 3 +-
.../welcome/_search_course_results.html.erb | 5 ++--
.../welcome/_search_syllabus_results.html.erb | 12 ++++----
.../welcome/_search_user_results.html.erb | 17 ++++++-----
lib/tasks/elasticsearch_batch_op.rake | 16 +++++-----
7 files changed, 52 insertions(+), 36 deletions(-)
diff --git a/app/models/user.rb b/app/models/user.rb
index 3386836ed..ed17010c6 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -431,6 +431,12 @@ class User < Principal
name = lastname + firstname
name.empty? || name.nil? ? login : name
end
+
+ def show_occupation
+ if self.user_extensions && self.user_extensions.school
+ self.user_extensions.school.name
+ end
+ end
## end
def get_at_show_name
diff --git a/app/views/welcome/_search_all_results.html.erb b/app/views/welcome/_search_all_results.html.erb
index 69ee1756b..4d3cc393d 100644
--- a/app/views/welcome/_search_all_results.html.erb
+++ b/app/views/welcome/_search_all_results.html.erb
@@ -16,11 +16,12 @@
<%= image_tag("search_icon_03.png", :width=>"8", :height=>"16" ,:class=>"fl") %><%= get_user_identity(User.find(item.id).user_extensions.identity) %>
- <%= User.find(item.id).user_extensions && User.find(item.id).user_extensions.brief_introduction.present? ? User.find(item.id).user_extensions.brief_introduction : '这位童鞋很懒,什么也没有留下~'%>
+ <% user = User.find(item.id)%>
+ <%= user.user_extensions && user.user_extensions.brief_introduction.present? ? user.user_extensions.brief_introduction : '这位童鞋很懒,什么也没有留下~'%>
- 加入时间:<%= format_date( User.find(item.id).created_on)%>
- 最后登录时间:<%= format_date( User.find(item.id).last_login_on)%>
- <%= User.find(item.id).user_extensions.occupation.present? ? '单位:'+User.find(item.id).user_extensions.occupation : ''%>
+ 加入时间:<%= format_date( user.created_on)%>
+ 最后登录时间:<%= format_date( user.last_login_on)%>
+ <%=user.show_occupation.nil? ? "": "单位:"+user.show_occupation %>
@@ -29,13 +30,15 @@
-
<%= item.try(:highlight).try(:title) ? item.highlight.title[0].html_safe : item.title %>课程
-
课程
+ <%= image_tag("search_icon_03.png", :width=>"8", :height=>"16" ,:class=>"fl") %>课程
-
- 创建者:<%=item.user.login+"("+item.user.show_name+")"%>
- 教师团队:<%=item.syllabus_members.count%>
- 班级:<%=item.courses.count%>
+ <% user = User.find(item.user_id)%>
+ <% syllabus = Syllabus.find(item.id) %>
+ 创建者:<%=user.login+"("+user.show_name+")"%>
+ 教师团队:<%=syllabus.syllabus_members.count%>
+ 班级:<%=syllabus.courses.count%>
更新时间:<%=format_date(item.updated_at)%>
- 单位:<%=item.user.user_extensions.occupation.present? ? item.user.user_extensions.occupation : '' %>
+ <%=user.show_occupation.nil? ? "": "单位:"+user.show_occupation %>
<% when 'course'%>
@@ -51,10 +54,11 @@
<%= item.try(:highlight).try(:description) ? item.highlight.description[0].html_safe : item.description %>
- 教师:<%= User.find(item.tea_id).realname %>
+ <% user = User.find(item.tea_id)%>
+ 教师:<%= user.realname %>
授课时间:<%= item.time.to_s + item.term%>
更新时间:<%= format_date(item.updated_at)%>
- <%= User.find(item.tea_id).user_extensions.occupation.present? ? '单位:'+User.find(item.tea_id).user_extensions.occupation : ''%>
+ <%=user.show_occupation.nil? ? "": "单位:"+user.show_occupation %>
@@ -69,7 +73,8 @@
<%= image_tag("search_icon_03.png", :width=>"8", :height=>"16" ,:class=>"fl") %>资源
- 发布者:<%= User.find(item.author_id).login%>(<%= User.find(item.author_id).realname%>)
+ <% user = User.find(item.author_id)%>
+ 发布者:<%= user.login%>(<%= user.realname%>)
发布时间:<%= format_date(item.created_on)%>
下载次数:<%= item.downloads%>次
diff --git a/app/views/welcome/_search_attachment_results.html.erb b/app/views/welcome/_search_attachment_results.html.erb
index e51706085..fa0468385 100644
--- a/app/views/welcome/_search_attachment_results.html.erb
+++ b/app/views/welcome/_search_attachment_results.html.erb
@@ -10,7 +10,8 @@
<%= image_tag("search_icon_03.png", :width=>"8", :height=>"16" ,:class=>"fl") %>资源
- 发布者:<%= User.find(attachment.author_id).login%>(<%= User.find(attachment.author_id).realname%>)
+ <% user = User.find(attachment.author_id)%>
+ 发布者:<%= user.login%>(<%= user.realname%>)
发布时间:<%= format_date(attachment.created_on)%>
下载次数:<%= attachment.downloads%>次
diff --git a/app/views/welcome/_search_course_results.html.erb b/app/views/welcome/_search_course_results.html.erb
index 322a47de5..dd4c9f405 100644
--- a/app/views/welcome/_search_course_results.html.erb
+++ b/app/views/welcome/_search_course_results.html.erb
@@ -13,10 +13,11 @@
<%= course.try(:highlight).try(:description) ? course.highlight.description[0].html_safe : (course.description.present? ? course.description : '暂时没有该班级描述') %>
- 教师:<%= User.find(course.tea_id).realname %>
+ <% user = User.find(course.tea_id)%>
+ 教师:<%= user.realname %>
授课时间:<%= course.time.to_s + course.term%>
更新时间:<%= format_date(course.updated_at)%>
- <%= User.find(course.tea_id).user_extensions.occupation.present? ? '单位:'+User.find(course.tea_id).user_extensions.occupation : ''%>
+ <%=user.show_occupation.nil? ? "": "单位:"+user.show_occupation %>
diff --git a/app/views/welcome/_search_syllabus_results.html.erb b/app/views/welcome/_search_syllabus_results.html.erb
index 779570a4e..163392341 100644
--- a/app/views/welcome/_search_syllabus_results.html.erb
+++ b/app/views/welcome/_search_syllabus_results.html.erb
@@ -1,16 +1,18 @@
<% unless syllabuses.nil? || syllabuses.empty?%>
- <% syllabuses.each do |syllabus|%>
+ <% syllabuses.each do |item|%>
-
- <%= syllabus.try(:highlight).try(:title) ? syllabus.highlight.title[0].html_safe : syllabus.title %>课程
-
课程
+ <%= item.try(:highlight).try(:title) ? item.highlight.title[0].html_safe : item.title %>课程
+ <%= image_tag("search_icon_03.png", :width=>"8", :height=>"16" ,:class=>"fl") %>课程
-
- 创建者:<%=syllabus.user.login+"("+syllabus.user.show_name+")"%>
+ <% user = User.find(item.user_id)%>
+ <% syllabus = Syllabus.find(item.id) %>
+ 创建者:<%=user.login+"("+user.show_name+")"%>
教师团队:<%=syllabus.syllabus_members.count%>
班级:<%=syllabus.courses.count%>
更新时间:<%=format_date(syllabus.updated_at)%>
- 单位:<%=syllabus.user.user_extensions.occupation.present? ? syllabus.user.user_extensions.occupation : '' %>
+ <%=user.show_occupation.nil? ? "": "单位:"+user.show_occupation %>
<% end %>
diff --git a/app/views/welcome/_search_user_results.html.erb b/app/views/welcome/_search_user_results.html.erb
index 06a40d021..3b9e18fba 100644
--- a/app/views/welcome/_search_user_results.html.erb
+++ b/app/views/welcome/_search_user_results.html.erb
@@ -1,20 +1,21 @@
<% unless users.nil? || users.empty?%>
-<% users.each do |user|%>
+<% users.each do |item|%>
-
- <%= link_to image_tag(url_to_avatar(User.find(user.id)), :width => "75", :height => "75",:class=>'searchCourseImage'), user_path(user.id), :alt => "用户头像" %>
+ <% user = User.find(item.id)%>
+ <%= link_to image_tag(url_to_avatar(user), :width => "75", :height => "75",:class=>'searchCourseImage'), user_path(user.id), :alt => "用户头像" %>
-
diff --git a/lib/tasks/elasticsearch_batch_op.rake b/lib/tasks/elasticsearch_batch_op.rake
index 6693fcf69..0c041ba8c 100644
--- a/lib/tasks/elasticsearch_batch_op.rake
+++ b/lib/tasks/elasticsearch_batch_op.rake
@@ -7,9 +7,8 @@ namespace :importer do
ENV['BATCH']='1000'
Rake::Task["elasticsearch:import:model"].execute
end
- task :importproject => :environment do
-
- ENV['CLASS']='Project'
+ task :importsyllabus => :environment do
+ ENV['CLASS']='Syllabus'
ENV['SCOPE']='indexable'
ENV['FORCE']='y'
ENV['BATCH']='1000'
@@ -22,15 +21,16 @@ namespace :importer do
ENV['BATCH']='1000'
Rake::Task["elasticsearch:import:model"].execute
end
- task :importsyllabus => :environment do
- ENV['CLASS']='Syllabus'
+ task :importattachment => :environment do
+ ENV['CLASS']='Attachment'
ENV['SCOPE']='indexable'
ENV['FORCE']='y'
ENV['BATCH']='1000'
Rake::Task["elasticsearch:import:model"].execute
end
- task :importattachment => :environment do
- ENV['CLASS']='Attachment'
+ task :importproject => :environment do
+
+ ENV['CLASS']='Project'
ENV['SCOPE']='indexable'
ENV['FORCE']='y'
ENV['BATCH']='1000'
@@ -45,5 +45,5 @@ namespace :importer do
end
desc "Run all tasks"
- task :all => [:importuser,:importproject,:importsyllabus,:importcourse,:importattachment,:importmemo]
+ task :all => [:importuser,:importsyllabus,:importcourse,:importattachment,:importproject,:importmemo]
end
\ No newline at end of file