diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index d58279b98..39e55ff4f 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,10 +13,6 @@ //= require rails-timeago //= require locales/jquery.timeago.de.js // -// lib/assets -//= require flash -//= require color_mode_picker -// // app/assets // --> Include some assets first, as they are used by other assets. // --> Hence, the order specified here is important. @@ -25,12 +21,8 @@ //= require base // 2. Programming groups are required by "channels/synchronized_editor_channel.js" //= require programming_groups -// 3. The turtle library is required by "editor/turtle.js" -//= require turtle -// 4. Some channels are required by "editor/editor.js.erb" +// 3. Some channels are required by "editor/editor.js.erb" //= require_tree ./channels -// 5. Require the editor components, as needed by "./editor.js" and "./community_solution.js" -//= require_tree ./editor // // All remaining assets are loaded in alphabetical order //= require_tree . diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index f828f9cd9..288b9ab71 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -10,10 +10,6 @@ * files in this directory. Styles in this file should be added after the last require_* statement. * It is generally better to create a new file per style scope. * - * lib/assets - *= require flash - * - * app/assets *= require_tree . *= require_self */ diff --git a/lib/assets/stylesheets/flash.css.scss b/app/assets/stylesheets/flash.css.scss similarity index 100% rename from lib/assets/stylesheets/flash.css.scss rename to app/assets/stylesheets/flash.css.scss diff --git a/app/javascript/application.js b/app/javascript/application.js index daaf6b697..535705280 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -88,3 +88,7 @@ window.ace = ace; // Publish ace in global namespace // Turbo import '@hotwired/turbo-rails'; import './turbo-migration'; + +// Import of Rails sprocket assets with minimal changes. After the initial migration these files should +// be moved to an appropriate place after some adjustments to fit modern Rails JS. +import 'sprocket-asset-import'; diff --git a/lib/assets/javascripts/color_mode_picker.js b/app/javascript/sprocket-asset-import/color-mode-picker.js similarity index 100% rename from lib/assets/javascripts/color_mode_picker.js rename to app/javascript/sprocket-asset-import/color-mode-picker.js diff --git a/app/assets/javascripts/editor/ajax.js b/app/javascript/sprocket-asset-import/editor/ajax.js similarity index 95% rename from app/assets/javascripts/editor/ajax.js rename to app/javascript/sprocket-asset-import/editor/ajax.js index 127944f63..7d1a51128 100644 --- a/app/assets/javascripts/editor/ajax.js +++ b/app/javascript/sprocket-asset-import/editor/ajax.js @@ -1,4 +1,4 @@ -CodeOceanEditorAJAX = { +export default { ajax: function(options) { return $.ajax(_.extend({ dataType: 'json', diff --git a/app/assets/javascripts/editor/editor.js b/app/javascript/sprocket-asset-import/editor/editor.js similarity index 99% rename from app/assets/javascripts/editor/editor.js rename to app/javascript/sprocket-asset-import/editor/editor.js index f0e27c220..cad8694da 100644 --- a/app/assets/javascripts/editor/editor.js +++ b/app/javascript/sprocket-asset-import/editor/editor.js @@ -1,4 +1,7 @@ -var CodeOceanEditor = { +import * as Routes from 'generated/routes'; +import { CodeOceanEditorTips } from './participantsupport'; + +const CodeOceanEditor = { THEME: window.getCurrentTheme() === 'dark' ? 'ace/theme/tomorrow_night' : 'ace/theme/tomorrow', //Color-Encoding for Percentages in Progress Bars (For submissions) @@ -28,8 +31,8 @@ var CodeOceanEditor = { lastCopyText: null, sendEvents: null, - eventURL: Routes.events_path(), - fileTypeURL: Routes.file_types_path(), + eventURL: Routes.events_path, + fileTypeURL: Routes.file_types_path, confirmDestroy: function (event) { event.preventDefault(); @@ -389,7 +392,7 @@ var CodeOceanEditor = { updateEditorModeToFileTypeID: function (editor, fileTypeID) { var newMode = 'ace/mode/text' - $.ajax(this.fileTypeURL + '/' + fileTypeID, { + $.ajax(this.fileTypeURL() + '/' + fileTypeID, { dataType: 'json' }).done(function (data) { if (data['editor_mode'] !== null) { @@ -668,7 +671,7 @@ var CodeOceanEditor = { publishCodeOceanEvent: function (payload) { if (this.sendEvents) { - $.ajax(this.eventURL, { + $.ajax(this.eventURL(), { type: 'POST', cache: false, dataType: 'JSON', @@ -1170,3 +1173,5 @@ var CodeOceanEditor = { CodeOceanEditor.editors = []; } }; + +export default CodeOceanEditor; diff --git a/app/assets/javascripts/editor/evaluation.js b/app/javascript/sprocket-asset-import/editor/evaluation.js similarity index 99% rename from app/assets/javascripts/editor/evaluation.js rename to app/javascript/sprocket-asset-import/editor/evaluation.js index a5ea6ef0e..72717372e 100644 --- a/app/assets/javascripts/editor/evaluation.js +++ b/app/javascript/sprocket-asset-import/editor/evaluation.js @@ -1,4 +1,4 @@ -CodeOceanEditorEvaluation = { +export default { // A list of non-printable characters that are not allowed in the code output. // Taken from https://stackoverflow.com/a/69024306 nonPrintableRegEx: /[\u0000-\u0008\u000B\u000C\u000F-\u001F\u007F-\u009F\u2000-\u200F\u2028-\u202F\u205F-\u206F\u3000\uFEFF]/g, diff --git a/app/assets/javascripts/editor/execution.js b/app/javascript/sprocket-asset-import/editor/execution.js similarity index 98% rename from app/assets/javascripts/editor/execution.js rename to app/javascript/sprocket-asset-import/editor/execution.js index d727c63cb..8fd1da306 100644 --- a/app/assets/javascripts/editor/execution.js +++ b/app/javascript/sprocket-asset-import/editor/execution.js @@ -1,4 +1,6 @@ -CodeOceanEditorWebsocket = { +import CommandSocket from './websocket' + +export default { websocket: null, // Replace `http` with `ws` for the WebSocket connection. This also works with `https` and `wss`. webSocketProtocol: window.location.protocol.replace(/^http/, 'ws').split(':')[0], diff --git a/app/javascript/sprocket-asset-import/editor/index.js b/app/javascript/sprocket-asset-import/editor/index.js new file mode 100644 index 000000000..4b737ee11 --- /dev/null +++ b/app/javascript/sprocket-asset-import/editor/index.js @@ -0,0 +1,19 @@ +import CodeOceanEditorAJAX from './ajax'; +import CodeOceanEditor from './editor'; +import CodeOceanEditorEvaluation from './evaluation'; +import CodeOceanEditorWebsocket from './execution'; +import { CodeOceanEditorFlowr, CodeOceanEditorRequestForComments } from './participantsupport'; +import CodeOceanEditorPrompt from './prompt'; +import CodeOceanEditorSubmissions from './submissions'; +import CodeOceanEditorTurtle from './turtle'; + +// TODO: Import explicitly in Part 3 of the asset migration. +window.CodeOceanEditorAJAX = CodeOceanEditorAJAX; +window.CodeOceanEditor = CodeOceanEditor; +window.CodeOceanEditorEvaluation = CodeOceanEditorEvaluation; +window.CodeOceanEditorWebsocket = CodeOceanEditorWebsocket; +window.CodeOceanEditorFlowr = CodeOceanEditorFlowr; +window.CodeOceanEditorPrompt = CodeOceanEditorPrompt; +window.CodeOceanEditorRequestForComments = CodeOceanEditorRequestForComments; +window.CodeOceanEditorSubmissions = CodeOceanEditorSubmissions; +window.CodeOceanEditorTurtle = CodeOceanEditorTurtle; diff --git a/app/assets/javascripts/editor/participantsupport.js b/app/javascript/sprocket-asset-import/editor/participantsupport.js similarity index 98% rename from app/assets/javascripts/editor/participantsupport.js rename to app/javascript/sprocket-asset-import/editor/participantsupport.js index b2223a3e1..d11d72090 100644 --- a/app/assets/javascripts/editor/participantsupport.js +++ b/app/javascript/sprocket-asset-import/editor/participantsupport.js @@ -1,4 +1,4 @@ -CodeOceanEditorFlowr = { +export const CodeOceanEditorFlowr = { flowrResultHtml: '