index界面以及试卷统计相关路由添加

This commit is contained in:
sw 2015-11-13 17:23:52 +08:00
parent 70c5b27a43
commit e6cd104ead
6 changed files with 109 additions and 3 deletions

View File

@ -3,9 +3,18 @@ class ExerciseController < ApplicationController
before_filter :find_course, :only => [:index,:new,:create] before_filter :find_course, :only => [:index,:new,:create]
def index def index
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
if @is_teacher
exercises = @course.exercises
else
exercises = @course.exercises.where(:exercise_status => 1)
end
@exercises = paginateHelper exercises,20 #分页
respond_to do |format|
format.html
end
end end
def show def show
end end
@ -30,6 +39,11 @@ class ExerciseController < ApplicationController
end end
#统计结果
def statistics_result
end
private private
def find_course def find_course
@course = Course.find params[:course_id] @course = Course.find params[:course_id]

View File

@ -1,4 +1,5 @@
class Exercise < ActiveRecord::Base class Exercise < ActiveRecord::Base
#exercise_status: 1,新建2发布3关闭
include Redmine::SafeAttributes include Redmine::SafeAttributes
belongs_to :user belongs_to :user
has_many :exercise_questions, :dependent => :destroy,:order => "#{ExerciseQuestion.table_name}.question_number" has_many :exercise_questions, :dependent => :destroy,:order => "#{ExerciseQuestion.table_name}.question_number"

View File

@ -0,0 +1,61 @@
<%# has_commit = has_commit_poll?(poll.id ,User.current)%>
<% exercise_name = exercise.exercise_name.empty? ? l(:label_poll_new) : exercise.exercise_name%>
<% if @is_teacher%>
<li title="<%= exercise.exercise_name %>">
<div style="width: 310px;float: left;">
<%# if has_commit %>
<%#= link_to poll_name, poll_result_poll_path(poll.id), :class => "polls_title polls_title_w fl c_dblue"%>
<%# else %>
<%#= link_to poll_name, exercise_path(poll.id), :class => "polls_title polls_title_w fl c_dblue" %>
<%# end %>
<%= link_to exercise_name, exercise_path(exercise.id), :class => "polls_title polls_title_w fl c_dblue" %>
</div>
</li>
<% if exercise.exercise_status == 1%>
<li class="pollsbtn fl ml10 pollsbtn_grey">统计结果</li>
<% else %>
<li><%= link_to l(:label_statistical_results), statistics_result_exercise_path(exercise.id), :class => "pollsbtn fl ml10"%></li>
<% end%>
<% if exercise.exercise_status == 1 %>
<li><a href="javascript:" class="pollsbtn btn_pu fl ml5" onclick="">发布试卷</a></li>
<% elsif exercise.exercise_status == 2%>
<li><a href="javascript:" class="pollsbtn btn_de fl ml5" onclick="">取消发布</a></li>
<% else%>
<li class="pollsbtn fl ml10 pollsbtn_grey" style="margin-left: 5px;" >发布试卷</li>
<% end%>
<%= link_to(l(:button_delete), exercise,:method => :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "polls_de fr ml5 mr10") %>
<% if exercise.exercise_status == 1 %>
<li><%= link_to l(:button_edit), edit_exercise_path(exercise.id), :class => "polls_de fr ml5"%></li>
<% else%>
<li class="polls_de_grey fr ml5" title="未发布的试卷才能进行编辑">编辑</li>
<% end%>
<% if exercise.exercise_status == 2 %>
<li><a class="polls_de fr ml5" onclick="" href="javascript:">关闭</a></li>
<% else %>
<li class="polls_de_grey fr ml5" title="发布的问卷才能进行关闭">关闭</li>
<% end%>
<% if exercise.exercise_status == 1%>
<li class="polls_de_grey fr ml5">导出</li>
<% elsif exercise.exercise_status == 2 || exercise.exercise_status == 3 %>
<li><%= link_to "导出", export_exercise_exercise_path(exercise.id,:format => "xls"), :class => "polls_de fr ml5"%></li>
<% end%>
<li class="polls_date fr"><%= format_date exercise.created_at.to_date%></li>
<% else%>
<% if exercise.exercise_status == 2%>
<%# if has_commit%>
<!--li><%#= link_to poll_name, poll_result_poll_path(poll.id), :class => "polls_title polls_title_st fl c_dblue" %></li>
<li class="pollsbtn_tip fl ml5">已答</li-->
<%#else%>
<%= link_to exercise_name, exercise_path(exercise.id), :class => "polls_title polls_title_st fl c_dblue"%>
<%#end%>
<% end%>
<li class="polls_date fr mr10"><%= format_date exercise.created_at.to_date%></li>
<% end%>

View File

@ -0,0 +1,25 @@
<div class="polls_head">
<h2>所有试卷
<span><%= @obj_count%></span>
</h2>
<% if @is_teacher%>
<%#= link_to "导入", other_poll_poll_index_path(:polls_group_id => @course.id), :remote=>true,:class => "newbtn"%>
<%= link_to "新建试卷 ", new_exercise_path(:course_id => @course.id), :class => "newbtn" %>
<% end%>
</div>
<div class="cl"></div>
<div id="polls_list" class="polls_list">
<% @exercises.each do |exercise|%>
<ul id="polls_<%= exercise.id %>" class="polls_list_ul">
<%= render :partial => 'exercise', :locals => {:exercise => exercise} %>
</ul>
<div class="cl"></div>
<% end%>
<ul class="wlist">
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%>
</ul>
<div class="cl"></div>
</div><!--列表end-->

View File

@ -1 +1,4 @@
111111111111 <%= stylesheet_link_tag 'polls', :media => 'all' %>
<div class="polls_content02" id="polls">
<%= render :partial => 'exercises_list'%>
</div><!--问卷内容end-->

View File

@ -99,6 +99,8 @@ RedmineApp::Application.routes.draw do
#show、index、new、create、edit、update、destroy路由自动生成 #show、index、new、create、edit、update、destroy路由自动生成
resources :exercise do resources :exercise do
member do #生成路径为 /exercise/:id/方法名 member do #生成路径为 /exercise/:id/方法名
get 'statistics_result'
get 'export_exercise'
end end
collection do #生成路径为 /exercise/方法名 collection do #生成路径为 /exercise/方法名