From dd48cc6d10b217e94e8fa8857fc92384ed302b9e Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Tue, 18 Sep 2018 17:22:01 +0200 Subject: [PATCH] Create events on user interaction --- .../editor/participantsupport.js.erb | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/editor/participantsupport.js.erb b/app/assets/javascripts/editor/participantsupport.js.erb index 5e6fd4a4..eb02176e 100644 --- a/app/assets/javascripts/editor/participantsupport.js.erb +++ b/app/assets/javascripts/editor/participantsupport.js.erb @@ -67,6 +67,16 @@ CodeOceanEditorFlowr = { } return results; }, + createEventHandler: function (eventType, data) { + return function () { + CodeOceanEditor.publishCodeOceanEvent({ + category: eventType, + data: data, + exercise_id: $('#editor').data('exercise-id'), + file_id: null + }); + }; + }, handleStderrOutputForFlowr: function () { if (! this.isFlowrEnabled) return; @@ -80,9 +90,16 @@ CodeOceanEditorFlowr = { var collapsibleTileHtml = self.flowrResultHtml.replace(/{{collapseId}}/g, 'collapse-' + index).replace(/{{headingId}}/g, 'heading-' + index); var resultTile = $(collapsibleTileHtml); - resultTile.find('h4 > a').text(result.title); - resultTile.find('.panel-body').html(result.body); - resultTile.find('.panel-body').append('Open this question'); + var questionUrl = 'https://stackoverflow.com/questions/' + result.question_id; + + var header = resultTile.find('h4 > a'); + header.text(result.title); + header.on('click', self.createEventHandler('editor_flowr_expand_question', questionUrl)); + + var body = resultTile.find('.panel-body'); + body.html(result.body); + body.append('Open this question'); + body.find('.btn').on('click', self.createEventHandler('editor_flowr_click_question', questionUrl)); flowrHintBody.append(resultTile); });