From a49cf3eb6bc13c689f0a17c1dd099e274733d1ea Mon Sep 17 00:00:00 2001 From: nwb Date: Wed, 4 Jun 2014 17:06:28 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E8=AF=BE=E7=A8=8B=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E8=B7=AF=E7=94=B1=202.=E8=AF=BE=E7=A8=8Bcontrol?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BD=9C=E4=B8=9A=E6=98=BE=E7=A4=BA=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 16 ++++++++++++++++ app/models/course.rb | 1 - app/views/users/_course_form.html.erb | 4 ++-- config/routes.rb | 2 ++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index bff99f35a..53717aef2 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -247,6 +247,22 @@ class CoursesController < ApplicationController end end + def homework + @offset, @limit = api_offset_and_limit({:limit => 10}) + @bids = @course.homeworks.order('deadline DESC') + @bids = @bids.like(params[:name]) if params[:name].present? + @bid_count = @bids.count + @bid_pages = Paginator.new @bid_count, @limit, params['page'] + + @offset ||= @bid_pages.reverse_offset + unless @offset == 0 + @bids = @bids.offset(@offset).limit(@limit).all.reverse + else + limit = @bid_count % @limit + @bids = @bids.offset(@offset).limit(limit).all.reverse + end + render :layout => 'base_courses' + end def get_course_activity courses, activities @course_ids=activities.keys() diff --git a/app/models/course.rb b/app/models/course.rb index 8dcb53387..bb80110a7 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -20,7 +20,6 @@ class Course < ActiveRecord::Base has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :homework_for_courses, :dependent => :destroy - has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy has_many :student, :through => :students_for_courses, :source => :user diff --git a/app/views/users/_course_form.html.erb b/app/views/users/_course_form.html.erb index 6de99f7d9..749a09733 100644 --- a/app/views/users/_course_form.html.erb +++ b/app/views/users/_course_form.html.erb @@ -23,10 +23,10 @@ <%= l(:label_x_base_courses_member, :count => membership.course.members.count) %> (<%= "#{membership.course.members.count}" %>)   <%= l(:label_homework) %> - (<%= link_to (membership.course.homeworks.count), {:controller => 'courses', :action => 'homework', :id => membership.course.identifier} %>) + (<%= link_to (membership.course.homeworks.count), {:controller => 'courses', :action => 'homework', :id => membership.course.extra} %>)    <%= l(:label_course_news) %> - (<%= link_to (membership.course.news.count), {:controller => 'news', :action => 'index', :course_id => membership.course.identifier} %>) + (<%= link_to (membership.course.news.count), {:controller => 'news', :action => 'index', :course_id => membership.course.extra} %>) diff --git a/config/routes.rb b/config/routes.rb index 9f7dea1bf..7074965f5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -548,6 +548,8 @@ RedmineApp::Application.routes.draw do resources :courses do member do get 'settings(/:tab)', :action => 'settings', :as => 'settings' + get 'homework', :action => 'homework', :as => 'homework' + get 'new_homework', :action => 'new_homework', :as => 'new_homework' post 'finishcourse' post 'restartcourse' end