From 0e2b7ba362f995ec0ceedef1d68ea434cda5219c Mon Sep 17 00:00:00 2001 From: yanxd Date: Thu, 3 Jul 2014 17:22:48 +0800 Subject: [PATCH 1/2] tag search fix --- app/controllers/tags_controller.rb | 41 ++++++++++++------- app/helpers/courses_helper.rb | 5 +++ app/views/tags/_show_attachments.html.erb | 2 +- app/views/tags/_show_bids.html.erb | 2 +- app/views/tags/_show_contests.html.erb | 2 +- app/views/tags/_show_courses.html.erb | 14 +++++++ app/views/tags/_show_forums.html.erb | 2 +- app/views/tags/_show_issues.html.erb | 2 +- .../tags/_show_open_source_projects.html.erb | 2 +- app/views/tags/_show_projects.html.erb | 2 +- app/views/tags/_show_users.html.erb | 2 +- app/views/tags/_tag_search_results.html.erb | 3 ++ app/views/tags/index.html.erb | 3 +- 13 files changed, 58 insertions(+), 24 deletions(-) create mode 100644 app/views/tags/_show_courses.html.erb diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 0216d529d..ba01aa990 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -64,15 +64,18 @@ class TagsController < ApplicationController @forum_tags_num, @attachments_tags_num, @open_source_projects_num = get_tags_size # 获取搜索结果 - @obj,@obj_pages,@results_count,@users_results, + @obj, + @obj_pages, + @results_count, + @users_results, @projects_results, - @@courses_results, @issues_results, @bids_results, - @forums_results, - @attachments_results, - @contests_tags, - @open_source_projects_results = refresh_results(@obj_id,@obj_flag,@selected_tags) + @forums_results, + attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags) # 这里是做tag推荐用的, 用来生产推荐的tags unless @obj.nil? @@ -97,14 +100,18 @@ class TagsController < ApplicationController $related_tags.delete(@tag) # 获取搜索结果 - @obj,@obj_pages,@results_count,@users_results, + @obj, + @obj_pages, + @results_count, + @users_results, @projects_results, - @@courses_results, @issues_results, @bids_results, - @forums_results, - @attachments_results, - @contests_results = refresh_results(@obj_id,@show_flag) + @forums_results, + attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results= refresh_results(@obj_id,@show_flag) end # 删除已选tag @@ -116,14 +123,18 @@ class TagsController < ApplicationController $selected_tags.delete(@tag) # 获取搜索结果 - @obj,@obj_pages,@results_count,@users_results, + @obj, + @obj_pages, + @results_count, + @users_results, @projects_results, - @@courses_results, @issues_results, @bids_results, @forums_results, - @attachments_results, - @contests_results = refresh_results(@obj_id,@show_flag) + attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results= refresh_results(@obj_id,@show_flag) end def show_all diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index b1ec023c8..b0cc3ce64 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -370,4 +370,9 @@ module CoursesHelper end return homework_users end + + def get_courses_by_tag(tag_name) + Course.tagged_with(tag_name).order('updated_at desc') + end + end diff --git a/app/views/tags/_show_attachments.html.erb b/app/views/tags/_show_attachments.html.erb index 3484d1351..43ed76e02 100644 --- a/app/views/tags/_show_attachments.html.erb +++ b/app/views/tags/_show_attachments.html.erb @@ -1,5 +1,5 @@
-<% if attachments_results.size < 0 %> +<% if attachments_results.try(:size).to_i < 0 %> <% else %>
<% attachments_results.each do |file| %> diff --git a/app/views/tags/_show_bids.html.erb b/app/views/tags/_show_bids.html.erb index 63f351738..e789979e1 100644 --- a/app/views/tags/_show_bids.html.erb +++ b/app/views/tags/_show_bids.html.erb @@ -1,5 +1,5 @@
- <% if bids_results.size > 0 %> + <% if bids_results.try(:size).to_i > 0 %>
<% bids_results.each do |bid| %>

