Skip to content

Commit 7dc7b82

Browse files
committed
Migrate .js.erb files to .js
This commit reverts the changes performed in 6541693, and uses local data attributes to pass settings to the frontend. The current solution is not ideal yet, but sufficient to continue with other important tasks.
1 parent 59a96ec commit 7dc7b82

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

app/assets/javascripts/editor/editor.js.erb renamed to app/assets/javascripts/editor/editor.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
// Note: Directives are only processed if they come before any application code.
2-
// Once you have a line that does not include a comment or whitespace then Sprockets will stop looking for directives.
3-
// If you use a directive outside of the "header" of the document it will not do anything, and won't raise any errors.
4-
// <% config_file = CodeOcean::Config.new(:code_ocean, erb: false) %>
5-
//= depend_on <%= config_file.path.basename %>
6-
71
var CodeOceanEditor = {
82
THEME: window.getCurrentTheme() === 'dark' ? 'ace/theme/tomorrow_night' : 'ace/theme/tomorrow',
93

@@ -33,7 +27,7 @@ var CodeOceanEditor = {
3327

3428
lastCopyText: null,
3529

36-
sendEvents: <%= config_file.read['codeocean_events'] ? config_file.read['codeocean_events']['enabled'] : false %>,
30+
sendEvents: null,
3731
eventURL: Routes.events_path(),
3832
fileTypeURL: Routes.file_types_path(),
3933

@@ -1093,6 +1087,7 @@ var CodeOceanEditor = {
10931087
},
10941088

10951089
initializeEverything: function () {
1090+
CodeOceanEditor.sendEvents = $('#editor').data('events-enabled');
10961091
CodeOceanEditor.editors = [];
10971092
this.initializeRegexes();
10981093
this.initializeEditors();

app/assets/javascripts/editor/participantsupport.js.erb renamed to app/assets/javascripts/editor/participantsupport.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
CodeOceanEditorFlowr = {
2-
isFlowrEnabled: <%= CodeOcean::Config.new(:code_ocean).read[:flowr][:enabled] %>,
32
flowrResultHtml:
43
'<div class="card mb-2">' +
54
'<div id="{{headingId}}" role="tab" class="card-header">' +
@@ -18,6 +17,13 @@ CodeOceanEditorFlowr = {
1817
'</div>' +
1918
'</div>',
2019

20+
getFlowrSettings: function () {
21+
if (this._flowrSettings === undefined) {
22+
this._flowrSettings = $('#editor').data('flowr');
23+
}
24+
return this._flowrSettings;
25+
},
26+
2127
getInsights: function () {
2228
var stackOverflowUrl = 'https://api.stackexchange.com/2.2/search/advanced';
2329

@@ -29,7 +35,7 @@ CodeOceanEditorFlowr = {
2935
var stackoverflowRequests = _.map(insights, function (insight) {
3036
var queryParams = {
3137
accepted: true,
32-
pagesize: <%= CodeOcean::Config.new(:code_ocean).read[:flowr][:answers_per_query] or 3 %>,
38+
pagesize: this.getFlowrSettings().answers_per_query,
3339
order: 'desc',
3440
sort: 'relevance',
3541
site: 'stackoverflow',
@@ -43,9 +49,9 @@ CodeOceanEditorFlowr = {
4349
url: stackOverflowUrl,
4450
data: queryParams
4551
}).promise();
46-
});
52+
}.bind(this));
4753
return jQuery.when.apply(jQuery, stackoverflowRequests);
48-
});
54+
}.bind(this));
4955
},
5056
collectResults: function(response) {
5157
var results = [];
@@ -71,7 +77,7 @@ CodeOceanEditorFlowr = {
7177
return results;
7278
},
7379
handleStderrOutputForFlowr: function () {
74-
if (! this.isFlowrEnabled) return;
80+
if (! this.getFlowrSettings().enabled) return;
7581

7682
var flowrHintBody = $('#flowrHint .card-body');
7783
flowrHintBody.empty();

app/helpers/exercise_helper.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,22 @@
33
module ExerciseHelper
44
include LtiHelper
55

6+
SETTINGS = CodeOcean::Config.new(:code_ocean)
7+
EVENT_SETTINGS = SETTINGS.read[:codeocean_events] || {}
8+
FLOWR_SETTINGS = SETTINGS.read[:flowr] || {}
9+
610
def embedding_parameters(exercise)
711
"locale=#{I18n.locale}&token=#{exercise.token}"
812
end
13+
14+
def flowr_settings
15+
{
16+
enabled: FLOWR_SETTINGS.fetch(:enabled, false),
17+
answers_per_query: FLOWR_SETTINGS.fetch(:answers_per_query, 3),
18+
}
19+
end
20+
21+
def editor_events_enabled
22+
EVENT_SETTINGS.fetch(:enabled, false)
23+
end
924
end

app/views/exercises/_editor.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- show_tips_interventions = @show_tips_interventions || 'false'
55
- hide_rfc_button = @hide_rfc_button || false
66

7-
#editor.row data-exercise-id[email protected] data-message-depleted=t('exercises.editor.depleted') data-message-timeout=t('exercises.editor.timeout', permitted_execution_time: @exercise.execution_environment.permitted_execution_time) data-message-out-of-memory=t('exercises.editor.out_of_memory', memory_limit: @exercise.execution_environment.memory_limit) data-submissions-url=submissions_path data-user-external-id=external_user_external_id data-working-times-url=working_times_exercise_path(@exercise) data-intervention-save-url=intervention_exercise_path(@exercise) data-rfc-interventions=show_rfc_interventions data-break-interventions=show_break_interventions data-tips-interventions=show_tips_interventions
7+
#editor.row data-exercise-id[email protected] data-message-depleted=t('exercises.editor.depleted') data-message-timeout=t('exercises.editor.timeout', permitted_execution_time: @exercise.execution_environment.permitted_execution_time) data-message-out-of-memory=t('exercises.editor.out_of_memory', memory_limit: @exercise.execution_environment.memory_limit) data-submissions-url=submissions_path data-user-external-id=external_user_external_id data-working-times-url=working_times_exercise_path(@exercise) data-intervention-save-url=intervention_exercise_path(@exercise) data-rfc-interventions=show_rfc_interventions data-break-interventions=show_break_interventions data-tips-interventions=show_tips_interventions data-flowr=flowr_settings.to_json data-events-enabled=editor_events_enabled.to_s
88
- unless @embed_options[:hide_sidebar]
99
- additional_classes = 'sidebar-col'
1010
- if @tips.blank?

config/initializers/assets.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
Rails.application.config.assets.version = '1.0'
77

88
# Add additional assets to the asset load path.
9-
# We require the config directory to enable asset dependencies on CodeOcean::Config values (stored as YML files in `config`).
10-
Rails.application.config.assets.paths << Rails.root.join('config')
9+
# Rails.application.config.assets.paths << Emoji.images_path

0 commit comments

Comments
 (0)