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() {
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');
});
};

View File

@@ -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

View File

@@ -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)') }

View File

@@ -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]}

View File

@@ -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)

View File

@@ -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)
| &nbsp;

View File

@@ -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))