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: 97 inserted, 53 deleted

@@ -1,45 +1,47
1 $(document).on 'change', '.btn-file :file', ->
1 $(document).on 'change', '.btn-file :file', ->
2 input = $(this)
2 input = $(this)
3 numFiles = if input.get(0).files then input.get(0).files.length else 1
3 numFiles = if input.get(0).files then input.get(0).files.length else 1
4 label = input.val().replace(/\\/g, '/').replace(/.*\//, '')
4 label = input.val().replace(/\\/g, '/').replace(/.*\//, '')
5 input.trigger 'fileselect', [
5 input.trigger 'fileselect', [
6 numFiles
6 numFiles
7 label
7 label
8 ]
8 ]
9 return
9 return
10
10
11
11
12 # document ready
12 # document ready
13
13
14 $ ->
14 $ ->
15 $(".select2").select2()
15 $(".select2").select2()
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
@@ -70,96 +70,115
70
70
71 if GraderConfiguration['system.user_setting_enabled']
71 if GraderConfiguration['system.user_setting_enabled']
72 append_to menu_items, "[#{I18n.t 'menu.settings'}]", 'users', 'index'
72 append_to menu_items, "[#{I18n.t 'menu.settings'}]", 'users', 'index'
73 end
73 end
74 append_to menu_items, "[#{I18n.t 'menu.log_out'}]", 'main', 'login'
74 append_to menu_items, "[#{I18n.t 'menu.log_out'}]", 'main', 'login'
75
75
76 menu_items.html_safe
76 menu_items.html_safe
77 end
77 end
78
78
79 def append_to(option,label, controller, action)
79 def append_to(option,label, controller, action)
80 option << ' ' if option!=''
80 option << ' ' if option!=''
81 option << link_to_unless_current(label,
81 option << link_to_unless_current(label,
82 :controller => controller,
82 :controller => controller,
83 :action => action)
83 :action => action)
84 end
84 end
85
85
86 def format_short_time(time)
86 def format_short_time(time)
87 now = Time.now.gmtime
87 now = Time.now.gmtime
88 st = ''
88 st = ''
89 if (time.yday != now.yday) or
89 if (time.yday != now.yday) or
90 (time.year != now.year)
90 (time.year != now.year)
91 st = time.strftime("%x ")
91 st = time.strftime("%x ")
92 end
92 end
93 st + time.strftime("%X")
93 st + time.strftime("%X")
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
142 if GraderConfiguration.analysis_mode?
161 if GraderConfiguration.analysis_mode?
143 header = <<ANALYSISMODE
162 header = <<ANALYSISMODE
144 <tr><td colspan="2" align="center">
163 <tr><td colspan="2" align="center">
145 <span class="contest-over-msg">ANALYSIS MODE</span>
164 <span class="contest-over-msg">ANALYSIS MODE</span>
146 </td></tr>
165 </td></tr>
147 ANALYSISMODE
166 ANALYSISMODE
148 end
167 end
149
168
150 contest_name = GraderConfiguration['contest.name']
169 contest_name = GraderConfiguration['contest.name']
151
170
152 #
171 #
153 # build real title bar
172 # build real title bar
154 result = <<TITLEBAR
173 result = <<TITLEBAR
155 <div class="title">
174 <div class="title">
156 <table>
175 <table>
157 #{header}
176 #{header}
158 <tr>
177 <tr>
159 <td class="left-col">
178 <td class="left-col">
160 #{user.full_name}<br/>
179 #{user.full_name}<br/>
161 #{t 'title_bar.current_time'} #{format_short_time(Time.zone.now)}
180 #{t 'title_bar.current_time'} #{format_short_time(Time.zone.now)}
162 #{time_left}
181 #{time_left}
163 <br/>
182 <br/>
164 </td>
183 </td>
165 <td class="right-col">#{contest_name}</td>
184 <td class="right-col">#{contest_name}</td>
@@ -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
19 + .col-md-7
20 + %div#editor{ style: "font-size: 14px; height: 400px; border-radius:5px;" }
21 + :javascript
22 + e = ace.edit("editor")
23 + e.setOptions({ maxLines: Infinity })
24 + e.setValue($("#data").text())
25 + e.gotoLine(1)
26 + e.getSession().setMode("#{get_ace_mode(@submission.language)}")
27 + e.setReadOnly(true)
28 + .col-md-5
29 + %table.table.table-striped
30 + %tr
31 + %td.text-right
32 + %strong User
33 + %td
25 - if @submission.user
34 - if @submission.user
26 = link_to "(#{@submission.user.login})", controller: "users", action: "profile", id: @submission.user
35 = link_to "(#{@submission.user.login})", controller: "users", action: "profile", id: @submission.user
27 = @submission.user.full_name
36 = @submission.user.full_name
28 - else
37 - else
29 = "(n/a)"
38 = "(n/a)"
30 - %tr{class: cycle('info-even','info-odd')}
39 + %tr
31 - %td.field Problem:
40 + %td.text-right
32 - %td.value
41 + %strong Task
42 + %td
33 - if @submission.problem!=nil
43 - if @submission.problem!=nil
34 = link_to "(#{@submission.problem.name})", controller: "problems", action: "stat", id: @submission.problem
44 = link_to "(#{@submission.problem.name})", controller: "problems", action: "stat", id: @submission.problem
35 = @submission.problem.full_name
45 = @submission.problem.full_name
36 - else
46 - else
37 = "(n/a)"
47 = "(n/a)"
38 - %tr{class: cycle('info-even','info-odd')}
48 + %tr
39 - %td.field Tries:
49 + %td.text-right
40 - %td.value= @submission.number
50 + %strong Tries
41 - %tr{class: cycle('info-even','info-odd')}
51 + %td= @submission.number
42 - %td.field Submitted:
52 + %tr
43 - %td.value #{time_ago_in_words(@submission.submitted_at)} ago (at #{@submission.submitted_at.to_formatted_s(:long)})
53 + %td.text-right
44 - %tr{class: cycle('info-even','info-odd')}
54 + %strong Language
45 - %td.field Graded:
55 + %td= @submission.language.pretty_name
46 - %td.value #{time_ago_in_words(@submission.graded_at)} ago (at #{@submission.graded_at.to_formatted_s(:long)})
56 + %tr
47 - %tr{class: cycle('info-even','info-odd')}
57 + %td.text-right
48 - %td.field Points:
58 + %strong Submitted
49 - %td.value #{@submission.points}/#{@submission.problem.full_score}
59 + %td #{time_ago_in_words(@submission.submitted_at)} ago (at #{@submission.submitted_at.to_formatted_s(:long)})
50 - %tr{class: cycle('info-even','info-odd')}
60 + %tr
51 - %td.field Comment:
61 + %td.text-right
52 - %td.value #{@submission.grader_comment}
62 + %strong Graded
53 - %tr{class: cycle('info-even','info-odd')}
63 + - if @submission.graded_at
54 - %td.field Runtime (s):
64 + %td #{time_ago_in_words(@submission.graded_at)} ago (at #{@submission.graded_at.to_formatted_s(:long)})
55 - %td.value #{@submission.max_runtime}
65 + - else
56 - %tr{class: cycle('info-even','info-odd')}
66 + %td -
57 - %td.field Memory (kb):
67 + %tr
58 - %td.value #{@submission.peak_memory}
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}
59 - if session[:admin]
83 - if session[:admin]
60 - %tr{class: cycle('info-even','info-odd')}
84 + %tr
61 - %td.field IP:
85 + %td.text-right
62 - %td.value #{@submission.ip_address}
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