diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 96a965f79..bed3d9061 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -3,9 +3,18 @@ class ExerciseController < ApplicationController before_filter :find_course, :only => [:index,:new,:create] 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 - + def show end @@ -30,6 +39,11 @@ class ExerciseController < ApplicationController end + #统计结果 + def statistics_result + + end + private def find_course @course = Course.find params[:course_id] diff --git a/app/models/exercise.rb b/app/models/exercise.rb index cbf3a6e91..e4295971e 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -1,4 +1,5 @@ class Exercise < ActiveRecord::Base + #exercise_status: 1,新建;2,发布;3,关闭 include Redmine::SafeAttributes belongs_to :user has_many :exercise_questions, :dependent => :destroy,:order => "#{ExerciseQuestion.table_name}.question_number" diff --git a/app/views/exercise/_exercise.html.erb b/app/views/exercise/_exercise.html.erb new file mode 100644 index 000000000..e469c471c --- /dev/null +++ b/app/views/exercise/_exercise.html.erb @@ -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%> +
  • +
    + <%# 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" %> +
    +
  • + + <% if exercise.exercise_status == 1%> +
  • 统计结果
  • + <% else %> +
  • <%= link_to l(:label_statistical_results), statistics_result_exercise_path(exercise.id), :class => "pollsbtn fl ml10"%>
  • + <% end%> + + <% if exercise.exercise_status == 1 %> +
  • 发布试卷
  • + <% elsif exercise.exercise_status == 2%> +
  • 取消发布
  • + <% else%> +
  • 发布试卷
  • + <% 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 %> +
  • <%= link_to l(:button_edit), edit_exercise_path(exercise.id), :class => "polls_de fr ml5"%>
  • + <% else%> +
  • 编辑
  • + <% end%> + + <% if exercise.exercise_status == 2 %> +
  • 关闭
  • + <% else %> +
  • 关闭
  • + <% end%> + + <% if exercise.exercise_status == 1%> +
  • 导出
  • + <% elsif exercise.exercise_status == 2 || exercise.exercise_status == 3 %> +
  • <%= link_to "导出", export_exercise_exercise_path(exercise.id,:format => "xls"), :class => "polls_de fr ml5"%>
  • + <% end%> + + +
  • <%= format_date exercise.created_at.to_date%>
  • +<% else%> + <% if exercise.exercise_status == 2%> + <%# if has_commit%> + + <%#else%> + <%= link_to exercise_name, exercise_path(exercise.id), :class => "polls_title polls_title_st fl c_dblue"%> + <%#end%> + <% end%> +
  • <%= format_date exercise.created_at.to_date%>
  • +<% end%> \ No newline at end of file diff --git a/app/views/exercise/_exercises_list.html.erb b/app/views/exercise/_exercises_list.html.erb new file mode 100644 index 000000000..16fa24b0e --- /dev/null +++ b/app/views/exercise/_exercises_list.html.erb @@ -0,0 +1,25 @@ +
    +

    所有试卷 + (<%= @obj_count%>) +

    + <% 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%> +
    +
    +
    + + <% @exercises.each do |exercise|%> + +
    + <% end%> + + + +
    +
    \ No newline at end of file diff --git a/app/views/exercise/index.html.erb b/app/views/exercise/index.html.erb index 52cfcc97f..1a8d15181 100644 --- a/app/views/exercise/index.html.erb +++ b/app/views/exercise/index.html.erb @@ -1 +1,4 @@ -111111111111 \ No newline at end of file +<%= stylesheet_link_tag 'polls', :media => 'all' %> +
    + <%= render :partial => 'exercises_list'%> +
    \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9c557c9a5..f1c41f65f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -99,6 +99,8 @@ RedmineApp::Application.routes.draw do #show、index、new、create、edit、update、destroy路由自动生成 resources :exercise do member do #生成路径为 /exercise/:id/方法名 + get 'statistics_result' + get 'export_exercise' end collection do #生成路径为 /exercise/方法名