代码优化
This commit is contained in:
parent
216537a844
commit
87788ab34c
|
@ -427,9 +427,7 @@ class CoursesController < ApplicationController
|
|||
@course_type = params[:course_type]
|
||||
@school_id = params[:school_id]
|
||||
per_page_option = 10
|
||||
|
||||
|
||||
if @school_id == "0" or @school_id.nil?
|
||||
if @school_id == "0" || @school_id.nil?
|
||||
@courses_all = Course.active.visible.
|
||||
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id")
|
||||
else
|
||||
|
@ -437,49 +435,37 @@ class CoursesController < ApplicationController
|
|||
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id").
|
||||
where("#{Course.table_name}.school_id = ?", @school_id)
|
||||
end
|
||||
|
||||
@course_count = @courses_all.count
|
||||
@course_pages = Paginator.new @course_count, per_page_option, params['page']
|
||||
|
||||
@course_activity_count=Hash.new
|
||||
@courses_all.each do |course|
|
||||
@course_activity_count[course.id]=0
|
||||
end
|
||||
|
||||
|
||||
case params[:course_sort_type]
|
||||
when '0'
|
||||
@courses = @courses_all.order("created_at desc")
|
||||
@s_type = 0
|
||||
@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'
|
||||
@courses = @courses_all.order("course_ac_para desc")
|
||||
@s_type = 1
|
||||
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||
|
||||
@course_activity_count=get_course_activity @courses, @course_activity_count
|
||||
when '2'
|
||||
@courses = @courses_all.order("watchers_count desc")
|
||||
@s_type = 2
|
||||
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||
|
||||
@course_activity_count=get_course_activity @courses, @course_activity_count
|
||||
|
||||
when '3'
|
||||
|
||||
@course_activity_count=get_course_activity @courses_all, @course_activity_count
|
||||
|
||||
@courses=handle_course @courses_all, @course_activity_count
|
||||
|
||||
@s_type = 3
|
||||
@courses = @courses[@course_pages.offset, @course_pages.per_page]
|
||||
else
|
||||
@s_type = 0
|
||||
@courses = @courses_all.order("created_at desc")
|
||||
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||
|
||||
@course_activity_count=get_course_activity @courses, @course_activity_count
|
||||
end
|
||||
|
||||
|
@ -521,18 +507,14 @@ class CoursesController < ApplicationController
|
|||
# 新建作业
|
||||
def new_homework
|
||||
@homework = Bid.new
|
||||
@homework.proportion
|
||||
@homework.safe_attributes = params[:bid]
|
||||
if (User.current.logged? && User.current.member_of_course?(Course.find params[:id] ))
|
||||
render :layout => 'base_courses'
|
||||
else
|
||||
render_403
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
def toggleCourse
|
||||
@course_prefs = Course.find_by_extra(@course.extra)
|
||||
unless (@course_prefs.teacher == User.current || User.current.admin?)
|
||||
|
@ -722,7 +704,4 @@ class CoursesController < ApplicationController
|
|||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -479,7 +479,6 @@ module CoursesHelper
|
|||
type << option2
|
||||
type
|
||||
end
|
||||
|
||||
#获取课程动态
|
||||
def get_course_activity courses, activities
|
||||
@course_ids=activities.keys()
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
</p>
|
||||
<p class="stats">
|
||||
<%= 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))) %>
|
||||
</p>
|
||||
|
||||
|
|
|
@ -9,17 +9,20 @@
|
|||
<div>
|
||||
<table class="underline-evreycontent" style="font-size: 14px;">
|
||||
<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>
|
||||
<table width="580px" border="0" style="width: 100%;table-layout: fixed">
|
||||
<tr>
|
||||
<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">
|
||||
<% if @canShowRealName %>
|
||||
<%= 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 %>
|
||||
<%= link_to_user(e.event_author) if e.respond_to?(:event_author) %>
|
||||
<% end %>
|
||||
|
@ -32,15 +35,26 @@
|
|||
<td colspan="2" width="580px">
|
||||
<p class="info-break">
|
||||
<%= h(truncate(strip_tags(e.event_description).gsub(/ /, ' '), length: 30, omission: '...')) %>
|
||||
</p></td>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left"><span class="font_lighter"> <%= l :label_activity_time %>
|
||||
: <%= format_activity_day(day) %> <%= format_time(e.event_datetime, false) %></span>
|
||||
<td align="left">
|
||||
<span class="font_lighter">
|
||||
<%= l :label_activity_time %>
|
||||
:
|
||||
<%= format_activity_day(day) %>
|
||||
<%= format_time(e.event_datetime, false) %>
|
||||
</span>
|
||||
</td>
|
||||
<% if e.event_type == "issue" %>
|
||||
<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>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
@ -51,30 +65,33 @@
|
|||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% end -%>
|
||||
<% if (@events_pages.page == @events_pages.last_page) %>
|
||||
<div class="font_description">
|
||||
<table width="660">
|
||||
<tr>
|
||||
<td><%= image_tag(url_to_avatar(@user), :class => "avatar") %></td>
|
||||
<td>
|
||||
<%= image_tag(url_to_avatar(@user), :class => "avatar") %>
|
||||
</td>
|
||||
<td colspan="2">
|
||||
<table width="580">
|
||||
<tr>
|
||||
<td>
|
||||
<% if @canShowRealName %>
|
||||
(<%= link_to_user(@user, @canShowRealName) %>
|
||||
)
|
||||
(<%= link_to_user(@user, @canShowRealName) %>)
|
||||
<% else %>
|
||||
<%= link_to_user(@user)%>
|
||||
<% end %>
|
||||
|
||||
<%= l(:label_user_create_project) %> <%= link_to @course.name %>
|
||||
<strong> !</strong></td>
|
||||
<%= l(:label_user_create_project) %>
|
||||
<%= link_to @course.name %>
|
||||
<strong> !</strong>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font_lighter" style="float: right"><%= l :label_create_time %>
|
||||
: <%= format_time(@course.created_at) %>
|
||||
<td class="font_lighter" style="float: right">
|
||||
<%= l :label_create_time %>:
|
||||
<%= format_time(@course.created_at) %>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -88,24 +105,27 @@
|
|||
<div class="font_description">
|
||||
<table width="660">
|
||||
<tr>
|
||||
<td><%= image_tag(url_to_avatar(@user), :class => "avatar") %></td>
|
||||
<td>
|
||||
<%= image_tag(url_to_avatar(@user), :class => "avatar") %>
|
||||
</td>
|
||||
<td colspan="2">
|
||||
<table width="580">
|
||||
<tr>
|
||||
<td>
|
||||
<% if @canShowRealName %>
|
||||
(<%= link_to_user(@user, @canShowRealName) %>
|
||||
)
|
||||
(<%= link_to_user(@user, @canShowRealName) %>)
|
||||
<% else %>
|
||||
<%= link_to_user(@user)%>
|
||||
<% end %>
|
||||
|
||||
<%= l(:label_user_create_project) %> <%= link_to @course.name %>
|
||||
<strong> !</strong></td>
|
||||
<%= l(:label_user_create_project) %>
|
||||
<%= link_to @course.name %>
|
||||
<strong> !</strong>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font_lighter" style="float: right"><%= l :label_create_time %>
|
||||
: <%= format_time(@course.created_at) %>
|
||||
<td class="font_lighter" style="float: right">
|
||||
<%= l :label_create_time %>:
|
||||
<%= format_time(@course.created_at) %>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
Loading…
Reference in New Issue