diff --git a/app/views/tags/_show_contests.html.erb b/app/views/tags/_show_contests.html.erb index 79c756522..bc2682fb8 100644 --- a/app/views/tags/_show_contests.html.erb +++ b/app/views/tags/_show_contests.html.erb @@ -1,5 +1,5 @@

- <% if contests_results.size > 0 %> + <% if contests_results.try(:size).to_i > 0 %>
<% contests_results.each do |contest| %>

diff --git a/app/views/tags/_show_courses.html.erb b/app/views/tags/_show_courses.html.erb new file mode 100644 index 000000000..c99e3e22d --- /dev/null +++ b/app/views/tags/_show_courses.html.erb @@ -0,0 +1,14 @@ +

+ <% if courses_results.try(:size).to_i > 0 %> +
+ <% courses_results.each do |course| %> +

+ <%= l(:label_course) %>:<%= link_to "#{course.name}",course_path(course) %> +
+ <%= l(:label_new_course_description) %>:<%= course.description %> + <%= course.updated_at %> +

+
+ <% end %> + <% end %> +
diff --git a/app/views/tags/_show_forums.html.erb b/app/views/tags/_show_forums.html.erb index 009ec1949..c6dd8a2ed 100644 --- a/app/views/tags/_show_forums.html.erb +++ b/app/views/tags/_show_forums.html.erb @@ -1,5 +1,5 @@
- <% if forums_results.size > 0 %> + <% if forums_results.try(:size).to_i > 0 %>
<% forums_results.each do |forum| %>

diff --git a/app/views/tags/_show_issues.html.erb b/app/views/tags/_show_issues.html.erb index ab98cc351..399caf513 100644 --- a/app/views/tags/_show_issues.html.erb +++ b/app/views/tags/_show_issues.html.erb @@ -1,5 +1,5 @@

- <% if issues_results.size > 0 %> + <% if issues_results.try(:size).to_i > 0 %>
<% issues_results.each do |issue| %>

diff --git a/app/views/tags/_show_open_source_projects.html.erb b/app/views/tags/_show_open_source_projects.html.erb index 2c8bc6374..8ea67f9a7 100644 --- a/app/views/tags/_show_open_source_projects.html.erb +++ b/app/views/tags/_show_open_source_projects.html.erb @@ -1,5 +1,5 @@

-<% if projects_results.size > 0 %> +<% if projects_results.try(:size).to_i > 0 %>
<% projects_results.each do |prj| %>
diff --git a/app/views/tags/_show_projects.html.erb b/app/views/tags/_show_projects.html.erb index 6186b6869..5dade07ef 100644 --- a/app/views/tags/_show_projects.html.erb +++ b/app/views/tags/_show_projects.html.erb @@ -1,5 +1,5 @@
-<% if projects_results.size > 0 %> +<% if projects_results.try(:size).to_i > 0 %>
<% projects_results.each do |prj| %>
diff --git a/app/views/tags/_show_users.html.erb b/app/views/tags/_show_users.html.erb index 6818bdd9c..d8b172ba9 100644 --- a/app/views/tags/_show_users.html.erb +++ b/app/views/tags/_show_users.html.erb @@ -1,5 +1,5 @@
- <% if users_results.size > 0 %> + <% if users_results.try(:size).to_i > 0 %>
<% users_results.each do |user| %>

