Description:
problem toggle on/off
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r558:9fc5999b7c8e - - 3 files changed: 14 inserted, 21 deleted
@@ -1,91 +1,86 | |||||
|
1 | class ProblemsController < ApplicationController |
|
1 | class ProblemsController < ApplicationController |
|
2 |
|
2 | ||
|
3 | before_filter :authenticate, :authorization |
|
3 | before_filter :authenticate, :authorization |
|
4 |
|
4 | ||
|
5 | in_place_edit_for :problem, :name |
|
5 | in_place_edit_for :problem, :name |
|
6 | in_place_edit_for :problem, :full_name |
|
6 | in_place_edit_for :problem, :full_name |
|
7 | in_place_edit_for :problem, :full_score |
|
7 | in_place_edit_for :problem, :full_score |
|
8 |
|
8 | ||
|
9 | def index |
|
9 | def index |
|
10 | - list |
|
10 | + @problems = Problem.find(:all, :order => 'date_added DESC') |
|
11 | - render :action => 'list' |
|
||
|
12 | end |
|
11 | end |
|
13 |
|
12 | ||
|
14 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
13 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
15 | verify :method => :post, :only => [ :destroy, |
|
14 | verify :method => :post, :only => [ :destroy, |
|
16 | :create, :quick_create, |
|
15 | :create, :quick_create, |
|
17 | :do_manage, |
|
16 | :do_manage, |
|
18 | :do_import, |
|
17 | :do_import, |
|
19 | :update ], |
|
18 | :update ], |
|
20 |
- :redirect_to => { :action => : |
|
19 | + :redirect_to => { :action => :index } |
|
21 | - |
|
||
|
22 | - def list |
|
||
|
23 | - @problems = Problem.find(:all, :order => 'date_added DESC') |
|
||
|
24 | - end |
|
||
|
25 |
|
20 | ||
|
26 | def show |
|
21 | def show |
|
27 | @problem = Problem.find(params[:id]) |
|
22 | @problem = Problem.find(params[:id]) |
|
28 | end |
|
23 | end |
|
29 |
|
24 | ||
|
30 | def new |
|
25 | def new |
|
31 | @problem = Problem.new |
|
26 | @problem = Problem.new |
|
32 | @description = nil |
|
27 | @description = nil |
|
33 | end |
|
28 | end |
|
34 |
|
29 | ||
|
35 | def create |
|
30 | def create |
|
36 | @problem = Problem.new(params[:problem]) |
|
31 | @problem = Problem.new(params[:problem]) |
|
37 | @description = Description.new(params[:description]) |
|
32 | @description = Description.new(params[:description]) |
|
38 | if @description.body!='' |
|
33 | if @description.body!='' |
|
39 | if !@description.save |
|
34 | if !@description.save |
|
40 | render :action => new and return |
|
35 | render :action => new and return |
|
41 | end |
|
36 | end |
|
42 | else |
|
37 | else |
|
43 | @description = nil |
|
38 | @description = nil |
|
44 | end |
|
39 | end |
|
45 | @problem.description = @description |
|
40 | @problem.description = @description |
|
46 | if @problem.save |
|
41 | if @problem.save |
|
47 | flash[:notice] = 'Problem was successfully created.' |
|
42 | flash[:notice] = 'Problem was successfully created.' |
|
48 |
- redirect_to |
|
43 | + redirect_to action: :index |
|
49 | else |
|
44 | else |
|
50 | render :action => 'new' |
|
45 | render :action => 'new' |
|
51 | end |
|
46 | end |
|
52 | end |
|
47 | end |
|
53 |
|
48 | ||
|
54 | def quick_create |
|
49 | def quick_create |
|
55 | @problem = Problem.new(params[:problem]) |
|
50 | @problem = Problem.new(params[:problem]) |
|
56 | @problem.full_name = @problem.name if @problem.full_name == '' |
|
51 | @problem.full_name = @problem.name if @problem.full_name == '' |
|
57 | @problem.full_score = 100 |
|
52 | @problem.full_score = 100 |
|
58 | @problem.available = false |
|
53 | @problem.available = false |
|
59 | @problem.test_allowed = true |
|
54 | @problem.test_allowed = true |
|
60 | @problem.output_only = false |
|
55 | @problem.output_only = false |
|
61 | @problem.date_added = Time.new |
|
56 | @problem.date_added = Time.new |
|
62 | if @problem.save |
|
57 | if @problem.save |
|
63 | flash[:notice] = 'Problem was successfully created.' |
|
58 | flash[:notice] = 'Problem was successfully created.' |
|
64 |
- redirect_to |
|
59 | + redirect_to action: :index |
|
65 | else |
|
60 | else |
|
66 | flash[:notice] = 'Error saving problem' |
|
61 | flash[:notice] = 'Error saving problem' |
|
67 |
- |
|
62 | + redirect_to action: :index |
|
68 | end |
|
63 | end |
|
69 | end |
|
64 | end |
|
70 |
|
65 | ||
|
71 | def edit |
|
66 | def edit |
|
72 | @problem = Problem.find(params[:id]) |
|
67 | @problem = Problem.find(params[:id]) |
|
73 | @description = @problem.description |
|
68 | @description = @problem.description |
|
74 | end |
|
69 | end |
|
75 |
|
70 | ||
|
76 | def update |
|
71 | def update |
|
77 | @problem = Problem.find(params[:id]) |
|
72 | @problem = Problem.find(params[:id]) |
|
78 | @description = @problem.description |
|
73 | @description = @problem.description |
|
79 | if @description == nil and params[:description][:body]!='' |
|
74 | if @description == nil and params[:description][:body]!='' |
|
80 | @description = Description.new(params[:description]) |
|
75 | @description = Description.new(params[:description]) |
|
81 | if !@description.save |
|
76 | if !@description.save |
|
82 | flash[:notice] = 'Error saving description' |
|
77 | flash[:notice] = 'Error saving description' |
|
83 | render :action => 'edit' and return |
|
78 | render :action => 'edit' and return |
|
84 | end |
|
79 | end |
|
85 | @problem.description = @description |
|
80 | @problem.description = @description |
|
86 | elsif @description!=nil |
|
81 | elsif @description!=nil |
|
87 | if !@description.update_attributes(params[:description]) |
|
82 | if !@description.update_attributes(params[:description]) |
|
88 | flash[:notice] = 'Error saving description' |
|
83 | flash[:notice] = 'Error saving description' |
|
89 | render :action => 'edit' and return |
|
84 | render :action => 'edit' and return |
|
90 | end |
|
85 | end |
|
91 | end |
|
86 | end |
@@ -100,73 +95,75 | |||||
|
100 | out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}" |
|
95 | out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}" |
|
101 | if not FileTest.exists? out_dirname |
|
96 | if not FileTest.exists? out_dirname |
|
102 | Dir.mkdir out_dirname |
|
97 | Dir.mkdir out_dirname |
|
103 | end |
|
98 | end |
|
104 |
|
99 | ||
|
105 | out_filename = "#{out_dirname}/#{@problem.name}.pdf" |
|
100 | out_filename = "#{out_dirname}/#{@problem.name}.pdf" |
|
106 | if FileTest.exists? out_filename |
|
101 | if FileTest.exists? out_filename |
|
107 | File.delete out_filename |
|
102 | File.delete out_filename |
|
108 | end |
|
103 | end |
|
109 |
|
104 | ||
|
110 | File.open(out_filename,"wb") do |file| |
|
105 | File.open(out_filename,"wb") do |file| |
|
111 | file.write(params[:file].read) |
|
106 | file.write(params[:file].read) |
|
112 | end |
|
107 | end |
|
113 | @problem.description_filename = "#{@problem.name}.pdf" |
|
108 | @problem.description_filename = "#{@problem.name}.pdf" |
|
114 | @problem.save |
|
109 | @problem.save |
|
115 | end |
|
110 | end |
|
116 | redirect_to :action => 'show', :id => @problem |
|
111 | redirect_to :action => 'show', :id => @problem |
|
117 | else |
|
112 | else |
|
118 | render :action => 'edit' |
|
113 | render :action => 'edit' |
|
119 | end |
|
114 | end |
|
120 | end |
|
115 | end |
|
121 |
|
116 | ||
|
122 | def destroy |
|
117 | def destroy |
|
123 | Problem.find(params[:id]).destroy |
|
118 | Problem.find(params[:id]).destroy |
|
124 |
- redirect_to |
|
119 | + redirect_to action: :index |
|
125 | end |
|
120 | end |
|
126 |
|
121 | ||
|
127 | def toggle |
|
122 | def toggle |
|
128 | @problem = Problem.find(params[:id]) |
|
123 | @problem = Problem.find(params[:id]) |
|
129 |
- @problem.available |
|
124 | + @problem.update_attributes(available: !(@problem.available) ) |
|
130 | - @problem.save |
|
125 | + respond_to do |format| |
|
|
126 | + format.js {} | ||
|
|
127 | + end | ||
|
131 | end |
|
128 | end |
|
132 |
|
129 | ||
|
133 | def turn_all_off |
|
130 | def turn_all_off |
|
134 | Problem.find(:all, |
|
131 | Problem.find(:all, |
|
135 | :conditions => "available = 1").each do |problem| |
|
132 | :conditions => "available = 1").each do |problem| |
|
136 | problem.available = false |
|
133 | problem.available = false |
|
137 | problem.save |
|
134 | problem.save |
|
138 | end |
|
135 | end |
|
139 |
- redirect_to |
|
136 | + redirect_to action: :index |
|
140 | end |
|
137 | end |
|
141 |
|
138 | ||
|
142 | def turn_all_on |
|
139 | def turn_all_on |
|
143 | Problem.find(:all, |
|
140 | Problem.find(:all, |
|
144 | :conditions => "available = 0").each do |problem| |
|
141 | :conditions => "available = 0").each do |problem| |
|
145 | problem.available = true |
|
142 | problem.available = true |
|
146 | problem.save |
|
143 | problem.save |
|
147 | end |
|
144 | end |
|
148 |
- redirect_to |
|
145 | + redirect_to action: :index |
|
149 | end |
|
146 | end |
|
150 |
|
147 | ||
|
151 | def stat |
|
148 | def stat |
|
152 | @problem = Problem.find(params[:id]) |
|
149 | @problem = Problem.find(params[:id]) |
|
153 | unless @problem.available or session[:admin] |
|
150 | unless @problem.available or session[:admin] |
|
154 | redirect_to :controller => 'main', :action => 'list' |
|
151 | redirect_to :controller => 'main', :action => 'list' |
|
155 | return |
|
152 | return |
|
156 | end |
|
153 | end |
|
157 | @submissions = Submission.includes(:user).where(problem_id: params[:id]).order(:user_id,:id) |
|
154 | @submissions = Submission.includes(:user).where(problem_id: params[:id]).order(:user_id,:id) |
|
158 |
|
155 | ||
|
159 | #stat summary |
|
156 | #stat summary |
|
160 | range =65 |
|
157 | range =65 |
|
161 | @histogram = { data: Array.new(range,0), summary: {} } |
|
158 | @histogram = { data: Array.new(range,0), summary: {} } |
|
162 | user = Hash.new(0) |
|
159 | user = Hash.new(0) |
|
163 | @submissions.find_each do |sub| |
|
160 | @submissions.find_each do |sub| |
|
164 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
161 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
165 | @histogram[:data][d.to_i] += 1 if d < range |
|
162 | @histogram[:data][d.to_i] += 1 if d < range |
|
166 | user[sub.user_id] = [user[sub.user_id], ((sub.try(:points) || 0) >= @problem.full_score) ? 1 : 0].max |
|
163 | user[sub.user_id] = [user[sub.user_id], ((sub.try(:points) || 0) >= @problem.full_score) ? 1 : 0].max |
|
167 | end |
|
164 | end |
|
168 | @histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
165 | @histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
169 |
|
166 | ||
|
170 | @summary = { attempt: user.count, solve: 0 } |
|
167 | @summary = { attempt: user.count, solve: 0 } |
|
171 | user.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
168 | user.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
172 | end |
|
169 | end |
@@ -1,27 +1,29 | |||||
|
1 | CafeGrader::Application.routes.draw do |
|
1 | CafeGrader::Application.routes.draw do |
|
2 | root :to => 'main#login' |
|
2 | root :to => 'main#login' |
|
3 |
|
3 | ||
|
4 | get "report/login" |
|
4 | get "report/login" |
|
5 |
|
5 | ||
|
6 | resources :contests |
|
6 | resources :contests |
|
7 |
|
7 | ||
|
8 | resources :announcements |
|
8 | resources :announcements |
|
9 | match 'announcements/toggle/:id' => 'announcements#toggle' |
|
9 | match 'announcements/toggle/:id' => 'announcements#toggle' |
|
10 |
|
10 | ||
|
11 | resources :sites |
|
11 | resources :sites |
|
12 |
|
12 | ||
|
|
13 | + resources :problem | ||
|
|
14 | + | ||
|
13 | resources :grader_configuration, controller: 'configurations' |
|
15 | resources :grader_configuration, controller: 'configurations' |
|
14 |
|
16 | ||
|
15 | match 'tasks/view/:file.:ext' => 'tasks#view' |
|
17 | match 'tasks/view/:file.:ext' => 'tasks#view' |
|
16 | match 'tasks/download/:id/:file.:ext' => 'tasks#download' |
|
18 | match 'tasks/download/:id/:file.:ext' => 'tasks#download' |
|
17 | match 'heartbeat/:id/edit' => 'heartbeat#edit' |
|
19 | match 'heartbeat/:id/edit' => 'heartbeat#edit' |
|
18 |
|
20 | ||
|
19 | #main |
|
21 | #main |
|
20 | get "main/list" |
|
22 | get "main/list" |
|
21 |
|
23 | ||
|
22 | # See how all your routes lay out with "rake routes" |
|
24 | # See how all your routes lay out with "rake routes" |
|
23 |
|
25 | ||
|
24 | # This is a legacy wild controller route that's not recommended for RESTful applications. |
|
26 | # This is a legacy wild controller route that's not recommended for RESTful applications. |
|
25 | # Note: This route will make all actions in every controller accessible via GET requests. |
|
27 | # Note: This route will make all actions in every controller accessible via GET requests. |
|
26 | match ':controller(/:action(/:id))(.:format)' |
|
28 | match ':controller(/:action(/:id))(.:format)' |
|
27 | end |
|
29 | end |
deleted file |
You need to be logged in to leave comments.
Login now