From 3a8a61e4048d263012669c7215934a5d6ab6c9e7 Mon Sep 17 00:00:00 2001 From: cxt Date: Mon, 13 Jun 2016 11:10:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E7=B2=BE=E5=93=81=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=A2=9E=E5=8A=A0=E2=80=9C=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E7=B2=BE=E5=93=81=E2=80=9D=E5=88=97=E3=80=81=E5=9C=A8=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E8=AF=BE=E7=A8=8B=E5=88=97=E8=A1=A8=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E2=80=9C=E5=BC=80=E8=AF=BE=E5=AD=A6=E6=9C=9F=E2=80=9D=E5=88=97?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E6=94=AF=E6=8C=81=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin_controller.rb | 27 ++++++++++++++++--- app/views/admin/_course_detail_tr.html.erb | 3 +++ .../admin/excellent_all_courses.html.erb | 9 ++++--- app/views/admin/excellent_courses.html.erb | 11 +++++--- config/routes.rb | 1 + 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index d3f681a06..4014a91bd 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -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 diff --git a/app/views/admin/_course_detail_tr.html.erb b/app/views/admin/_course_detail_tr.html.erb index ca15a6696..bea14fd3d 100644 --- a/app/views/admin/_course_detail_tr.html.erb +++ b/app/views/admin/_course_detail_tr.html.erb @@ -27,6 +27,9 @@ <%= course.course_activities.count%> + + <%= course.time %> + <%= link_to( course.is_excellent == 1 || course.excellent_option == 1 ? "取消精品" : "设为精品", { :controller => 'admin', :action => 'set_excellent_course', :id => course.id },:remote=>true, :class => 'icon-del') %> diff --git a/app/views/admin/excellent_all_courses.html.erb b/app/views/admin/excellent_all_courses.html.erb index 86e4556f9..eb5f8c1a2 100644 --- a/app/views/admin/excellent_all_courses.html.erb +++ b/app/views/admin/excellent_all_courses.html.erb @@ -45,11 +45,14 @@ 资源数 - + 帖子数 - - <%=link_to '动态数', excellent_all_courses_path(:order=> @order == "desc" ? 'asc' : 'desc') %> + + <%=link_to '动态数', excellent_all_courses_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'act') %> + + + <%=link_to '开课学期', excellent_all_courses_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'time') %> diff --git a/app/views/admin/excellent_courses.html.erb b/app/views/admin/excellent_courses.html.erb index fef6da84d..c107713a0 100644 --- a/app/views/admin/excellent_courses.html.erb +++ b/app/views/admin/excellent_courses.html.erb @@ -2,7 +2,7 @@

<%=l(:label_excellent_courses_list)%>

-<%= render 'tab_excellent_courses' %> +<%= render 'admin/tab_excellent_courses' %>

<%=l(:label_excellent_courses_list)%> @@ -33,12 +33,14 @@ 资源数 - + 帖子数 - + 动态数 + + @@ -74,6 +76,9 @@ <%= course.course_activities.count%> + + <%= link_to( course.is_excellent == 1 || course.excellent_option == 1 ? "取消精品" : "设为精品", { :controller => 'admin', :action => 'cancel_excellent_course', :id => course.id }, :class => 'icon-del') %> + <% end %> diff --git a/config/routes.rb b/config/routes.rb index e4b462d93..91ab5cffe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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