Send paste events to CodeOcean events API instead of LearningAnalytics
This commit is contained in:
@ -29,9 +29,10 @@ var CodeOceanEditor = {
|
|||||||
|
|
||||||
lastCopyText: null,
|
lastCopyText: null,
|
||||||
|
|
||||||
|
<% self.class.include Rails.application.routes.url_helpers %>
|
||||||
<% @config ||= CodeOcean::Config.new(:code_ocean).read(erb: false) %>
|
<% @config ||= CodeOcean::Config.new(:code_ocean).read(erb: false) %>
|
||||||
sendLearningAnalyticEvents: <%= @config['codeocean_events'] ? @config['codeocean_events']['enabled'] : false %>,
|
sendEvents: <%= @config['codeocean_events'] ? @config['codeocean_events']['enabled'] : false %>,
|
||||||
learningAnalyticsURL: "<%= @config['codeocean_events'] ? @config['codeocean_events']['url'] : "" %>",
|
eventURL: "<%= @config['codeocean_events'] ? events_path : '' %>",
|
||||||
|
|
||||||
|
|
||||||
configureEditors: function () {
|
configureEditors: function () {
|
||||||
@ -151,12 +152,12 @@ configureEditors: function () {
|
|||||||
handlePasteEvent: function (pasteObject) {
|
handlePasteEvent: function (pasteObject) {
|
||||||
var same = (this.lastCopyText === pasteObject.text);
|
var same = (this.lastCopyText === pasteObject.text);
|
||||||
|
|
||||||
// if the text is not copied from within the editor (from any file), send an event to lanalytics
|
// if the text is not copied from within the editor (from any file), send an event to the backend
|
||||||
if (!same) {
|
if (!same) {
|
||||||
this.publishCodeOceanEvent("codeocean_editor_paste", {
|
this.publishCodeOceanEvent({
|
||||||
text: pasteObject.text,
|
category: 'editor_paste',
|
||||||
codeocean_user_id: $('#editor').data('user-id'),
|
data: pasteObject.text,
|
||||||
exercise: $('#editor').data('exercise-id'),
|
exercise_id: $('#editor').data('exercise-id'),
|
||||||
file_id: "1"
|
file_id: "1"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -381,38 +382,18 @@ configureEditors: function () {
|
|||||||
//panel.find('.row .col-sm-9').eq(4).find('a').attr('href', '#output-' + index);
|
//panel.find('.row .col-sm-9').eq(4).find('a').attr('href', '#output-' + index);
|
||||||
},
|
},
|
||||||
|
|
||||||
// move URL to config file, only fire event if desired.
|
publishCodeOceanEvent: function (payload) {
|
||||||
publishCodeOceanEvent: function (eventName, contextData) {
|
if(this.sendEvents){
|
||||||
if(this.sendLearningAnalyticEvents){
|
$.ajax(this.eventURL, {
|
||||||
|
|
||||||
// enhance contextData hash with the user agent
|
|
||||||
contextData['user_agent'] = navigator.userAgent;
|
|
||||||
|
|
||||||
var payload = {
|
|
||||||
user: {
|
|
||||||
uuid: $('#editor').data('user-external-id')
|
|
||||||
},
|
|
||||||
verb: {
|
|
||||||
type: eventName
|
|
||||||
},
|
|
||||||
resource: {
|
|
||||||
type: 'page',
|
|
||||||
uuid: document.location.href
|
|
||||||
},
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
with_result: {},
|
|
||||||
in_context: contextData
|
|
||||||
};
|
|
||||||
|
|
||||||
$.ajax(this.learningAnalyticsURL, {
|
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
cache: false,
|
cache: false,
|
||||||
dataType: 'JSON',
|
dataType: 'JSON',
|
||||||
data: payload,
|
data: {
|
||||||
success: {},
|
event: payload
|
||||||
error: {}
|
},
|
||||||
})
|
success: _.noop,
|
||||||
|
error: _.noop
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user