implement file import

This commit is contained in:
Karol
2019-08-21 18:27:42 +02:00
parent 017644c4a5
commit 2af93ea308
3 changed files with 23 additions and 9 deletions

View File

@ -9,7 +9,7 @@ class Exercise < ApplicationRecord
after_initialize :generate_token
after_initialize :set_default_values
belongs_to :execution_environment
belongs_to :execution_environment, optional: true
has_many :submissions
has_and_belongs_to_many :proxy_exercises

View File

@ -21,19 +21,33 @@ module ProformaService
title: @task.title,
description: @task.description,
instructions: @task.internal_description,
# exercise_files: task_files.values,
# execution_environment: execution_environment,
files: task_files
# tests: tests,
# execution_environment: execution_environment,
# state_list: @exercise.persisted? ? 'updated' : 'new'
)
end
def task_files
@task_files ||= Hash[
@task.all_files.reject { |file| file.id == 'ms-placeholder-file' }.map do |task_file|
[task_file.id, exercise_file_from_task_file(task_file)]
end
]
@task.all_files.map do |file|
CodeOcean::File.new(
context: @exercise,
file_type: FileType.find_by(file_extension: File.extname(file.filename)),
hidden: file.visible == 'no',
name: File.basename(file.filename, '.*'),
read_only: file.usage_by_lms != 'edit',
# native_file: somehting something,
role: file.internal_description.underscore.gsub(' ', '_'),
# feedback_message: #if file is testfilethingy take that message,
# weight: see above,
path: File.dirname(file.filename)
)
end
# @task_files ||= Hash[
# @task.all_files.reject { |file| file.id == 'ms-placeholder-file' }.map do |task_file|
# [task_file.id, exercise_file_from_task_file(task_file)]
# end
# ]
end
def exercise_file_from_task_file(task_file)

View File

@ -12,7 +12,7 @@ h1
= row(label: 'exercise.title', value: @exercise.title)
= row(label: 'exercise.user', value: link_to_if(policy(@exercise.author).show?, @exercise.author, @exercise.author))
= row(label: 'exercise.description', value: render_markdown(@exercise.description), class: 'm-0')
= row(label: 'exercise.execution_environment', value: link_to_if(policy(@exercise.execution_environment).show?, @exercise.execution_environment, @exercise.execution_environment))
= row(label: 'exercise.execution_environment', value: link_to_if(@exercise.execution_environment && policy(@exercise.execution_environment).show?, @exercise.execution_environment, @exercise.execution_environment))
/= row(label: 'exercise.instructions', value: render_markdown(@exercise.instructions))
= row(label: 'exercise.maximum_score', value: @exercise.maximum_score)
= row(label: 'exercise.public', value: @exercise.public?)