提交作业逻辑和视图修改

This commit is contained in:
nwb 2014-06-17 15:06:31 +08:00
parent 78612488e5
commit 936c40b490
8 changed files with 122 additions and 31 deletions

View File

@ -8,7 +8,7 @@ class BidsController < ApplicationController
menu_item :homework_statistics, :only => :homework_statistics
#Ended by young
before_filter :find_bid, :only => [:show, :show_project, :create,:destroy,:more,:back,:add,:delete,:new,:show_results,:set_reward, :add_homework, :fork, :create_fork,
:show_course, :show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
:show_course, :show_courseEx,:show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
# added by fq
before_filter :require_login, :only => [:join_in_contest, :unjoin_in_contest]
# end
@ -448,7 +448,7 @@ class BidsController < ApplicationController
# 显示作业课程
# add by nwb
def show_course
def show_courseEx
# flash[:notice] = ""
@membership = User.current.coursememberships.all(:conditions => Course.visible_condition(User.current))
@option = []
@ -462,6 +462,7 @@ class BidsController < ApplicationController
@user = @bid.author
@bidding_project = @bid.biding_projects.all
if params[:student_id].present?
@temp = []
@bidding_project.each do |pro|

View File

@ -74,7 +74,26 @@ class ContestsController < ApplicationController
end
end
def show_contest
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 show_contest
@user = @contest.author
@jours = @contest.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
@limit = 10

View File

@ -1,21 +1,21 @@
class HomeworkAttachController < ApplicationController
###############################
#判断当前角色权限时需先找到当前操作的project
before_filter :find_project_by_bid_id, :only => [:new]
before_filter :find_project_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users]
before_filter :find_course_by_bid_id, :only => [:new]
before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users]
#判断当前角色是否有操作权限
#勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy]
def find_project_by_bid_id
def find_course_by_bid_id
@bid = Bid.find(params[:id])
@project = @bid.courses[0]
@course = @bid.courses[0]
rescue ActiveRecord::RecordNotFound
render_404
end
def find_project_by_hoemwork_id
def find_course_by_hoemwork_id
@homework = HomeworkAttach.find(params[:id])
@project = @homework.bid.courses[0]
@course = @homework.bid.courses[0]
end
#获取作业的成员
@ -35,7 +35,7 @@ class HomeworkAttachController < ApplicationController
#作业添加成员(参与人员)
def add_homework_users
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
#@homework = HomeworkAttach.find(params[:id])
if params[:membership]
if params[:membership][:user_ids]
@ -59,7 +59,7 @@ class HomeworkAttachController < ApplicationController
#作业删除成员(参与人员)
def destory_homework_users
#@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
homework_user = @homework.homework_users.where("user_id = #{params[:user_id]}").first
homework_user.destroy
get_homework_member @homework
@ -73,7 +73,7 @@ class HomeworkAttachController < ApplicationController
def create
bid = Bid.find params[:bid_id]
if User.current.admin? || User.current.member_of?(bid.courses.first)
if User.current.admin? || User.current.member_of_course?(bid.courses.first) # modify by nwb
if bid.homeworks.where("user_id = ?",User.current).count == 0
user_id = params[:user_id]
bid_id = params[:bid_id]
@ -97,7 +97,7 @@ class HomeworkAttachController < ApplicationController
if @homework.save
respond_to do |format|
format.html { redirect_to project_for_bid_path @homework.bid }
format.html { redirect_to course_for_bid_path @homework.bid }
format.json { head :no_content }
end
else
@ -113,7 +113,7 @@ class HomeworkAttachController < ApplicationController
def new
@bid = Bid.find(params[:id])
if User.current.admin? || User.current.member_of?(@bid.courses.first)
if User.current.admin? || User.current.member_of_course?(@bid.courses.first) #nwb
#该课程的学生的集合(新建不实现功能:添加成员)
#@members = @bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id <> #{User.current.id}", {:role_id => [5, 10]})
@ -138,7 +138,7 @@ class HomeworkAttachController < ApplicationController
def get_homework_member_list
@homework = HomeworkAttach.find(params[:bid_id])
course = @homework.bid.courses.first
if User.current.admin? || User.current.member_of?(course)
if User.current.admin? || User.current.member_of_course?(course)
get_homework_member @homework
else
raise "error"
@ -163,7 +163,7 @@ class HomeworkAttachController < ApplicationController
def edit
#@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
#@members = @homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => [5, 10]})
get_homework_member @homework
else
@ -174,7 +174,7 @@ class HomeworkAttachController < ApplicationController
def update
#@homework = HomeworkAttach.find(params[:id])
course = @homework.bid.courses.first
if User.current.admin? || User.current.member_of?(course)
if User.current.admin? || User.current.member_of_course?(course)
name = params[:homework_name]
description = params[:homework_description]
@homework.name = name
@ -184,7 +184,7 @@ class HomeworkAttachController < ApplicationController
end
if @homework.save
respond_to do |format|
format.html { redirect_to project_for_bid_path @homework.bid }
format.html { redirect_to course_for_bid_path @homework.bid }
format.json { head :no_content }
end
else
@ -199,7 +199,7 @@ class HomeworkAttachController < ApplicationController
if User.current.admin? || User.current == @homework
if @homework.destroy
respond_to do |format|
format.html { redirect_to project_for_bid_path @homework.bid }
format.html { redirect_to course_for_bid_path @homework.bid }
format.json { head :no_content }
end
else
@ -212,7 +212,7 @@ class HomeworkAttachController < ApplicationController
#显示作业信息
def show
#@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
# 打分统计
stars_reates = @homework.
rates(:quality)

