代码优化

course_group
sw 11 years ago
parent 216537a844
commit 87788ab34c

@ -427,9 +427,7 @@ class CoursesController < ApplicationController
@course_type = params[:course_type] @course_type = params[:course_type]
@school_id = params[:school_id] @school_id = params[:school_id]
per_page_option = 10 per_page_option = 10
if @school_id == "0" || @school_id.nil?
if @school_id == "0" or @school_id.nil?
@courses_all = Course.active.visible. @courses_all = Course.active.visible.
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id") joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id")
else else
@ -437,49 +435,37 @@ class CoursesController < ApplicationController
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id"). joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id").
where("#{Course.table_name}.school_id = ?", @school_id) where("#{Course.table_name}.school_id = ?", @school_id)
end end
@course_count = @courses_all.count @course_count = @courses_all.count
@course_pages = Paginator.new @course_count, per_page_option, params['page'] @course_pages = Paginator.new @course_count, per_page_option, params['page']
@course_activity_count=Hash.new @course_activity_count=Hash.new
@courses_all.each do |course| @courses_all.each do |course|
@course_activity_count[course.id]=0 @course_activity_count[course.id]=0
end end
case params[:course_sort_type] case params[:course_sort_type]
when '0' when '0'
@courses = @courses_all.order("created_at desc") @courses = @courses_all.order("created_at desc")
@s_type = 0 @s_type = 0
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses, @course_activity_count
@course_activity_count=get_course_activity @courses, @course_activity_count
when '1' when '1'
@courses = @courses_all.order("course_ac_para desc") @courses = @courses_all.order("course_ac_para desc")
@s_type = 1 @s_type = 1
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses, @course_activity_count @course_activity_count=get_course_activity @courses, @course_activity_count
when '2' when '2'
@courses = @courses_all.order("watchers_count desc") @courses = @courses_all.order("watchers_count desc")
@s_type = 2 @s_type = 2
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses, @course_activity_count @course_activity_count=get_course_activity @courses, @course_activity_count
when '3' when '3'
@course_activity_count=get_course_activity @courses_all, @course_activity_count @course_activity_count=get_course_activity @courses_all, @course_activity_count
@courses=handle_course @courses_all, @course_activity_count @courses=handle_course @courses_all, @course_activity_count
@s_type = 3 @s_type = 3
@courses = @courses[@course_pages.offset, @course_pages.per_page] @courses = @courses[@course_pages.offset, @course_pages.per_page]
else else
@s_type = 0 @s_type = 0
@courses = @courses_all.order("created_at desc") @courses = @courses_all.order("created_at desc")
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
@course_activity_count=get_course_activity @courses, @course_activity_count @course_activity_count=get_course_activity @courses, @course_activity_count
end end
@ -521,18 +507,14 @@ class CoursesController < ApplicationController
# 新建作业 # 新建作业
def new_homework def new_homework
@homework = Bid.new @homework = Bid.new
@homework.proportion
@homework.safe_attributes = params[:bid] @homework.safe_attributes = params[:bid]
if (User.current.logged? && User.current.member_of_course?(Course.find params[:id] )) if (User.current.logged? && User.current.member_of_course?(Course.find params[:id] ))
render :layout => 'base_courses' render :layout => 'base_courses'
else else
render_403 render_403
end end
end end
def toggleCourse def toggleCourse
@course_prefs = Course.find_by_extra(@course.extra) @course_prefs = Course.find_by_extra(@course.extra)
unless (@course_prefs.teacher == User.current || User.current.admin?) unless (@course_prefs.teacher == User.current || User.current.admin?)
@ -722,7 +704,4 @@ class CoursesController < ApplicationController
render_404 render_404
end end
end end
end end

@ -479,7 +479,6 @@ module CoursesHelper
type << option2 type << option2
type type
end end
#获取课程动态 #获取课程动态
def get_course_activity courses, activities def get_course_activity courses, activities
@course_ids=activities.keys() @course_ids=activities.keys()

@ -47,7 +47,6 @@
</p> </p>
<p class="stats"> <p class="stats">
<%= content_tag('span', "#{garble @course.members.count}", :class => "info") %> <%= content_tag('span', "#{garble @course.members.count}", :class => "info") %>
<%#= content_tag('span', l(:label_x_member, :count => @course.members.count)) %>
<%= content_tag('span', l(:label_x_member, :count => memberCount(@course))) %> <%= content_tag('span', l(:label_x_member, :count => memberCount(@course))) %>
</p> </p>