diff --git a/app/views/tags/_tag_search_results.html.erb b/app/views/tags/_tag_search_results.html.erb index 1ea452dec..43048be58 100644 --- a/app/views/tags/_tag_search_results.html.erb +++ b/app/views/tags/_tag_search_results.html.erb @@ -26,6 +26,9 @@ <%#= l(:label_attachment)%> 开源项目:(<%= @results_count %>) <%= render :partial => "show_open_source_projects",:locals => {:projects_results => open_source_projects_results}%> + <% when show_flag == '9'%> + <%= l(:label_course)%>(<%= @results_count %>) + <%= render :partial => "show_courses",:locals => {:courses_results => courses_results}%> <% else %> <%= l(:label_tags_all_objects)%> diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index c74721c3e..a5cda9944 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -23,7 +23,7 @@ <%= l(:label_user_plural) %>(<%= @users_tags_num %>) | <%= l(:label_tags_call)%>(<%= @bids_tags_num %>) | <%= l(:field_filename)%>(<%= @attachments_tags_num %>) | - 开源项目(<%= @open_source_projects_num %>) + 开源项目(<%= @open_source_projects_num %>) | <%= l(:label_tags_contest)%>(<%= @contests_tags_num %>) |

@@ -37,6 +37,7 @@ :attachments_results=> @attachments_results, :contests_results => @contests_results, :open_source_projects_results => @open_source_projects_results, + :courses_results => @courses_results, :show_flag => @obj_flag} %>
From 4d25ec16231cdcfe9f4627166ccc63e844bb25f5 Mon Sep 17 00:00:00 2001 From: nwb Date: Thu, 3 Jul 2014 17:28:13 +0800 Subject: [PATCH 2/2] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=9E=83=E5=9C=BE=E6=95=B0=E6=8D=AE=E6=B8=85=E7=90=86=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E6=96=87=E4=BB=B6=202.=E8=AF=BE=E7=A8=8B=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E9=80=BB=E8=BE=91=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/welcome_controller.rb | 5 ++++ app/helpers/watchers_helper.rb | 24 +++++++++++++++ app/helpers/welcome_helper.rb | 3 +- app/views/welcome/course.html.erb | 29 +++++++------------ .../20140703085204_clear_course_data.rb | 11 +++++++ db/schema.rb | 2 +- 6 files changed, 54 insertions(+), 20 deletions(-) create mode 100644 db/migrate/20140703085204_clear_course_data.rb diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index dd0b776b4..f16dbd97f 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -30,6 +30,11 @@ class WelcomeController < ApplicationController end def course + if params[:school_id] + @school_id = params[:school_id] + else + @school_id = User.current.user_extensions.school.id + end @logoLink ||= logolink() end diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 00867d9f8..ea72e8184 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -67,6 +67,30 @@ module WatchersHelper link_to text, url, :remote => true, :method => method, :class => css end + + # add by nwb + # 关注课程 + def new_course_watcher_link(objects, user, options=[]) + return '' unless user && user.logged? + objects = Array.wrap(objects) + + watched = objects.any? {|object| object.watched_by?(user)} + @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or (objects.first.instance_of?(Contest))) + css = @watch_flag ? ([watcher_css(objects), watched ? 'icon ' : 'icon '].join(' ') << options[0].to_s) : + ([watcher_css(objects), watched ? 'icon icon-fav ' : 'icon icon-fav-off '].join(' ') << options[0].to_s) + + text = @watch_flag ? + (watched ? l(:button_unfollow) : l(:button_follow)) : (watched ? l(:button_unwatch) : l(:button_watch)) + + url = watch_path( + :object_type => objects.first.class.to_s.underscore, + :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) + ) + method = watched ? 'delete' : 'post' + + link_to text, url, :remote => true, :method => method, :class => css + end + # added by fq, modify nyan # Somebody may use option params def join_in_course(course, user, options=[]) diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index f753052c1..0054b003f 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -233,8 +233,9 @@ module WelcomeHelper def find_all_new_hot_course limit = 9 ,school_id = 0 #sort_project_by_hot_rails 1, 'course_ac_para DESC', limit time_now = Time.new.strftime("%Y"); - Course.visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id <> + courses = Course.visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id <> ?", school_id).order("course_ac_para DESC").limit(limit).all + courses end def find_all_hot_bid diff --git a/app/views/welcome/course.html.erb b/app/views/welcome/course.html.erb index ca7f0bb7a..970d9c178 100644 --- a/app/views/welcome/course.html.erb +++ b/app/views/welcome/course.html.erb @@ -39,24 +39,24 @@
- <% if params[:school_id].nil? and User.current.user_extensions.school.nil? %> + <% if @school_id.nil? and User.current.user_extensions.school.nil? %> <% else%> - <% if params[:school_id] == "0" %> + <% if @school_id == "0" %> <% else %> - <% if params[:school_id].nil? %> + <% if @school_id.nil? %> <%= link_to School.find(User.current.user_extensions.school.id).name, options={:action => 'course',:school_id => User.current.user_extensions.school.id}, html_options={:class => 'font_welcome_school',:method => 'get'}%>
<% else %> - <%= link_to School.find(params[:school_id]).name ,options={:action => 'course',:school_id => params[:school_id]}, html_options={:class => 'font_welcome_school',:method => 'get'}%> + <%= link_to School.find(@school_id).name ,options={:action => 'course',:school_id => @school_id}, html_options={:class => 'font_welcome_school',:method => 'get'}%>
<% end %> <% end %> <% end %>
<%= l(:label_welcome_trustie) %><%= l(:label_welcome_trustie_course) %> - <% if params[:school_id].nil? and User.current.user_extensions.school.nil? %> + <% if @school_id.nil? and User.current.user_extensions.school.nil? %> , <%= l(:label_welcome_trustie_course_description) %> <% else %> - <% if params[:school_id] == "0" %> + <% if @school_id == "0" %> , <%= l(:label_welcome_trustie_course_description) %> <% end %> <% end %> @@ -73,7 +73,7 @@

