Description:
add jquery to manage problem, now we can select a range of problem
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r456:2cbe975cbc59 - - 9 files changed: 65 inserted, 61 deleted

file renamed from app/assets/javascripts/new.js to app/assets/javascripts/local_jquery.js
@@ -143,50 +143,54
143 143 Problem.find(:all,
144 144 :conditions => "available = 0").each do |problem|
145 145 problem.available = true
146 146 problem.save
147 147 end
148 148 redirect_to :action => 'list'
149 149 end
150 150
151 151 def stat
152 152 @problem = Problem.find(params[:id])
153 153 if !@problem.available
154 154 redirect_to :controller => 'main', :action => 'list'
155 155 else
156 156 @submissions = Submission.includes(:user).where(problem_id: params[:id]).order(:user_id,:id)
157 157 end
158 158 end
159 159
160 160 def manage
161 161 @problems = Problem.find(:all, :order => 'date_added DESC')
162 162 end
163 163
164 164 def do_manage
165 165 if params.has_key? 'change_date_added'
166 166 change_date_added
167 - else params.has_key? 'add_to_contest'
167 + elsif params.has_key? 'add_to_contest'
168 168 add_to_contest
169 + elsif params.has_key? 'enable_problem'
170 + set_available(true)
171 + elsif params.has_key? 'disable_problem'
172 + set_available(false)
169 173 end
170 174 redirect_to :action => 'manage'
171 175 end
172 176
173 177 def import
174 178 @allow_test_pair_import = allow_test_pair_import?
175 179 end
176 180
177 181 def do_import
178 182 old_problem = Problem.find_by_name(params[:name])
179 183 if !allow_test_pair_import? and params.has_key? :import_to_db
180 184 params.delete :import_to_db
181 185 end
182 186 @problem, import_log = Problem.create_from_import_form_params(params,
183 187 old_problem)
184 188
185 189 if !@problem.errors.empty?
186 190 render :action => 'import' and return
187 191 end
188 192
189 193 if old_problem!=nil
190 194 flash[:notice] = "The test data has been replaced for problem #{@problem.name}"
191 195 end
192 196 @log = import_log
@@ -213,36 +217,44
213 217 end
214 218
215 219 def change_date_added
216 220 problems = get_problems_from_params
217 221 year = params[:date_added][:year].to_i
218 222 month = params[:date_added][:month].to_i
219 223 day = params[:date_added][:day].to_i
220 224 date = Date.new(year,month,day)
221 225 problems.each do |p|
222 226 p.date_added = date
223 227 p.save
224 228 end
225 229 end
226 230
227 231 def add_to_contest
228 232 problems = get_problems_from_params
229 233 contest = Contest.find(params[:contest][:id])
230 234 if contest!=nil and contest.enabled
231 235 problems.each do |p|
232 236 p.contests << contest
233 237 end
234 238 end
235 239 end
236 240
241 + def set_available(avail)
242 + problems = get_problems_from_params
243 + problems.each do |p|
244 + p.available = avail
245 + p.save
246 + end
247 + end
248 +
237 249 def get_problems_from_params
238 250 problems = []
239 251 params.keys.each do |k|
240 252 if k.index('prob-')==0
241 - name, id = k.split('-')
253 + name, id, order = k.split('-')
242 254 problems << Problem.find(id)
243 255 end
244 256 end
245 257 problems
246 258 end
247 259
248 260 end
@@ -1,43 +1,85
1 1 - content_for :head do
2 2 = stylesheet_link_tag 'problems'
3 + = javascript_include_tag 'local_jquery'
4 +
5 + :javascript
6 + $(document).ready( function() {
7 + function shiftclick(start,stop,value) {
8 + $('tr input').each( function(id,input) {
9 + var $input=$(input);
10 + var iid=parseInt($input.attr('id').split('-')[2]);
11 + if(iid>=start&&iid<=stop){
12 + $input.prop('checked',value)
13 + }
14 + });
15 + }
16 +
17 + $('tr input').click( function(e) {
18 + if (e.shiftKey) {
19 + stop = parseInt($(this).attr('id').split('-')[2]);
20 + var orig_stop = stop
21 + if (typeof start !== 'undefined') {
22 + if (start > stop) {
23 + var tmp = start;
24 + start = stop;
25 + stop = tmp;
26 + }
27 + shiftclick(start,stop,$(this).is(':checked') )
28 + }
29 + start = orig_stop
30 + } else {
31 + start = parseInt($(this).attr('id').split('-')[2]);
32 + }
33 + });
34 + });
35 +
3 36
4 37 %h1 Manage problems
5 38
6 39 %p= link_to '[Back to problem list]', :action => 'list'
7 40
8 41 = form_tag :action=>'do_manage' do
9 42 .submitbox
10 - What do you want to do?
43 + What do you want to do to the selected problem?
11 44 %br/
45 + (You can shift-click to select a range of problems)
12 46 %ul
13 47 %li
14 48 Change date added to
15 49 = select_date Date.current, :prefix => 'date_added'
16 50 &nbsp;&nbsp;&nbsp;
17 51 = submit_tag 'Change', :name => 'change_date_added'
52 + %li
53 + Set available to
54 + = submit_tag 'True', :name => 'enable_problem'
55 + = submit_tag 'False', :name => 'disable_problem'
18 56
19 57 - if GraderConfiguration.multicontests?
20 58 %li
21 59 Add to
22 60 = select("contest","id",Contest.all.collect {|c| [c.title, c.id]})
23 61 = submit_tag 'Add', :name => 'add_to_contest'
24 62
25 63 %table
26 - %tr
27 - %th/
64 + %tr{style: "text-align: left;"}
65 + %th= check_box_tag 'select_all'
28 66 %th Name
29 67 %th Full name
68 + %th Available
30 69 %th Date added
31 70 - if GraderConfiguration.multicontests?
32 71 %th Contests
33 72
73 + - num = 0
34 74 - for problem in @problems
75 + - num += 1
35 76 %tr{:id => "row-prob-#{problem.id}", :name=> "prob-#{problem.id}"}
36 - %td= check_box_tag "prob-#{problem.id}"
77 + %td= check_box_tag "prob-#{problem.id}-#{num}"
37 78 %td= problem.name
38 79 %td= problem.full_name
80 + %td= problem.available
39 81 %td= problem.date_added
40 82 - if GraderConfiguration.multicontests?
41 83 %td
42 84 - problem.contests.each do |contest|
43 85 = "(#{contest.name} [#{link_to 'x', :action => 'remove_contest', :id => problem.id, :contest_id => contest.id }])"
@@ -1,27 +1,27
1 1 - content_for :header do
2 2 = stylesheet_link_tag 'tablesorter-theme.cafe'
3 - = javascript_include_tag 'new'
3 + = javascript_include_tag 'local_jquery'
4 4
5 5 %script{:type=>"text/javascript"}
6 6 $(function () {
7 7 $('#since_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
8 8 $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
9 9 $('#my_table').tablesorter({widthFixed: true, widgets: ['zebra']});
10 10 });
11 11
12 12 %h1 Login status
13 13
14 14 =render partial: 'report_menu'
15 15 =render partial: 'date_range', locals: {param_text: 'Login date range:', title: 'Query login stat in the range' }
16 16
17 17 %table.tablesorter-cafe#my_table
18 18 %thead
19 19 %tr
20 20 %th login
21 21 %th full name
22 22 %th login count
23 23 %th earliest
24 24 %th latest
25 25 %th IP
26 26 %tbody
27 27 - @logins.each do |l|
@@ -1,26 +1,26
1 1 - content_for :header do
2 - = javascript_include_tag 'new'
2 + = javascript_include_tag 'local_jquery'
3 3
4 4 %script{:type=>"text/javascript"}
5 5 $(function () {
6 6 $('#since_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
7 7 $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
8 8 });
9 9
10 10 %h1 Login status
11 11
12 12 =render partial: 'report_menu'
13 13 =render partial: 'date_range', locals: {param_text: 'Submission date range:', title: 'Query submission stat in the range' }
14 14
15 15 %table.info
16 16 %thead
17 17 %tr.info-head
18 18 %th login
19 19 %th full name
20 20 %th total submissions
21 21 %th submissions
22 22 %tbody
23 23 - @submissions.each do |user_id,data|
24 24 %tr{class: cycle('info-even','info-odd')}
25 25 %td= data[:login]
26 26 %td= data[:full_name]
@@ -1,26 +1,26
1 1 - content_for :header do
2 - = javascript_include_tag 'new'
2 + = javascript_include_tag 'local_jquery'
3 3 = stylesheet_link_tag 'tablesorter-theme.cafe'
4 4
5 5 %script{:type=>"text/javascript"}
6 6 $(function () {
7 7 $('#since_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
8 8 $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
9 9 $('#my_table').tablesorter({widgets: ['zebra']});
10 10 });
11 11
12 12 %h1 User grading results
13 13 %h2= params[:action] == 'user_stat' ? "Show scores from latest submission" : "Show max scores in submission range"
14 14
15 15
16 16 - if @problem and @problem.errors
17 17 =error_messages_for 'problem'
18 18
19 19 = render partial: 'submission_range'
20 20
21 21 - if params[:action] == 'user_stat'
22 22 %h3 Latest score
23 23 = link_to '[download csv with all problems]', controller: :user_admin, action: :user_stat, commit: 'download csv'
24 24 - else
25 25 %h3 Max score
26 26 = link_to '[Show only latest submissions]', controller: :user_admin, action: :user_stat
@@ -1,26 +1,26
1 1 - content_for :header do
2 - = javascript_include_tag 'new'
2 + = javascript_include_tag 'local_jquery'
3 3
4 4 %script{:type=>"text/javascript"}
5 5 $(function () {
6 6 $('#submission_table').tablesorter({widgets: ['zebra']});
7 7 });
8 8
9 9 :css
10 10 .fix-width {
11 11 font-family: Droid Sans Mono,Consolas, monospace, mono, Courier New, Courier;
12 12 }
13 13
14 14 %h1= @user.full_name + ' Profile'
15 15
16 16 %h2 Basic info
17 17 <b>Login:</b> #{@user.login} <br/>
18 18 <b>Full name:</b> #{@user.full_name} <br />
19 19
20 20
21 21 %h2 Problem Stat
22 22
23 23 %h2 Submissions
24 24
25 25 %table.tablesorter-cafe#submission_table
26 26 %thead
@@ -39,27 +39,27
39 39 # Configure sensitive parameters which will be filtered from the log file.
40 40 config.filter_parameters += [:password]
41 41
42 42 # Enable escaping HTML in JSON.
43 43 config.active_support.escape_html_entities_in_json = true
44 44
45 45 # Use SQL instead of Active Record's schema dumper when creating the database.
46 46 # This is necessary if your schema can't be completely dumped by the schema dumper,
47 47 # like if you have constraints or database-specific column types
48 48 # config.active_record.schema_format = :sql
49 49
50 50 # Enforce whitelist mode for mass assignment.
51 51 # This will create an empty whitelist of attributes available for mass-assignment for all models
52 52 # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
53 53 # parameters by using an attr_accessible or attr_protected declaration.
54 54 config.active_record.whitelist_attributes = false
55 55
56 56 # Enable the asset pipeline
57 57 config.assets.enabled = true
58 58
59 59 # Version of your assets, change this if you want to expire all your assets
60 60 config.assets.version = '1.0'
61 61
62 62 config.assets.precompile += ['announcement_refresh.js','effects.js','site_update.js','graders.css','problems.css']
63 - config.assets.precompile += ['new.js','tablesorter-theme.cafe.css']
63 + config.assets.precompile += ['local_jquery.js','tablesorter-theme.cafe.css']
64 64 end
65 65 end
deleted file
You need to be logged in to leave comments. Login now