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 |
@@ -54,14 +54,17 | |||
|
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' |
@@ -6,12 +6,13 | |||
|
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) |
@@ -58,12 +59,17 | |||
|
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) |
@@ -158,20 +164,22 | |||
|
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 |
@@ -15,12 +15,13 | |||
|
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 |
@@ -35,7 +35,11 | |||
|
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 |
@@ -66,12 +66,20 | |||
|
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 |
@@ -58,12 +58,16 | |||
|
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 | + | |
|
65 | + def long_name | |
|
66 | + "[#{name}] #{full_name}" | |
|
67 | + end | |
|
64 | 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 |
@@ -20,7 +20,7 | |||
|
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,7 +1,9 | |||
|
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 |
@@ -30,12 +32,18 | |||
|
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 |
You need to be logged in to leave comments.
Login now