Forward person when a programming group is created with them
Further, we remove the "check invitation" button and extract some methods to our new ProgrammingGroups object in JavaScript. Co-authored-by: Sebastian Serth <Sebastian.Serth@hpi.de>
This commit is contained in:
30
app/assets/javascripts/channels/pg_matching_channel.js
Normal file
30
app/assets/javascripts/channels/pg_matching_channel.js
Normal file
@@ -0,0 +1,30 @@
|
||||
$(document).on('turbolinks:load', function () {
|
||||
|
||||
if ($.isController('programming_groups') && window.location.pathname.includes('programming_groups/new')) {
|
||||
const matching_page = $('#matching');
|
||||
const exercise_id = matching_page.data('exercise-id');
|
||||
|
||||
App.pg_matching = App.cable.subscriptions.create({
|
||||
channel: "PgMatchingChannel", exercise_id: exercise_id
|
||||
}, {
|
||||
connected() {
|
||||
// Called when the subscription is ready for use on the server
|
||||
},
|
||||
|
||||
disconnected() {
|
||||
// Called when the subscription has been terminated by the server
|
||||
},
|
||||
|
||||
received(data) {
|
||||
// Called when there's incoming data on the websocket for this channel
|
||||
switch (data.action) {
|
||||
case 'invited':
|
||||
if (!ProgrammingGroups.is_other_user(data.user)) {
|
||||
window.location.reload();
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
@@ -1,25 +1,14 @@
|
||||
$(document).on('turbolinks:load', function () {
|
||||
|
||||
if (window.location.pathname.includes('/implement')) {
|
||||
function is_other_user(user) {
|
||||
return !_.isEqual(current_user, user);
|
||||
}
|
||||
|
||||
function is_other_session(other_session_id) {
|
||||
return session_id !== other_session_id;
|
||||
}
|
||||
|
||||
const editor = $('#editor');
|
||||
const exercise_id = editor.data('exercise-id');
|
||||
let session_id;
|
||||
|
||||
if ($.isController('exercises') && is_other_user(current_contributor)) {
|
||||
if ($.isController('exercises') && ProgrammingGroups.is_other_user(current_contributor)) {
|
||||
|
||||
App.synchronized_editor = App.cable.subscriptions.create({
|
||||
channel: "SynchronizedEditorChannel", exercise_id: exercise_id
|
||||
}, {
|
||||
|
||||
|
||||
connected() {
|
||||
// Called when the subscription is ready for use on the server
|
||||
},
|
||||
@@ -33,19 +22,19 @@ $(document).on('turbolinks:load', function () {
|
||||
// Called when there's incoming data on the websocket for this channel
|
||||
switch (data.action) {
|
||||
case 'session_id':
|
||||
session_id = data.session_id;
|
||||
ProgrammingGroups.session_id = data.session_id;
|
||||
break;
|
||||
case 'editor_change':
|
||||
if (is_other_session(data.session_id)) {
|
||||
if (ProgrammingGroups.is_other_session(data.session_id)) {
|
||||
CodeOceanEditor.applyChanges(data.delta, data.active_file);
|
||||
}
|
||||
break;
|
||||
case 'connection_change':
|
||||
if (is_other_session(data.session_id) && data.status === 'connected') {
|
||||
const message = {files: CodeOceanEditor.collectFiles(), session_id: session_id};
|
||||
if (ProgrammingGroups.is_other_session(data.session_id) && data.status === 'connected') {
|
||||
const message = {files: CodeOceanEditor.collectFiles(), session_id: ProgrammingGroups.session_id};
|
||||
this.perform('current_content', message);
|
||||
}
|
||||
if (is_other_user(data.user)) {
|
||||
if (ProgrammingGroups.is_other_user(data.user)) {
|
||||
CodeOceanEditor.showPartnersConnectionStatus(data.status, data.user.displayname);
|
||||
this.perform('connection_status');
|
||||
}
|
||||
@@ -58,13 +47,13 @@ $(document).on('turbolinks:load', function () {
|
||||
}
|
||||
break;
|
||||
case 'connection_status':
|
||||
if (is_other_user(data.user)) {
|
||||
if (ProgrammingGroups.is_other_user(data.user)) {
|
||||
CodeOceanEditor.showPartnersConnectionStatus(data.status, data.user.displayname);
|
||||
}
|
||||
break;
|
||||
case 'current_content':
|
||||
case 'reset_content':
|
||||
if (is_other_session(data.session_id)) {
|
||||
if (ProgrammingGroups.is_other_session(data.session_id)) {
|
||||
CodeOceanEditor.setEditorContent(data);
|
||||
}
|
||||
break;
|
||||
@@ -76,7 +65,7 @@ $(document).on('turbolinks:load', function () {
|
||||
},
|
||||
|
||||
editor_change(delta, active_file) {
|
||||
const message = {session_id: session_id, active_file: active_file, delta: delta}
|
||||
const message = {session_id: ProgrammingGroups.session_id, active_file: active_file, delta: delta}
|
||||
this.perform('editor_change', message);
|
||||
},
|
||||
|
||||
|
@@ -1,4 +1,6 @@
|
||||
var ProgrammingGroups = {
|
||||
const ProgrammingGroups = {
|
||||
session_id: null,
|
||||
|
||||
getStoredViewedPPInfo: function () {
|
||||
return localStorage.getItem('viewed_pp_info')
|
||||
},
|
||||
@@ -7,10 +9,17 @@ var ProgrammingGroups = {
|
||||
localStorage.setItem('viewed_pp_info', 'true')
|
||||
},
|
||||
|
||||
|
||||
initializeEventHandler: function () {
|
||||
$('#dont_show_info_pp_modal_again').on('click', this.setStoredViewedPPInfo.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
is_other_user: function (user) {
|
||||
return !_.isEqual(current_user, user);
|
||||
},
|
||||
|
||||
is_other_session: function (other_session_id) {
|
||||
return this.session_id !== other_session_id;
|
||||
},
|
||||
};
|
||||
|
||||
$(document).on('turbolinks:load', function () {
|
||||
|
Reference in New Issue
Block a user