augmentStacktraceInOutput no longer duplicates results

This commit is contained in:
Sebastian Serth
2020-05-04 23:14:36 +02:00
parent cb3eece863
commit 7154bafb7e

View File

@ -36,7 +36,7 @@ var CodeOceanEditor = {
fileTypeURL: "<%= file_types_path %>", fileTypeURL: "<%= file_types_path %>",
configureEditors: function () { configureEditors: function () {
_.each(['modePath', 'themePath', 'workerPath'], function (attribute) { _.each(['modePath', 'themePath', 'workerPath'], function (attribute) {
ace.config.set(attribute, this.ACE_FILES_PATH); ace.config.set(attribute, this.ACE_FILES_PATH);
}.bind(this)); }.bind(this));
@ -59,7 +59,7 @@ configureEditors: function () {
confirmResetActiveFile: function (event) { confirmResetActiveFile: function (event) {
event.preventDefault(); event.preventDefault();
let message = $('#start-over-active-file').data('message-confirm'); let message = $('#start-over-active-file').data('message-confirm');
message = message.replace('%{filename}', CodeOceanEditor.active_file.filename.replace(/#$/,'')) message = message.replace('%{filename}', CodeOceanEditor.active_file.filename.replace(/#$/, ''))
if (confirm(message)) { if (confirm(message)) {
this.resetCode(true); // delete only active file this.resetCode(true); // delete only active file
} }
@ -99,13 +99,13 @@ configureEditors: function () {
} }
}, },
showOutput: function(event) { showOutput: function (event) {
event.preventDefault(); event.preventDefault();
this.showOutputBar(); this.showOutputBar();
$('body').scrollTo($(event.target).attr('href')); $('body').scrollTo($(event.target).attr('href'));
}, },
renderProgressBar: function(score, maximum_score) { renderProgressBar: function (score, maximum_score) {
var percentage = score / maximum_score * 100; var percentage = score / maximum_score * 100;
var progress_bar = $('#score .progress-bar'); var progress_bar = $('#score .progress-bar');
progress_bar.removeClass().addClass(this.getProgressBarClass(percentage)); progress_bar.removeClass().addClass(this.getProgressBarClass(percentage));
@ -118,7 +118,7 @@ configureEditors: function () {
}, },
// The event ready.jstree is fired too early and thus doesn't work. // The event ready.jstree is fired too early and thus doesn't work.
selectFileInJsTree: function(filetree, file_id) { selectFileInJsTree: function (filetree, file_id) {
if (!filetree.is(':visible')) if (!filetree.is(':visible'))
// The left sidebar is not shown and thus the filetree is not rendered. // The left sidebar is not shown and thus the filetree is not rendered.
return; return;
@ -131,7 +131,7 @@ configureEditors: function () {
} }
}, },
showFirstFile: function() { showFirstFile: function () {
var frame = $('.frame[data-role="main_file"]').isPresent() ? $('.frame[data-role="main_file"]') : $('.frame').first(); var frame = $('.frame[data-role="main_file"]').isPresent() ? $('.frame[data-role="main_file"]') : $('.frame').first();
var file_id = frame.find('.editor').data('file-id'); var file_id = frame.find('.editor').data('file-id');
this.setActiveFile(frame.data('filename'), file_id); this.setActiveFile(frame.data('filename'), file_id);
@ -141,7 +141,7 @@ configureEditors: function () {
this.toggleButtonStates(); this.toggleButtonStates();
}, },
showFrame: function(frame) { showFrame: function (frame) {
this.active_frame = frame; this.active_frame = frame;
$('.frame').hide(); $('.frame').hide();
frame.show(); frame.show();
@ -194,14 +194,14 @@ configureEditors: function () {
}, },
resizeAceEditors: function (){ resizeAceEditors: function () {
$('.editor').each(function (index, element) { $('.editor').each(function (index, element) {
this.resizeParentOfAceEditor(element); this.resizeParentOfAceEditor(element);
}.bind(this)); }.bind(this));
window.dispatchEvent(new Event('resize')); window.dispatchEvent(new Event('resize'));
}, },
resizeParentOfAceEditor: function (element){ resizeParentOfAceEditor: function (element) {
// calculate needed size: window height - position of top of ACE editor - height of autosave label below editor - 5 for bar margins // calculate needed size: window height - position of top of ACE editor - height of autosave label below editor - 5 for bar margins
var windowHeight = window.innerHeight - $(element).offset().top - $('#autosave-label').height() - 5; var windowHeight = window.innerHeight - $(element).offset().top - $('#autosave-label').height() - 5;
$(element).parent().height(windowHeight); $(element).parent().height(windowHeight);
@ -215,7 +215,7 @@ configureEditors: function () {
this.resizeParentOfAceEditor(element); this.resizeParentOfAceEditor(element);
// Resize frame on window size change // Resize frame on window size change
$(window).resize(function(){ $(window).resize(function () {
this.resizeParentOfAceEditor(element); this.resizeParentOfAceEditor(element);
}.bind(this)); }.bind(this));
@ -246,9 +246,8 @@ configureEditors: function () {
editor.setTheme(this.THEME); editor.setTheme(this.THEME);
// set options for autocompletion // set options for autocompletion
if($(element).data('allow-auto-completion')){ if ($(element).data('allow-auto-completion')) {
editor.setOptions({ editor.setOptions({
enableBasicAutocompletion: true, enableBasicAutocompletion: true,
enableSnippets: false, enableSnippets: false,
@ -338,13 +337,13 @@ configureEditors: function () {
$('#request-for-comments').on('click', this.requestComments.bind(this)); $('#request-for-comments').on('click', this.requestComments.bind(this));
}, },
initializeSideBarCollapse: function() { initializeSideBarCollapse: function () {
$('#sidebar-collapse-collapsed').on('click',this.handleSideBarToggle.bind(this)); $('#sidebar-collapse-collapsed').on('click', this.handleSideBarToggle.bind(this));
$('#sidebar-collapse').on('click',this.handleSideBarToggle.bind(this)) $('#sidebar-collapse').on('click', this.handleSideBarToggle.bind(this))
$('#sidebar').on('transitionend',this.resizeAceEditors.bind(this)); $('#sidebar').on('transitionend', this.resizeAceEditors.bind(this));
}, },
handleSideBarToggle: function() { handleSideBarToggle: function () {
$('#sidebar').toggleClass('sidebar-col').toggleClass('sidebar-col-collapsed'); $('#sidebar').toggleClass('sidebar-col').toggleClass('sidebar-col-collapsed');
$('#sidebar-collapsed').toggleClass('d-none'); $('#sidebar-collapsed').toggleClass('d-none');
$('#sidebar-uncollapsed').toggleClass('d-none'); $('#sidebar-uncollapsed').toggleClass('d-none');
@ -384,14 +383,14 @@ configureEditors: function () {
}); });
$('#askForCommentsButton').on('click', this.requestComments.bind(this)); $('#askForCommentsButton').on('click', this.requestComments.bind(this));
$('#closeAskForCommentsButton').on('click', function(){ $('#closeAskForCommentsButton').on('click', function () {
$('#comment-modal').modal('hide'); $('#comment-modal').modal('hide');
}); });
setTimeout(function () { setTimeout(function () {
button.prop('disabled', false); button.prop('disabled', false);
button.tooltip('show'); button.tooltip('show');
setTimeout(function() { setTimeout(function () {
button.tooltip('hide'); button.tooltip('hide');
}, this.REQUEST_TOOLTIP_TIME); }, this.REQUEST_TOOLTIP_TIME);
}.bind(this), this.REQUEST_FOR_COMMENTS_DELAY); }.bind(this), this.REQUEST_FOR_COMMENTS_DELAY);
@ -466,7 +465,7 @@ configureEditors: function () {
}, },
publishCodeOceanEvent: function (payload) { publishCodeOceanEvent: function (payload) {
if(this.sendEvents){ if (this.sendEvents) {
$.ajax(this.eventURL, { $.ajax(this.eventURL, {
type: 'POST', type: 'POST',
cache: false, cache: false,
@ -520,19 +519,22 @@ configureEditors: function () {
augmentStacktraceInOutput: function () { augmentStacktraceInOutput: function () {
if (this.tracepositions_regex) { if (this.tracepositions_regex) {
var element = $('#output>pre'); $('#output>pre').each($.proxy(function(index, element) {
var text = element.text(); element = $(element)
const text = element.text();
element.on("click", "a", this.jumpToSourceLine.bind(this)); element.on("click", "a", this.jumpToSourceLine.bind(this));
var matches; let matches;
while (matches = this.tracepositions_regex.exec(text)) { while (matches = this.tracepositions_regex.exec(text)) {
var frame = $('div.frame[data-filename="' + matches[1] + '"]') const frame = $('div.frame[data-filename="' + matches[1] + '"]')
if (frame.length > 0) { if (frame.length > 0) {
element.html(text.replace(matches[0], "<a href='#' data-file='" + matches[1] + "' data-line='" + matches[2] + "'>" + matches[0] + "</a>")); element.html(text.replace(new RegExp(matches[0], 'g'), "<a href='#' data-file='" + matches[1] + "' data-line='" + matches[2] + "'>" + matches[0] + "</a>"));
} }
} }
}, this));
} }
}, },
@ -558,12 +560,12 @@ configureEditors: function () {
}; };
}, },
showSpinner: function(initiator) { showSpinner: function (initiator) {
$(initiator).find('i.fa').hide(); $(initiator).find('i.fa').hide();
$(initiator).find('i.fa-spin').show(); $(initiator).find('i.fa-spin').show();
}, },
showStatus: function(output) { showStatus: function (output) {
if (output.status === 'timeout') { if (output.status === 'timeout') {
this.showTimeoutMessage(); this.showTimeoutMessage();
} else if (output.status === 'container_depleted') { } else if (output.status === 'container_depleted') {
@ -577,14 +579,14 @@ configureEditors: function () {
} }
}, },
clearHints: function() { clearHints: function () {
var container = $('#error-hints'); var container = $('#error-hints');
container.find('ul.body > li.hint').remove(); container.find('ul.body > li.hint').remove();
container.fadeOut(); container.fadeOut();
}, },
showHint: function(message) { showHint: function (message) {
var template = function(description, hint) { var template = function (description, hint) {
return '\ return '\
<li class="hint">\ <li class="hint">\
<div class="description">\ <div class="description">\
@ -601,21 +603,21 @@ configureEditors: function () {
container.fadeIn(); container.fadeIn();
}, },
showContainerDepletedMessage: function() { showContainerDepletedMessage: function () {
$.flash.danger({ $.flash.danger({
icon: ['fa', 'fa-clock-o'], icon: ['fa', 'fa-clock-o'],
text: $('#editor').data('message-depleted') text: $('#editor').data('message-depleted')
}); });
}, },
showTimeoutMessage: function() { showTimeoutMessage: function () {
$.flash.info({ $.flash.info({
icon: ['fa', 'fa-clock-o'], icon: ['fa', 'fa-clock-o'],
text: $('#editor').data('message-timeout') text: $('#editor').data('message-timeout')
}); });
}, },
showWebsocketError: function(error) { showWebsocketError: function (error) {
if (window.navigator.userAgent.indexOf('Edge') > -1 || window.navigator.userAgent.indexOf('Trident') > -1) { if (window.navigator.userAgent.indexOf('Edge') > -1 || window.navigator.userAgent.indexOf('Trident') > -1) {
// Mute errors in Microsoft Edge and Internet Explorer // Mute errors in Microsoft Edge and Internet Explorer
return; return;
@ -627,42 +629,42 @@ configureEditors: function () {
Sentry.captureException(JSON.stringify(error)); Sentry.captureException(JSON.stringify(error));
}, },
showFileDialog: function(event) { showFileDialog: function (event) {
event.preventDefault(); event.preventDefault();
this.createSubmission('#create-file', null, function(response) { this.createSubmission('#create-file', null, function (response) {
$('#code_ocean_file_context_id').val(response.id); $('#code_ocean_file_context_id').val(response.id);
$('#modal-file').modal('show'); $('#modal-file').modal('show');
}.bind(this)); }.bind(this));
}, },
initializeOutputBarToggle: function() { initializeOutputBarToggle: function () {
$('#toggle-sidebar-output').on('click',this.hideOutputBar.bind(this)); $('#toggle-sidebar-output').on('click', this.hideOutputBar.bind(this));
$('#toggle-sidebar-output-collapsed').on('click',this.showOutputBar.bind(this)); $('#toggle-sidebar-output-collapsed').on('click', this.showOutputBar.bind(this));
$('#output_sidebar').on('transitionend',this.resizeAceEditors.bind(this)); $('#output_sidebar').on('transitionend', this.resizeAceEditors.bind(this));
}, },
showOutputBar: function() { showOutputBar: function () {
$('#output_sidebar_collapsed').addClass('d-none'); $('#output_sidebar_collapsed').addClass('d-none');
$('#output_sidebar_uncollapsed').removeClass('d-none'); $('#output_sidebar_uncollapsed').removeClass('d-none');
$('#output_sidebar').removeClass('output-col-collapsed').addClass('output-col'); $('#output_sidebar').removeClass('output-col-collapsed').addClass('output-col');
}, },
hideOutputBar: function() { hideOutputBar: function () {
$('#output_sidebar_collapsed').removeClass('d-none'); $('#output_sidebar_collapsed').removeClass('d-none');
$('#output_sidebar_uncollapsed').addClass('d-none'); $('#output_sidebar_uncollapsed').addClass('d-none');
$('#output_sidebar').removeClass('output-col').addClass('output-col-collapsed'); $('#output_sidebar').removeClass('output-col').addClass('output-col-collapsed');
}, },
initializeSideBarTooltips: function() { initializeSideBarTooltips: function () {
$('[data-toggle="tooltip"]').tooltip() $('[data-toggle="tooltip"]').tooltip()
}, },
initializeDescriptionToggle: function() { initializeDescriptionToggle: function () {
$('#exercise-headline').on('click', this.toggleDescriptionCard.bind(this)); $('#exercise-headline').on('click', this.toggleDescriptionCard.bind(this));
$('a#toggle').on('click', this.toggleDescriptionCard.bind(this)); $('a#toggle').on('click', this.toggleDescriptionCard.bind(this));
}, },
toggleDescriptionCard: function() { toggleDescriptionCard: function () {
$('#description-card').toggleClass('description-card-collapsed').toggleClass('description-card'); $('#description-card').toggleClass('description-card-collapsed').toggleClass('description-card');
$('#description-symbol').toggleClass('fa-chevron-down').toggleClass('fa-chevron-right'); $('#description-symbol').toggleClass('fa-chevron-down').toggleClass('fa-chevron-right');
var toggle = $('a#toggle'); var toggle = $('a#toggle');
@ -674,11 +676,15 @@ configureEditors: function () {
/** /**
* interventions * interventions
* */ * */
initializeInterventionTimer: function() { initializeInterventionTimer: function () {
if ($('#editor').data('rfc-interventions') || $('#editor').data('break-interventions')) { // split in break or rfc intervention if ($('#editor').data('rfc-interventions') || $('#editor').data('break-interventions')) { // split in break or rfc intervention
window.onblur = function() { window.blurred = true; }; window.onblur = function () {
window.onfocus = function() { window.blurred = false; }; window.blurred = true;
};
window.onfocus = function () {
window.blurred = false;
};
var delta = 100; // time in ms to wait for window event before time gets stopped var delta = 100; // time in ms to wait for window event before time gets stopped
var tid; var tid;
@ -706,10 +712,12 @@ configureEditors: function () {
var timeUntilIntervention = Math.max(percentile75 - accumulatedWorkTimeUser, minTimeIntervention); var timeUntilIntervention = Math.max(percentile75 - accumulatedWorkTimeUser, minTimeIntervention);
} }
tid = setInterval(function() { tid = setInterval(function () {
if ( window.blurred ) { return; } if (window.blurred) {
return;
}
timeUntilIntervention -= delta; timeUntilIntervention -= delta;
if ( timeUntilIntervention <= 0 ) { if (timeUntilIntervention <= 0) {
clearInterval(tid); clearInterval(tid);
// timeUntilIntervention passed // timeUntilIntervention passed
if ($('#editor').data('break-interventions')) { if ($('#editor').data('break-interventions')) {
@ -722,7 +730,7 @@ configureEditors: function () {
type: 'POST', type: 'POST',
url: $('#editor').data('intervention-save-url') url: $('#editor').data('intervention-save-url')
}); });
} else if ($('#editor').data('rfc-interventions')){ } else if ($('#editor').data('rfc-interventions')) {
var button = $('#requestComments'); var button = $('#requestComments');
// only show intervention if user did not requested for a comment already // only show intervention if user did not requested for a comment already
if (!button.prop('disabled')) { if (!button.prop('disabled')) {
@ -745,8 +753,8 @@ configureEditors: function () {
} }
}, },
initializeSearchButton: function(){ initializeSearchButton: function () {
$('#btn-search-col').button().click(function(){ $('#btn-search-col').button().click(function () {
var search = $('#search-input-text').val(); var search = $('#search-input-text').val();
var course_token = $('#editor').data('course_token') var course_token = $('#editor').data('course_token')
var save_search_url = $('#editor').data('search-save-url') var save_search_url = $('#editor').data('search-save-url')
@ -758,14 +766,15 @@ configureEditors: function () {
}, },
dataType: 'json', dataType: 'json',
type: 'POST', type: 'POST',
url: save_search_url}); url: save_search_url
});
}) })
$('#sidebar-search-collapsed').on('click',this.handleSideBarToggle.bind(this)); $('#sidebar-search-collapsed').on('click', this.handleSideBarToggle.bind(this));
}, },
initializeEverything: function() { initializeEverything: function () {
this.initializeRegexes(); this.initializeRegexes();
this.initializeCodePilot(); this.initializeCodePilot();
$('.score, #development-environment').show(); $('.score, #development-environment').show();