View File

@ -21,7 +21,7 @@ class Bid < ActiveRecord::Base
belongs_to :author, :class_name => 'User', :foreign_key => :author_id
belongs_to :course
has_many :biding_projects, :dependent => :destroy
has_many :courses, :through => :biding_courses
has_many :projects, :through => :biding_projects
has_many :courses_member, :class_name => 'User', :through => :courses
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy

View File

@ -8,10 +8,10 @@
<td>
<table width="580" border="0">
<tr>
<td colspan="2" valign="top"><span><%= link_to_project(course) %></span>
<span style="float: right"><%= l(:label_homework) %> (<span class=""><%= link_to (course.homeworks.count), {:controller => 'projects', :action => 'homework', :id => course.identifier} %></span>)
<td colspan="2" valign="top"><span><%= link_to_course(course) %></span>
<span style="float: right"><%= l(:label_homework) %> (<span class=""><%= link_to (course.homeworks.count), {:controller => 'courses', :action => 'homework', :id => course.id} %></span>)
&nbsp;&nbsp;&nbsp;
<%= l(:label_course_news)%> (<span style="color: #ed8924"><%= link_to (course.news.count), {:controller => 'news', :action => 'index', :project_id => course.identifier} %></span>)
<%= l(:label_course_news)%> (<span style="color: #ed8924"><%= link_to (course.news.count), {:controller => 'news', :action => 'index', :course_id => course.id} %></span>)
</span>
</td>
</tr>
@ -22,10 +22,9 @@
</p></td>
</tr>
<tr>
<td align="left"><span class="font_lighter"> <%= format_time(course.created_on) %></span></td><!-- modified by ming -->
<td align="left"><span class="font_lighter"> <%= format_time(course.created_at) %></span></td><!-- modified by ming -->
<td align="right" >
<% t_course = Course.find_by_extra(course.identifier) %>
教师:<%= link_to(t_course.teacher.lastname+t_course.teacher.firstname, user_path(t_course.teacher)) %>
教师:<%= link_to(course.teacher.lastname+course.teacher.firstname, user_path(course.teacher)) %>
</td>
</tr>
</table></td>

View File

