Use file template to generate new file content

This commit is contained in:
Maximilian Grundke
2016-06-10 13:41:38 +02:00
parent 1cd879bcb6
commit 4f8feb38e1
7 changed files with 16 additions and 2 deletions

View File

@ -10,6 +10,9 @@ module CodeOcean
def create def create
@file = CodeOcean::File.new(file_params) @file = CodeOcean::File.new(file_params)
if @file.file_template_id
@file.content = FileTemplate.find(@file.file_template_id).content
end
authorize! authorize!
create_and_respond(object: @file, path: proc { implement_exercise_path(@file.context.exercise, tab: 2) }) create_and_respond(object: @file, path: proc { implement_exercise_path(@file.context.exercise, tab: 2) })
end end

View File

@ -1,6 +1,6 @@
module FileParameters module FileParameters
def file_attributes def file_attributes
%w(content context_id feedback_message file_id file_type_id hidden id name native_file path read_only role weight) %w(content context_id feedback_message file_id file_type_id hidden id name native_file path read_only role weight file_template_id)
end end
private :file_attributes private :file_attributes
end end

View File

@ -8,5 +8,8 @@
.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, {selected: @exercise.execution_environment.file_type.try(:id)}, 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')
.form-group
= f.label(:file_template_id, t('activerecord.attributes.file.file_template_id'))
= f.collection_select(:file_template_id, FileTemplate.all.order(:name), :id, :name, {}, 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

@ -54,6 +54,7 @@ de:
read_only: Schreibgeschützt read_only: Schreibgeschützt
role: Rolle role: Rolle
weight: Punktzahl weight: Punktzahl
file_template_id: "Dateivorlage"
file_type: file_type:
binary: Binär binary: Binär
editor_mode: Editor-Modus editor_mode: Editor-Modus

View File

@ -54,6 +54,7 @@ en:
read_only: Read-only read_only: Read-only
role: Role role: Role
weight: Score weight: Score
file_template_id: "File Template"
file_type: file_type:
binary: Binary binary: Binary
editor_mode: Editor Mode editor_mode: Editor Mode

View File

@ -0,0 +1,5 @@
class AddFileTemplateToFile < ActiveRecord::Migration
def change
add_reference :files, :file_template
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: 20160609185708) do ActiveRecord::Schema.define(version: 20160610111602) 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"
@ -140,6 +140,7 @@ ActiveRecord::Schema.define(version: 20160609185708) do
t.string "feedback_message" t.string "feedback_message"
t.float "weight" t.float "weight"
t.string "path" t.string "path"
t.integer "file_template_id"
end end
add_index "files", ["context_id", "context_type"], name: "index_files_on_context_id_and_context_type", using: :btree add_index "files", ["context_id", "context_type"], name: "index_files_on_context_id_and_context_type", using: :btree