diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb
index 69e8ebd80..d80817d31 100644
--- a/app/controllers/exercise_controller.rb
+++ b/app/controllers/exercise_controller.rb
@@ -1,7 +1,7 @@
class ExerciseController < ApplicationController
layout "base_courses"
- before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy, :commit_exercise, :commit_answer]
+ before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy, :commit_exercise, :commit_answer,:publish_exercise,:republish_exercise]
before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list]
include ExerciseHelper
@@ -261,7 +261,7 @@ class ExerciseController < ApplicationController
end
# 发布试卷
- def publish_excercise
+ def publish_exercise
@exercise.exercise_status = 2
@exercise.publish_time = Time.now
if @exercise.save
@@ -276,16 +276,17 @@ class ExerciseController < ApplicationController
end
# 重新发布试卷
- def republish_excercise
+ # 重新发布的时候会删除所有的答题
+ def republish_exercise
@exercise.exercise_questions.each do |exercise_question|
exercise_question.exercise_ansers.destroy_all
end
- # @poll.poll_users.destroy_all
- # @poll.polls_status = 1
- # @poll.save
- # respond_to do |format|
- # format.js
- # end
+ @exercise.exercise_users.destroy_all
+ @exercise.exercise_status = 1
+ @exercise.save
+ respond_to do |format|
+ format.js
+ end
end
def student_exercise_list
diff --git a/app/views/exercise/_alert.html.erb b/app/views/exercise/_alert.html.erb
new file mode 100644
index 000000000..b3de53d1f
--- /dev/null
+++ b/app/views/exercise/_alert.html.erb
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/views/exercise/_exercise.html.erb b/app/views/exercise/_exercise.html.erb
index 15a684a62..e44cd69c6 100644
--- a/app/views/exercise/_exercise.html.erb
+++ b/app/views/exercise/_exercise.html.erb
@@ -19,9 +19,9 @@
<% end%>
<% if exercise.exercise_status == 1 %>
- 发布试卷
+ 发布试卷
<% elsif exercise.exercise_status == 2%>
- 取消发布
+ 取消发布
<% else%>
发布试卷
<% end%>
diff --git a/app/views/exercise/_exercise_republish.html.erb b/app/views/exercise/_exercise_republish.html.erb
new file mode 100644
index 000000000..e69de29bb
diff --git a/app/views/exercise/index.html.erb b/app/views/exercise/index.html.erb
index bbe4dd707..14db03e09 100644
--- a/app/views/exercise/index.html.erb
+++ b/app/views/exercise/index.html.erb
@@ -1,4 +1,63 @@
<%= stylesheet_link_tag 'polls', :media => 'all' %>
+
<%= render :partial => 'exercises_list'%>
\ No newline at end of file
diff --git a/app/views/exercise/publish_exercise.js.erb b/app/views/exercise/publish_exercise.js.erb
new file mode 100644
index 000000000..ac2899402
--- /dev/null
+++ b/app/views/exercise/publish_exercise.js.erb
@@ -0,0 +1,10 @@
+$("#exercises_<%= @exercise.id %>").html("<%= escape_javascript(render :partial => 'exercise',:locals => {:exercise => @exercise}) %>");
+$('#ajax-modal').html("<%= escape_javascript(render :partial => 'alert', locals: { :message => l(:label_memo_create_succ)}) %>");
+showModal('ajax-modal', '250px');
+//$('#ajax-modal').css('height','111px');
+$('#ajax-modal').siblings().remove();
+$('#ajax-modal').before("" +
+ "");
+$('#ajax-modal').parent().removeClass("alert_praise");
+$('#ajax-modal').parent().css("top","").css("left","");
+$('#ajax-modal').parent().addClass("poll_alert_form");
\ No newline at end of file
diff --git a/app/views/exercise/republish_exercise.js.erb b/app/views/exercise/republish_exercise.js.erb
new file mode 100644
index 000000000..320cd3cf0
--- /dev/null
+++ b/app/views/exercise/republish_exercise.js.erb
@@ -0,0 +1,10 @@
+$("#exercises_<%= @exercise.id %>").html("<%= escape_javascript(render :partial => 'exercise_content',:locals => {:exercise => @exercise}) %>");
+$('#ajax-modal').html("<%= escape_javascript(render :partial => 'alert', locals: { :message => l(:label_poll_republish_success)}) %>");
+showModal('ajax-modal', '250px');
+//$('#ajax-modal').css('height','80px');
+$('#ajax-modal').siblings().remove();
+$('#ajax-modal').before("" +
+ "");
+$('#ajax-modal').parent().removeClass("alert_praise");
+$('#ajax-modal').parent().css("top","").css("left","");
+$('#ajax-modal').parent().addClass("poll_alert_form");
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 516b8977f..559bf4376 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -152,6 +152,8 @@ RedmineApp::Application.routes.draw do
get 'statistics_result'
get 'student_exercise_list'
get 'export_exercise'
+ get 'publish_exercise'
+ get 'republish_exercise'
post 'create_exercise_question'
post 'commit_answer'
post 'commit_exercise'
diff --git a/db/migrate/20151119124148_add_end_at_to_exercise_user.rb b/db/migrate/20151119124148_add_end_at_to_exercise_user.rb
new file mode 100644
index 000000000..db4cc4c47
--- /dev/null
+++ b/db/migrate/20151119124148_add_end_at_to_exercise_user.rb
@@ -0,0 +1,5 @@
+class AddEndAtToExerciseUser < ActiveRecord::Migration
+ def change
+ add_column :exercise_users, :end_at, :datetime
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 07dac5706..042058c5a 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20151118015638) do
+ActiveRecord::Schema.define(:version => 20151119124148) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@@ -241,58 +241,6 @@ ActiveRecord::Schema.define(:version => 20151118015638) do
add_index "changesets_issues", ["changeset_id", "issue_id"], :name => "changesets_issues_ids", :unique => true
- create_table "code_review_assignments", :force => true do |t|
- t.integer "issue_id"
- t.integer "change_id"
- t.integer "attachment_id"
- t.string "file_path"
- t.string "rev"
- t.string "rev_to"
- t.string "action_type"
- t.integer "changeset_id"
- end
-
- create_table "code_review_project_settings", :force => true do |t|
- t.integer "project_id"
- t.integer "tracker_id"
- t.datetime "created_at"
- t.datetime "updated_at"
- t.integer "updated_by"
- t.boolean "hide_code_review_tab", :default => false
- t.integer "auto_relation", :default => 1
- t.integer "assignment_tracker_id"
- t.text "auto_assign"
- t.integer "lock_version", :default => 0, :null => false
- t.boolean "tracker_in_review_dialog", :default => false
- end
-
- create_table "code_review_user_settings", :force => true do |t|
- t.integer "user_id", :default => 0, :null => false
- t.integer "mail_notification", :default => 0, :null => false
- t.datetime "created_at"
- t.datetime "updated_at"
- end
-
- create_table "code_reviews", :force => true do |t|
- t.integer "project_id"
- t.integer "change_id"
- t.datetime "created_at"
- t.datetime "updated_at"
- t.integer "line"
- t.integer "updated_by_id"
- t.integer "lock_version", :default => 0, :null => false
- t.integer "status_changed_from"
- t.integer "status_changed_to"
- t.integer "issue_id"
- t.string "action_type"
- t.string "file_path"
- t.string "rev"
- t.string "rev_to"
- t.integer "attachment_id"
- t.integer "file_count", :default => 0, :null => false
- t.boolean "diff_all"
- end
-
create_table "comments", :force => true do |t|
t.string "commented_type", :limit => 30, :default => "", :null => false
t.integer "commented_id", :default => 0, :null => false
@@ -614,6 +562,7 @@ ActiveRecord::Schema.define(:version => 20151118015638) do
t.datetime "start_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.datetime "end_at"
end
create_table "exercises", :force => true do |t|