@ -0,0 +1,72 @@
<% if @bid.homework_type == Bid::HomeworkFile %>
<!-- 提交文件类型 -->
<%= render :partial => 'homework' %>
<% else %>
<!-- 提交引用项目 -->
<script type="text/javascript" language="javascript">
function clearInfo(id, content) {
var text = $('#' + id);
if (text.val() == content) {
$('#' + id).val('');
}
}
function showInfo(id, content) {
var text = $('#' + id);
if (text.val() == '') {
$('#' + id).val(content);
}
}
function cancel() {
$("#put-bid-form").hide();
}
</script>
<% if User.current.logged? %>
<!--我要竞标弹出框-->
<div id='flash' style="float:left; width: 100%; display: none"></div>
<div id="put-bid-form" style="display: none">
<%= form_for "bid_for_save", :remote => true, :url => {:controller => 'bids', :action => 'add'},
:update => "bidding_project_list",
:complete => '$("#put-bid-form").hide();' do |f| %>
<table id="bidding_table" border="0" width="100%" style="margin-left: 40px;">
<tr>
<td><%= select_tag 'bid', options_for_select(select_option_helper(@option)), :name => 'bid', :class => 'grayline' %></td>
<div id="prompt_create_pro">
<td>
<div class="font_lighter" style="font-size: 13px;">
<%= link_to '创建项目', new_project_path(course: 0, project_type: 0), :target => '_blank' %>
</div>
</td>
</div>
</tr>
<% if @bid.reward_type == Bid::Homework %>
<tr>
<td><%= f.text_area :bid_message, :id => "bid_message", :required => true, :rows => 4, :cols => 40, :placeholder => l(:label_bid_reason_homework), :style => "resize: none;", :class => 'noline' %></td>
</tr>
<% else %>
<tr>
<td><%= f.text_area :bid_message, :id => "bid_message", :required => true, :rows => 4, :cols => 40, :placeholder => l(:label_bid_reason), :style => "resize: none;", :class => 'noline' %></td>
</tr>
<% end %>
<tr>
<td align="right">
<%= submit_tag l(:button_add), :name => nil, :class => "enterprise",
:onmouseout => "this.style.backgroundPosition = 'left top'",
:onmouseover => "this.style.backgroundPosition = 'left -30px'" %>
<%= submit_tag l(:button_cancel), :name => nil, :onclick => "cancel();",
:type => 'button', :class => "enterprise", :onmouseout => "this.style.backgroundPosition = 'left top'",
:onmouseover => "this.style.backgroundPosition = 'left -30px'" %>
</td>
</tr>
</table>
<% end %>
</div>
<% end %>
<div id='bidding_project_list'>
<%= render :partial => 'project_list', :locals => {:bidding_project => @bidding_project, :bid => @bid} %>
</div>
<% end %>

View File

@ -6,9 +6,9 @@
</tr>
<tr>
<td style="padding-left: 8px"><a><%= link_to request.host()+"/courses", :controller => 'projects', :action => 'course'%></a></td>
<td><p class="top-content-list-homework"><%=link_to "主页", home_path %> > <%=link_to l(:label_course_practice), :controller => 'projects', :action => 'course' %> >
<span><%= link_to(@bid.courses.first.name.to_s, homework_project_path(@bid.courses.first)) if @bid.courses.first%></span> >
<td style="padding-left: 8px"><a><%= link_to request.host()+"/courses", :controller => 'courses', :action => 'index'%></a></td>
<td><p class="top-content-list-homework"><%=link_to "主页", home_path %> > <%=link_to l(:label_course_practice), :controller => 'courses', :action => 'index' %> >
<span><%= link_to(@bid.courses.first.name.to_s, homework_course_path(@bid.courses.first)) if @bid.courses.first%></span> >
<%=link_to(@bid.name, respond_path(@bid)) %> > <span><%= link_to "创建作业", new_homework_attach_path(@bid)%></span></p></td>
</tr>
</table>

View File

@ -633,7 +633,7 @@ RedmineApp::Application.routes.draw do
match 'calls/new_bid', :controller => 'bids', :action => 'new_bid'
match 'contest/new_contest', :controller => 'bids', :action => 'new_contest' #huang
match 'calls/:id/show_project', :controller => 'bids', :action => 'show_project', :as => 'project_for_bid'
match 'calls/:id/show_course', :controller => 'bids', :action => 'show_course', :as => 'course_for_bid' # nwb added
match 'calls/:id/show_course', :controller => 'bids', :action => 'show_courseEx', :as => 'course_for_bid' # nwb added
match 'calls/:id/new_exercise_book', :controller => 'homework_attach', :action => 'new', :as => 'new_homework_attach'
match 'calls/:id/add', :controller => 'bids', :action => 'add'
match 'calls/:id/delete', :controller => 'bids', :action => 'delete'