extended execution environments by a default file type that is used as the default for associated exercises' files

This commit is contained in:
Hauke Klement
2015-03-10 18:14:26 +01:00
parent 039c891364
commit 3ae749bfc5
12 changed files with 37 additions and 5 deletions

View File

@ -1,5 +1,6 @@
$(function() { $(function() {
var ACE_FILES_PATH = '/assets/ace/'; 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 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; var TAB_KEY_CODE = 9;
@ -12,6 +13,7 @@ $(function() {
disable_search_threshold: 5, disable_search_threshold: 5,
search_contains: true search_contains: true
}); });
$('#files li:last select[name*="file_type_id"]').val(getSelectedExecutionEnvironment().file_type_id);
$('body, html').scrollTo('#add-file'); $('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() { var highlightCode = function() {
$('pre code').each(function(index, element) { $('pre code').each(function(index, element) {
hljs.highlightBlock(element); hljs.highlightBlock(element);
@ -40,8 +48,7 @@ $(function() {
var file_type_id = FILE_TYPES['.' + filename.split('.')[1]]; var file_type_id = FILE_TYPES['.' + filename.split('.')[1]];
var parent = $(this).parents('li'); var parent = $(this).parents('li');
parent.find('input[name*="name"]').val(filename.split('.')[0]); 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"]').val(file_type_id).trigger('chosen:updated');
parent.find('select[name*="file_type_id"]').trigger('chosen:updated');
}); });
}; };

View File

@ -29,7 +29,7 @@ class ExecutionEnvironmentsController < ApplicationController
end end
def execution_environment_params 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 end
private :execution_environment_params private :execution_environment_params

View File

@ -6,6 +6,7 @@ class ExecutionEnvironment < ActiveRecord::Base
after_initialize :set_default_values after_initialize :set_default_values
has_many :exercises has_many :exercises
belongs_to :file_type
has_many :hints has_many :hints
scope :with_exercises, -> { where('id IN (SELECT execution_environment_id FROM exercises)') } scope :with_exercises, -> { where('id IN (SELECT execution_environment_id FROM exercises)') }

View File

@ -7,6 +7,7 @@ class FileType < ActiveRecord::Base
after_initialize :set_default_values after_initialize :set_default_values
has_many :execution_environments
has_many :files has_many :files
validates :binary, inclusion: {in: [true, false]} validates :binary, inclusion: {in: [true, false]}

View File

@ -7,6 +7,6 @@
= f.select(:path, @paths, {}, class: 'form-control') = f.select(:path, @paths, {}, class: 'form-control')
.form-group .form-group
= f.label(:file_type_id, t('activerecord.attributes.file.file_type_id')) = 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) = f.hidden_field(:context_id)
.actions = render('shared/submit_button', f: f, object: CodeOcean::File.new) .actions = render('shared/submit_button', f: f, object: CodeOcean::File.new)

View File

@ -3,6 +3,9 @@
.form-group .form-group
= f.label(:name) = f.label(:name)
= f.text_field(:name, class: 'form-control', required: true) = 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 .form-group
= f.label(:docker_image) = f.label(:docker_image)
| &nbsp; | &nbsp;

View File

@ -4,6 +4,7 @@ h1
= row(label: 'execution_environment.name', value: @execution_environment.name) = 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.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| - [: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.#{attribute}", value: @execution_environment.send(attribute))
= row(label: 'execution_environment.testing_framework', value: @testing_framework_adapter.try(:framework_name)) = row(label: 'execution_environment.testing_framework', value: @testing_framework_adapter.try(:framework_name))

View File

@ -10,6 +10,8 @@ de:
execution_environment: execution_environment:
docker_image: Docker-Image docker_image: Docker-Image
exposed_ports: Zugängliche Ports exposed_ports: Zugängliche Ports
file_type: Standard-Dateityp
file_type_id: Standard-Dateityp
help: Hilfetext help: Hilfetext
name: Name name: Name
permitted_execution_time: Erlaubte Ausführungszeit (in Sekunden) permitted_execution_time: Erlaubte Ausführungszeit (in Sekunden)

View File

@ -10,6 +10,8 @@ en:
execution_environment: execution_environment:
docker_image: Docker Image docker_image: Docker Image
exposed_ports: Exposed Ports exposed_ports: Exposed Ports
file_type: Default File Type
file_type_id: Default File Type
help: Help Text help: Help Text
name: Name name: Name
permitted_execution_time: Permitted Execution Time (in Seconds) permitted_execution_time: Permitted Execution Time (in Seconds)

View File

@ -0,0 +1,5 @@
class AddFileTypeIdToExecutionEnvironments < ActiveRecord::Migration
def change
add_reference :execution_environments, :file_type
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -45,6 +45,7 @@ ActiveRecord::Schema.define(version: 20150204080832) do
t.integer "user_id" t.integer "user_id"
t.string "user_type" t.string "user_type"
t.integer "pool_size" t.integer "pool_size"
t.integer "file_type_id"
end end
create_table "exercises", force: true do |t| create_table "exercises", force: true do |t|

View File

@ -2,6 +2,7 @@ FactoryGirl.define do
factory :coffee_script, class: ExecutionEnvironment do factory :coffee_script, class: ExecutionEnvironment do
created_by_teacher created_by_teacher
docker_image 'hklement/ubuntu-coffee:latest' docker_image 'hklement/ubuntu-coffee:latest'
association :file_type, factory: :dot_coffee
help help
name 'CoffeeScript' name 'CoffeeScript'
permitted_execution_time 10.seconds permitted_execution_time 10.seconds
@ -13,6 +14,7 @@ FactoryGirl.define do
factory :html, class: ExecutionEnvironment do factory :html, class: ExecutionEnvironment do
created_by_teacher created_by_teacher
docker_image 'hklement/ubuntu-html:latest' docker_image 'hklement/ubuntu-html:latest'
association :file_type, factory: :dot_html
help help
name 'HTML5' name 'HTML5'
permitted_execution_time 10.seconds permitted_execution_time 10.seconds
@ -26,6 +28,7 @@ FactoryGirl.define do
factory :java, class: ExecutionEnvironment do factory :java, class: ExecutionEnvironment do
created_by_teacher created_by_teacher
docker_image 'hklement/ubuntu-java:latest' docker_image 'hklement/ubuntu-java:latest'
association :file_type, factory: :dot_java
help help
name 'Java 8' name 'Java 8'
permitted_execution_time 10.seconds permitted_execution_time 10.seconds
@ -39,6 +42,7 @@ FactoryGirl.define do
factory :jruby, class: ExecutionEnvironment do factory :jruby, class: ExecutionEnvironment do
created_by_teacher created_by_teacher
docker_image 'hklement/ubuntu-jruby:latest' docker_image 'hklement/ubuntu-jruby:latest'
association :file_type, factory: :dot_rb
help help
name 'JRuby 1.7' name 'JRuby 1.7'
permitted_execution_time 10.seconds permitted_execution_time 10.seconds
@ -52,6 +56,7 @@ FactoryGirl.define do
factory :node_js, class: ExecutionEnvironment do factory :node_js, class: ExecutionEnvironment do
created_by_teacher created_by_teacher
docker_image 'hklement/ubuntu-node:latest' docker_image 'hklement/ubuntu-node:latest'
association :file_type, factory: :dot_js
help help
name 'Node.js' name 'Node.js'
permitted_execution_time 10.seconds permitted_execution_time 10.seconds
@ -63,6 +68,7 @@ FactoryGirl.define do
factory :python, class: ExecutionEnvironment do factory :python, class: ExecutionEnvironment do
created_by_teacher created_by_teacher
docker_image 'hklement/ubuntu-python:latest' docker_image 'hklement/ubuntu-python:latest'
association :file_type, factory: :dot_py
help help
name 'Python 3.4' name 'Python 3.4'
permitted_execution_time 10.seconds permitted_execution_time 10.seconds
@ -76,6 +82,7 @@ FactoryGirl.define do
factory :ruby, class: ExecutionEnvironment do factory :ruby, class: ExecutionEnvironment do
created_by_teacher created_by_teacher
docker_image 'hklement/ubuntu-ruby:latest' docker_image 'hklement/ubuntu-ruby:latest'
association :file_type, factory: :dot_rb
help help
name 'Ruby 2.2' name 'Ruby 2.2'
permitted_execution_time 10.seconds permitted_execution_time 10.seconds
@ -89,6 +96,7 @@ FactoryGirl.define do
factory :sinatra, class: ExecutionEnvironment do factory :sinatra, class: ExecutionEnvironment do
created_by_teacher created_by_teacher
docker_image 'hklement/ubuntu-sinatra:latest' docker_image 'hklement/ubuntu-sinatra:latest'
association :file_type, factory: :dot_rb
exposed_ports '4567' exposed_ports '4567'
help help
name 'Sinatra' name 'Sinatra'
@ -103,6 +111,7 @@ FactoryGirl.define do
factory :sqlite, class: ExecutionEnvironment do factory :sqlite, class: ExecutionEnvironment do
created_by_teacher created_by_teacher
docker_image 'hklement/ubuntu-sqlite:latest' docker_image 'hklement/ubuntu-sqlite:latest'
association :file_type, factory: :dot_sql
help help
name 'SQLite' name 'SQLite'
permitted_execution_time 1.minute permitted_execution_time 1.minute