Description:
use ace editor for submission viewing
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r566:46de378c3b60 - - 3 files changed: 97 inserted, 53 deleted
@@ -1,45 +1,47 | |||
|
1 | 1 | $(document).on 'change', '.btn-file :file', -> |
|
2 | 2 | input = $(this) |
|
3 | 3 | numFiles = if input.get(0).files then input.get(0).files.length else 1 |
|
4 | 4 | label = input.val().replace(/\\/g, '/').replace(/.*\//, '') |
|
5 | 5 | input.trigger 'fileselect', [ |
|
6 | 6 | numFiles |
|
7 | 7 | label |
|
8 | 8 | ] |
|
9 | 9 | return |
|
10 | 10 | |
|
11 | 11 | |
|
12 | 12 | # document ready |
|
13 | 13 | |
|
14 | 14 | $ -> |
|
15 | 15 | $(".select2").select2() |
|
16 | 16 | #$(".bootstrap-switch").bootstrapSwitch() |
|
17 | 17 | $(".bootstrap-toggle").bootstrapToggle() |
|
18 | 18 | $('.btn-file :file').on 'fileselect', (event, numFiles, label) -> |
|
19 | 19 | input = $(this).parents('.input-group').find(':text') |
|
20 | 20 | log = if numFiles > 1 then numFiles + ' files selected' else label |
|
21 | 21 | if input.length |
|
22 | 22 | input.val log |
|
23 | 23 | else |
|
24 | 24 | if log |
|
25 | 25 | alert log |
|
26 | 26 | return |
|
27 | 27 | $(".go-button").on 'click', (event) -> |
|
28 | 28 | link = $(this).attr("data-source") |
|
29 | 29 | url = $(link).val() |
|
30 | 30 | if url |
|
31 | 31 | window.location.href = url |
|
32 | 32 | return |
|
33 | 33 | $('.ajax-toggle').on 'click', (event) -> |
|
34 | 34 | target = $(event.target) |
|
35 | 35 | target.removeClass 'btn-default' |
|
36 | 36 | target.removeClass 'btn-success' |
|
37 | 37 | target.addClass 'btn-warning' |
|
38 | 38 | target.text '...' |
|
39 | 39 | return |
|
40 | 40 | |
|
41 | - editor = ace.edit("editor") | |
|
42 | - editor.setTheme("ace/theme/merbivore") | |
|
43 | - editor.getSession().setMode("ace/mode/javascript") | |
|
41 | + #ace editor | |
|
42 | + e = ace.edit("editor") | |
|
43 | + e.setTheme('ace/theme/merbivore') | |
|
44 | + e.getSession().setTabSize(2) | |
|
45 | + e.getSession().setUseSoftTabs(true) | |
|
44 | 46 | |
|
45 | 47 | return |
@@ -22,157 +22,176 | |||
|
22 | 22 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-cog')}".html_safe, 'users', 'index', {title: I18n.t('menu.settings'), data: {toggle: 'tooltip'}}) |
|
23 | 23 | end |
|
24 | 24 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-log-out')} #{user.full_name}".html_safe, 'main', 'login', {title: I18n.t('menu.log_out'), data: {toggle: 'tooltip'}}) |
|
25 | 25 | |
|
26 | 26 | |
|
27 | 27 | result = content_tag(:ul,left_menu.html_safe,class: 'nav navbar-nav') + content_tag(:ul,right_menu.html_safe,class: 'nav navbar-nav navbar-right') |
|
28 | 28 | end |
|
29 | 29 | |
|
30 | 30 | def add_menu(title, controller, action,html_option = {}) |
|
31 | 31 | link_option = {controller: controller, action: action} |
|
32 | 32 | html_option[:class] = (html_option[:class] || '') + " active" if current_page?(link_option) |
|
33 | 33 | content_tag(:li, link_to(title,link_option),html_option) |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def user_header |
|
37 | 37 | menu_items = '' |
|
38 | 38 | user = User.find(session[:user_id]) |
|
39 | 39 | |
|
40 | 40 | if (user!=nil) and (session[:admin]) |
|
41 | 41 | # admin menu |
|
42 | 42 | menu_items << "<b>Administrative task:</b> " |
|
43 | 43 | append_to menu_items, '[Announcements]', 'announcements', 'index' |
|
44 | 44 | append_to menu_items, '[Msg console]', 'messages', 'console' |
|
45 | 45 | append_to menu_items, '[Problems]', 'problems', 'index' |
|
46 | 46 | append_to menu_items, '[Users]', 'user_admin', 'index' |
|
47 | 47 | append_to menu_items, '[Results]', 'user_admin', 'user_stat' |
|
48 | 48 | append_to menu_items, '[Report]', 'report', 'multiple_login' |
|
49 | 49 | append_to menu_items, '[Graders]', 'graders', 'list' |
|
50 | 50 | append_to menu_items, '[Contests]', 'contest_management', 'index' |
|
51 | 51 | append_to menu_items, '[Sites]', 'sites', 'index' |
|
52 | 52 | append_to menu_items, '[System config]', 'configurations', 'index' |
|
53 | 53 | menu_items << "<br/>" |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | # main page |
|
57 | 57 | append_to menu_items, "[#{I18n.t 'menu.main'}]", 'main', 'list' |
|
58 | 58 | append_to menu_items, "[#{I18n.t 'menu.messages'}]", 'messages', 'list' |
|
59 | 59 | |
|
60 | 60 | if (user!=nil) and (GraderConfiguration.show_tasks_to?(user)) |
|
61 | 61 | append_to menu_items, "[#{I18n.t 'menu.tasks'}]", 'tasks', 'list' |
|
62 | 62 | append_to menu_items, "[#{I18n.t 'menu.submissions'}]", 'main', 'submission' |
|
63 | 63 | append_to menu_items, "[#{I18n.t 'menu.test'}]", 'test', 'index' |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | if GraderConfiguration['right.user_hall_of_fame'] |
|
67 | 67 | append_to menu_items, "[#{I18n.t 'menu.hall_of_fame'}]", 'report', 'problem_hof' |
|
68 | 68 | end |
|
69 | 69 | append_to menu_items, "[#{I18n.t 'menu.help'}]", 'main', 'help' |
|
70 | 70 | |
|
71 | 71 | if GraderConfiguration['system.user_setting_enabled'] |
|
72 | 72 | append_to menu_items, "[#{I18n.t 'menu.settings'}]", 'users', 'index' |
|
73 | 73 | end |
|
74 | 74 | append_to menu_items, "[#{I18n.t 'menu.log_out'}]", 'main', 'login' |
|
75 | 75 | |
|
76 | 76 | menu_items.html_safe |
|
77 | 77 | end |
|
78 | 78 | |
|
79 | 79 | def append_to(option,label, controller, action) |
|
80 | 80 | option << ' ' if option!='' |
|
81 | 81 | option << link_to_unless_current(label, |
|
82 | 82 | :controller => controller, |
|
83 | 83 | :action => action) |
|
84 | 84 | end |
|
85 | 85 | |
|
86 | 86 | def format_short_time(time) |
|
87 | 87 | now = Time.now.gmtime |
|
88 | 88 | st = '' |
|
89 | 89 | if (time.yday != now.yday) or |
|
90 | 90 | (time.year != now.year) |
|
91 | 91 | st = time.strftime("%x ") |
|
92 | 92 | end |
|
93 | 93 | st + time.strftime("%X") |
|
94 | 94 | end |
|
95 | 95 | |
|
96 | 96 | def format_short_duration(duration) |
|
97 | 97 | return '' if duration==nil |
|
98 | 98 | d = duration.to_f |
|
99 | 99 | return Time.at(d).gmtime.strftime("%X") |
|
100 | 100 | end |
|
101 | 101 | |
|
102 | 102 | def read_textfile(fname,max_size=2048) |
|
103 | 103 | begin |
|
104 | 104 | File.open(fname).read(max_size) |
|
105 | 105 | rescue |
|
106 | 106 | nil |
|
107 | 107 | end |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | def toggle_button(on,toggle_url,id, option={}) |
|
111 | 111 | btn_size = option[:size] || 'btn-xs' |
|
112 | 112 | link_to (on ? "Yes" : "No"), toggle_url, |
|
113 | 113 | {class: "btn btn-block #{btn_size} btn-#{on ? 'success' : 'default'} ajax-toggle", |
|
114 | 114 | id: id, |
|
115 | 115 | data: {remote: true, method: 'get'}} |
|
116 | 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 | 137 | def user_title_bar(user) |
|
119 | 138 | header = '' |
|
120 | 139 | time_left = '' |
|
121 | 140 | |
|
122 | 141 | # |
|
123 | 142 | # if the contest is over |
|
124 | 143 | if GraderConfiguration.time_limit_mode? |
|
125 | 144 | if user.contest_finished? |
|
126 | 145 | header = <<CONTEST_OVER |
|
127 | 146 | <tr><td colspan="2" align="center"> |
|
128 | 147 | <span class="contest-over-msg">THE CONTEST IS OVER</span> |
|
129 | 148 | </td></tr> |
|
130 | 149 | CONTEST_OVER |
|
131 | 150 | end |
|
132 | 151 | if !user.contest_started? |
|
133 | 152 | time_left = " " + (t 'title_bar.contest_not_started') |
|
134 | 153 | else |
|
135 | 154 | time_left = " " + (t 'title_bar.remaining_time') + |
|
136 | 155 | " #{format_short_duration(user.contest_time_left)}" |
|
137 | 156 | end |
|
138 | 157 | end |
|
139 | 158 | |
|
140 | 159 | # |
|
141 | 160 | # if the contest is in the anaysis mode |
|
142 | 161 | if GraderConfiguration.analysis_mode? |
|
143 | 162 | header = <<ANALYSISMODE |
|
144 | 163 | <tr><td colspan="2" align="center"> |
|
145 | 164 | <span class="contest-over-msg">ANALYSIS MODE</span> |
|
146 | 165 | </td></tr> |
|
147 | 166 | ANALYSISMODE |
|
148 | 167 | end |
|
149 | 168 | |
|
150 | 169 | contest_name = GraderConfiguration['contest.name'] |
|
151 | 170 | |
|
152 | 171 | # |
|
153 | 172 | # build real title bar |
|
154 | 173 | result = <<TITLEBAR |
|
155 | 174 | <div class="title"> |
|
156 | 175 | <table> |
|
157 | 176 | #{header} |
|
158 | 177 | <tr> |
|
159 | 178 | <td class="left-col"> |
|
160 | 179 | #{user.full_name}<br/> |
|
161 | 180 | #{t 'title_bar.current_time'} #{format_short_time(Time.zone.now)} |
|
162 | 181 | #{time_left} |
|
163 | 182 | <br/> |
|
164 | 183 | </td> |
|
165 | 184 | <td class="right-col">#{contest_name}</td> |
|
166 | 185 | </tr> |
|
167 | 186 | </table> |
|
168 | 187 | </div> |
|
169 | 188 | TITLEBAR |
|
170 | 189 | result.html_safe |
|
171 | 190 | end |
|
172 | 191 | |
|
173 | 192 | def markdown(text) |
|
174 | 193 | markdown = RDiscount.new(text) |
|
175 | 194 | markdown.to_html.html_safe |
|
176 | 195 | end |
|
177 | 196 | |
|
178 | 197 | end |
@@ -1,67 +1,90 | |||
|
1 | - %style{type: "text/css"} | |
|
2 |
- |
|
|
3 | - :css | |
|
4 | - .field { | |
|
5 | - font-weight: bold; | |
|
6 | - text-align: right; | |
|
7 | - padding: 3px; | |
|
8 | - } | |
|
9 | - | |
|
1 | + //%style{type: "text/css"} | |
|
2 | + // = @css_style | |
|
10 | 3 | |
|
11 | 4 | %h1= "Submission: #{@submission.id}" |
|
12 | 5 | |
|
13 | - | |
|
14 | - %h2 Stat | |
|
6 | + %textarea#data{style: "display:none;"} | |
|
7 | + :preserve | |
|
8 | + #{@submission.source} | |
|
15 | 9 | |
|
16 | - %table.info | |
|
17 | - %thead | |
|
18 | - %tr.info-head | |
|
19 | - %th Field | |
|
20 | - %th Value | |
|
21 | - %tbody | |
|
22 | - %tr{class: cycle('info-even','info-odd')} | |
|
23 | - %td.field User: | |
|
24 | - %td.value | |
|
10 | + //%div.highlight{:style => "border: 1px solid black;"} | |
|
11 | + //=@formatted_code.html_safe | |
|
12 | + .containter | |
|
13 | + .row | |
|
14 | + .col-md-7 | |
|
15 | + %h2 Source Code | |
|
16 | + .col-md-5 | |
|
17 | + %h2 Stat | |
|
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 | 34 | - if @submission.user |
|
26 | 35 | = link_to "(#{@submission.user.login})", controller: "users", action: "profile", id: @submission.user |
|
27 | 36 | = @submission.user.full_name |
|
28 | 37 | - else |
|
29 | 38 | = "(n/a)" |
|
30 | - %tr{class: cycle('info-even','info-odd')} | |
|
31 | - %td.field Problem: | |
|
32 | - %td.value | |
|
39 | + %tr | |
|
40 | + %td.text-right | |
|
41 | + %strong Task | |
|
42 | + %td | |
|
33 | 43 | - if @submission.problem!=nil |
|
34 | 44 | = link_to "(#{@submission.problem.name})", controller: "problems", action: "stat", id: @submission.problem |
|
35 | 45 | = @submission.problem.full_name |
|
36 | 46 | - else |
|
37 | 47 | = "(n/a)" |
|
38 | - %tr{class: cycle('info-even','info-odd')} | |
|
39 | - %td.field Tries: | |
|
40 | - %td.value= @submission.number | |
|
41 | - %tr{class: cycle('info-even','info-odd')} | |
|
42 | - %td.field Submitted: | |
|
43 | - %td.value #{time_ago_in_words(@submission.submitted_at)} ago (at #{@submission.submitted_at.to_formatted_s(:long)}) | |
|
44 | - %tr{class: cycle('info-even','info-odd')} | |
|
45 | - %td.field Graded: | |
|
46 | - %td.value #{time_ago_in_words(@submission.graded_at)} ago (at #{@submission.graded_at.to_formatted_s(:long)}) | |
|
47 | - %tr{class: cycle('info-even','info-odd')} | |
|
48 | - %td.field Points: | |
|
49 | - %td.value #{@submission.points}/#{@submission.problem.full_score} | |
|
50 | - %tr{class: cycle('info-even','info-odd')} | |
|
51 | - %td.field Comment: | |
|
52 | - %td.value #{@submission.grader_comment} | |
|
53 | - %tr{class: cycle('info-even','info-odd')} | |
|
54 | - %td.field Runtime (s): | |
|
55 | - %td.value #{@submission.max_runtime} | |
|
56 | - %tr{class: cycle('info-even','info-odd')} | |
|
57 | - %td.field Memory (kb): | |
|
58 | - %td.value #{@submission.peak_memory} | |
|
48 | + %tr | |
|
49 | + %td.text-right | |
|
50 | + %strong Tries | |
|
51 | + %td= @submission.number | |
|
52 | + %tr | |
|
53 | + %td.text-right | |
|
54 | + %strong Language | |
|
55 | + %td= @submission.language.pretty_name | |
|
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} | |
|
59 | 83 | - if session[:admin] |
|
60 | - %tr{class: cycle('info-even','info-odd')} | |
|
61 | - %td.field IP: | |
|
62 | - %td.value #{@submission.ip_address} | |
|
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