Add support for running CodeOcean under a subpath

* Also refactor (JavaScript) routes
This commit is contained in:
Sebastian Serth
2021-07-06 17:02:12 +02:00
parent 7914608efe
commit 237c225732
14 changed files with 40 additions and 28 deletions

View File

@@ -51,7 +51,7 @@ $(document).on('turbolinks:load', function() {
} else {
var jqxhr = $.ajax({
dataType: 'json',
url: '/admin/dashboard',
url: Routes.admin_dashboard_path(),
method: 'GET'
});
jqxhr.done(function(response) {

View File

@@ -1,7 +1,7 @@
var CodeOceanEditor = {
//ACE-Editor-Path
// ruby part adds the relative_url_root, if it is set.
ACE_FILES_PATH: '<%= (defined? Rails.application.config.relative_url_root) && Rails.application.config.relative_url_root != nil && Rails.application.config.relative_url_root != "" ? Rails.application.config.relative_url_root : "" %>' + '/assets/ace/',
ACE_FILES_PATH: '<%= "#{Rails.application.config.relative_url_root.chomp('/')}/assets/ace/" %>',
THEME: 'ace/theme/textmate',
//Color-Encoding for Percentages in Progress Bars (For submissions)

View File

@@ -142,7 +142,7 @@ CodeOceanEditorRequestForComments = {
var createRequestForComments = function (submission) {
$.ajax({
method: 'POST',
url: '/request_for_comments',
url: Routes.request_for_comments_path(),
data: {
request_for_comment: {
exercise_id: exercise_id,

View File

@@ -1,6 +1,6 @@
$(document).on('turbolinks:load', function () {
// ruby part adds the relative_url_root, if it is set.
var ACE_FILES_PATH = '<%= (defined? Rails.application.config.relative_url_root) && Rails.application.config.relative_url_root != nil && Rails.application.config.relative_url_root != "" ? Rails.application.config.relative_url_root : "" %>' + '/assets/ace/';
var ACE_FILES_PATH = '<%= "#{Rails.application.config.relative_url_root.chomp('/')}/assets/ace/" %>';
var THEME = 'ace/theme/textmate';
var TAB_KEY_CODE = 9;
@@ -351,7 +351,7 @@ $(document).on('turbolinks:load', function () {
return $.ajax({
type: 'POST',
url: '/exercises/' + exerciseID + '/export_external_check',
url: Routes.export_external_check_exercise_path(exerciseID),
dataType: 'json',
success: function (response) {
$messageDiv.html(response.message);
@@ -370,7 +370,7 @@ $(document).on('turbolinks:load', function () {
return $.ajax({
type: 'POST',
url: '/exercises/' + exerciseID + '/export_external_confirm',
url: Routes.export_external_confirm_exercise_path(exerciseID),
dataType: 'json',
success: function (response) {
$messageDiv.html(response.message)
@@ -427,9 +427,8 @@ $(document).on('turbolinks:load', function () {
};
var updateFileTemplates = function (fileType) {
var rel_url_root = '<%= (defined? Rails.application.config.relative_url_root) && Rails.application.config.relative_url_root != nil && Rails.application.config.relative_url_root != "" ? Rails.application.config.relative_url_root : "" %>';
var jqxhr = $.ajax({
url: rel_url_root + '/file_templates/by_file_type/' + fileType + '.json',
url: Routes.by_file_type_file_templates_path(fileType),
dataType: 'json'
});
jqxhr.done(function (response) {

View File

@@ -1,5 +1,5 @@
(function() {
var ACE_FILES_PATH = '/assets/ace/';
var ACE_FILES_PATH = '<%= "#{Rails.application.config.relative_url_root.chomp('/')}/assets/ace/" %>';
window.MarkdownEditor = function(selector) {
ace.config.set('modePath', ACE_FILES_PATH);

View File

@@ -1,6 +1,6 @@
$(document).on('turbolinks:load', function() {
var ACE_FILES_PATH = '/assets/ace/';
var ACE_FILES_PATH = '<%= "#{Rails.application.config.relative_url_root.chomp('/')}/assets/ace/" %>';
var THEME = 'ace/theme/textmate';
var currentSubmission = 0;

View File

@@ -44,7 +44,7 @@ module StatisticsHelper
data: ExternalUser.joins(:submissions)
.where(['submissions.created_at >= ?', DateTime.now - 5.minutes])
.distinct('external_users.id').count,
url: 'statistics/graphs',
url: statistics_graphs_path,
},
]
end

View File

@@ -148,7 +148,7 @@ javascript:
});
// set file paths for ace
var ACE_FILES_PATH = '/assets/ace/';
var ACE_FILES_PATH = "#{Rails.application.config.relative_url_root.chomp('/')}/assets/ace/";
_.each(['modePath', 'themePath', 'workerPath'], function(attribute) {
ace.config.set(attribute, ACE_FILES_PATH);
});
@@ -231,7 +231,7 @@ javascript:
var jqrequest = $.ajax({
dataType: 'json',
method: 'GET',
url: '/comments',
url: Routes.comments_path(),
data: {
file_id: fileid
}
@@ -254,7 +254,7 @@ javascript:
function deleteComment(commentId, editor, file_id, callback) {
var jqxhr = $.ajax({
type: 'DELETE',
url: "/comments/" + commentId
url: Routes.comments_path(commentId)
});
jqxhr.done(function () {
setAnnotations(editor, file_id);
@@ -266,7 +266,7 @@ javascript:
function updateComment(commentId, text, editor, file_id, callback) {
var jqxhr = $.ajax({
type: 'PATCH',
url: "/comments/" + commentId,
url: Routes.comments_path(commentId),
data: {
comment: {
text: text
@@ -293,7 +293,7 @@ javascript:
},
dataType: 'json',
method: 'POST',
url: "/comments"
url: Routes.comments_path()
});
jqxhr.done(function(){
setAnnotations(editor, file_id);
@@ -312,7 +312,7 @@ javascript:
},
dataType: 'json',
method: 'POST',
url: "/subscriptions.json"
url: Routes.subscriptions_path({format: 'json'})
});
jqxhr.done(function(subscription) {
checkbox.data('subscription', subscription.id);
@@ -329,7 +329,7 @@ javascript:
checkbox.attr("disabled", true);
var subscriptionId = checkbox.data('subscription');
var jqxhr = $.ajax({
url: '/subscriptions/' + subscriptionId + '/unsubscribe.json'
url: Routes.unsubscribe_subscription_path(subscriptionId, {format: 'json'})
});
jqxhr.done(function(response) {
checkbox.prop('checked', false);