added the ability to customize the path for new files when implementing an exercise
This commit is contained in:
@ -26,6 +26,17 @@ class ExercisesController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def collect_paths(files)
|
||||||
|
unique_paths = files.map(&:path).reject(&:blank?).uniq
|
||||||
|
subpaths = unique_paths.map do |path|
|
||||||
|
(path.split('/').length + 1).times.map do |n|
|
||||||
|
path.split('/').shift(n).join('/')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
subpaths.flatten.uniq
|
||||||
|
end
|
||||||
|
private :collect_paths
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@exercise = Exercise.new(exercise_params)
|
@exercise = Exercise.new(exercise_params)
|
||||||
authorize!
|
authorize!
|
||||||
@ -62,6 +73,7 @@ class ExercisesController < ApplicationController
|
|||||||
def implement
|
def implement
|
||||||
@submission = Submission.where(exercise_id: @exercise.id, user_id: current_user.id).order('created_at DESC').first
|
@submission = Submission.where(exercise_id: @exercise.id, user_id: current_user.id).order('created_at DESC').first
|
||||||
@files = (@submission ? @submission.collect_files : @exercise.files).select(&:visible).sort_by(&:name_with_extension)
|
@files = (@submission ? @submission.collect_files : @exercise.files).select(&:visible).sort_by(&:name_with_extension)
|
||||||
|
@paths = collect_paths(@files)
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
.form-group
|
.form-group
|
||||||
= f.label(:name, t('activerecord.attributes.file.name'))
|
= f.label(:name, t('activerecord.attributes.file.name'))
|
||||||
= f.text_field(:name, class: 'form-control', required: true)
|
= f.text_field(:name, class: 'form-control', required: true)
|
||||||
|
.form-group
|
||||||
|
= f.label(:path, t('activerecord.attributes.file.path'))
|
||||||
|
= 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, {}, class: 'form-control')
|
||||||
|
@ -8,6 +8,7 @@ describe 'exercises/implement.html.slim' do
|
|||||||
before(:each) do
|
before(:each) do
|
||||||
assign(:exercise, exercise)
|
assign(:exercise, exercise)
|
||||||
assign(:files, files)
|
assign(:files, files)
|
||||||
|
assign(:paths, [])
|
||||||
render
|
render
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user