Description:
live editor using cloud9 ace for problem
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r564:484b31caab29 - - 16 files changed: 121 inserted, 1 deleted
@@ -0,0 +1,10 | |||
|
1 | + # Place all the behaviors and hooks related to the matching controller here. | |
|
2 | + # All this logic will automatically be available in application.js. | |
|
3 | + # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ | |
|
4 | + | |
|
5 | + | |
|
6 | + $ -> | |
|
7 | + $("#live_submit").on "click", (event) -> | |
|
8 | + h = $("#editor_text") | |
|
9 | + e = ace.edit("editor") | |
|
10 | + h.val(e.getValue()) |
@@ -0,0 +1,12 | |||
|
1 | + // Place all the styles related to the sources controller here. | |
|
2 | + // They will automatically be included in application.css. | |
|
3 | + // You can use Sass (SCSS) here: http://sass-lang.com/ | |
|
4 | + | |
|
5 | + #editor { | |
|
6 | + position: absolute; | |
|
7 | + top: 0; | |
|
8 | + right: 0; | |
|
9 | + bottom: 0; | |
|
10 | + left: 0; | |
|
11 | + } | |
|
12 | + |
@@ -0,0 +1,7 | |||
|
1 | + class SourcesController < ApplicationController | |
|
2 | + before_filter :authenticate, :except => [:index, :login] | |
|
3 | + | |
|
4 | + def direct_edit | |
|
5 | + @problem = Problem.find_by_id(params[:pid]) | |
|
6 | + end | |
|
7 | + end |
@@ -0,0 +1,21 | |||
|
1 | + %h1 Live submit | |
|
2 | + = form_tag({controller: :main, :action => 'submit'}, :multipart => true, class: 'form-inline') do | |
|
3 | + = hidden_field_tag 'editor_text' | |
|
4 | + = hidden_field_tag 'submission[problem_id]', @problem.id | |
|
5 | + .form-group | |
|
6 | + = label_tag "Task:" | |
|
7 | + = text_field_tag 'asdf', "#{@problem.long_name}", class: 'form-control', disabled: true | |
|
8 | + | |
|
9 | + .form-group | |
|
10 | + = label_tag 'Language' | |
|
11 | + = select_tag 'language_id', options_from_collection_for_select(Language.all, 'id', 'pretty_name',"C++"), class: 'form-control', style: "width: 100px" | |
|
12 | + .form-group | |
|
13 | + = submit_tag 'Submit', class: 'btn btn-success', id: 'live_submit' | |
|
14 | + | |
|
15 | + %br | |
|
16 | + | |
|
17 | + .container | |
|
18 | + .row | |
|
19 | + .col-md-12 | |
|
20 | + %div#editor{style: 'height: 400px'} | |
|
21 | + Hahaha |
@@ -0,0 +1,12 | |||
|
1 | + require 'spec_helper' | |
|
2 | + | |
|
3 | + describe SourcesController do | |
|
4 | + | |
|
5 | + describe "GET 'direct_edit'" do | |
|
6 | + it "returns http success" do | |
|
7 | + get 'direct_edit' | |
|
8 | + response.should be_success | |
|
9 | + end | |
|
10 | + end | |
|
11 | + | |
|
12 | + end |
@@ -0,0 +1,15 | |||
|
1 | + require 'spec_helper' | |
|
2 | + | |
|
3 | + # Specs in this file have access to a helper object that includes | |
|
4 | + # the SourcesHelper. For example: | |
|
5 | + # | |
|
6 | + # describe SourcesHelper do | |
|
7 | + # describe "string concat" do | |
|
8 | + # it "concats two strings with spaces" do | |
|
9 | + # expect(helper.concat_strings("this","that")).to eq("this that") | |
|
10 | + # end | |
|
11 | + # end | |
|
12 | + # end | |
|
13 | + describe SourcesHelper do | |
|
14 | + pending "add some examples to (or delete) #{__FILE__}" | |
|
15 | + end |
@@ -0,0 +1,5 | |||
|
1 | + require 'spec_helper' | |
|
2 | + | |
|
3 | + describe "sources/direct_edit.html.haml" do | |
|
4 | + pending "add some examples to (or delete) #{__FILE__}" | |
|
5 | + end |
@@ -12,61 +12,64 | |||
|
12 | 12 | # Gems used only for assets and not required |
|
13 | 13 | # in production environments by default. |
|
14 | 14 | group :assets do |
|
15 | 15 | gem 'sass-rails', '~> 3.2.6' |
|
16 | 16 | gem 'coffee-rails', '~> 3.2.2' |
|
17 | 17 | |
|
18 | 18 | # See https://github.com/sstephenson/execjs#readme for more supported runtimes |
|
19 | 19 | # gem 'therubyracer', :platforms => :ruby |
|
20 | 20 | |
|
21 | 21 | gem 'uglifier' |
|
22 | 22 | end |
|
23 | 23 | |
|
24 | 24 | gem 'prototype-rails' |
|
25 | 25 | |
|
26 | 26 | # To use ActiveModel has_secure_password |
|
27 | 27 | # gem 'bcrypt-ruby', '~> 3.0.0' |
|
28 | 28 | |
|
29 | 29 | # To use Jbuilder templates for JSON |
|
30 | 30 | # gem 'jbuilder' |
|
31 | 31 | |
|
32 | 32 | # Use unicorn as the app server |
|
33 | 33 | # gem 'unicorn' |
|
34 | 34 | |
|
35 | 35 | # Deploy with Capistrano |
|
36 | 36 | # gem 'capistrano' |
|
37 | 37 | |
|
38 | 38 | # To use debugger |
|
39 | 39 | # gem 'debugger' |
|
40 | 40 | # |
|
41 | 41 | |
|
42 | 42 | #in-place editor |
|
43 | 43 | gem 'best_in_place', '~> 3.0.1' |
|
44 | 44 | |
|
45 | 45 | # jquery addition |
|
46 | 46 | gem 'jquery-rails' |
|
47 | 47 | gem 'jquery-ui-sass-rails' |
|
48 | 48 | gem 'jquery-timepicker-addon-rails' |
|
49 | 49 | gem 'jquery-tablesorter' |
|
50 | 50 | |
|
51 | 51 | #syntax highlighter |
|
52 | 52 | gem 'rouge' |
|
53 | 53 | |
|
54 | 54 | #add bootstrap |
|
55 | 55 | gem 'bootstrap-sass', '~> 3.2.0' |
|
56 | 56 | gem 'bootstrap-switch-rails' |
|
57 | 57 | gem 'bootstrap-toggle-rails' |
|
58 | 58 | gem 'autoprefixer-rails' |
|
59 | 59 | |
|
60 | + gem 'ace-rails-ap' | |
|
61 | + | |
|
60 | 62 | |
|
61 | 63 | gem 'haml' |
|
64 | + gem 'haml-rails' | |
|
62 | 65 | gem 'mail' |
|
63 | 66 | gem 'rdiscount' |
|
64 | 67 | gem 'test-unit' |
|
65 | 68 | gem 'will_paginate', '~> 3.0.7' |
|
66 | 69 | gem 'dynamic_form' |
|
67 | 70 | gem 'in_place_editing' |
|
68 | 71 | gem 'verification', :git => 'https://github.com/sikachu/verification.git' |
|
69 | 72 | |
|
70 | 73 | group :test, :development do |
|
71 | 74 | gem 'rspec-rails', '~> 2.99.0' |
|
72 | 75 | end |
@@ -1,111 +1,117 | |||
|
1 | 1 | GIT |
|
2 | 2 | remote: https://github.com/sikachu/verification.git |
|
3 | 3 | revision: 76eaf51b13276ecae54bd9cd115832595d2ff56d |
|
4 | 4 | specs: |
|
5 | 5 | verification (1.0.3) |
|
6 | 6 | actionpack (>= 3.0.0, < 5.0) |
|
7 | 7 | activesupport (>= 3.0.0, < 5.0) |
|
8 | 8 | |
|
9 | 9 | GEM |
|
10 | 10 | remote: https://rubygems.org/ |
|
11 | 11 | specs: |
|
12 | + ace-rails-ap (4.0.2) | |
|
12 | 13 | actionmailer (3.2.21) |
|
13 | 14 | actionpack (= 3.2.21) |
|
14 | 15 | mail (~> 2.5.4) |
|
15 | 16 | actionpack (3.2.21) |
|
16 | 17 | activemodel (= 3.2.21) |
|
17 | 18 | activesupport (= 3.2.21) |
|
18 | 19 | builder (~> 3.0.0) |
|
19 | 20 | erubis (~> 2.7.0) |
|
20 | 21 | journey (~> 1.0.4) |
|
21 | 22 | rack (~> 1.4.5) |
|
22 | 23 | rack-cache (~> 1.2) |
|
23 | 24 | rack-test (~> 0.6.1) |
|
24 | 25 | sprockets (~> 2.2.1) |
|
25 | 26 | activemodel (3.2.21) |
|
26 | 27 | activesupport (= 3.2.21) |
|
27 | 28 | builder (~> 3.0.0) |
|
28 | 29 | activerecord (3.2.21) |
|
29 | 30 | activemodel (= 3.2.21) |
|
30 | 31 | activesupport (= 3.2.21) |
|
31 | 32 | arel (~> 3.0.2) |
|
32 | 33 | tzinfo (~> 0.3.29) |
|
33 | 34 | activeresource (3.2.21) |
|
34 | 35 | activemodel (= 3.2.21) |
|
35 | 36 | activesupport (= 3.2.21) |
|
36 | 37 | activesupport (3.2.21) |
|
37 | 38 | i18n (~> 0.6, >= 0.6.4) |
|
38 | 39 | multi_json (~> 1.0) |
|
39 | 40 | arel (3.0.3) |
|
40 | 41 | autoprefixer-rails (6.0.3) |
|
41 | 42 | execjs |
|
42 | 43 | json |
|
43 | 44 | best_in_place (3.0.3) |
|
44 | 45 | actionpack (>= 3.2) |
|
45 | 46 | railties (>= 3.2) |
|
46 | 47 | bootstrap-sass (3.2.0.2) |
|
47 | 48 | sass (~> 3.2) |
|
48 | 49 | bootstrap-switch-rails (3.3.3) |
|
49 | 50 | bootstrap-toggle-rails (2.2.1.0) |
|
50 | 51 | builder (3.0.4) |
|
51 | 52 | coffee-rails (3.2.2) |
|
52 | 53 | coffee-script (>= 2.2.0) |
|
53 | 54 | railties (~> 3.2.0) |
|
54 | 55 | coffee-script (2.3.0) |
|
55 | 56 | coffee-script-source |
|
56 | 57 | execjs |
|
57 | 58 | coffee-script-source (1.9.0) |
|
58 | 59 | diff-lcs (1.2.5) |
|
59 | 60 | dynamic_form (1.1.4) |
|
60 | 61 | erubis (2.7.0) |
|
61 | 62 | execjs (2.3.0) |
|
62 | 63 | haml (4.0.6) |
|
63 | 64 | tilt |
|
65 | + haml-rails (0.4) | |
|
66 | + actionpack (>= 3.1, < 4.1) | |
|
67 | + activesupport (>= 3.1, < 4.1) | |
|
68 | + haml (>= 3.1, < 4.1) | |
|
69 | + railties (>= 3.1, < 4.1) | |
|
64 | 70 | hike (1.2.3) |
|
65 | 71 | i18n (0.7.0) |
|
66 | 72 | in_place_editing (1.2.0) |
|
67 | 73 | journey (1.0.4) |
|
68 | 74 | jquery-rails (3.1.2) |
|
69 | 75 | railties (>= 3.0, < 5.0) |
|
70 | 76 | thor (>= 0.14, < 2.0) |
|
71 | 77 | jquery-tablesorter (1.13.4) |
|
72 | 78 | railties (>= 3.1, < 5) |
|
73 | 79 | jquery-timepicker-addon-rails (1.4.1) |
|
74 | 80 | railties (>= 3.1) |
|
75 | 81 | jquery-ui-rails (4.0.3) |
|
76 | 82 | jquery-rails |
|
77 | 83 | railties (>= 3.1.0) |
|
78 | 84 | jquery-ui-sass-rails (4.0.3.0) |
|
79 | 85 | jquery-rails |
|
80 | 86 | jquery-ui-rails (= 4.0.3) |
|
81 | 87 | railties (>= 3.1.0) |
|
82 | 88 | json (1.8.2) |
|
83 | 89 | mail (2.5.4) |
|
84 | 90 | mime-types (~> 1.16) |
|
85 | 91 | treetop (~> 1.4.8) |
|
86 | 92 | mime-types (1.25.1) |
|
87 | 93 | multi_json (1.10.1) |
|
88 | 94 | mysql2 (0.3.20) |
|
89 | 95 | polyglot (0.3.5) |
|
90 | 96 | power_assert (0.2.2) |
|
91 | 97 | prototype-rails (3.2.1) |
|
92 | 98 | rails (~> 3.2) |
|
93 | 99 | rack (1.4.5) |
|
94 | 100 | rack-cache (1.2) |
|
95 | 101 | rack (>= 0.4) |
|
96 | 102 | rack-ssl (1.3.4) |
|
97 | 103 | rack |
|
98 | 104 | rack-test (0.6.3) |
|
99 | 105 | rack (>= 1.0) |
|
100 | 106 | rails (3.2.21) |
|
101 | 107 | actionmailer (= 3.2.21) |
|
102 | 108 | actionpack (= 3.2.21) |
|
103 | 109 | activerecord (= 3.2.21) |
|
104 | 110 | activeresource (= 3.2.21) |
|
105 | 111 | activesupport (= 3.2.21) |
|
106 | 112 | bundler (~> 1.0) |
|
107 | 113 | railties (= 3.2.21) |
|
108 | 114 | railties (3.2.21) |
|
109 | 115 | actionpack (= 3.2.21) |
|
110 | 116 | activesupport (= 3.2.21) |
|
111 | 117 | rack-ssl (~> 1.3.2) |
@@ -116,74 +122,76 | |||
|
116 | 122 | rdiscount (2.1.8) |
|
117 | 123 | rdoc (3.12.2) |
|
118 | 124 | json (~> 1.4) |
|
119 | 125 | rouge (1.8.0) |
|
120 | 126 | rspec-collection_matchers (1.1.2) |
|
121 | 127 | rspec-expectations (>= 2.99.0.beta1) |
|
122 | 128 | rspec-core (2.99.2) |
|
123 | 129 | rspec-expectations (2.99.2) |
|
124 | 130 | diff-lcs (>= 1.1.3, < 2.0) |
|
125 | 131 | rspec-mocks (2.99.3) |
|
126 | 132 | rspec-rails (2.99.0) |
|
127 | 133 | actionpack (>= 3.0) |
|
128 | 134 | activemodel (>= 3.0) |
|
129 | 135 | activesupport (>= 3.0) |
|
130 | 136 | railties (>= 3.0) |
|
131 | 137 | rspec-collection_matchers |
|
132 | 138 | rspec-core (~> 2.99.0) |
|
133 | 139 | rspec-expectations (~> 2.99.0) |
|
134 | 140 | rspec-mocks (~> 2.99.0) |
|
135 | 141 | sass (3.4.11) |
|
136 | 142 | sass-rails (3.2.6) |
|
137 | 143 | railties (~> 3.2.0) |
|
138 | 144 | sass (>= 3.1.10) |
|
139 | 145 | tilt (~> 1.3) |
|
140 | 146 | select2-rails (4.0.1) |
|
141 | 147 | thor (~> 0.14) |
|
142 | 148 | sprockets (2.2.3) |
|
143 | 149 | hike (~> 1.2) |
|
144 | 150 | multi_json (~> 1.0) |
|
145 | 151 | rack (~> 1.0) |
|
146 | 152 | tilt (~> 1.1, != 1.3.0) |
|
147 | 153 | test-unit (3.0.9) |
|
148 | 154 | power_assert |
|
149 | 155 | thor (0.19.1) |
|
150 | 156 | tilt (1.4.1) |
|
151 | 157 | treetop (1.4.15) |
|
152 | 158 | polyglot |
|
153 | 159 | polyglot (>= 0.3.1) |
|
154 | 160 | tzinfo (0.3.43) |
|
155 | 161 | uglifier (2.7.0) |
|
156 | 162 | execjs (>= 0.3.0) |
|
157 | 163 | json (>= 1.8.0) |
|
158 | 164 | will_paginate (3.0.7) |
|
159 | 165 | |
|
160 | 166 | PLATFORMS |
|
161 | 167 | ruby |
|
162 | 168 | |
|
163 | 169 | DEPENDENCIES |
|
170 | + ace-rails-ap | |
|
164 | 171 | autoprefixer-rails |
|
165 | 172 | best_in_place (~> 3.0.1) |
|
166 | 173 | bootstrap-sass (~> 3.2.0) |
|
167 | 174 | bootstrap-switch-rails |
|
168 | 175 | bootstrap-toggle-rails |
|
169 | 176 | coffee-rails (~> 3.2.2) |
|
170 | 177 | dynamic_form |
|
171 | 178 | haml |
|
179 | + haml-rails | |
|
172 | 180 | in_place_editing |
|
173 | 181 | jquery-rails |
|
174 | 182 | jquery-tablesorter |
|
175 | 183 | jquery-timepicker-addon-rails |
|
176 | 184 | jquery-ui-sass-rails |
|
177 | 185 | |
|
178 | 186 | mysql2 |
|
179 | 187 | prototype-rails |
|
180 | 188 | rails (= 3.2.21) |
|
181 | 189 | rdiscount |
|
182 | 190 | rouge |
|
183 | 191 | rspec-rails (~> 2.99.0) |
|
184 | 192 | sass-rails (~> 3.2.6) |
|
185 | 193 | select2-rails |
|
186 | 194 | test-unit |
|
187 | 195 | uglifier |
|
188 | 196 | verification! |
|
189 | 197 | will_paginate (~> 3.0.7) |
@@ -1,28 +1,29 | |||
|
1 | 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files |
|
2 | 2 | // listed below. |
|
3 | 3 | // |
|
4 | 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, |
|
5 | 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. |
|
6 | 6 | // |
|
7 | 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the |
|
8 | 8 | // the compiled file. |
|
9 | 9 | // |
|
10 | 10 | // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD |
|
11 | 11 | // GO AFTER THE REQUIRES BELOW. |
|
12 | 12 | // |
|
13 | 13 | //= require jquery |
|
14 | 14 | //= require jquery_ujs |
|
15 | 15 | //= require jquery.ui.all |
|
16 | 16 | //= require bootstrap-sprockets |
|
17 | 17 | //x= require bootstrap-switch |
|
18 | 18 | //= require bootstrap-toggle |
|
19 | 19 | //= require select2 |
|
20 | 20 | //= require custom |
|
21 | + //= require ace-rails-ap | |
|
21 | 22 | |
|
22 | 23 | |
|
23 | 24 | // since this is after blank line, it is not downloaded |
|
24 | 25 | //x= require prototype |
|
25 | 26 | //x= require prototype_ujs |
|
26 | 27 | //x= require effects |
|
27 | 28 | //x= require dragdrop |
|
28 | 29 | //x= require controls |
@@ -1,41 +1,45 | |||
|
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/monokai") | |
|
43 | + editor.getSession().setMode("ace/mode/javascript") | |
|
44 | + | |
|
41 | 45 | return |
@@ -24,96 +24,104 | |||
|
24 | 24 | # COMMENT OUT: only need when having high load |
|
25 | 25 | # caches_action :index, :login |
|
26 | 26 | |
|
27 | 27 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
28 | 28 | # assigned action login as a default action. |
|
29 | 29 | def index |
|
30 | 30 | redirect_to :action => 'login' |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | def login |
|
34 | 34 | saved_notice = flash[:notice] |
|
35 | 35 | reset_session |
|
36 | 36 | flash.now[:notice] = saved_notice |
|
37 | 37 | |
|
38 | 38 | # EXPERIMENT: |
|
39 | 39 | # Hide login if in single user mode and the url does not |
|
40 | 40 | # explicitly specify /login |
|
41 | 41 | # |
|
42 | 42 | # logger.info "PATH: #{request.path}" |
|
43 | 43 | # if GraderConfiguration['system.single_user_mode'] and |
|
44 | 44 | # request.path!='/main/login' |
|
45 | 45 | # @hidelogin = true |
|
46 | 46 | # end |
|
47 | 47 | |
|
48 | 48 | @announcements = Announcement.find_for_frontpage |
|
49 | 49 | render :action => 'login', :layout => 'empty' |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | def list |
|
53 | 53 | prepare_list_information |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | def help |
|
57 | 57 | @user = User.find(session[:user_id]) |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | def submit |
|
61 | 61 | user = User.find(session[:user_id]) |
|
62 | 62 | |
|
63 | 63 | @submission = Submission.new |
|
64 | 64 | @submission.problem_id = params[:submission][:problem_id] |
|
65 | 65 | @submission.user = user |
|
66 | 66 | @submission.language_id = 0 |
|
67 | 67 | if (params['file']) and (params['file']!='') |
|
68 | 68 | @submission.source = File.open(params['file'].path,'r:UTF-8',&:read) |
|
69 | 69 | @submission.source.encode!('UTF-8','UTF-8',invalid: :replace, replace: '') |
|
70 | 70 | @submission.source_filename = params['file'].original_filename |
|
71 | 71 | end |
|
72 | + | |
|
73 | + if (params[:editor_text]) | |
|
74 | + language = Language.find_by_id(params[:language_id]) | |
|
75 | + @submission.source = params[:editor_text] | |
|
76 | + @submission.source_filename = "live_edit.#{language.ext}" | |
|
77 | + @submission.language = language | |
|
78 | + end | |
|
79 | + | |
|
72 | 80 | @submission.submitted_at = Time.new.gmtime |
|
73 | 81 | @submission.ip_address = request.remote_ip |
|
74 | 82 | |
|
75 | 83 | if GraderConfiguration.time_limit_mode? and user.contest_finished? |
|
76 | 84 | @submission.errors.add(:base,"The contest is over.") |
|
77 | 85 | prepare_list_information |
|
78 | 86 | render :action => 'list' and return |
|
79 | 87 | end |
|
80 | 88 | |
|
81 | 89 | if @submission.valid? |
|
82 | 90 | if @submission.save == false |
|
83 | 91 | flash[:notice] = 'Error saving your submission' |
|
84 | 92 | elsif Task.create(:submission_id => @submission.id, |
|
85 | 93 | :status => Task::STATUS_INQUEUE) == false |
|
86 | 94 | flash[:notice] = 'Error adding your submission to task queue' |
|
87 | 95 | end |
|
88 | 96 | else |
|
89 | 97 | prepare_list_information |
|
90 | 98 | render :action => 'list' and return |
|
91 | 99 | end |
|
92 | 100 | redirect_to :action => 'list' |
|
93 | 101 | end |
|
94 | 102 | |
|
95 | 103 | def source |
|
96 | 104 | submission = Submission.find(params[:id]) |
|
97 | 105 | if ((submission.user_id == session[:user_id]) and |
|
98 | 106 | (submission.problem != nil) and |
|
99 | 107 | (submission.problem.available)) |
|
100 | 108 | send_data(submission.source, |
|
101 | 109 | {:filename => submission.download_filename, |
|
102 | 110 | :type => 'text/plain'}) |
|
103 | 111 | else |
|
104 | 112 | flash[:notice] = 'Error viewing source' |
|
105 | 113 | redirect_to :action => 'list' |
|
106 | 114 | end |
|
107 | 115 | end |
|
108 | 116 | |
|
109 | 117 | def compiler_msg |
|
110 | 118 | @submission = Submission.find(params[:id]) |
|
111 | 119 | if @submission.user_id == session[:user_id] |
|
112 | 120 | render :action => 'compiler_msg', :layout => 'empty' |
|
113 | 121 | else |
|
114 | 122 | flash[:notice] = 'Error viewing source' |
|
115 | 123 | redirect_to :action => 'list' |
|
116 | 124 | end |
|
117 | 125 | end |
|
118 | 126 | |
|
119 | 127 | def submission |
@@ -17,96 +17,100 | |||
|
17 | 17 | Problem.available.all(:order => "date_added DESC, name ASC") |
|
18 | 18 | end |
|
19 | 19 | |
|
20 | 20 | def self.create_from_import_form_params(params, old_problem=nil) |
|
21 | 21 | org_problem = old_problem || Problem.new |
|
22 | 22 | import_params, problem = Problem.extract_params_and_check(params, |
|
23 | 23 | org_problem) |
|
24 | 24 | |
|
25 | 25 | if !problem.errors.empty? |
|
26 | 26 | return problem, 'Error importing' |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | problem.full_score = 100 |
|
30 | 30 | problem.date_added = Time.new |
|
31 | 31 | problem.test_allowed = true |
|
32 | 32 | problem.output_only = false |
|
33 | 33 | problem.available = false |
|
34 | 34 | |
|
35 | 35 | if not problem.save |
|
36 | 36 | return problem, 'Error importing' |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | import_to_db = params.has_key? :import_to_db |
|
40 | 40 | |
|
41 | 41 | importer = TestdataImporter.new(problem) |
|
42 | 42 | |
|
43 | 43 | if not importer.import_from_file(import_params[:file], |
|
44 | 44 | import_params[:time_limit], |
|
45 | 45 | import_params[:memory_limit], |
|
46 | 46 | import_params[:checker_name], |
|
47 | 47 | import_to_db) |
|
48 | 48 | problem.errors.add(:base,'Import error.') |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | 51 | return problem, importer.log_msg |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def self.download_file_basedir |
|
55 | 55 | return "#{Rails.root}/data/tasks" |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | def get_submission_stat |
|
59 | 59 | result = Hash.new |
|
60 | 60 | #total number of submission |
|
61 | 61 | result[:total_sub] = Submission.where(problem_id: self.id).count |
|
62 | 62 | result[:attempted_user] = Submission.where(problem_id: self.id).group_by(:user_id) |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | + def long_name | |
|
66 | + "[#{name}] #{full_name}" | |
|
67 | + end | |
|
68 | + | |
|
65 | 69 | protected |
|
66 | 70 | |
|
67 | 71 | def self.to_i_or_default(st, default) |
|
68 | 72 | if st!='' |
|
69 | 73 | result = st.to_i |
|
70 | 74 | end |
|
71 | 75 | result ||= default |
|
72 | 76 | end |
|
73 | 77 | |
|
74 | 78 | def self.to_f_or_default(st, default) |
|
75 | 79 | if st!='' |
|
76 | 80 | result = st.to_f |
|
77 | 81 | end |
|
78 | 82 | result ||= default |
|
79 | 83 | end |
|
80 | 84 | |
|
81 | 85 | def self.extract_params_and_check(params, problem) |
|
82 | 86 | time_limit = Problem.to_f_or_default(params[:time_limit], |
|
83 | 87 | DEFAULT_TIME_LIMIT) |
|
84 | 88 | memory_limit = Problem.to_i_or_default(params[:memory_limit], |
|
85 | 89 | DEFAULT_MEMORY_LIMIT) |
|
86 | 90 | |
|
87 | 91 | if time_limit<=0 or time_limit >60 |
|
88 | 92 | problem.errors.add(:base,'Time limit out of range.') |
|
89 | 93 | end |
|
90 | 94 | |
|
91 | 95 | if memory_limit==0 and params[:memory_limit]!='0' |
|
92 | 96 | problem.errors.add(:base,'Memory limit format errors.') |
|
93 | 97 | elsif memory_limit<=0 or memory_limit >512 |
|
94 | 98 | problem.errors.add(:base,'Memory limit out of range.') |
|
95 | 99 | end |
|
96 | 100 | |
|
97 | 101 | if params[:file]==nil or params[:file]=='' |
|
98 | 102 | problem.errors.add(:base,'No testdata file.') |
|
99 | 103 | end |
|
100 | 104 | |
|
101 | 105 | checker_name = 'text' |
|
102 | 106 | if ['text','float'].include? params[:checker] |
|
103 | 107 | checker_name = params[:checker] |
|
104 | 108 | end |
|
105 | 109 | |
|
106 | 110 | file = params[:file] |
|
107 | 111 | |
|
108 | 112 | if !problem.errors.empty? |
|
109 | 113 | return nil, problem |
|
110 | 114 | end |
|
111 | 115 | |
|
112 | 116 | problem.name = params[:name] |
@@ -1,26 +1,26 | |||
|
1 | 1 | |
|
2 | 2 | - if submission==nil |
|
3 | 3 | = "-" |
|
4 | 4 | - else |
|
5 | 5 | - if submission.graded_at==nil |
|
6 | 6 | =t 'main.submitted_at' |
|
7 | 7 | = format_short_time(submission.submitted_at.localtime) |
|
8 | 8 | - else |
|
9 | 9 | = t 'main.graded_at' |
|
10 | 10 | = "#{format_short_time(submission.graded_at.localtime)}, " |
|
11 | 11 | - if GraderConfiguration['ui.show_score'] |
|
12 | 12 | = t 'main.score' |
|
13 | 13 | = "#{(submission.points*100/submission.problem.full_score).to_i} " |
|
14 | 14 | = " [" |
|
15 | 15 | %tt |
|
16 | 16 | = submission.grader_comment |
|
17 | 17 | = "]" |
|
18 | 18 | - if GraderConfiguration.show_grading_result |
|
19 | 19 | = " | " |
|
20 | 20 | = link_to '[detailed result]', :action => 'result', :id => submission.id |
|
21 | 21 | = " | " |
|
22 | 22 | = link_to("[#{t 'main.cmp_msg'}]", {:action => 'compiler_msg', :id => submission.id}, {:popup => true}) |
|
23 | 23 | = " | " |
|
24 | 24 | = link_to("[#{t 'main.src_link'}]",{:action => 'source', :id => submission.id}) |
|
25 | 25 | = " | " |
|
26 |
- = link_to "[#{t 'main.submissions_link'}]", :action => 'submission', :id => problem |
|
|
26 | + = link_to "[#{t 'main.submissions_link'}]", :action => 'submission', :id => submission.problem.id |
@@ -1,54 +1,62 | |||
|
1 | 1 | CafeGrader::Application.routes.draw do |
|
2 | + get "sources/direct_edit" | |
|
3 | + | |
|
2 | 4 | root :to => 'main#login' |
|
3 | 5 | |
|
4 | 6 | |
|
5 | 7 | resources :contests |
|
6 | 8 | |
|
7 | 9 | resources :sites |
|
8 | 10 | |
|
9 | 11 | resources :announcements do |
|
10 | 12 | member do |
|
11 | 13 | get 'toggle' |
|
12 | 14 | end |
|
13 | 15 | end |
|
14 | 16 | |
|
15 | 17 | |
|
16 | 18 | resources :problems do |
|
17 | 19 | member do |
|
18 | 20 | get 'toggle' |
|
19 | 21 | end |
|
20 | 22 | collection do |
|
21 | 23 | get 'turn_all_off' |
|
22 | 24 | get 'turn_all_on' |
|
23 | 25 | get 'import' |
|
24 | 26 | get 'manage' |
|
25 | 27 | end |
|
26 | 28 | end |
|
27 | 29 | |
|
28 | 30 | resources :grader_configuration, controller: 'configurations' |
|
29 | 31 | |
|
30 | 32 | resources :users do |
|
31 | 33 | member do |
|
32 | 34 | get 'toggle_activate', 'toggle_enable' |
|
33 | 35 | end |
|
34 | 36 | end |
|
35 | 37 | |
|
38 | + #resources :sources do | |
|
39 | + # collection do | |
|
40 | + # end | |
|
41 | + #end | |
|
42 | + get 'sources/direct_edit/:pid', to: 'sources#direct_edit', as: 'direct_edit' | |
|
43 | + | |
|
36 | 44 | |
|
37 | 45 | match 'tasks/view/:file.:ext' => 'tasks#view' |
|
38 | 46 | match 'tasks/download/:id/:file.:ext' => 'tasks#download' |
|
39 | 47 | match 'heartbeat/:id/edit' => 'heartbeat#edit' |
|
40 | 48 | |
|
41 | 49 | #main |
|
42 | 50 | get "main/list" |
|
43 | 51 | get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission' |
|
44 | 52 | |
|
45 | 53 | #report |
|
46 | 54 | get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof' |
|
47 | 55 | get "report/login" |
|
48 | 56 | |
|
49 | 57 | # See how all your routes lay out with "rake routes" |
|
50 | 58 | |
|
51 | 59 | # This is a legacy wild controller route that's not recommended for RESTful applications. |
|
52 | 60 | # Note: This route will make all actions in every controller accessible via GET requests. |
|
53 | 61 | match ':controller(/:action(/:id))(.:format)' |
|
54 | 62 | end |
You need to be logged in to leave comments.
Login now