Description:
- refactor direct_edit into submissions/edit
- also refactor short
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r597:03908adb0b24 - - 12 files changed: 395 inserted, 371 deleted
@@ -0,0 +1,29 | |||||
|
|
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()) | ||
|
|
11 | + | ||
|
|
12 | + $("#language_id").on "change", (event) -> | ||
|
|
13 | + text = $("#language_id option:selected").text() | ||
|
|
14 | + mode = 'ace/mode/c_cpp' | ||
|
|
15 | + switch text | ||
|
|
16 | + when 'Pascal' then mode = 'ace/mode/pascal' | ||
|
|
17 | + when 'C++','C' then mode = 'ace/mode/c_cpp' | ||
|
|
18 | + when 'Ruby' then mode = 'ace/mode/ruby' | ||
|
|
19 | + when 'Python' then mode = 'ace/mode/python' | ||
|
|
20 | + when 'Java' then mode = 'ace/mode/java' | ||
|
|
21 | + editor = ace.edit('editor') | ||
|
|
22 | + editor.getSession().setMode(mode) | ||
|
|
23 | + | ||
|
|
24 | + e = ace.edit("editor") | ||
|
|
25 | + | ||
|
|
26 | + | ||
|
|
27 | + | ||
|
|
28 | + | ||
|
|
29 | + return |
@@ -0,0 +1,4 | |||||
|
|
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 | + |
@@ -0,0 +1,2 | |||||
|
|
1 | + :javascript | ||
|
|
2 | + $("#latest_status").html("#{j render({partial: 'submission_short', locals: {submission: @submission, problem_name: @problem.name}})}") |
@@ -1,41 +1,24 | |||||
|
1 | class SubmissionsController < ApplicationController |
|
1 | class SubmissionsController < ApplicationController |
|
2 | before_filter :authenticate |
|
2 | before_filter :authenticate |
|
3 | - |
|
3 | + before_filter :submission_authorization, only: [:show, :direct_edit_submission] |
|
4 | - before_filter(only: [:show]) { |
|
||
|
5 | - #check if authenticated |
|
||
|
6 | - return false unless authenticate |
|
||
|
7 | - |
|
||
|
8 | - #admin always has privileged |
|
||
|
9 | - if @current_user.admin? |
|
||
|
10 | - return true |
|
||
|
11 | - end |
|
||
|
12 | - |
|
||
|
13 | - sub = Submission.find(params[:id]) |
|
||
|
14 | - if sub.problem.available? |
|
||
|
15 | - return true if GraderConfiguration["right.user_view_submission"] or sub.user == @current_user |
|
||
|
16 | - end |
|
||
|
17 | - |
|
||
|
18 | - #default to NO |
|
||
|
19 | - unauthorized_redirect |
|
||
|
20 | - return false |
|
||
|
21 | - } |
|
||
|
22 |
|
4 | ||
|
23 | # GET /submissions |
|
5 | # GET /submissions |
|
24 | # GET /submissions.json |
|
6 | # GET /submissions.json |
|
|
7 | + # Show problem selection and user's submission of that problem | ||
|
25 | def index |
|
8 | def index |
|
26 | @user = @current_user |
|
9 | @user = @current_user |
|
27 | @problems = @user.available_problems |
|
10 | @problems = @user.available_problems |
|
28 |
|
11 | ||
|
29 | if params[:problem_id]==nil |
|
12 | if params[:problem_id]==nil |
|
30 | @problem = nil |
|
13 | @problem = nil |
|
31 | @submissions = nil |
|
14 | @submissions = nil |
|
32 | else |
|
15 | else |
|
33 | @problem = Problem.find_by_id(params[:problem_id]) |
|
16 | @problem = Problem.find_by_id(params[:problem_id]) |
|
34 | if (@problem == nil) or (not @problem.available) |
|
17 | if (@problem == nil) or (not @problem.available) |
|
35 |
- redirect_to |
|
18 | + redirect_to main_list_path |
|
36 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
19 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
37 | return |
|
20 | return |
|
38 | end |
|
21 | end |
|
39 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
22 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
40 | end |
|
23 | end |
|
41 | end |
|
24 | end |
@@ -47,66 +30,108 | |||||
|
47 |
|
30 | ||
|
48 | #log the viewing |
|
31 | #log the viewing |
|
49 | user = User.find(session[:user_id]) |
|
32 | user = User.find(session[:user_id]) |
|
50 | SubmissionViewLog.create(user_id: session[:user_id],submission_id: @submission.id) unless user.admin? |
|
33 | SubmissionViewLog.create(user_id: session[:user_id],submission_id: @submission.id) unless user.admin? |
|
51 | end |
|
34 | end |
|
52 |
|
35 | ||
|
53 | - # GET /submissions/new |
|
36 | + #on-site new submission on specific problem |
|
54 | - # GET /submissions/new.json |
|
37 | + def direct_edit_problem |
|
55 | - def new |
|
38 | + @problem = Problem.find(params[:problem_id]) |
|
56 | - @submission = Submission.new |
|
39 | + @source = '' |
|
57 | - |
|
40 | + render 'edit' |
|
58 | - respond_to do |format| |
|
||
|
59 | - format.html # new.html.erb |
|
||
|
60 | - format.json { render json: @submission } |
|
||
|
61 | - end |
|
||
|
62 | end |
|
41 | end |
|
63 |
|
42 | ||
|
64 | # GET /submissions/1/edit |
|
43 | # GET /submissions/1/edit |
|
65 | def edit |
|
44 | def edit |
|
66 | @submission = Submission.find(params[:id]) |
|
45 | @submission = Submission.find(params[:id]) |
|
|
46 | + @source = @submission.source.to_s | ||
|
|
47 | + @problem = @submission.problem | ||
|
|
48 | + @lang_id = @submission.language.id | ||
|
67 | end |
|
49 | end |
|
68 |
|
50 | ||
|
69 | - # POST /submissions |
|
||
|
70 | - # POST /submissions.json |
|
||
|
71 | - def create |
|
||
|
72 | - @submission = Submission.new(params[:submission]) |
|
||
|
73 |
|
51 | ||
|
|
52 | + def get_latest_submission_status | ||
|
|
53 | + @problem = Problem.find(params[:pid]) | ||
|
|
54 | + @submission = Submission.find_last_by_user_and_problem(params[:uid],params[:pid]) | ||
|
|
55 | + puts User.find(params[:uid]).login | ||
|
|
56 | + puts Problem.find(params[:pid]).name | ||
|
|
57 | + puts 'nil' unless @submission | ||
|
74 | respond_to do |format| |
|
58 | respond_to do |format| |
|
75 | - if @submission.save |
|
59 | + format.js |
|
76 | - format.html { redirect_to @submission, notice: 'Submission was successfully created.' } |
|
||
|
77 | - format.json { render json: @submission, status: :created, location: @submission } |
|
||
|
78 | - else |
|
||
|
79 | - format.html { render action: "new" } |
|
||
|
80 | - format.json { render json: @submission.errors, status: :unprocessable_entity } |
|
||
|
81 | - end |
|
||
|
82 | end |
|
60 | end |
|
83 | end |
|
61 | end |
|
84 |
|
62 | ||
|
85 |
- |
|
63 | + # # GET /submissions/new |
|
86 |
- |
|
64 | + # # GET /submissions/new.json |
|
87 |
- |
|
65 | + # def new |
|
88 |
- |
|
66 | + # @submission = Submission.new |
|
|
67 | + # | ||
|
|
68 | + # respond_to do |format| | ||
|
|
69 | + # format.html # new.html.erb | ||
|
|
70 | + # format.json { render json: @submission } | ||
|
|
71 | + # end | ||
|
|
72 | + # end | ||
|
|
73 | + # | ||
|
|
74 | + # | ||
|
|
75 | + # # POST /submissions | ||
|
|
76 | + # # POST /submissions.json | ||
|
|
77 | + # def create | ||
|
|
78 | + # @submission = Submission.new(params[:submission]) | ||
|
|
79 | + # | ||
|
|
80 | + # respond_to do |format| | ||
|
|
81 | + # if @submission.save | ||
|
|
82 | + # format.html { redirect_to @submission, notice: 'Submission was successfully created.' } | ||
|
|
83 | + # format.json { render json: @submission, status: :created, location: @submission } | ||
|
|
84 | + # else | ||
|
|
85 | + # format.html { render action: "new" } | ||
|
|
86 | + # format.json { render json: @submission.errors, status: :unprocessable_entity } | ||
|
|
87 | + # end | ||
|
|
88 | + # end | ||
|
|
89 | + # end | ||
|
|
90 | + # | ||
|
|
91 | + # # PUT /submissions/1 | ||
|
|
92 | + # # PUT /submissions/1.json | ||
|
|
93 | + # def update | ||
|
|
94 | + # @submission = Submission.find(params[:id]) | ||
|
|
95 | + # | ||
|
|
96 | + # respond_to do |format| | ||
|
|
97 | + # if @submission.update_attributes(params[:submission]) | ||
|
|
98 | + # format.html { redirect_to @submission, notice: 'Submission was successfully updated.' } | ||
|
|
99 | + # format.json { head :no_content } | ||
|
|
100 | + # else | ||
|
|
101 | + # format.html { render action: "edit" } | ||
|
|
102 | + # format.json { render json: @submission.errors, status: :unprocessable_entity } | ||
|
|
103 | + # end | ||
|
|
104 | + # end | ||
|
|
105 | + # end | ||
|
|
106 | + # | ||
|
|
107 | + # # DELETE /submissions/1 | ||
|
|
108 | + # # DELETE /submissions/1.json | ||
|
|
109 | + # def destroy | ||
|
|
110 | + # @submission = Submission.find(params[:id]) | ||
|
|
111 | + # @submission.destroy | ||
|
|
112 | + # | ||
|
|
113 | + # respond_to do |format| | ||
|
|
114 | + # format.html { redirect_to submissions_url } | ||
|
|
115 | + # format.json { head :no_content } | ||
|
|
116 | + # end | ||
|
|
117 | + # end | ||
|
89 |
|
118 | ||
|
90 | - respond_to do |format| |
|
119 | + protected |
|
91 | - if @submission.update_attributes(params[:submission]) |
|
120 | + def submission_authorization |
|
92 | - format.html { redirect_to @submission, notice: 'Submission was successfully updated.' } |
|
121 | + #admin always has privileged |
|
93 | - format.json { head :no_content } |
|
122 | + if @current_user.admin? |
|
94 | - else |
|
123 | + return true |
|
95 | - format.html { render action: "edit" } |
|
||
|
96 | - format.json { render json: @submission.errors, status: :unprocessable_entity } |
|
||
|
97 | - end |
|
||
|
98 | end |
|
124 | end |
|
99 | - end |
|
125 | + |
|
|
126 | + sub = Submission.find(params[:id]) | ||
|
|
127 | + if sub.problem.available? | ||
|
|
128 | + puts "sub = #{sub.user.id}, current = #{@current_user.id}" | ||
|
|
129 | + return true if GraderConfiguration["right.user_view_submission"] or sub.user == @current_user | ||
|
|
130 | + end | ||
|
100 |
|
131 | ||
|
101 | - # DELETE /submissions/1 |
|
132 | + #default to NO |
|
102 | - # DELETE /submissions/1.json |
|
133 | + unauthorized_redirect |
|
103 | - def destroy |
|
134 | + return false |
|
104 | - @submission = Submission.find(params[:id]) |
|
||
|
105 | - @submission.destroy |
|
||
|
106 | - |
|
||
|
107 | - respond_to do |format| |
|
||
|
108 | - format.html { redirect_to submissions_url } |
|
||
|
109 | - format.json { head :no_content } |
|
||
|
110 | - end |
|
||
|
111 | end |
|
135 | end |
|
|
136 | + | ||
|
112 | end |
|
137 | end |
@@ -20,7 +20,7 | |||||
|
20 | %tt |
|
20 | %tt |
|
21 | = submission.grader_comment |
|
21 | = submission.grader_comment |
|
22 | = "]" |
|
22 | = "]" |
|
23 | %td |
|
23 | %td |
|
24 | = render :partial => 'compiler_message', :locals => {:compiler_message => submission.compiler_message } |
|
24 | = render :partial => 'compiler_message', :locals => {:compiler_message => submission.compiler_message } |
|
25 | %td |
|
25 | %td |
|
26 |
- = link_to 'Edit', |
|
26 | + = link_to 'Edit', edit_submission_path(submission.id), class: 'btn btn-success' |
@@ -1,12 +1,12 | |||||
|
1 |
|
1 | ||
|
2 | - if submission.nil? |
|
2 | - if submission.nil? |
|
3 | = "-" |
|
3 | = "-" |
|
4 | - else |
|
4 | - else |
|
5 | - if submission.graded_at.nil? |
|
5 | - if submission.graded_at.nil? |
|
6 | - =t 'main.submitted_at' |
|
6 | + = t 'main.submitted_at' |
|
7 | = format_short_time(submission.submitted_at.localtime) |
|
7 | = format_short_time(submission.submitted_at.localtime) |
|
8 | - else |
|
8 | - else |
|
9 | = t 'main.graded_at' |
|
9 | = t 'main.graded_at' |
|
10 | = "#{format_short_time(submission.graded_at.localtime)}, " |
|
10 | = "#{format_short_time(submission.graded_at.localtime)}, " |
|
11 | - if GraderConfiguration['ui.show_score'] |
|
11 | - if GraderConfiguration['ui.show_score'] |
|
12 | = t 'main.score' |
|
12 | = t 'main.score' |
@@ -10,9 +10,9 | |||||
|
10 | = link_to "[subs]", main_submission_path(problem.id) |
|
10 | = link_to "[subs]", main_submission_path(problem.id) |
|
11 | %td |
|
11 | %td |
|
12 | = render :partial => 'submission_short', |
|
12 | = render :partial => 'submission_short', |
|
13 | :locals => {:submission => @prob_submissions[problem.id][:submission], :problem_name => problem.name, :problem_id => problem.id } |
|
13 | :locals => {:submission => @prob_submissions[problem.id][:submission], :problem_name => problem.name, :problem_id => problem.id } |
|
14 | %td |
|
14 | %td |
|
15 | - if @prob_submissions[problem.id][:submission] |
|
15 | - if @prob_submissions[problem.id][:submission] |
|
16 |
- = link_to 'Edit', |
|
16 | + = link_to 'Edit', edit_submission_path(@prob_submissions[problem.id][:submission]), class: 'btn btn-success' |
|
17 | - else |
|
17 | - else |
|
18 | - = link_to 'New', direct_edit_path(problem.id), class: 'btn btn-success' |
|
18 | + = link_to 'New', direct_edit_problem_submissions_path(problem.id), class: 'btn btn-success' |
@@ -1,7 +1,268 | |||||
|
1 | - %h1 Editing submission |
|
1 | + %h2 Live submit |
|
|
2 | + %br | ||
|
|
3 | + | ||
|
|
4 | + %textarea#text_haha{style: "display:none"}~ @source | ||
|
|
5 | + .container | ||
|
|
6 | + .row | ||
|
|
7 | + .col-md-12 | ||
|
|
8 | + .alert.alert-info | ||
|
|
9 | + Write your code in the following box, choose language, and click submit button when finished | ||
|
|
10 | + .row | ||
|
|
11 | + .col-md-8 | ||
|
|
12 | + %div#editor{style: 'height: 500px; border-radius: 7px; font-size: 14px;'} | ||
|
|
13 | + .col-md-4 | ||
|
|
14 | + = form_tag({controller: :main, :action => 'submit'}, :multipart => true, class: 'form') do | ||
|
|
15 | + | ||
|
|
16 | + = hidden_field_tag 'editor_text', @source | ||
|
|
17 | + = hidden_field_tag 'submission[problem_id]', @problem.id | ||
|
|
18 | + .form-group | ||
|
|
19 | + = label_tag "Task:" | ||
|
|
20 | + = text_field_tag 'asdf', "#{@problem.long_name}", class: 'form-control', disabled: true | ||
|
|
21 | + | ||
|
|
22 | + .form-group | ||
|
|
23 | + = label_tag 'Language' | ||
|
|
24 | + = select_tag 'language_id', options_from_collection_for_select(Language.all, 'id', 'pretty_name', @lang_id || Language.find_by_pretty_name("Python").id || Language.first.id), class: 'form-control select', style: "width: 100px" | ||
|
|
25 | + .form-group | ||
|
|
26 | + = submit_tag 'Submit', class: 'btn btn-success', id: 'live_submit', | ||
|
|
27 | + data: {confirm: "Submitting this source code for task #{@problem.long_name}?"} | ||
|
|
28 | + .panel.panel-info | ||
|
|
29 | + .panel-heading | ||
|
|
30 | + Latest Submission Status | ||
|
|
31 | + .panel-body | ||
|
|
32 | + - if @submission | ||
|
|
33 | + = render :partial => 'submission_short', | ||
|
|
34 | + :locals => {:submission => @submission, :problem_name => @problem.name } | ||
|
|
35 | + .row | ||
|
|
36 | + .col-md-12 | ||
|
|
37 | + %h2 Console | ||
|
|
38 | + %textarea#console{style: 'height: 100%; width: 100%;background-color:#000;color:#fff;font-family: consolas, monaco, "Droid Sans Mono";',rows: 20} | ||
|
|
39 | + | ||
|
|
40 | + :javascript | ||
|
|
41 | + $(document).ready(function() { | ||
|
|
42 | + e = ace.edit("editor") | ||
|
|
43 | + e.setValue($("#text_haha").val()); | ||
|
|
44 | + e.gotoLine(1); | ||
|
|
45 | + $("#language_id").trigger('change'); | ||
|
|
46 | + brython(); | ||
|
|
47 | + }); | ||
|
|
48 | + | ||
|
|
49 | + | ||
|
|
50 | + %script#__main__{type:'text/python3'} | ||
|
|
51 | + :plain | ||
|
|
52 | + import sys | ||
|
|
53 | + import traceback | ||
|
|
54 | + | ||
|
|
55 | + from browser import document as doc | ||
|
|
56 | + from browser import window, alert, console | ||
|
|
57 | + | ||
|
|
58 | + _credits = """ Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands | ||
|
|
59 | + for supporting Python development. See www.python.org for more information.""" | ||
|
|
60 | + | ||
|
|
61 | + _copyright = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com | ||
|
|
62 | + All Rights Reserved. | ||
|
2 |
|
63 | ||
|
3 | - = render 'form' |
|
64 | + Copyright (c) 2001-2013 Python Software Foundation. |
|
|
65 | + All Rights Reserved. | ||
|
|
66 | + | ||
|
|
67 | + Copyright (c) 2000 BeOpen.com. | ||
|
|
68 | + All Rights Reserved. | ||
|
|
69 | + | ||
|
|
70 | + Copyright (c) 1995-2001 Corporation for National Research Initiatives. | ||
|
|
71 | + All Rights Reserved. | ||
|
|
72 | + | ||
|
|
73 | + Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam. | ||
|
|
74 | + All Rights Reserved.""" | ||
|
|
75 | + | ||
|
|
76 | + _license = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com | ||
|
|
77 | + All rights reserved. | ||
|
|
78 | + | ||
|
|
79 | + Redistribution and use in source and binary forms, with or without | ||
|
|
80 | + modification, are permitted provided that the following conditions are met: | ||
|
|
81 | + | ||
|
|
82 | + Redistributions of source code must retain the above copyright notice, this | ||
|
|
83 | + list of conditions and the following disclaimer. Redistributions in binary | ||
|
|
84 | + form must reproduce the above copyright notice, this list of conditions and | ||
|
|
85 | + the following disclaimer in the documentation and/or other materials provided | ||
|
|
86 | + with the distribution. | ||
|
|
87 | + Neither the name of the <ORGANIZATION> nor the names of its contributors may | ||
|
|
88 | + be used to endorse or promote products derived from this software without | ||
|
|
89 | + specific prior written permission. | ||
|
|
90 | + | ||
|
|
91 | + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
|
|
92 | + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
|
|
93 | + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
|
|
94 | + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
|
|
95 | + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
|
|
96 | + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
|
|
97 | + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
|
|
98 | + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
|
|
99 | + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
|
|
100 | + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
|
|
101 | + POSSIBILITY OF SUCH DAMAGE. | ||
|
|
102 | + """ | ||
|
|
103 | + | ||
|
|
104 | + def credits(): | ||
|
|
105 | + print(_credits) | ||
|
|
106 | + credits.__repr__ = lambda:_credits | ||
|
|
107 | + | ||
|
|
108 | + def copyright(): | ||
|
|
109 | + print(_copyright) | ||
|
|
110 | + copyright.__repr__ = lambda:_copyright | ||
|
|
111 | + | ||
|
|
112 | + def license(): | ||
|
|
113 | + print(_license) | ||
|
|
114 | + license.__repr__ = lambda:_license | ||
|
|
115 | + | ||
|
|
116 | + def write(data): | ||
|
|
117 | + doc['console'].value += str(data) | ||
|
|
118 | + | ||
|
|
119 | + | ||
|
|
120 | + sys.stdout.write = sys.stderr.write = write | ||
|
|
121 | + history = [] | ||
|
|
122 | + current = 0 | ||
|
|
123 | + _status = "main" # or "block" if typing inside a block | ||
|
|
124 | + | ||
|
|
125 | + # execution namespace | ||
|
|
126 | + editor_ns = {'credits':credits, | ||
|
|
127 | + 'copyright':copyright, | ||
|
|
128 | + 'license':license, | ||
|
|
129 | + '__name__':'__main__'} | ||
|
4 |
|
130 | ||
|
5 | - = link_to 'Show', @submission |
|
131 | + def cursorToEnd(*args): |
|
6 | - \| |
|
132 | + pos = len(doc['console'].value) |
|
7 | - = link_to 'Back', submissions_path |
|
133 | + doc['console'].setSelectionRange(pos, pos) |
|
|
134 | + doc['console'].scrollTop = doc['console'].scrollHeight | ||
|
|
135 | + | ||
|
|
136 | + def get_col(area): | ||
|
|
137 | + # returns the column num of cursor | ||
|
|
138 | + sel = doc['console'].selectionStart | ||
|
|
139 | + lines = doc['console'].value.split('\n') | ||
|
|
140 | + for line in lines[:-1]: | ||
|
|
141 | + sel -= len(line) + 1 | ||
|
|
142 | + return sel | ||
|
|
143 | + | ||
|
|
144 | + | ||
|
|
145 | + def myKeyPress(event): | ||
|
|
146 | + global _status, current | ||
|
|
147 | + if event.keyCode == 9: # tab key | ||
|
|
148 | + event.preventDefault() | ||
|
|
149 | + doc['console'].value += " " | ||
|
|
150 | + elif event.keyCode == 13: # return | ||
|
|
151 | + src = doc['console'].value | ||
|
|
152 | + if _status == "main": | ||
|
|
153 | + currentLine = src[src.rfind('>>>') + 4:] | ||
|
|
154 | + elif _status == "3string": | ||
|
|
155 | + currentLine = src[src.rfind('>>>') + 4:] | ||
|
|
156 | + currentLine = currentLine.replace('\n... ', '\n') | ||
|
|
157 | + else: | ||
|
|
158 | + currentLine = src[src.rfind('...') + 4:] | ||
|
|
159 | + if _status == 'main' and not currentLine.strip(): | ||
|
|
160 | + doc['console'].value += '\n>>> ' | ||
|
|
161 | + event.preventDefault() | ||
|
|
162 | + return | ||
|
|
163 | + doc['console'].value += '\n' | ||
|
|
164 | + history.append(currentLine) | ||
|
|
165 | + current = len(history) | ||
|
|
166 | + if _status == "main" or _status == "3string": | ||
|
|
167 | + try: | ||
|
|
168 | + _ = editor_ns['_'] = eval(currentLine, editor_ns) | ||
|
|
169 | + if _ is not None: | ||
|
|
170 | + write(repr(_)+'\n') | ||
|
|
171 | + doc['console'].value += '>>> ' | ||
|
|
172 | + _status = "main" | ||
|
|
173 | + except IndentationError: | ||
|
|
174 | + doc['console'].value += '... ' | ||
|
|
175 | + _status = "block" | ||
|
|
176 | + except SyntaxError as msg: | ||
|
|
177 | + if str(msg) == 'invalid syntax : triple string end not found' or \ | ||
|
|
178 | + str(msg).startswith('Unbalanced bracket'): | ||
|
|
179 | + doc['console'].value += '... ' | ||
|
|
180 | + _status = "3string" | ||
|
|
181 | + elif str(msg) == 'eval() argument must be an expression': | ||
|
|
182 | + try: | ||
|
|
183 | + exec(currentLine, editor_ns) | ||
|
|
184 | + except: | ||
|
|
185 | + traceback.print_exc() | ||
|
|
186 | + doc['console'].value += '>>> ' | ||
|
|
187 | + _status = "main" | ||
|
|
188 | + elif str(msg) == 'decorator expects function': | ||
|
|
189 | + doc['console'].value += '... ' | ||
|
|
190 | + _status = "block" | ||
|
|
191 | + else: | ||
|
|
192 | + traceback.print_exc() | ||
|
|
193 | + doc['console'].value += '>>> ' | ||
|
|
194 | + _status = "main" | ||
|
|
195 | + except: | ||
|
|
196 | + traceback.print_exc() | ||
|
|
197 | + doc['console'].value += '>>> ' | ||
|
|
198 | + _status = "main" | ||
|
|
199 | + elif currentLine == "": # end of block | ||
|
|
200 | + block = src[src.rfind('>>>') + 4:].splitlines() | ||
|
|
201 | + block = [block[0]] + [b[4:] for b in block[1:]] | ||
|
|
202 | + block_src = '\n'.join(block) | ||
|
|
203 | + # status must be set before executing code in globals() | ||
|
|
204 | + _status = "main" | ||
|
|
205 | + try: | ||
|
|
206 | + _ = exec(block_src, editor_ns) | ||
|
|
207 | + if _ is not None: | ||
|
|
208 | + print(repr(_)) | ||
|
|
209 | + except: | ||
|
|
210 | + traceback.print_exc() | ||
|
|
211 | + doc['console'].value += '>>> ' | ||
|
|
212 | + else: | ||
|
|
213 | + doc['console'].value += '... ' | ||
|
|
214 | + | ||
|
|
215 | + cursorToEnd() | ||
|
|
216 | + event.preventDefault() | ||
|
|
217 | + | ||
|
|
218 | + def myKeyDown(event): | ||
|
|
219 | + global _status, current | ||
|
|
220 | + if event.keyCode == 37: # left arrow | ||
|
|
221 | + sel = get_col(doc['console']) | ||
|
|
222 | + if sel < 5: | ||
|
|
223 | + event.preventDefault() | ||
|
|
224 | + event.stopPropagation() | ||
|
|
225 | + elif event.keyCode == 36: # line start | ||
|
|
226 | + pos = doc['console'].selectionStart | ||
|
|
227 | + col = get_col(doc['console']) | ||
|
|
228 | + doc['console'].setSelectionRange(pos - col + 4, pos - col + 4) | ||
|
|
229 | + event.preventDefault() | ||
|
|
230 | + elif event.keyCode == 38: # up | ||
|
|
231 | + if current > 0: | ||
|
|
232 | + pos = doc['console'].selectionStart | ||
|
|
233 | + col = get_col(doc['console']) | ||
|
|
234 | + # remove current line | ||
|
|
235 | + doc['console'].value = doc['console'].value[:pos - col + 4] | ||
|
|
236 | + current -= 1 | ||
|
|
237 | + doc['console'].value += history[current] | ||
|
|
238 | + event.preventDefault() | ||
|
|
239 | + elif event.keyCode == 40: # down | ||
|
|
240 | + if current < len(history) - 1: | ||
|
|
241 | + pos = doc['console'].selectionStart | ||
|
|
242 | + col = get_col(doc['console']) | ||
|
|
243 | + # remove current line | ||
|
|
244 | + doc['console'].value = doc['console'].value[:pos - col + 4] | ||
|
|
245 | + current += 1 | ||
|
|
246 | + doc['console'].value += history[current] | ||
|
|
247 | + event.preventDefault() | ||
|
|
248 | + elif event.keyCode == 8: # backspace | ||
|
|
249 | + src = doc['console'].value | ||
|
|
250 | + lstart = src.rfind('\n') | ||
|
|
251 | + if (lstart == -1 and len(src) < 5) or (len(src) - lstart < 6): | ||
|
|
252 | + event.preventDefault() | ||
|
|
253 | + event.stopPropagation() | ||
|
|
254 | + | ||
|
|
255 | + | ||
|
|
256 | + doc['console'].bind('keypress', myKeyPress) | ||
|
|
257 | + doc['console'].bind('keydown', myKeyDown) | ||
|
|
258 | + doc['console'].bind('click', cursorToEnd) | ||
|
|
259 | + v = sys.implementation.version | ||
|
|
260 | + doc['console'].value = "Brython %s.%s.%s on %s %s\n>>> " % ( | ||
|
|
261 | + v[0], v[1], v[2], window.navigator.appName, window.navigator.appVersion) | ||
|
|
262 | + #doc['console'].value += 'Type "copyright", "credits" or "license" for more information.' | ||
|
|
263 | + doc['console'].focus() | ||
|
|
264 | + cursorToEnd() | ||
|
|
265 | + | ||
|
|
266 | + | ||
|
|
267 | + | ||
|
|
268 | + |
@@ -34,21 +34,17 | |||||
|
34 | end |
|
34 | end |
|
35 | end |
|
35 | end |
|
36 |
|
36 | ||
|
37 | resources :submissions do |
|
37 | resources :submissions do |
|
38 | collection do |
|
38 | collection do |
|
39 | get 'prob/:problem_id', to: 'submissions#index', as: 'problem' |
|
39 | get 'prob/:problem_id', to: 'submissions#index', as: 'problem' |
|
|
40 | + get 'direct_edit_problem/:problem_id', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem' | ||
|
|
41 | + get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status' | ||
|
40 | end |
|
42 | end |
|
41 | end |
|
43 | end |
|
42 |
|
44 | ||
|
43 | - #source code edit |
|
||
|
44 | - get 'sources/direct_edit/:pid', to: 'sources#direct_edit', as: 'direct_edit' |
|
||
|
45 | - get 'sources/direct_edit_submission/:sid', to: 'sources#direct_edit_submission', as: 'direct_edit_submission' |
|
||
|
46 | - get 'sources/get_latest_submission_status/:uid/:pid', to: 'sources#get_latest_submission_status', as: 'get_latest_submission_status' |
|
||
|
47 | - |
|
||
|
48 | - |
|
||
|
49 | match 'tasks/view/:file.:ext' => 'tasks#view' |
|
45 | match 'tasks/view/:file.:ext' => 'tasks#view' |
|
50 | match 'tasks/download/:id/:file.:ext' => 'tasks#download' |
|
46 | match 'tasks/download/:id/:file.:ext' => 'tasks#download' |
|
51 | match 'heartbeat/:id/edit' => 'heartbeat#edit' |
|
47 | match 'heartbeat/:id/edit' => 'heartbeat#edit' |
|
52 |
|
48 | ||
|
53 | #main |
|
49 | #main |
|
54 | get "main/list" |
|
50 | get "main/list" |
deleted file |
deleted file |
deleted file |
You need to be logged in to leave comments.
Login now