Conflicts:
	app/views/welcome/course.html.erb
This commit is contained in:
sw 2014-07-03 18:14:44 +08:00
commit 2bdb0e20e9
19 changed files with 112 additions and 44 deletions

View File

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

View File

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

View File

@ -383,4 +383,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

View File

@ -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=[])

View File

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

View File

@ -1,5 +1,5 @@
<div id="issues">
<% if attachments_results.size < 0 %>
<% if attachments_results.try(:size).to_i < 0 %>
<% else %>
<hr />
<% attachments_results.each do |file| %>

View File

@ -1,5 +1,5 @@
<div id="issues">
<% if bids_results.size > 0 %>
<% if bids_results.try(:size).to_i > 0 %>
<hr />
<% bids_results.each do |bid| %>
<p class="font_description2">

View File

@ -1,5 +1,5 @@
<div id="issues">
<% if contests_results.size > 0 %>
<% if contests_results.try(:size).to_i > 0 %>
<hr />
<% contests_results.each do |contest| %>
<p class="font_description2">

View File

@ -0,0 +1,14 @@
<div id="issues">
<% if courses_results.try(:size).to_i > 0 %>
<hr />
<% courses_results.each do |course| %>
<p class="font_description2">
<strong><%= l(:label_course) %>:<%= link_to "#{course.name}",course_path(course) %></strong>
<br />
<strong><%= l(:label_new_course_description) %>:</strong><%= course.description %>
<%= course.updated_at %>
</p>
<div class="line_under"></div>
<% end %>
<% end %>
</div>

View File

@ -1,5 +1,5 @@
<div id="issues">
<% if forums_results.size > 0 %>
<% if forums_results.try(:size).to_i > 0 %>
<hr />
<% forums_results.each do |forum| %>
<p class="font_description2">

View File

@ -1,5 +1,5 @@
<div id="issues">
<% if issues_results.size > 0 %>
<% if issues_results.try(:size).to_i > 0 %>
<hr />
<% issues_results.each do |issue| %>
<p class="font_description2">

View File

@ -1,5 +1,5 @@
<div id="projects">
<% if projects_results.size > 0 %>
<% if projects_results.try(:size).to_i > 0 %>
<hr />
<% projects_results.each do |prj| %>
<div>

View File

@ -1,5 +1,5 @@
<div id="projects">
<% if projects_results.size > 0 %>
<% if projects_results.try(:size).to_i > 0 %>
<hr />
<% projects_results.each do |prj| %>
<div>

View File

@ -1,5 +1,5 @@
<div id="users">
<% if users_results.size > 0 %>
<% if users_results.try(:size).to_i > 0 %>
<hr />
<% users_results.each do |user| %>
<p class="font_description2">

View File

@ -26,6 +26,9 @@
<strong><%#= l(:label_attachment)%>
开源项目:(<%= @results_count %>)</strong>
<%= render :partial => "show_open_source_projects",:locals => {:projects_results => open_source_projects_results}%>
<% when show_flag == '9'%>
<strong><%= l(:label_course)%>(<%= @results_count %>)</strong>
<%= render :partial => "show_courses",:locals => {:courses_results => courses_results}%>
<% else %>
<strong><%= l(:label_tags_all_objects)%></strong>
<!-- 这里为显示搜有过滤结果预留了默认设置 -->

View File

@ -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 %>) |
</div>
<div id="show_results">
@ -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}
%>
</div>

View File

@ -39,24 +39,24 @@
</div>
<div class="course welcome_left" id="welcome_left" >
<span class="font_welcome_school"> <% if params[:school_id].nil? and User.current.user_extensions.school.nil? %>
<span class="font_welcome_school"> <% 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'}%>
<br />
<% 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'}%>
<br />
<% end %>
<% end %>
<% end %> </span>
<span class="font_welcome_trustie"><%= l(:label_welcome_trustie) %><%= l(:label_welcome_trustie_course) %> </span>
<% if params[:school_id].nil? and User.current.user_extensions.school.nil? %>
<% if @school_id.nil? and User.current.user_extensions.school.nil? %>
<span class="font_welcome_tdescription">, <%= l(:label_welcome_trustie_course_description) %></span>
<% else %>
<% if params[:school_id] == "0" %>
<% if @school_id == "0" %>
<span class="font_welcome_tdescription">, <%= l(:label_welcome_trustie_course_description) %></span>
<% end %>
<% end %>
@ -73,7 +73,7 @@
<div id="J_Slide" class="d-p-index-box d-p-index-hotproject">
<h3><strong>新开课程</strong></h3>
<% school_course = find_miracle_course(10, 7,params[:school_id] || params[:id]) %>
<% school_course = find_miracle_course(10, 7,@school_id) %>
<% if(school_course.count == 0) %>
<span><%= link_to "更多>>", {:controller => 'courses', :action => 'index', :school_id => nil} %></span>
<div class="d-p-projectlist-box">
@ -86,7 +86,7 @@
该学校未开设任何课程,您可以查看其他学校课程
</p>
<h1></h1>
<% find_all_new_hot_course(9,params[:school_id] || params[:id]).map do |project| %>
<% find_all_new_hot_course(9,@school_id).map do |project| %>
<li class='<%= cycle("odd", "even") %>' title=<%=project.description.to_s%>>
<div class='avatar'>
<%= image_tag(get_course_avatar(project), :class => "avatar-4") %>
@ -116,13 +116,6 @@
<!-- <div class='desc_item' style="">
<span class='font_lighter' title=<%#=project.description.to_s%>><%#=project.description.truncate(25, omission: '...')%></span>
</div> -->
<div>
<% if !course_endTime_timeout?(project)%>
<div >
<%#= new_watcher_link(project, User.current)%>
</div>
<% end %>
</div>
</li>
<% end %>
</ul>
@ -134,7 +127,7 @@
</span>
<% else %>
<span>
<%= link_to "更多>>", {:controller => 'courses', :action => 'index', :school_id => params[:school_id]} %>
<%= link_to "更多>>", {:controller => 'courses', :action => 'index', :school_id => @school_id} %>
</span>
<% end %>
<div class="d-p-projectlist-box">
@ -181,7 +174,7 @@
该学校开设课程较少,您可以查看其他学校课程
</p>
</li>
<% find_all_new_hot_course(9 - school_course.count,params[:school_id] || params[:id]).map do |project| %>
<% find_all_new_hot_course(9 - school_course.count,@school_id).map do |project| %>
<li class='<%= cycle("odd", "even") %>' title=<%=project.description.to_s%>>
<div class='avatar'>
<%= image_tag(get_course_avatar(project), :class => "avatar-4") %>
@ -211,7 +204,7 @@
<div>
<% if !course_endTime_timeout?(project)%>
<div >
<%#= new_watcher_link(project, User.current)%>
<%= new_watcher_link(project, User.current)%>
</div>
<% end %>
</div>

View File

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

View File

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