@ -9,17 +9,20 @@
<div> <div>
<table class="underline-evreycontent" style="font-size: 14px;"> <table class="underline-evreycontent" style="font-size: 14px;">
<tr> <tr>
<td valign="top" width="50"><%= image_tag(url_to_avatar(e.event_author), :class => "avatar") %></td> <td valign="top" width="50">
<%= image_tag(url_to_avatar(e.event_author), :class => "avatar") %>
</td>
<td> <td>
<table width="580px" border="0" style="width: 100%;table-layout: fixed"> <table width="580px" border="0" style="width: 100%;table-layout: fixed">
<tr> <tr>
<td colspan="2" valign="top" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;"> <td colspan="2" valign="top" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
<strong> <%= h(e.event_title) if @course.nil? || (e.course != nil && @course.id != e.course.id) %></strong> <strong>
<%= h(e.event_title) if @course.nil? || (e.course != nil && @course.id != e.course.id) %>
</strong>
<span class="font_lighter"> <span class="font_lighter">
<% if @canShowRealName %> <% if @canShowRealName %>
<%= link_to_user(e.event_author) if e.respond_to?(:event_author) %> <%= link_to_user(e.event_author) if e.respond_to?(:event_author) %>
(<%= link_to_user(e.event_author, @canShowRealName) if e.respond_to?(:event_author) %> (<%= link_to_user(e.event_author, @canShowRealName) if e.respond_to?(:event_author) %>)
)
<% else %> <% else %>
<%= link_to_user(e.event_author) if e.respond_to?(:event_author) %> <%= link_to_user(e.event_author) if e.respond_to?(:event_author) %>
<% end %> <% end %>
@ -32,15 +35,26 @@
<td colspan="2" width="580px"> <td colspan="2" width="580px">
<p class="info-break"> <p class="info-break">
<%= h(truncate(strip_tags(e.event_description).gsub(/&nbsp;/, ' '), length: 30, omission: '...')) %> <%= h(truncate(strip_tags(e.event_description).gsub(/&nbsp;/, ' '), length: 30, omission: '...')) %>
</p></td> </p>
</td>
</tr> </tr>
<tr> <tr>
<td align="left"><span class="font_lighter"> <%= l :label_activity_time %> <td align="left">
&nbsp; <%= format_activity_day(day) %> <%= format_time(e.event_datetime, false) %></span> <span class="font_lighter">
<%= l :label_activity_time %>
&nbsp;
<%= format_activity_day(day) %>
<%= format_time(e.event_datetime, false) %>
</span>
</td> </td>
<% if e.event_type == "issue" %> <% if e.event_type == "issue" %>
<td align="right"> <td align="right">
<span> <%= link_to l(:label_find_all_comments), issue_path(e.id) %> </span><span class="font_lighter"><%= l(:label_comments_count, :count => e.journals.count) %></span> <span>
<%= link_to l(:label_find_all_comments), issue_path(e.id) %>
</span>
<span class="font_lighter">
<%= l(:label_comments_count, :count => e.journals.count) %>
</span>
</td> </td>
<% end %> <% end %>
</tr> </tr>
@ -51,30 +65,33 @@
</div> </div>
<% end %> <% end %>
</div> </div>
<% end -%> <% end -%>
<% if (@events_pages.page == @events_pages.last_page) %> <% if (@events_pages.page == @events_pages.last_page) %>
<div class="font_description"> <div class="font_description">
<table width="660"> <table width="660">
<tr> <tr>
<td><%= image_tag(url_to_avatar(@user), :class => "avatar") %></td> <td>
<%= image_tag(url_to_avatar(@user), :class => "avatar") %>
</td>
<td colspan="2"> <td colspan="2">
<table width="580"> <table width="580">
<tr> <tr>
<td> <td>
<% if @canShowRealName %> <% if @canShowRealName %>
(<%= link_to_user(@user, @canShowRealName) %> (<%= link_to_user(@user, @canShowRealName) %>)
)
<% else %> <% else %>
<%= link_to_user(@user)%> <%= link_to_user(@user)%>
<% end %> <% end %>
<%= l(:label_user_create_project) %> <%= link_to @course.name %> <%= l(:label_user_create_project) %>
<strong> !</strong></td> <%= link_to @course.name %>
<strong> !</strong>
</td>
</tr> </tr>
<tr> <tr>
<td class="font_lighter" style="float: right"><%= l :label_create_time %> <td class="font_lighter" style="float: right">
: <%= format_time(@course.created_at) %> <%= l :label_create_time %>:
<%= format_time(@course.created_at) %>
</table> </table>
</td> </td>
</tr> </tr>
@ -88,24 +105,27 @@
<div class="font_description"> <div class="font_description">
<table width="660"> <table width="660">
<tr> <tr>
<td><%= image_tag(url_to_avatar(@user), :class => "avatar") %></td> <td>
<%= image_tag(url_to_avatar(@user), :class => "avatar") %>
</td>
<td colspan="2"> <td colspan="2">
<table width="580"> <table width="580">
<tr> <tr>
<td> <td>
<% if @canShowRealName %> <% if @canShowRealName %>
(<%= link_to_user(@user, @canShowRealName) %> (<%= link_to_user(@user, @canShowRealName) %>)
)
<% else %> <% else %>
<%= link_to_user(@user)%> <%= link_to_user(@user)%>
<% end %> <% end %>
<%= l(:label_user_create_project) %>
<%= l(:label_user_create_project) %> <%= link_to @course.name %> <%= link_to @course.name %>
<strong> !</strong></td> <strong> !</strong>
</td>
</tr> </tr>
<tr> <tr>
<td class="font_lighter" style="float: right"><%= l :label_create_time %> <td class="font_lighter" style="float: right">
: <%= format_time(@course.created_at) %> <%= l :label_create_time %>:
<%= format_time(@course.created_at) %>
</table> </table>
</td> </td>
</tr> </tr>

Loading…
Cancel
Save