Description:
fix refresh button on submission edit page
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r699:dd5555537101 - - 2 files changed: 5 inserted, 4 deleted

@@ -1,229 +1,230
1 %h2 Live submit
1 %h2 Live submit
2 %br
2 %br
3
3
4 %textarea#text_sourcecode{style: "display:none"}~ @source
4 %textarea#text_sourcecode{style: "display:none"}~ @source
5 .container
5 .container
6 .row
6 .row
7 .col-md-12
7 .col-md-12
8 .alert.alert-info
8 .alert.alert-info
9 Write your code in the following box, choose language, and click submit button when finished
9 Write your code in the following box, choose language, and click submit button when finished
10 .row
10 .row
11 .col-md-8
11 .col-md-8
12 %div#editor{style: 'height: 500px; border-radius: 7px; font-size: 14px;'}
12 %div#editor{style: 'height: 500px; border-radius: 7px; font-size: 14px;'}
13 .col-md-4
13 .col-md-4
14 - # submission form
14 - # submission form
15 = form_tag({controller: :main, :action => 'submit'}, :multipart => true, class: 'form') do
15 = form_tag({controller: :main, :action => 'submit'}, :multipart => true, class: 'form') do
16
16
17 = hidden_field_tag 'editor_text', @source
17 = hidden_field_tag 'editor_text', @source
18 = hidden_field_tag 'submission[problem_id]', @problem.id
18 = hidden_field_tag 'submission[problem_id]', @problem.id
19 .form-group
19 .form-group
20 = label_tag "Task:"
20 = label_tag "Task:"
21 = text_field_tag 'asdf', "#{@problem.long_name}", class: 'form-control', disabled: true
21 = text_field_tag 'asdf', "#{@problem.long_name}", class: 'form-control', disabled: true
22
22
23 .form-group
23 .form-group
24 = label_tag 'Language'
24 = label_tag 'Language'
25 = select_tag 'language_id', options_from_collection_for_select(Language.all, 'id', 'pretty_name', @lang_id || Language.find_by_pretty_name("Python").id || Language.first.id), class: 'form-control select', style: "width: 100px"
25 = select_tag 'language_id', options_from_collection_for_select(Language.all, 'id', 'pretty_name', @lang_id || Language.find_by_pretty_name("Python").id || Language.first.id), class: 'form-control select', style: "width: 100px"
26 .form-group
26 .form-group
27 = submit_tag 'Submit', class: 'btn btn-success', id: 'live_submit',
27 = submit_tag 'Submit', class: 'btn btn-success', id: 'live_submit',
28 data: {confirm: "Submitting this source code for task #{@problem.long_name}?"}
28 data: {confirm: "Submitting this source code for task #{@problem.long_name}?"}
29 - # latest submission status
29 - # latest submission status
30 .panel{class: (@submission && @submission.graded_at) ? "panel-info" : "panel-warning"}
30 .panel{class: (@submission && @submission.graded_at) ? "panel-info" : "panel-warning"}
31 .panel-heading
31 .panel-heading
32 Latest Submission Status
32 Latest Submission Status
33 = link_to "Refresh",get_latest_submission_status_submissions_path(@submission.user,@problem), class: "btn btn-default btn-sm", remote: true if @submission
33 = link_to "Refresh",get_latest_submission_status_submissions_path(@submission.user,@problem), class: "btn btn-default btn-sm", remote: true if @submission
34 .panel-body
34 .panel-body
35 - - if @submission
35 + %div#latest_status
36 - = render :partial => 'submission_short',
36 + - if @submission
37 - :locals => {submission: @submission, problem_name: @problem.name, problem_id: @problem.id }
37 + = render :partial => 'submission_short',
38 + :locals => {submission: @submission, problem_name: @problem.name, problem_id: @problem.id }
38 .row
39 .row
39 .col-md-12
40 .col-md-12
40 %h2 Console
41 %h2 Console
41 %textarea#console{style: 'height: 100%; width: 100%;background-color:#000;color:#fff;font-family: consolas, monaco, "Droid Sans Mono";',rows: 20}
42 %textarea#console{style: 'height: 100%; width: 100%;background-color:#000;color:#fff;font-family: consolas, monaco, "Droid Sans Mono";',rows: 20}
42
43
43 :javascript
44 :javascript
44 $(document).ready(function() {
45 $(document).ready(function() {
45 e = ace.edit("editor")
46 e = ace.edit("editor")
46 e.setValue($("#text_sourcecode").val());
47 e.setValue($("#text_sourcecode").val());
47 e.gotoLine(1);
48 e.gotoLine(1);
48 $("#language_id").trigger('change');
49 $("#language_id").trigger('change');
49 brython();
50 brython();
50 });
51 });
51
52
52
53
53 %script#__main__{type:'text/python3'}
54 %script#__main__{type:'text/python3'}
54 :plain
55 :plain
55 import sys
56 import sys
56 import traceback
57 import traceback
57
58
58 from browser import document as doc
59 from browser import document as doc
59 from browser import window, alert, console
60 from browser import window, alert, console
60
61
61 _credits = """ Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
62 _credits = """ Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
62 for supporting Python development. See www.python.org for more information."""
63 for supporting Python development. See www.python.org for more information."""
63
64
64 _copyright = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com
65 _copyright = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com
65 All Rights Reserved.
66 All Rights Reserved.
66
67
67 Copyright (c) 2001-2013 Python Software Foundation.
68 Copyright (c) 2001-2013 Python Software Foundation.
68 All Rights Reserved.
69 All Rights Reserved.
69
70
70 Copyright (c) 2000 BeOpen.com.
71 Copyright (c) 2000 BeOpen.com.
71 All Rights Reserved.
72 All Rights Reserved.
72
73
73 Copyright (c) 1995-2001 Corporation for National Research Initiatives.
74 Copyright (c) 1995-2001 Corporation for National Research Initiatives.
74 All Rights Reserved.
75 All Rights Reserved.
75
76
76 Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
77 Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
77 All Rights Reserved."""
78 All Rights Reserved."""
78
79
79 _license = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com
80 _license = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com
80 All rights reserved.
81 All rights reserved.
81
82
82 Redistribution and use in source and binary forms, with or without
83 Redistribution and use in source and binary forms, with or without
83 modification, are permitted provided that the following conditions are met:
84 modification, are permitted provided that the following conditions are met:
84
85
85 Redistributions of source code must retain the above copyright notice, this
86 Redistributions of source code must retain the above copyright notice, this
86 list of conditions and the following disclaimer. Redistributions in binary
87 list of conditions and the following disclaimer. Redistributions in binary
87 form must reproduce the above copyright notice, this list of conditions and
88 form must reproduce the above copyright notice, this list of conditions and
88 the following disclaimer in the documentation and/or other materials provided
89 the following disclaimer in the documentation and/or other materials provided
89 with the distribution.
90 with the distribution.
90 Neither the name of the <ORGANIZATION> nor the names of its contributors may
91 Neither the name of the <ORGANIZATION> nor the names of its contributors may
91 be used to endorse or promote products derived from this software without
92 be used to endorse or promote products derived from this software without
92 specific prior written permission.
93 specific prior written permission.
93
94
94 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
95 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
95 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
96 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
96 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
97 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
97 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
98 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
98 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
99 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
99 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
100 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
100 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
101 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
101 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
102 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
102 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
103 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
103 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
104 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
104 POSSIBILITY OF SUCH DAMAGE.
105 POSSIBILITY OF SUCH DAMAGE.
105 """
106 """
106
107
107 def credits():
108 def credits():
108 print(_credits)
109 print(_credits)
109 credits.__repr__ = lambda:_credits
110 credits.__repr__ = lambda:_credits
110
111
111 def copyright():
112 def copyright():
112 print(_copyright)
113 print(_copyright)
113 copyright.__repr__ = lambda:_copyright
114 copyright.__repr__ = lambda:_copyright
114
115
115 def license():
116 def license():
116 print(_license)
117 print(_license)
117 license.__repr__ = lambda:_license
118 license.__repr__ = lambda:_license
118
119
119 def write(data):
120 def write(data):
120 doc['console'].value += str(data)
121 doc['console'].value += str(data)
121
122
122
123
123 sys.stdout.write = sys.stderr.write = write
124 sys.stdout.write = sys.stderr.write = write
124 history = []
125 history = []
125 current = 0
126 current = 0
126 _status = "main" # or "block" if typing inside a block
127 _status = "main" # or "block" if typing inside a block
127
128
128 # execution namespace
129 # execution namespace
129 editor_ns = {'credits':credits,
130 editor_ns = {'credits':credits,
130 'copyright':copyright,
131 'copyright':copyright,
131 'license':license,
132 'license':license,
132 '__name__':'__main__'}
133 '__name__':'__main__'}
133
134
134 def cursorToEnd(*args):
135 def cursorToEnd(*args):
135 pos = len(doc['console'].value)
136 pos = len(doc['console'].value)
136 doc['console'].setSelectionRange(pos, pos)
137 doc['console'].setSelectionRange(pos, pos)
137 doc['console'].scrollTop = doc['console'].scrollHeight
138 doc['console'].scrollTop = doc['console'].scrollHeight
138
139
139 def get_col(area):
140 def get_col(area):
140 # returns the column num of cursor
141 # returns the column num of cursor
141 sel = doc['console'].selectionStart
142 sel = doc['console'].selectionStart
142 lines = doc['console'].value.split('\n')
143 lines = doc['console'].value.split('\n')
143 for line in lines[:-1]:
144 for line in lines[:-1]:
144 sel -= len(line) + 1
145 sel -= len(line) + 1
145 return sel
146 return sel
146
147
147
148
148 def myKeyPress(event):
149 def myKeyPress(event):
149 global _status, current
150 global _status, current
150 if event.keyCode == 9: # tab key
151 if event.keyCode == 9: # tab key
151 event.preventDefault()
152 event.preventDefault()
152 doc['console'].value += " "
153 doc['console'].value += " "
153 elif event.keyCode == 13: # return
154 elif event.keyCode == 13: # return
154 src = doc['console'].value
155 src = doc['console'].value
155 if _status == "main":
156 if _status == "main":
156 currentLine = src[src.rfind('>>>') + 4:]
157 currentLine = src[src.rfind('>>>') + 4:]
157 elif _status == "3string":
158 elif _status == "3string":
158 currentLine = src[src.rfind('>>>') + 4:]
159 currentLine = src[src.rfind('>>>') + 4:]
159 currentLine = currentLine.replace('\n... ', '\n')
160 currentLine = currentLine.replace('\n... ', '\n')
160 else:
161 else:
161 currentLine = src[src.rfind('...') + 4:]
162 currentLine = src[src.rfind('...') + 4:]
162 if _status == 'main' and not currentLine.strip():
163 if _status == 'main' and not currentLine.strip():
163 doc['console'].value += '\n>>> '
164 doc['console'].value += '\n>>> '
164 event.preventDefault()
165 event.preventDefault()
165 return
166 return
166 doc['console'].value += '\n'
167 doc['console'].value += '\n'
167 history.append(currentLine)
168 history.append(currentLine)
168 current = len(history)
169 current = len(history)
169 if _status == "main" or _status == "3string":
170 if _status == "main" or _status == "3string":
170 try:
171 try:
171 _ = editor_ns['_'] = eval(currentLine, editor_ns)
172 _ = editor_ns['_'] = eval(currentLine, editor_ns)
172 if _ is not None:
173 if _ is not None:
173 write(repr(_)+'\n')
174 write(repr(_)+'\n')
174 doc['console'].value += '>>> '
175 doc['console'].value += '>>> '
175 _status = "main"
176 _status = "main"
176 except IndentationError:
177 except IndentationError:
177 doc['console'].value += '... '
178 doc['console'].value += '... '
178 _status = "block"
179 _status = "block"
179 except SyntaxError as msg:
180 except SyntaxError as msg:
180 if str(msg) == 'invalid syntax : triple string end not found' or \
181 if str(msg) == 'invalid syntax : triple string end not found' or \
181 str(msg).startswith('Unbalanced bracket'):
182 str(msg).startswith('Unbalanced bracket'):
182 doc['console'].value += '... '
183 doc['console'].value += '... '
183 _status = "3string"
184 _status = "3string"
184 elif str(msg) == 'eval() argument must be an expression':
185 elif str(msg) == 'eval() argument must be an expression':
185 try:
186 try:
186 exec(currentLine, editor_ns)
187 exec(currentLine, editor_ns)
187 except:
188 except:
188 traceback.print_exc()
189 traceback.print_exc()
189 doc['console'].value += '>>> '
190 doc['console'].value += '>>> '
190 _status = "main"
191 _status = "main"
191 elif str(msg) == 'decorator expects function':
192 elif str(msg) == 'decorator expects function':
192 doc['console'].value += '... '
193 doc['console'].value += '... '
193 _status = "block"
194 _status = "block"
194 else:
195 else:
195 traceback.print_exc()
196 traceback.print_exc()
196 doc['console'].value += '>>> '
197 doc['console'].value += '>>> '
197 _status = "main"
198 _status = "main"
198 except:
199 except:
199 traceback.print_exc()
200 traceback.print_exc()
200 doc['console'].value += '>>> '
201 doc['console'].value += '>>> '
201 _status = "main"
202 _status = "main"
202 elif currentLine == "": # end of block
203 elif currentLine == "": # end of block
203 block = src[src.rfind('>>>') + 4:].splitlines()
204 block = src[src.rfind('>>>') + 4:].splitlines()
204 block = [block[0]] + [b[4:] for b in block[1:]]
205 block = [block[0]] + [b[4:] for b in block[1:]]
205 block_src = '\n'.join(block)
206 block_src = '\n'.join(block)
206 # status must be set before executing code in globals()
207 # status must be set before executing code in globals()
207 _status = "main"
208 _status = "main"
208 try:
209 try:
209 _ = exec(block_src, editor_ns)
210 _ = exec(block_src, editor_ns)
210 if _ is not None:
211 if _ is not None:
211 print(repr(_))
212 print(repr(_))
212 except:
213 except:
213 traceback.print_exc()
214 traceback.print_exc()
214 doc['console'].value += '>>> '
215 doc['console'].value += '>>> '
215 else:
216 else:
216 doc['console'].value += '... '
217 doc['console'].value += '... '
217
218
218 cursorToEnd()
219 cursorToEnd()
219 event.preventDefault()
220 event.preventDefault()
220
221
221 def myKeyDown(event):
222 def myKeyDown(event):
222 global _status, current
223 global _status, current
223 if event.keyCode == 37: # left arrow
224 if event.keyCode == 37: # left arrow
224 sel = get_col(doc['console'])
225 sel = get_col(doc['console'])
225 if sel < 5:
226 if sel < 5:
226 event.preventDefault()
227 event.preventDefault()
227 event.stopPropagation()
228 event.stopPropagation()
228 elif event.keyCode == 36: # line start
229 elif event.keyCode == 36: # line start
229 pos = doc['console'].selectionStart
230 pos = doc['console'].selectionStart
@@ -1,2 +1,2
1 :plain
1 :plain
2 - $("#latest_status").html("#{j render({partial: 'submission_short', locals: {submission: @submission, problem_name: @problem.name}})}")
2 + $("#latest_status").html("#{j render({partial: 'submission_short', locals: {submission: @submission, problem_name: @problem.name, problem_id: @problem.id}})}")
You need to be logged in to leave comments. Login now