file import wip, "native" missing

This commit is contained in:
Karol
2019-08-22 18:37:47 +02:00
parent 2af93ea308
commit aafb3f21df
2 changed files with 51 additions and 59 deletions

View File

@ -123,10 +123,10 @@ class ExercisesController < ApplicationController
# saved = exercise.save # saved = exercise.save
if exercise.save if exercise.save
# render text: 'SUCCESS', status: 200 # render text: 'SUCCESS', status: 200
render json: {status: 201} render json: {}, status: 201
else else
logger.info(exercise.errors.full_messages) logger.info(exercise.errors.full_messages)
render json: {status: 400} render json: {}, status: 400
end end
# rescue => error # rescue => error
# if error.class == Hash # if error.class == Hash

View File

@ -21,76 +21,68 @@ module ProformaService
title: @task.title, title: @task.title,
description: @task.description, description: @task.description,
instructions: @task.internal_description, instructions: @task.internal_description,
files: task_files files: files
# tests: tests, # tests: tests,
# execution_environment: execution_environment, # execution_environment: execution_environment,
# state_list: @exercise.persisted? ? 'updated' : 'new' # state_list: @exercise.persisted? ? 'updated' : 'new'
) )
end end
def files
test_files + task_files.values
end
def test_files
@task.tests.map do |test_object|
task_files.delete(test_object.files.first.id).tap do |file|
file.weight = 1.0
file.feedback_message = test_object.meta_data['feedback-message']
end
end
end
def task_files def task_files
@task.all_files.map do |file| @task_files ||= Hash[
@task.all_files.reject { |file| file.id == 'ms-placeholder-file' }.map do |task_file|
[task_file.id, codeocean_file_from_task_file(task_file)]
end
]
end
def codeocean_file_from_task_file(file)
CodeOcean::File.new( CodeOcean::File.new(
context: @exercise, context: @exercise,
content: file.content,
file_type: FileType.find_by(file_extension: File.extname(file.filename)), file_type: FileType.find_by(file_extension: File.extname(file.filename)),
hidden: file.visible == 'no', hidden: file.visible == 'no',
name: File.basename(file.filename, '.*'), name: File.basename(file.filename, '.*'),
read_only: file.usage_by_lms != 'edit', read_only: file.usage_by_lms != 'edit',
# native_file: somehting something, # native_file: somehting something, uploader something
role: file.internal_description.underscore.gsub(' ', '_'), role: file.internal_description.underscore.gsub(' ', '_'),
# feedback_message: #if file is testfilethingy take that message, # feedback_message: file.purpose == 'test' ? file.test.feedback_message : nil,
# weight: see above, # weight: file.test? ? 1.0 : nil,
path: File.dirname(file.filename) 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) # ExerciseFile.new({
ExerciseFile.new({ # full_file_name: task_file.filename,
full_file_name: task_file.filename, # read_only: task_file.usage_by_lms.in?(%w[display download]),
read_only: task_file.usage_by_lms.in?(%w[display download]), # hidden: task_file.visible == 'no',
hidden: task_file.visible == 'no', # role: task_file.internal_description
role: task_file.internal_description # }.tap do |params|
}.tap do |params| # if task_file.binary
if task_file.binary # params[:attachment] = file_base64(task_file)
params[:attachment] = file_base64(task_file) # params[:attachment_file_name] = task_file.filename
params[:attachment_file_name] = task_file.filename # params[:attachment_content_type] = task_file.mimetype
params[:attachment_content_type] = task_file.mimetype # else
else # params[:content] = task_file.content
params[:content] = task_file.content # end
end # end)
end)
end end
def file_base64(file) def file_base64(file)
"data:#{file.mimetype || 'image/jpeg'};base64,#{Base64.encode64(file.content)}" "data:#{file.mimetype || 'image/jpeg'};base64,#{Base64.encode64(file.content)}"
end end
def tests
@task.tests.map do |test_object|
Test.new(
feedback_message: test_object.meta_data['feedback-message'],
testing_framework: TestingFramework.where(
name: test_object.meta_data['testing-framework'],
version: test_object.meta_data['testing-framework-version']
).first_or_initialize,
exercise_file: test_file(test_object)
)
end
end
def test_file(test_object)
task_files.delete(test_object.files.first.id).tap { |file| file.purpose = 'test' }
end
def execution_environment
ExecutionEnvironment.last
# ExecutionEnvironment.where(language: @task.proglang[:name], version: @task.proglang[:version]).first_or_initialize
end
end end
end end