Enable switching between files of a submission

This commit is contained in:
Maximilian Grundke
2015-12-03 13:52:18 +01:00
parent 5c5769bab2
commit efe3895894
2 changed files with 19 additions and 21 deletions

View File

@ -8,14 +8,13 @@ $(function() {
var fileTrees = []
var showFirstFile = function() {
var frame = $('.frame[data-role="main_file"]').isPresent() ? $('.frame[data-role="main_file"]') : $('.frame').first();
var file_id = frame.find('.editor').data('file-id');
$(fileTrees[currentSubmission]).jstree().select_node(file_id);
showFrame(frame);
$(fileTrees[currentSubmission]).jstree().select_node(active_file.file_id);
showActiveFrame();
showFileTree(currentSubmission);
};
var showFrame = function(frame) {
var showActiveFrame = function() {
var frame = $('.data[data-file-id="' + active_file.id + '"]').parent().find('.frame');
$('.frame').hide();
frame.show();
};
@ -28,8 +27,7 @@ $(function() {
filename: $(this).text(),
id: parseInt($(this).attr('id'))
};
var frame = $('[data-file-id="' + active_file.id + '"]').parent();
showFrame(frame);
showActiveFrame()
});
fileTrees.push(fileTree);
});
@ -74,17 +72,12 @@ $(function() {
currentSubmission = slider.val();
showFileTree(currentSubmission);
var currentFiles = files[currentSubmission];
editors.each(function(index, editor) {
currentEditor = ace.edit(editor);
fileContent = "";
if (currentFiles[index]) {
fileContent = currentFiles[index].content
}
currentEditor.getSession().setValue(fileContent);
});
console.log(currentFiles);
active_file = currentFiles[0];
showFirstFile();
});
active_file = files[0][0]
initializeFileTree();
showFirstFile();
}

View File

@ -10,11 +10,16 @@ h1 = "#{@exercise} (external user #{@external_user})"
.hidden#data data-submissions=ActiveSupport::JSON.encode(submissions) data-files=ActiveSupport::JSON.encode(all_files)
#stats-editor.row
#files class=(@exercise.hide_file_tree ? 'hidden col-sm-3' : 'col-sm-3') data-entries=FileTree.new(initial_files).to_js_tree
div id='frames' class=(@exercise.hide_file_tree ? 'col-sm-12' : 'col-sm-9')
- initial_files.each do |file|
= render('editor_frame', exercise: @exercise, file: file)
- index = 0
- all_files.each do |files|
#stats-editor.row
.files class=(@exercise.hide_file_tree ? 'hidden col-sm-3' : 'col-sm-3') data-index=index data-entries=FileTree.new(files).to_js_tree
.frames class=(@exercise.hide_file_tree ? 'col-sm-12' : 'col-sm-9')
- files.each do |file|
.frame-container
= render('editor_frame', exercise: @exercise, file: file)
.hidden.data data-file-id=file.id
- index += 1
#slider
input type='range' orient='horizontal' list='datapoints' min=0 max=submissions.length-1 value=0