Merge branch 'master' of github.com:flxw/codeocean

This commit is contained in:
Felix Wolff
2015-04-09 16:58:00 +02:00
4 changed files with 43 additions and 42 deletions

View File

@ -231,7 +231,7 @@ $(function() {
showTab(3); showTab(3);
}; };
var stderrOutput = '' var stderrOutput = '';
var handleStderrOutputForFlowr = function(event) { var handleStderrOutputForFlowr = function(event) {
var json = JSON.parse(event.data); var json = JSON.parse(event.data);
@ -239,35 +239,35 @@ $(function() {
stderrOutput += json.stderr; stderrOutput += json.stderr;
} else if (json.code) { } else if (json.code) {
if (stderrOutput == '') { if (stderrOutput == '') {
return return;
} }
var flowrUrl = $('#flowrHint').data('url') var flowrUrl = $('#flowrHint').data('url');
var flowrHintBody = $('#flowrHint .panel-body') var flowrHintBody = $('#flowrHint .panel-body');
var queryParameters = { var queryParameters = {
query: stderrOutput query: stderrOutput
} }
flowrHintBody.empty() flowrHintBody.empty();
jQuery.getJSON(flowrUrl, queryParameters, function(data) { jQuery.getJSON(flowrUrl, queryParameters, function(data) {
for (var question in data.queryResults) { for (var question in data.queryResults) {
var collapsibleTileHtml = flowrResultHtml.replace(/{{collapseId}}/g, 'collapse-' + question).replace(/{{headingId}}/g, 'heading-' + question) var collapsibleTileHtml = flowrResultHtml.replace(/{{collapseId}}/g, 'collapse-' + question).replace(/{{headingId}}/g, 'heading-' + question);
var resultTile = $(collapsibleTileHtml) var resultTile = $(collapsibleTileHtml);
resultTile.find('h4 > a').text(data.queryResults[question].title + ' | Found via ' + data.queryResults[question].source) resultTile.find('h4 > a').text(data.queryResults[question].title + ' | Found via ' + data.queryResults[question].source);
resultTile.find('.panel-body').html(data.queryResults[question].body) resultTile.find('.panel-body').html(data.queryResults[question].body);
resultTile.find('.panel-body').append('<a href="' + data.queryResults[question].url + '" class="btn btn-primary btn-block">Open this question</a>') resultTile.find('.panel-body').append('<a href="' + data.queryResults[question].url + '" class="btn btn-primary btn-block">Open this question</a>');
flowrHintBody.append(resultTile) flowrHintBody.append(resultTile);
} }
if (data.queryResults.length !== 0) { if (data.queryResults.length !== 0) {
$('#flowrHint').fadeIn() $('#flowrHint').fadeIn();
} }
}) })
stderrOutput = '' stderrOutput = '';
} }
}; };
@ -315,8 +315,8 @@ $(function() {
var file_id = $(element).data('file-id'); var file_id = $(element).data('file-id');
setAnnotations(editor, file_id); setAnnotations(editor, file_id);
session.on('annotationRemoval', handleAnnotationRemoval) session.on('annotationRemoval', handleAnnotationRemoval);
session.on('annotationChange', handleAnnotationChange) session.on('annotationChange', handleAnnotationChange);
// TODO refactor here // TODO refactor here
// Code for clicks on gutter / sidepanel // Code for clicks on gutter / sidepanel
@ -330,54 +330,54 @@ $(function() {
var row = e.getDocumentPosition().row; var row = e.getDocumentPosition().row;
e.stop(); e.stop();
var commentModal = $('#comment-modal') var commentModal = $('#comment-modal');
if (hasCommentsInRow(editor, row)) { if (hasCommentsInRow(editor, row)) {
var rowComments = getCommentsForRow(editor, row) var rowComments = getCommentsForRow(editor, row);
var comments = _.pluck(rowComments, 'text').join('\n') var comments = _.pluck(rowComments, 'text').join('\n');
commentModal.find('#other-comments').text(comments) commentModal.find('#other-comments').text(comments);
} else { } else {
commentModal.find('#other-comments').text('none') commentModal.find('#other-comments').text('none');
} }
commentModal.find('#addCommentButton').off('click') commentModal.find('#addCommentButton').off('click');
commentModal.find('#removeAllButton').off('click') commentModal.find('#removeAllButton').off('click');
commentModal.find('#addCommentButton').on('click', function(e){ commentModal.find('#addCommentButton').on('click', function(e){
var user_id = $(element).data('user-id') var user_id = $(element).data('user-id');
var commenttext = commentModal.find('textarea').val() var commenttext = commentModal.find('textarea').val();
if (commenttext !== "") { if (commenttext !== "") {
createComment(user_id, file_id, row, editor, commenttext) createComment(user_id, file_id, row, editor, commenttext);
commentModal.modal('hide') commentModal.modal('hide');
} }
}) })
commentModal.find('#removeAllButton').on('click', function(e){ commentModal.find('#removeAllButton').on('click', function(e){
var user_id = $(element).data('user-id') var user_id = $(element).data('user-id');
deleteComment(user_id,file_id,row,editor); deleteComment(user_id,file_id,row,editor);
commentModal.modal('hide') commentModal.modal('hide');
}) })
commentModal.modal('show') commentModal.modal('show');
}); });
}); });
}; };
var hasCommentsInRow = function (editor, row){ var hasCommentsInRow = function (editor, row){
return editor.getSession().getAnnotations().some(function(element) { return editor.getSession().getAnnotations().some(function(element) {
return element.row === row return element.row === row;
}) })
} }
var getCommentsForRow = function (editor, row){ var getCommentsForRow = function (editor, row){
return editor.getSession().getAnnotations().filter(function(element) { return editor.getSession().getAnnotations().filter(function(element) {
return element.row === row return element.row === row;
}) })
} }
var setAnnotations = function (editor, file_id){ var setAnnotations = function (editor, file_id){
var session = editor.getSession() var session = editor.getSession();
var url = "/comments"; var url = "/comments";
var jqrequest = $.ajax({ var jqrequest = $.ajax({
@ -498,7 +498,7 @@ $(function() {
$('#create-file').on('click', showFileDialog); $('#create-file').on('click', showFileDialog);
$('#destroy-file').on('click', confirmDestroy); $('#destroy-file').on('click', confirmDestroy);
$('#download').on('click', downloadCode); $('#download').on('click', downloadCode);
$('#request-for-comments').on('click', requestComments) $('#request-for-comments').on('click', requestComments);
}; };
var initializeTooltips = function() { var initializeTooltips = function() {

View File

@ -90,7 +90,7 @@ class ExercisesController < ApplicationController
if current_user.respond_to? :external_id if current_user.respond_to? :external_id
@user_id = current_user.external_id @user_id = current_user.external_id
else else
@user_id = '00000001-3100-4444-9999-000000000001' @user_id = current_user.id
end end
end end

View File

@ -23,15 +23,15 @@
<script type="text/javascript"> <script type="text/javascript">
//(function() { //(function() {
var commentitor = $('#commentitor') var commentitor = $('#commentitor');
var userid = commentitor.data('user-id') var userid = commentitor.data('user-id');
var fileid = commentitor.data('file-id') var fileid = commentitor.data('file-id');
var lineInput = $('#lineInput') var lineInput = $('#lineInput');
var commentInput = $('#commentInput') var commentInput = $('#commentInput');
commentitor = ace.edit(commentitor[0]) commentitor = ace.edit(commentitor[0]);
$('#submitComment').click(addComment) $('#submitComment').click(addComment);
setAnnotations() setAnnotations();
function setAnnotations() { function setAnnotations() {
var session = commentitor.getSession() var session = commentitor.getSession()

View File

@ -6,6 +6,7 @@ describe 'exercises/implement.html.slim' do
let(:non_binary_files) { files.reject { |file| file.file_type.binary? } } let(:non_binary_files) { files.reject { |file| file.file_type.binary? } }
before(:each) do before(:each) do
assign(:current_user, FactoryGirl.create(:admin))
assign(:exercise, exercise) assign(:exercise, exercise)
assign(:files, files) assign(:files, files)
assign(:paths, []) assign(:paths, [])