diff --git a/Gemfile b/Gemfile --- a/Gemfile +++ b/Gemfile @@ -57,8 +57,11 @@ gem 'bootstrap-toggle-rails' gem 'autoprefixer-rails' +gem 'ace-rails-ap' + gem 'haml' +gem 'haml-rails' gem 'mail' gem 'rdiscount' gem 'test-unit' diff --git a/Gemfile.lock b/Gemfile.lock --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,6 +9,7 @@ GEM remote: https://rubygems.org/ specs: + ace-rails-ap (4.0.2) actionmailer (3.2.21) actionpack (= 3.2.21) mail (~> 2.5.4) @@ -61,6 +62,11 @@ execjs (2.3.0) haml (4.0.6) tilt + haml-rails (0.4) + actionpack (>= 3.1, < 4.1) + activesupport (>= 3.1, < 4.1) + haml (>= 3.1, < 4.1) + railties (>= 3.1, < 4.1) hike (1.2.3) i18n (0.7.0) in_place_editing (1.2.0) @@ -161,6 +167,7 @@ ruby DEPENDENCIES + ace-rails-ap autoprefixer-rails best_in_place (~> 3.0.1) bootstrap-sass (~> 3.2.0) @@ -169,6 +176,7 @@ coffee-rails (~> 3.2.2) dynamic_form haml + haml-rails in_place_editing jquery-rails jquery-tablesorter diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -18,6 +18,7 @@ //= require bootstrap-toggle //= require select2 //= require custom +//= require ace-rails-ap // since this is after blank line, it is not downloaded diff --git a/app/assets/javascripts/custom.js.coffee b/app/assets/javascripts/custom.js.coffee --- a/app/assets/javascripts/custom.js.coffee +++ b/app/assets/javascripts/custom.js.coffee @@ -38,4 +38,8 @@ target.text '...' return + editor = ace.edit("editor") + editor.setTheme("ace/theme/monokai") + editor.getSession().setMode("ace/mode/javascript") + return diff --git a/app/assets/javascripts/sources.js.coffee b/app/assets/javascripts/sources.js.coffee new file mode 100644 --- /dev/null +++ b/app/assets/javascripts/sources.js.coffee @@ -0,0 +1,10 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ + + +$ -> + $("#live_submit").on "click", (event) -> + h = $("#editor_text") + e = ace.edit("editor") + h.val(e.getValue()) diff --git a/app/assets/stylesheets/sources.css.scss b/app/assets/stylesheets/sources.css.scss new file mode 100644 --- /dev/null +++ b/app/assets/stylesheets/sources.css.scss @@ -0,0 +1,12 @@ +// Place all the styles related to the sources controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +#editor { + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 0; +} + diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -69,6 +69,14 @@ @submission.source.encode!('UTF-8','UTF-8',invalid: :replace, replace: '') @submission.source_filename = params['file'].original_filename end + + if (params[:editor_text]) + language = Language.find_by_id(params[:language_id]) + @submission.source = params[:editor_text] + @submission.source_filename = "live_edit.#{language.ext}" + @submission.language = language + end + @submission.submitted_at = Time.new.gmtime @submission.ip_address = request.remote_ip diff --git a/app/controllers/sources_controller.rb b/app/controllers/sources_controller.rb new file mode 100644 --- /dev/null +++ b/app/controllers/sources_controller.rb @@ -0,0 +1,7 @@ +class SourcesController < ApplicationController + before_filter :authenticate, :except => [:index, :login] + + def direct_edit + @problem = Problem.find_by_id(params[:pid]) + end +end diff --git a/app/helpers/sources_helper.rb b/app/helpers/sources_helper.rb new file mode 100644 --- /dev/null +++ b/app/helpers/sources_helper.rb @@ -0,0 +1,2 @@ +module SourcesHelper +end diff --git a/app/models/problem.rb b/app/models/problem.rb --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -61,6 +61,10 @@ result[:total_sub] = Submission.where(problem_id: self.id).count result[:attempted_user] = Submission.where(problem_id: self.id).group_by(:user_id) end + + def long_name + "[#{name}] #{full_name}" + end protected diff --git a/app/views/main/_submission_short.html.haml b/app/views/main/_submission_short.html.haml --- a/app/views/main/_submission_short.html.haml +++ b/app/views/main/_submission_short.html.haml @@ -23,4 +23,4 @@ = " | " = link_to("[#{t 'main.src_link'}]",{:action => 'source', :id => submission.id}) = " | " - = link_to "[#{t 'main.submissions_link'}]", :action => 'submission', :id => problem_name + = link_to "[#{t 'main.submissions_link'}]", :action => 'submission', :id => submission.problem.id diff --git a/app/views/sources/direct_edit.html.haml b/app/views/sources/direct_edit.html.haml new file mode 100644 --- /dev/null +++ b/app/views/sources/direct_edit.html.haml @@ -0,0 +1,21 @@ +%h1 Live submit += form_tag({controller: :main, :action => 'submit'}, :multipart => true, class: 'form-inline') do + = hidden_field_tag 'editor_text' + = hidden_field_tag 'submission[problem_id]', @problem.id + .form-group + = label_tag "Task:" + = text_field_tag 'asdf', "#{@problem.long_name}", class: 'form-control', disabled: true + + .form-group + = label_tag 'Language' + = select_tag 'language_id', options_from_collection_for_select(Language.all, 'id', 'pretty_name',"C++"), class: 'form-control', style: "width: 100px" + .form-group + = submit_tag 'Submit', class: 'btn btn-success', id: 'live_submit' + +%br + +.container + .row + .col-md-12 + %div#editor{style: 'height: 400px'} + Hahaha diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ CafeGrader::Application.routes.draw do + get "sources/direct_edit" + root :to => 'main#login' @@ -33,6 +35,12 @@ end end + #resources :sources do + # collection do + # end + #end + get 'sources/direct_edit/:pid', to: 'sources#direct_edit', as: 'direct_edit' + match 'tasks/view/:file.:ext' => 'tasks#view' match 'tasks/download/:id/:file.:ext' => 'tasks#download' diff --git a/spec/controllers/sources_controller_spec.rb b/spec/controllers/sources_controller_spec.rb new file mode 100644 --- /dev/null +++ b/spec/controllers/sources_controller_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe SourcesController do + + describe "GET 'direct_edit'" do + it "returns http success" do + get 'direct_edit' + response.should be_success + end + end + +end diff --git a/spec/helpers/sources_helper_spec.rb b/spec/helpers/sources_helper_spec.rb new file mode 100644 --- /dev/null +++ b/spec/helpers/sources_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the SourcesHelper. For example: +# +# describe SourcesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +describe SourcesHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/sources/direct_edit.html.haml_spec.rb b/spec/views/sources/direct_edit.html.haml_spec.rb new file mode 100644 --- /dev/null +++ b/spec/views/sources/direct_edit.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "sources/direct_edit.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end