Description:
use ace editor for submission viewing
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r566:46de378c3b60 - - 3 files changed: 109 inserted, 65 deleted

@@ -16,30 +16,32
16 #$(".bootstrap-switch").bootstrapSwitch()
16 #$(".bootstrap-switch").bootstrapSwitch()
17 $(".bootstrap-toggle").bootstrapToggle()
17 $(".bootstrap-toggle").bootstrapToggle()
18 $('.btn-file :file').on 'fileselect', (event, numFiles, label) ->
18 $('.btn-file :file').on 'fileselect', (event, numFiles, label) ->
19 input = $(this).parents('.input-group').find(':text')
19 input = $(this).parents('.input-group').find(':text')
20 log = if numFiles > 1 then numFiles + ' files selected' else label
20 log = if numFiles > 1 then numFiles + ' files selected' else label
21 if input.length
21 if input.length
22 input.val log
22 input.val log
23 else
23 else
24 if log
24 if log
25 alert log
25 alert log
26 return
26 return
27 $(".go-button").on 'click', (event) ->
27 $(".go-button").on 'click', (event) ->
28 link = $(this).attr("data-source")
28 link = $(this).attr("data-source")
29 url = $(link).val()
29 url = $(link).val()
30 if url
30 if url
31 window.location.href = url
31 window.location.href = url
32 return
32 return
33 $('.ajax-toggle').on 'click', (event) ->
33 $('.ajax-toggle').on 'click', (event) ->
34 target = $(event.target)
34 target = $(event.target)
35 target.removeClass 'btn-default'
35 target.removeClass 'btn-default'
36 target.removeClass 'btn-success'
36 target.removeClass 'btn-success'
37 target.addClass 'btn-warning'
37 target.addClass 'btn-warning'
38 target.text '...'
38 target.text '...'
39 return
39 return
40 -
40 +
41 - editor = ace.edit("editor")
41 + #ace editor
42 - editor.setTheme("ace/theme/merbivore")
42 + e = ace.edit("editor")
43 - editor.getSession().setMode("ace/mode/javascript")
43 + e.setTheme('ace/theme/merbivore')
44 + e.getSession().setTabSize(2)
45 + e.getSession().setUseSoftTabs(true)
44
46
45 return
47 return
@@ -94,48 +94,67
94 end
94 end
95
95
96 def format_short_duration(duration)
96 def format_short_duration(duration)
97 return '' if duration==nil
97 return '' if duration==nil
98 d = duration.to_f
98 d = duration.to_f
99 return Time.at(d).gmtime.strftime("%X")
99 return Time.at(d).gmtime.strftime("%X")
100 end
100 end
101
101
102 def read_textfile(fname,max_size=2048)
102 def read_textfile(fname,max_size=2048)
103 begin
103 begin
104 File.open(fname).read(max_size)
104 File.open(fname).read(max_size)
105 rescue
105 rescue
106 nil
106 nil
107 end
107 end
108 end
108 end
109
109
110 def toggle_button(on,toggle_url,id, option={})
110 def toggle_button(on,toggle_url,id, option={})
111 btn_size = option[:size] || 'btn-xs'
111 btn_size = option[:size] || 'btn-xs'
112 link_to (on ? "Yes" : "No"), toggle_url,
112 link_to (on ? "Yes" : "No"), toggle_url,
113 {class: "btn btn-block #{btn_size} btn-#{on ? 'success' : 'default'} ajax-toggle",
113 {class: "btn btn-block #{btn_size} btn-#{on ? 'success' : 'default'} ajax-toggle",
114 id: id,
114 id: id,
115 data: {remote: true, method: 'get'}}
115 data: {remote: true, method: 'get'}}
116 end
116 end
117
117
118 + def get_ace_mode(language)
119 + # return ace mode string from Language
120 +
121 + case language.pretty_name
122 + when 'Pascal'
123 + 'ace/mode/pascal'
124 + when 'C++','C'
125 + 'ace/mode/c_cpp'
126 + when 'Ruby'
127 + 'ace/mode/ruby'
128 + when 'Python'
129 + 'ace/mode/python'
130 + when 'Java'
131 + 'ace/mode/java'
132 + else
133 + 'ace/mode/c_cpp'
134 + end
135 + end
136 +
118 def user_title_bar(user)
137 def user_title_bar(user)
119 header = ''
138 header = ''
120 time_left = ''
139 time_left = ''
121
140
122 #
141 #
123 # if the contest is over
142 # if the contest is over
124 if GraderConfiguration.time_limit_mode?
143 if GraderConfiguration.time_limit_mode?
125 if user.contest_finished?
144 if user.contest_finished?
126 header = <<CONTEST_OVER
145 header = <<CONTEST_OVER
127 <tr><td colspan="2" align="center">
146 <tr><td colspan="2" align="center">
128 <span class="contest-over-msg">THE CONTEST IS OVER</span>
147 <span class="contest-over-msg">THE CONTEST IS OVER</span>
129 </td></tr>
148 </td></tr>
130 CONTEST_OVER
149 CONTEST_OVER
131 end
150 end
132 if !user.contest_started?
151 if !user.contest_started?
133 time_left = "&nbsp;&nbsp;" + (t 'title_bar.contest_not_started')
152 time_left = "&nbsp;&nbsp;" + (t 'title_bar.contest_not_started')
134 else
153 else
135 time_left = "&nbsp;&nbsp;" + (t 'title_bar.remaining_time') +
154 time_left = "&nbsp;&nbsp;" + (t 'title_bar.remaining_time') +
136 " #{format_short_duration(user.contest_time_left)}"
155 " #{format_short_duration(user.contest_time_left)}"
137 end
156 end
138 end
157 end
139
158
140 #
159 #
141 # if the contest is in the anaysis mode
160 # if the contest is in the anaysis mode
@@ -1,67 +1,90
1 - %style{type: "text/css"}
1 + //%style{type: "text/css"}
2 - = @css_style
2 + // = @css_style
3 - :css
4 - .field {
5 - font-weight: bold;
6 - text-align: right;
7 - padding: 3px;
8 - }
9 -
10
3
11 %h1= "Submission: #{@submission.id}"
4 %h1= "Submission: #{@submission.id}"
12
5
13 -
6 + %textarea#data{style: "display:none;"}
14 - %h2 Stat
7 + :preserve
8 + #{@submission.source}
15
9
16 - %table.info
10 + //%div.highlight{:style => "border: 1px solid black;"}
17 - %thead
11 + //=@formatted_code.html_safe
18 - %tr.info-head
12 + .containter
19 - %th Field
13 + .row
20 - %th Value
14 + .col-md-7
21 - %tbody
15 + %h2 Source Code
22 - %tr{class: cycle('info-even','info-odd')}
16 + .col-md-5
23 - %td.field User:
17 + %h2 Stat
24 - %td.value
18 + .row
25 - - if @submission.user
19 + .col-md-7
26 - = link_to "(#{@submission.user.login})", controller: "users", action: "profile", id: @submission.user
20 + %div#editor{ style: "font-size: 14px; height: 400px; border-radius:5px;" }
27 - = @submission.user.full_name
21 + :javascript
28 - - else
22 + e = ace.edit("editor")
29 - = "(n/a)"
23 + e.setOptions({ maxLines: Infinity })
30 - %tr{class: cycle('info-even','info-odd')}
24 + e.setValue($("#data").text())
31 - %td.field Problem:
25 + e.gotoLine(1)
32 - %td.value
26 + e.getSession().setMode("#{get_ace_mode(@submission.language)}")
33 - - if @submission.problem!=nil
27 + e.setReadOnly(true)
34 - = link_to "(#{@submission.problem.name})", controller: "problems", action: "stat", id: @submission.problem
28 + .col-md-5
35 - = @submission.problem.full_name
29 + %table.table.table-striped
36 - - else
30 + %tr
37 - = "(n/a)"
31 + %td.text-right
38 - %tr{class: cycle('info-even','info-odd')}
32 + %strong User
39 - %td.field Tries:
33 + %td
40 - %td.value= @submission.number
34 + - if @submission.user
41 - %tr{class: cycle('info-even','info-odd')}
35 + = link_to "(#{@submission.user.login})", controller: "users", action: "profile", id: @submission.user
42 - %td.field Submitted:
36 + = @submission.user.full_name
43 - %td.value #{time_ago_in_words(@submission.submitted_at)} ago (at #{@submission.submitted_at.to_formatted_s(:long)})
37 + - else
44 - %tr{class: cycle('info-even','info-odd')}
38 + = "(n/a)"
45 - %td.field Graded:
39 + %tr
46 - %td.value #{time_ago_in_words(@submission.graded_at)} ago (at #{@submission.graded_at.to_formatted_s(:long)})
40 + %td.text-right
47 - %tr{class: cycle('info-even','info-odd')}
41 + %strong Task
48 - %td.field Points:
42 + %td
49 - %td.value #{@submission.points}/#{@submission.problem.full_score}
43 + - if @submission.problem!=nil
50 - %tr{class: cycle('info-even','info-odd')}
44 + = link_to "(#{@submission.problem.name})", controller: "problems", action: "stat", id: @submission.problem
51 - %td.field Comment:
45 + = @submission.problem.full_name
52 - %td.value #{@submission.grader_comment}
46 + - else
53 - %tr{class: cycle('info-even','info-odd')}
47 + = "(n/a)"
54 - %td.field Runtime (s):
48 + %tr
55 - %td.value #{@submission.max_runtime}
49 + %td.text-right
56 - %tr{class: cycle('info-even','info-odd')}
50 + %strong Tries
57 - %td.field Memory (kb):
51 + %td= @submission.number
58 - %td.value #{@submission.peak_memory}
52 + %tr
59 - - if session[:admin]
53 + %td.text-right
60 - %tr{class: cycle('info-even','info-odd')}
54 + %strong Language
61 - %td.field IP:
55 + %td= @submission.language.pretty_name
62 - %td.value #{@submission.ip_address}
56 + %tr
57 + %td.text-right
58 + %strong Submitted
59 + %td #{time_ago_in_words(@submission.submitted_at)} ago (at #{@submission.submitted_at.to_formatted_s(:long)})
60 + %tr
61 + %td.text-right
62 + %strong Graded
63 + - if @submission.graded_at
64 + %td #{time_ago_in_words(@submission.graded_at)} ago (at #{@submission.graded_at.to_formatted_s(:long)})
65 + - else
66 + %td -
67 + %tr
68 + %td.text-right
69 + %strong Points
70 + %td #{@submission.points}/#{@submission.problem.full_score}
71 + %tr
72 + %td.text-right
73 + %strong Comment
74 + %td #{@submission.grader_comment}
75 + %tr
76 + %td.text-right
77 + %strong Runtime (s)
78 + %td #{@submission.max_runtime}
79 + %tr
80 + %td.text-right
81 + %strong Memory (kb)
82 + %td #{@submission.peak_memory}
83 + - if session[:admin]
84 + %tr
85 + %td.text-right
86 + %strong IP
87 + %td #{@submission.ip_address}
63
88
64 - %h2 Source code
65 - //%div.highlight{:style => "border: 1px solid black;"}
66 - =@formatted_code.html_safe
67
89
90 +
You need to be logged in to leave comments. Login now