新开课程

- <% school_course = find_miracle_course(10, 7,params[:school_id]) %> + <% school_course = find_miracle_course(10, 7,@school_id) %> <% if(school_course.count == 0) %> <%= link_to "更多>>", {:controller => 'courses', :action => 'index', :school_id => nil} %>
@@ -86,7 +86,7 @@ 该学校未开设任何课程,您可以查看其他学校课程

- <% find_all_new_hot_course(9,params[:school_id]).map do |project| %> + <% find_all_new_hot_course(9,@school_id).map do |project| %>
  • >
    <%= image_tag(get_course_avatar(project), :class => "avatar-4") %> @@ -94,7 +94,7 @@
    - <% course = Course.find_by_extra(project.identifier)%> + <% course = Course.find_by_extra(project.extra)%> <% if(course.school == nil) %>               <% else %> @@ -116,13 +116,6 @@ -
    - <% if !course_endTime_timeout?(project)%> -
    - <%= new_watcher_link(project, User.current)%> -
    - <% end %> -
  • <% end %> @@ -134,7 +127,7 @@ <% else %> - <%= link_to "更多>>", {:controller => 'courses', :action => 'index', :school_id => params[:school_id]} %> + <%= link_to "更多>>", {:controller => 'courses', :action => 'index', :school_id => @school_id} %> <% end %>
    @@ -181,7 +174,7 @@ 该学校开设课程较少,您可以查看其他学校课程

    - <% find_all_new_hot_course(9 - school_course.count,params[:school_id]).map do |project| %> + <% find_all_new_hot_course(9 - school_course.count,@school_id).map do |project| %>
  • >
    <%= image_tag(get_course_avatar(project), :class => "avatar-4") %> diff --git a/db/migrate/20140703085204_clear_course_data.rb b/db/migrate/20140703085204_clear_course_data.rb new file mode 100644 index 000000000..1592257b8 --- /dev/null +++ b/db/migrate/20140703085204_clear_course_data.rb @@ -0,0 +1,11 @@ +class ClearCourseData < ActiveRecord::Migration + def up + # 清理课程表垃圾数据 + # 之前删除项目未删除课程的数据 + sql = 'delete from courses where name is null and extra not in (select identifier from projects)' + execute(sql) + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 476c0b23d..fecaa5000 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140701075839) do +ActiveRecord::Schema.define(:version => 20140703085204) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false