Show if partner is online

This commit is contained in:
kiragrammel
2023-09-04 16:22:00 +02:00
committed by Sebastian Serth
parent 97764bd02e
commit 056a8e5107
7 changed files with 49 additions and 7 deletions

View File

@ -23,13 +23,24 @@ $(document).on('turbolinks:load', function () {
received(data) { received(data) {
// Called when there's incoming data on the websocket for this channel // Called when there's incoming data on the websocket for this channel
if (current_user_id !== data['current_user_id']) { if (current_user_id !== data.current_user_id) {
CodeOceanEditor.applyChanges(data['delta']['data'], data['active_file']); switch(data.command) {
case 'editor_change':
CodeOceanEditor.applyChanges(data.delta.data, data.active_file);
break;
case 'connection_change':
CodeOceanEditor.showPartnersConnectionStatus(data.status, data.current_user_name);
this.perform('send_hello');
break;
case 'hello':
CodeOceanEditor.showPartnersConnectionStatus(data.status, data.current_user_name);
break;
}
} }
}, },
send_changes(delta, active_file) { send_changes(delta, active_file) {
const delta_with_user_id = {current_user_id: current_user_id, active_file: active_file, delta: delta} const delta_with_user_id = {command: 'editor_change', current_user_id: current_user_id, active_file: active_file, delta: delta}
this.perform('send_changes', {delta_with_user_id: delta_with_user_id}); this.perform('send_changes', {delta_with_user_id: delta_with_user_id});
} }
}); });

View File

@ -1044,6 +1044,17 @@ var CodeOceanEditor = {
delta_data.text === last_delta.text; delta_data.text === last_delta.text;
}, },
showPartnersConnectionStatus: function (status, username) {
switch(status) {
case 'connected':
$('#pg_session').text(I18n.t('exercises.editor.is_online', {name: username}));
break;
case 'disconnected':
$('#pg_session').text(I18n.t('exercises.editor.is_offline', {name: username}));
break;
}
},
initializeEverything: function () { initializeEverything: function () {
CodeOceanEditor.editors = []; CodeOceanEditor.editors = [];
this.initializeRegexes(); this.initializeRegexes();

View File

@ -3,7 +3,7 @@ CodeOceanEditorSubmissions = {
AUTOSAVE_INTERVAL: 15 * 1000, AUTOSAVE_INTERVAL: 15 * 1000,
autosaveTimer: null, autosaveTimer: null,
autosaveLabel: "#statusbar span", autosaveLabel: "#statusbar #autosave",
/** /**
* Submission-Creation * Submission-Creation

View File

@ -3,11 +3,13 @@
class SynchronizedEditorChannel < ApplicationCable::Channel class SynchronizedEditorChannel < ApplicationCable::Channel
def subscribed def subscribed
stream_from specific_channel stream_from specific_channel
ActionCable.server.broadcast(specific_channel, {command: 'connection_change', status: 'connected', current_user_id: current_user.id, current_user_name: current_user.name})
end end
def unsubscribed def unsubscribed
# Any cleanup needed when channel is unsubscribed # Any cleanup needed when channel is unsubscribed
stop_all_streams stop_all_streams
ActionCable.server.broadcast(specific_channel, {command: 'connection_change', status: 'disconnected', current_user_id: current_user.id, current_user_name: current_user.name})
end end
def specific_channel def specific_channel
@ -22,4 +24,8 @@ class SynchronizedEditorChannel < ApplicationCable::Channel
def send_changes(message) def send_changes(message)
ActionCable.server.broadcast(specific_channel, message['delta_with_user_id']) ActionCable.server.broadcast(specific_channel, message['delta_with_user_id'])
end end
def send_hello
ActionCable.server.broadcast(specific_channel, {command: 'hello', status: 'connected', current_user_id: current_user.id, current_user_name: current_user.name})
end
end end

View File

@ -4,7 +4,7 @@
- show_tips_interventions = @show_tips_interventions || "false" - show_tips_interventions = @show_tips_interventions || "false"
- hide_rfc_button = @hide_rfc_button || false - hide_rfc_button = @hide_rfc_button || false
#editor.row data-exercise-id=@exercise.id 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-id=current_user.id data-contributor-id=current_contributor.id 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 #editor.row data-exercise-id=@exercise.id 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-id=current_user.id data-user-name=current_user.name data-contributor-id=current_contributor.id 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
- unless @embed_options[:hide_sidebar] - unless @embed_options[:hide_sidebar]
- additional_classes = 'sidebar-col' - additional_classes = 'sidebar-col'
- if @tips.blank? - if @tips.blank?
@ -39,12 +39,22 @@
= t('exercises.editor.download') = t('exercises.editor.download')
div div
ruby:
if current_contributor.programming_group?
current_contributor.users.each do |user|
if user.id != current_user.id
@programming_partners_name = user.name
end
end
end
- if current_contributor.programming_group? - if current_contributor.programming_group?
span#pg_session
= t('exercises.editor.is_offline', name: @programming_partners_name)
= " | "
= t('exercises.editor.pair_programming_session') = t('exercises.editor.pair_programming_session')
= " | " = " | "
= t('exercises.editor.lastsaved') = t('exercises.editor.lastsaved')
span span id="autosave"
button style="display:none" id="autosave"
= " | " = " | "

View File

@ -385,6 +385,8 @@ de:
expand_action_sidebar: Aktions-Leiste Ausklappen expand_action_sidebar: Aktions-Leiste Ausklappen
expand_output_sidebar: Ausgabe-Leiste Ausklappen expand_output_sidebar: Ausgabe-Leiste Ausklappen
input: Ihre Eingabe input: Ihre Eingabe
is_offline: "%{name} ist offline"
is_online: "%{name} ist online"
lastsaved: 'Zuletzt gespeichert: ' lastsaved: 'Zuletzt gespeichert: '
network: 'Während Ihr Code läuft, ist Port %{port} unter folgender Adresse erreichbar: <a href="%{address}" target="_blank" rel="noopener">%{address}</a>.' network: 'Während Ihr Code läuft, ist Port %{port} unter folgender Adresse erreichbar: <a href="%{address}" target="_blank" rel="noopener">%{address}</a>.'
pair_programming_session: Pair Programming Session pair_programming_session: Pair Programming Session

View File

@ -385,6 +385,8 @@ en:
expand_action_sidebar: Expand Action Sidebar expand_action_sidebar: Expand Action Sidebar
expand_output_sidebar: Expand Output Sidebar expand_output_sidebar: Expand Output Sidebar
input: Your input input: Your input
is_offline: "%{name} is offline"
is_online: "%{name} is online"
lastsaved: 'Last saved: ' lastsaved: 'Last saved: '
network: 'While your code is running, port %{port} is accessible using the following address: <a href="%{address}" target="_blank" rel="noopener">%{address}</a>.' network: 'While your code is running, port %{port} is accessible using the following address: <a href="%{address}" target="_blank" rel="noopener">%{address}</a>.'
pair_programming_session: Pair Programming Session pair_programming_session: Pair Programming Session