Description:
problem toggle on/off
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r558:9fc5999b7c8e - - 3 files changed: 14 inserted, 21 deleted

@@ -1,79 +1,74
1 1 class ProblemsController < ApplicationController
2 2
3 3 before_filter :authenticate, :authorization
4 4
5 5 in_place_edit_for :problem, :name
6 6 in_place_edit_for :problem, :full_name
7 7 in_place_edit_for :problem, :full_score
8 8
9 9 def index
10 - list
11 - render :action => 'list'
10 + @problems = Problem.find(:all, :order => 'date_added DESC')
12 11 end
13 12
14 13 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
15 14 verify :method => :post, :only => [ :destroy,
16 15 :create, :quick_create,
17 16 :do_manage,
18 17 :do_import,
19 18 :update ],
20 - :redirect_to => { :action => :list }
21 -
22 - def list
23 - @problems = Problem.find(:all, :order => 'date_added DESC')
24 - end
19 + :redirect_to => { :action => :index }
25 20
26 21 def show
27 22 @problem = Problem.find(params[:id])
28 23 end
29 24
30 25 def new
31 26 @problem = Problem.new
32 27 @description = nil
33 28 end
34 29
35 30 def create
36 31 @problem = Problem.new(params[:problem])
37 32 @description = Description.new(params[:description])
38 33 if @description.body!=''
39 34 if !@description.save
40 35 render :action => new and return
41 36 end
42 37 else
43 38 @description = nil
44 39 end
45 40 @problem.description = @description
46 41 if @problem.save
47 42 flash[:notice] = 'Problem was successfully created.'
48 - redirect_to :action => 'list'
43 + redirect_to action: :index
49 44 else
50 45 render :action => 'new'
51 46 end
52 47 end
53 48
54 49 def quick_create
55 50 @problem = Problem.new(params[:problem])
56 51 @problem.full_name = @problem.name if @problem.full_name == ''
57 52 @problem.full_score = 100
58 53 @problem.available = false
59 54 @problem.test_allowed = true
60 55 @problem.output_only = false
61 56 @problem.date_added = Time.new
62 57 if @problem.save
63 58 flash[:notice] = 'Problem was successfully created.'
64 - redirect_to :action => 'list'
59 + redirect_to action: :index
65 60 else
66 61 flash[:notice] = 'Error saving problem'
67 - redirect_to :action => 'list'
62 + redirect_to action: :index
68 63 end
69 64 end
70 65
71 66 def edit
72 67 @problem = Problem.find(params[:id])
73 68 @description = @problem.description
74 69 end
75 70
76 71 def update
77 72 @problem = Problem.find(params[:id])
78 73 @description = @problem.description
79 74 if @description == nil and params[:description][:body]!=''
@@ -112,49 +107,51
112 107 end
113 108 @problem.description_filename = "#{@problem.name}.pdf"
114 109 @problem.save
115 110 end
116 111 redirect_to :action => 'show', :id => @problem
117 112 else
118 113 render :action => 'edit'
119 114 end
120 115 end
121 116
122 117 def destroy
123 118 Problem.find(params[:id]).destroy
124 - redirect_to :action => 'list'
119 + redirect_to action: :index
125 120 end
126 121
127 122 def toggle
128 123 @problem = Problem.find(params[:id])
129 - @problem.available = !(@problem.available)
130 - @problem.save
124 + @problem.update_attributes(available: !(@problem.available) )
125 + respond_to do |format|
126 + format.js {}
127 + end
131 128 end
132 129
133 130 def turn_all_off
134 131 Problem.find(:all,
135 132 :conditions => "available = 1").each do |problem|
136 133 problem.available = false
137 134 problem.save
138 135 end
139 - redirect_to :action => 'list'
136 + redirect_to action: :index
140 137 end
141 138
142 139 def turn_all_on
143 140 Problem.find(:all,
144 141 :conditions => "available = 0").each do |problem|
145 142 problem.available = true
146 143 problem.save
147 144 end
148 - redirect_to :action => 'list'
145 + redirect_to action: :index
149 146 end
150 147
151 148 def stat
152 149 @problem = Problem.find(params[:id])
153 150 unless @problem.available or session[:admin]
154 151 redirect_to :controller => 'main', :action => 'list'
155 152 return
156 153 end
157 154 @submissions = Submission.includes(:user).where(problem_id: params[:id]).order(:user_id,:id)
158 155
159 156 #stat summary
160 157 range =65
@@ -1,24 +1,26
1 1 CafeGrader::Application.routes.draw do
2 2 root :to => 'main#login'
3 3
4 4 get "report/login"
5 5
6 6 resources :contests
7 7
8 8 resources :announcements
9 9 match 'announcements/toggle/:id' => 'announcements#toggle'
10 10
11 11 resources :sites
12 12
13 + resources :problem
14 +
13 15 resources :grader_configuration, controller: 'configurations'
14 16
15 17 match 'tasks/view/:file.:ext' => 'tasks#view'
16 18 match 'tasks/download/:id/:file.:ext' => 'tasks#download'
17 19 match 'heartbeat/:id/edit' => 'heartbeat#edit'
18 20
19 21 #main
20 22 get "main/list"
21 23
22 24 # See how all your routes lay out with "rake routes"
23 25
24 26 # This is a legacy wild controller route that's not recommended for RESTful applications.
deleted file
You need to be logged in to leave comments. Login now