在精品课程列表增加“取消精品”列、在全部课程列表增加“开课学期”列,并支持排序

This commit is contained in:
cxt 2016-06-13 11:10:28 +08:00
parent 02e2831980
commit 3a8a61e404
5 changed files with 41 additions and 10 deletions

View File

@ -67,12 +67,15 @@ class AdminController < ApplicationController
def excellent_all_courses
name = params[:name]
@order = ""
if params[:order] == 'asc'
courses = Course.find_by_sql("SELECT c.*,count(c.id) FROM courses c,course_activities ca WHERE c.id = ca.course_id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count(c.id) asc, c.id desc")
@sort = ""
if params[:sort] && (params[:order] == 'act')
courses = Course.find_by_sql("SELECT c.*,count(c.id) FROM courses c,course_activities ca WHERE c.id = ca.course_id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count(c.id) #{params[:sort]}, c.id desc")
@order = params[:order]
elsif params[:order] == 'desc'
courses = Course.find_by_sql("SELECT c.*,count(c.id) FROM courses c,course_activities ca WHERE c.id = ca.course_id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count(c.id) DESC, c.id desc")
@sort = params[:sort]
elsif params[:sort] && (params[:order] == 'time')
courses = Course.find_by_sql("SELECT * FROM courses WHERE name like '%#{name}%' ORDER BY time #{params[:sort]},id desc")
@order = params[:order]
@sort = params[:sort]
else
courses = Course.like(name).order('created_at desc')
end
@ -99,6 +102,22 @@ class AdminController < ApplicationController
end
end
#取消精品
def cancel_excellent_course
@course = Course.find params[:id]
unless @course.nil?
if @course.is_excellent == 1 || @course.excellent_option == 1
@course.update_column('is_excellent', 0)
@course.update_column('excellent_option', 0)
end
end
respond_to do |format|
format.html{
redirect_to excellent_courses_url
}
end
end
#管理员界面课程资源列表
def course_resource_list

View File

@ -27,6 +27,9 @@
<td class="center">
<%= course.course_activities.count%>
</td>
<td class="center">
<%= course.time %>
</td>
<td class="buttons">
<%= link_to( course.is_excellent == 1 || course.excellent_option == 1 ? "取消精品" : "设为精品", { :controller => 'admin', :action => 'set_excellent_course', :id => course.id },:remote=>true, :class => 'icon-del') %>
</td>

View File

@ -45,11 +45,14 @@
<th style="width: 25px;">
资源数
</th>
<th style="width: 50px;">
<th style="width: 30px;">
帖子数
</th>
<th style="width: 50px;" class = "<%= @order == 'desc' ? 'st_up' : (@order == 'asc' ? 'st_down' : '') %>">
<%=link_to '动态数', excellent_all_courses_path(:order=> @order == "desc" ? 'asc' : 'desc') %>
<th style="width: 30px;" class = "<%= @order == 'act' ? (@sort == 'desc' ? 'st_up' : (@sort == 'asc' ? 'st_down' : '')) : '' %>">
<%=link_to '动态数', excellent_all_courses_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'act') %>
</th>
<th style="width: 40px;" class = "<%= @order == 'time' ? (@sort == 'desc' ? 'st_up' : (@sort == 'asc' ? 'st_down' : '')) : '' %>">
<%=link_to '开课学期', excellent_all_courses_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'time') %>
</th>
<th style="width: 40px;">
</tr>

View File

@ -2,7 +2,7 @@
<h3>
<%=l(:label_excellent_courses_list)%>
</h3>
<%= render 'tab_excellent_courses' %>
<%= render 'admin/tab_excellent_courses' %>
<h3>
<%=l(:label_excellent_courses_list)%>
@ -33,12 +33,14 @@
<th style="width: 25px;">
资源数
</th>
<th style="width: 70px;">
<th style="width: 50px;">
帖子数
</th>
<th style="width: 70px;">
<th style="width: 50px;">
动态数
</th>
<th style="width: 40px;">
</tr>
</tr>
</thead>
<tbody>
@ -74,6 +76,9 @@
<td class="center">
<%= course.course_activities.count%>
</td>
<td class="buttons">
<%= link_to( course.is_excellent == 1 || course.excellent_option == 1 ? "取消精品" : "设为精品", { :controller => 'admin', :action => 'cancel_excellent_course', :id => course.id }, :class => 'icon-del') %>
</td>
</tr>
<% end %>
</tbody>

View File

@ -1019,6 +1019,7 @@ RedmineApp::Application.routes.draw do
get 'admin/excellent_courses', as: :excellent_courses
get 'admin/excellent_all_courses', as: :excellent_all_courses
match 'admin/set_excellent_course/:id', :to => 'admin#set_excellent_course'
match 'admin/cancel_excellent_course/:id', :to => 'admin#cancel_excellent_course'
get 'admin/course_resource_list'
get 'admin/project_resource_list'
match 'admin/users', :via => :get