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) {
// Called when there's incoming data on the websocket for this channel
if (current_user_id !== data['current_user_id']) {
CodeOceanEditor.applyChanges(data['delta']['data'], data['active_file']);
if (current_user_id !== data.current_user_id) {
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) {
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});
}
});

View File

@ -1044,6 +1044,17 @@ var CodeOceanEditor = {
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 () {
CodeOceanEditor.editors = [];
this.initializeRegexes();

View File

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

View File

@ -3,11 +3,13 @@
class SynchronizedEditorChannel < ApplicationCable::Channel
def subscribed
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
def unsubscribed
# Any cleanup needed when channel is unsubscribed
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
def specific_channel
@ -22,4 +24,8 @@ class SynchronizedEditorChannel < ApplicationCable::Channel
def send_changes(message)
ActionCable.server.broadcast(specific_channel, message['delta_with_user_id'])
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

View File

@ -4,7 +4,7 @@
- show_tips_interventions = @show_tips_interventions || "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]
- additional_classes = 'sidebar-col'
- if @tips.blank?
@ -39,12 +39,22 @@
= t('exercises.editor.download')
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?
span#pg_session
= t('exercises.editor.is_offline', name: @programming_partners_name)
= " | "
= t('exercises.editor.pair_programming_session')
= " | "
= t('exercises.editor.lastsaved')
span
button style="display:none" id="autosave"
span id="autosave"
= " | "