# HG changeset patch # User Nattee Niparnan # Date 2018-05-01 10:45:09 # Node ID 4f2d84656f3a6e760f07fd6b0d0053d3d4db9590 # Parent 93040f45d6042def280a3ab7158907afa85b1af4 # Parent 83f5b778c08bf221c8fe497bfef487c870f7cb96 Merge pull request #22 from nattee/master fix viewing stat and add load file to the live edit view diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -16,6 +16,9 @@ :retrieve_password] before_filter :authenticate, :profile_authorization, only: [:profile] + before_filter :admin_authorization, only: [:stat, :toggle_activate, :toggle_enable] + + verify :method => :post, :only => [:chg_passwd], :redirect_to => { :action => :index } diff --git a/app/views/submissions/edit.html.haml b/app/views/submissions/edit.html.haml --- a/app/views/submissions/edit.html.haml +++ b/app/views/submissions/edit.html.haml @@ -19,11 +19,21 @@ .form-group = label_tag "Task:" = text_field_tag 'asdf', "#{@problem.long_name}", class: 'form-control', disabled: true + .form-group + = label_tag "Description:" + = link_to_description_if_any "[download] ".html_safe, @problem .form-group - = label_tag 'Language' + = label_tag 'Language:' = 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" .form-group + .input-group + %span.input-group-btn + %span.btn.btn-default.btn-file + Browse + = file_field_tag 'load_file' + = text_field_tag '' , nil, {readonly: true, class: 'form-control'} + .form-group = submit_tag 'Submit', class: 'btn btn-success', id: 'live_submit', data: {confirm: "Submitting this source code for task #{@problem.long_name}?"} - # latest submission status @@ -47,10 +57,25 @@ e.setValue($("#text_sourcecode").val()); e.gotoLine(1); $("#language_id").trigger('change'); - brython(); + + $("#load_file").on('change',function(evt) { + var file = evt.target.files[0]; + var reader = new FileReader(); + reader.onload = function(theFile) { + var e = ace.edit("editor") + e.setValue(theFile.target.result); + e.gotoLine(1); + }; + reader.readAsText(file) + }); + + //brython(); }); + + + %script#__main__{type:'text/python3'} :plain import sys