extended execution environments by a default file type that is used as the default for associated exercises' files
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
$(function() {
|
||||
var ACE_FILES_PATH = '/assets/ace/';
|
||||
var EXECUTION_ENVIRONMENTS = <%= ExecutionEnvironment.where('file_type_id IS NOT NULL').select(:file_type_id, :id).to_json %>;
|
||||
var FILE_TYPES = <%= FileType.where('file_extension IS NOT NULL').map { |file_type| [file_type.file_extension, file_type.id] }.to_h.to_json %>;
|
||||
var TAB_KEY_CODE = 9;
|
||||
|
||||
@ -12,6 +13,7 @@ $(function() {
|
||||
disable_search_threshold: 5,
|
||||
search_contains: true
|
||||
});
|
||||
$('#files li:last select[name*="file_type_id"]').val(getSelectedExecutionEnvironment().file_type_id);
|
||||
$('body, html').scrollTo('#add-file');
|
||||
};
|
||||
|
||||
@ -28,6 +30,12 @@ $(function() {
|
||||
});
|
||||
};
|
||||
|
||||
var getSelectedExecutionEnvironment = function() {
|
||||
return _.find(EXECUTION_ENVIRONMENTS, function(execution_environment) {
|
||||
return execution_environment.id === parseInt($('#exercise_execution_environment_id').val());
|
||||
}, this);
|
||||
};
|
||||
|
||||
var highlightCode = function() {
|
||||
$('pre code').each(function(index, element) {
|
||||
hljs.highlightBlock(element);
|
||||
@ -40,8 +48,7 @@ $(function() {
|
||||
var file_type_id = FILE_TYPES['.' + filename.split('.')[1]];
|
||||
var parent = $(this).parents('li');
|
||||
parent.find('input[name*="name"]').val(filename.split('.')[0]);
|
||||
parent.find('select[name*="file_type_id"]').val(file_type_id);
|
||||
parent.find('select[name*="file_type_id"]').trigger('chosen:updated');
|
||||
parent.find('select[name*="file_type_id"]').val(file_type_id).trigger('chosen:updated');
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -29,7 +29,7 @@ class ExecutionEnvironmentsController < ApplicationController
|
||||
end
|
||||
|
||||
def execution_environment_params
|
||||
params[:execution_environment].permit(:docker_image, :exposed_ports, :editor_mode, :file_extension, :help, :indent_size, :name, :permitted_execution_time, :pool_size, :run_command, :test_command, :testing_framework).merge(user_id: current_user.id, user_type: current_user.class.name)
|
||||
params[:execution_environment].permit(:docker_image, :exposed_ports, :editor_mode, :file_extension, :file_type_id, :help, :indent_size, :name, :permitted_execution_time, :pool_size, :run_command, :test_command, :testing_framework).merge(user_id: current_user.id, user_type: current_user.class.name)
|
||||
end
|
||||
private :execution_environment_params
|
||||
|
||||
|
@ -6,6 +6,7 @@ class ExecutionEnvironment < ActiveRecord::Base
|
||||
after_initialize :set_default_values
|
||||
|
||||
has_many :exercises
|
||||
belongs_to :file_type
|
||||
has_many :hints
|
||||
|
||||
scope :with_exercises, -> { where('id IN (SELECT execution_environment_id FROM exercises)') }
|
||||
|
@ -7,6 +7,7 @@ class FileType < ActiveRecord::Base
|
||||
|
||||
after_initialize :set_default_values
|
||||
|
||||
has_many :execution_environments
|
||||
has_many :files
|
||||
|
||||
validates :binary, inclusion: {in: [true, false]}
|
||||
|
@ -7,6 +7,6 @@
|
||||
= f.select(:path, @paths, {}, class: 'form-control')
|
||||
.form-group
|
||||
= f.label(:file_type_id, t('activerecord.attributes.file.file_type_id'))
|
||||
= f.collection_select(:file_type_id, FileType.where(binary: false).order(:name), :id, :name, {}, class: 'form-control')
|
||||
= f.collection_select(:file_type_id, FileType.where(binary: false).order(:name), :id, :name, {selected: @exercise.execution_environment.file_type.try(:id)}, class: 'form-control')
|
||||
= f.hidden_field(:context_id)
|
||||
.actions = render('shared/submit_button', f: f, object: CodeOcean::File.new)
|
||||
|
@ -3,6 +3,9 @@
|
||||
.form-group
|
||||
= f.label(:name)
|
||||
= f.text_field(:name, class: 'form-control', required: true)
|
||||
.form-group
|
||||
= f.label(:file_type_id)
|
||||
= f.collection_select(:file_type_id, FileType.all.order(:name), :id, :name, {include_blank: true}, class: 'form-control')
|
||||
.form-group
|
||||
= f.label(:docker_image)
|
||||
|
|
||||
|
@ -4,6 +4,7 @@ h1
|
||||
|
||||
= row(label: 'execution_environment.name', value: @execution_environment.name)
|
||||
= row(label: 'execution_environment.user', value: link_to(@execution_environment.author, @execution_environment.author))
|
||||
= row(label: 'execution_environment.file_type', value: @execution_environment.file_type.present? ? link_to(@execution_environment.file_type, @execution_environment.file_type) : nil)
|
||||
- [:docker_image, :exposed_ports, :permitted_execution_time, :pool_size, :run_command, :test_command].each do |attribute|
|
||||
= row(label: "execution_environment.#{attribute}", value: @execution_environment.send(attribute))
|
||||
= row(label: 'execution_environment.testing_framework', value: @testing_framework_adapter.try(:framework_name))
|
||||
|
@ -10,6 +10,8 @@ de:
|
||||
execution_environment:
|
||||
docker_image: Docker-Image
|
||||
exposed_ports: Zugängliche Ports
|
||||
file_type: Standard-Dateityp
|
||||
file_type_id: Standard-Dateityp
|
||||
help: Hilfetext
|
||||
name: Name
|
||||
permitted_execution_time: Erlaubte Ausführungszeit (in Sekunden)
|
||||
|
@ -10,6 +10,8 @@ en:
|
||||
execution_environment:
|
||||
docker_image: Docker Image
|
||||
exposed_ports: Exposed Ports
|
||||
file_type: Default File Type
|
||||
file_type_id: Default File Type
|
||||
help: Help Text
|
||||
name: Name
|
||||
permitted_execution_time: Permitted Execution Time (in Seconds)
|
||||
|
@ -0,0 +1,5 @@
|
||||
class AddFileTypeIdToExecutionEnvironments < ActiveRecord::Migration
|
||||
def change
|
||||
add_reference :execution_environments, :file_type
|
||||
end
|
||||
end
|
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150204080832) do
|
||||
ActiveRecord::Schema.define(version: 20150310150712) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -45,6 +45,7 @@ ActiveRecord::Schema.define(version: 20150204080832) do
|
||||
t.integer "user_id"
|
||||
t.string "user_type"
|
||||
t.integer "pool_size"
|
||||
t.integer "file_type_id"
|
||||
end
|
||||
|
||||
create_table "exercises", force: true do |t|
|
||||
|
@ -2,6 +2,7 @@ FactoryGirl.define do
|
||||
factory :coffee_script, class: ExecutionEnvironment do
|
||||
created_by_teacher
|
||||
docker_image 'hklement/ubuntu-coffee:latest'
|
||||
association :file_type, factory: :dot_coffee
|
||||
help
|
||||
name 'CoffeeScript'
|
||||
permitted_execution_time 10.seconds
|
||||
@ -13,6 +14,7 @@ FactoryGirl.define do
|
||||
factory :html, class: ExecutionEnvironment do
|
||||
created_by_teacher
|
||||
docker_image 'hklement/ubuntu-html:latest'
|
||||
association :file_type, factory: :dot_html
|
||||
help
|
||||
name 'HTML5'
|
||||
permitted_execution_time 10.seconds
|
||||
@ -26,6 +28,7 @@ FactoryGirl.define do
|
||||
factory :java, class: ExecutionEnvironment do
|
||||
created_by_teacher
|
||||
docker_image 'hklement/ubuntu-java:latest'
|
||||
association :file_type, factory: :dot_java
|
||||
help
|
||||
name 'Java 8'
|
||||
permitted_execution_time 10.seconds
|
||||
@ -39,6 +42,7 @@ FactoryGirl.define do
|
||||
factory :jruby, class: ExecutionEnvironment do
|
||||
created_by_teacher
|
||||
docker_image 'hklement/ubuntu-jruby:latest'
|
||||
association :file_type, factory: :dot_rb
|
||||
help
|
||||
name 'JRuby 1.7'
|
||||
permitted_execution_time 10.seconds
|
||||
@ -52,6 +56,7 @@ FactoryGirl.define do
|
||||
factory :node_js, class: ExecutionEnvironment do
|
||||
created_by_teacher
|
||||
docker_image 'hklement/ubuntu-node:latest'
|
||||
association :file_type, factory: :dot_js
|
||||
help
|
||||
name 'Node.js'
|
||||
permitted_execution_time 10.seconds
|
||||
@ -63,6 +68,7 @@ FactoryGirl.define do
|
||||
factory :python, class: ExecutionEnvironment do
|
||||
created_by_teacher
|
||||
docker_image 'hklement/ubuntu-python:latest'
|
||||
association :file_type, factory: :dot_py
|
||||
help
|
||||
name 'Python 3.4'
|
||||
permitted_execution_time 10.seconds
|
||||
@ -76,6 +82,7 @@ FactoryGirl.define do
|
||||
factory :ruby, class: ExecutionEnvironment do
|
||||
created_by_teacher
|
||||
docker_image 'hklement/ubuntu-ruby:latest'
|
||||
association :file_type, factory: :dot_rb
|
||||
help
|
||||
name 'Ruby 2.2'
|
||||
permitted_execution_time 10.seconds
|
||||
@ -89,6 +96,7 @@ FactoryGirl.define do
|
||||
factory :sinatra, class: ExecutionEnvironment do
|
||||
created_by_teacher
|
||||
docker_image 'hklement/ubuntu-sinatra:latest'
|
||||
association :file_type, factory: :dot_rb
|
||||
exposed_ports '4567'
|
||||
help
|
||||
name 'Sinatra'
|
||||
@ -103,6 +111,7 @@ FactoryGirl.define do
|
||||
factory :sqlite, class: ExecutionEnvironment do
|
||||
created_by_teacher
|
||||
docker_image 'hklement/ubuntu-sqlite:latest'
|
||||
association :file_type, factory: :dot_sql
|
||||
help
|
||||
name 'SQLite'
|
||||
permitted_execution_time 1.minute
|
||||
|
Reference in New Issue
Block a user