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

This commit is contained in:
Hauke Klement
2015-04-11 21:30:13 +02:00
48 changed files with 19499 additions and 112 deletions

View File

@ -13,11 +13,12 @@ $(function() {
var THEME = 'ace/theme/textmate';
var editors = [];
var active_file;
var active_frame;
var active_file = undefined;
var active_frame = undefined;
var running = false;
var qa_api = undefined;
var flowrResultHtml = '<div class="panel panel-default"><div id="{{headingId}}" role="tab" class="panel-heading"><h4 class="panel-title"><a data-toggle="collapse" data-parent="#flowrHint" href="#{{collapseId}}" aria-expanded="true" aria-controls="{{collapseId}}"></a></h4></div><div id="{{collapseId}}" role="tabpanel" aria-labelledby="{{headingId}}" class="panel-collapse collapse"><div class="panel-body"></div></div></div>';
var flowrResultHtml = '<div class="panel panel-default"><div id="{{headingId}}" role="tab" class="panel-heading"><h4 class="panel-title"><a data-toggle="collapse" data-parent="#flowrHint" href="#{{collapseId}}" aria-expanded="true" aria-controls="{{collapseId}}"></a></h4></div><div id="{{collapseId}}" role="tabpanel" aria-labelledby="{{headingId}}" class="panel-collapse collapse"><div class="panel-body"></div></div></div>'
var ajax = function(options) {
return $.ajax(_.extend({
@ -91,21 +92,48 @@ $(function() {
var createSubmission = function(initiator, filter, callback) {
showSpinner(initiator);
var annotations = {};
var annotations_arr = [];
var file_ids = [];
$('.editor').each(function(index, element) {
var file_id = $(element).data('id');
var editor = ace.edit(element);
//annotations[file_id] = editor.getSession().getAnnotations();
var cleaned_annotations = editor.getSession().getAnnotations();
for(var i = cleaned_annotations.length-1; i>=0; --i){
cleaned_annotations[i].text = cleaned_annotations[i].text.replace(cleaned_annotations[i].username + ": ", "");
}
annotations_arr = annotations_arr.concat(editor.getSession().getAnnotations());
});
var jqxhr = ajax({
data: {
submission: {
cause: $(initiator).data('cause') || $(initiator).prop('id'),
exercise_id: $('#editor').data('exercise-id'),
files_attributes: (filter || _.identity)(collectFiles())
}
},
source_submission_id: $('.ace_editor',$('#editor'))[0].dataset.id,
//annotations: annotations,
annotations_arr: annotations_arr
},
dataType: 'json',
method: 'POST',
url: $(initiator).data('url') || $('#editor').data('submissions-url')
});
jqxhr.always(hideSpinner);
jqxhr.done(createSubmissionCallback);
jqxhr.done(callback);
jqxhr.fail(ajaxError);
};
var createSubmissionCallback = function(data){
var id = $('.editor').data('id');
};
var destroyFile = function() {
createSubmission($('#destroy-file'), function(files) {
return _.reject(files, function(file) {
@ -141,11 +169,20 @@ $(function() {
event_source.addEventListener('close', handleStderrOutputForFlowr);
}
if (qa_api) {
event_source.addEventListener('close', handleStreamedResponseForCodePilot);
}
event_source.addEventListener('status', function(event) {
showStatus(JSON.parse(event.data));
});
};
var handleStreamedResponseForCodePilot = function(event) {
qa_api.executeCommand('syncOutput', [chunkBuffer]);
chunkBuffer = [{streamedResponse: true}];
}
var evaluateCodeWithoutStreamedResponse = function(url, callback) {
var jqxhr = ajax({
method: 'GET',
@ -221,33 +258,55 @@ $(function() {
showTab(3);
};
var stderrOutput = '';
// activate flowr only for half of the audience
var isFlowrEnabled = parseInt($('#editor').data('user-id'))%2 == 0;
var handleStderrOutputForFlowr = function(event) {
var flowrUrl = $('#flowrHint').data('url');
if (!isFlowrEnabled) return
var json = JSON.parse(event.data);
var stderrOutput = '';
if (json.stderr) {
stderrOutput += json.stderr;
} else if (json.code) {
if (stderrOutput == '') {
return;
}
var flowrUrl = $('#flowrHint').data('url');
var flowrHintBody = $('#flowrHint .panel-body');
var queryParameters = {
query: stderrOutput
}
$.getJSON(flowrUrl + '&query=' + escape(stderrOutput), function(data) {
_.each(_.compact(data.queryResults), function(question, index) {
var collapsibleTileHtml = flowrResultHtml.replace(/{{collapseId}}/g, 'collapse-' + index).replace(/{{headingId}}/g, 'heading-' + index);
flowrHintBody.empty();
jQuery.getJSON(flowrUrl, queryParameters, function(data) {
for (var question in data.queryResults) {
var collapsibleTileHtml = flowrResultHtml.replace(/{{collapseId}}/g, 'collapse-' + question).replace(/{{headingId}}/g, 'heading-' + question);
var resultTile = $(collapsibleTileHtml);
resultTile.find('h4 > a').text(question.title);
resultTile.find('.panel-body').append(question.body);
flowrHintBody.append(resultTile);
});
$('#flowrHint').fadeIn();
});
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').append('<a href="' + data.queryResults[question].url + '" class="btn btn-primary btn-block">Open this question</a>');
flowrHintBody.append(resultTile);
}
if (data.queryResults.length !== 0) {
$('#flowrHint').fadeIn();
}
})
stderrOutput = '';
}
};
var handleTestResponse = function(response) {
clearOutput();
printOutput(response[0], false, 0);
if (qa_api) {
qa_api.executeCommand('syncOutput', [response]);
}
showStatus(response[0]);
showTab(2);
};
@ -260,6 +319,19 @@ $(function() {
var initializeEditors = function() {
$('.editor').each(function(index, element) {
var editor = ace.edit(element);
if (qa_api) {
editor.getSession().on("change", function (deltaObject) {
qa_api.executeCommand('syncEditor', [active_file, deltaObject]);
});
}
var document = editor.getSession().getDocument();
// insert pre-existing code into editor. we have to use insertLines, otherwise the deltas are not properly added
var file_id = $(element).data('file-id');
var content = $('.editor-content[data-file-id=' + file_id + ']');
setActiveFile($(element).parent().data('filename'), file_id);
document.insertLines(0, content.text().split(/\n/));
editor.setReadOnly($(element).data('read-only') !== undefined);
editor.setShowPrintMargin(false);
editor.setTheme(THEME);
@ -269,9 +341,168 @@ $(function() {
session.setTabSize($(element).data('indent-size'));
session.setUseSoftTabs(true);
session.setUseWrapMode(true);
var file_id = $(element).data('id');
setAnnotations(editor, file_id);
session.on('annotationRemoval', handleAnnotationRemoval);
session.on('annotationChange', handleAnnotationChange);
// TODO refactor here
// Code for clicks on gutter / sidepanel
editor.on("guttermousedown", function(e){
var target = e.domEvent.target;
if (target.className.indexOf("ace_gutter-cell") == -1) return;
if (!editor.isFocused()) return;
if (e.clientX > 25 + target.getBoundingClientRect().left) return;
var row = e.getDocumentPosition().row;
e.stop();
var commentModal = $('#comment-modal');
if (hasCommentsInRow(editor, row)) {
var rowComments = getCommentsForRow(editor, row);
var comments = _.pluck(rowComments, 'text').join('\n');
commentModal.find('#other-comments').text(comments);
} else {
commentModal.find('#other-comments').text('none');
}
commentModal.find('#addCommentButton').off('click');
commentModal.find('#removeAllButton').off('click');
commentModal.find('#addCommentButton').on('click', function(e){
var user_id = $(element).data('user-id');
var commenttext = commentModal.find('textarea').val();
if (commenttext !== "") {
createComment(user_id, file_id, row, editor, commenttext);
commentModal.modal('hide');
}
})
commentModal.find('#removeAllButton').on('click', function(e){
var user_id = $(element).data('user-id');
deleteComment(user_id,file_id,row,editor);
commentModal.modal('hide');
})
commentModal.modal('show');
});
});
};
var hasCommentsInRow = function (editor, row){
return editor.getSession().getAnnotations().some(function(element) {
return element.row === row;
})
}
var getCommentsForRow = function (editor, row){
return editor.getSession().getAnnotations().filter(function(element) {
return element.row === row;
})
}
var setAnnotations = function (editor, file_id){
var session = editor.getSession();
var url = "/comments";
var jqrequest = $.ajax({
dataType: 'json',
method: 'GET',
url: url,
data: {
file_id: file_id
}
});
jqrequest.done(function(response){
setAnnotationsCallback(response, session);
});
jqrequest.fail(ajaxError);
}
var setAnnotationsCallback = function (response, session) {
var annotations = response;
$.each(annotations, function(index, comment){
comment.className = "code-ocean_comment";
comment.text = comment.username + ": " + comment.text;
// comment.text = comment.user_id + ": " + comment.text;
});
session.setAnnotations(annotations);
}
var deleteComment = function (user_id, file_id, row, editor) {
var jqxhr = $.ajax({
type: 'DELETE',
url: "/comments",
data: {
row: row,
file_id: file_id,
user_id: user_id
}
});
jqxhr.done(function (response) {
setAnnotations(editor, file_id);
});
jqxhr.fail(ajaxError);
}
var createComment = function (user_id, file_id, row, editor, commenttext){
var jqxhr = $.ajax({
data: {
comment: {
user_id: user_id,
file_id: file_id,
row: row,
column: 0,
text: commenttext
}
},
dataType: 'json',
method: 'POST',
url: "/comments"
});
jqxhr.done(function(response){
setAnnotations(editor, file_id);
});
jqxhr.fail(ajaxError);
}
var handleAnnotationRemoval = function(removedAnnotations) {
removedAnnotations.forEach(function(annotation) {
$.ajax({
method: 'DELETE',
url: '/comment_by_id',
data: {
id: annotation.id,
}
})
})
}
var handleAnnotationChange = function(changedAnnotations) {
changedAnnotations.forEach(function(annotation) {
$.ajax({
method: 'PUT',
url: '/comments',
data: {
id: annotation.id,
user_id: $('#editor').data('user-id'),
comment: {
row: annotation.row,
text: annotation.text
}
}
})
})
}
var initializeEventHandlers = function() {
$(document).on('click', '#results a', showOutput);
$(document).on('keypress', handleKeyPress);
@ -298,6 +529,7 @@ $(function() {
$('#create-file').on('click', showFileDialog);
$('#destroy-file').on('click', confirmDestroy);
$('#download').on('click', downloadCode);
$('#request-for-comments').on('click', requestComments);
};
var initializeTooltips = function() {
@ -323,6 +555,13 @@ $(function() {
return 'executable' in active_frame.data();
};
var setActiveFile = function (filename, fileId) {
active_file = {
filename: filename,
id: fileId
};
}
var isActiveFileRenderable = function() {
return 'renderable' in active_frame.data();
};
@ -355,10 +594,17 @@ $(function() {
panel.find('.row .col-sm-9').eq(3).find('a').attr('href', '#output-' + index);
};
var chunkBuffer = [{streamedResponse: true}];
var printChunk = function(event) {
var output = JSON.parse(event.data);
if (output) {
printOutput(output, true, 0);
printOutput(output, true, 0);
// send test response to QA
// we are expecting an array of outputs:
if (qa_api) {
chunkBuffer.push(output);
}
} else {
clearOutput();
$('#hint').fadeOut();
@ -405,6 +651,10 @@ $(function() {
})) {
showTimeoutMessage();
}
if (qa_api) {
// send test response to QA
qa_api.executeCommand('syncOutput', [response]);
}
};
var renderCode = function(event) {
@ -419,7 +669,7 @@ $(function() {
printOutput({
stderr: message
}, true, 0);
sendError(message);
sendError(message, response.id);
showTab(2);
};
}
@ -494,12 +744,13 @@ $(function() {
});
};
var sendError = function(message) {
var sendError = function(message, submission_id) {
showSpinner($('#render'));
var jqxhr = ajax({
data: {
error: {
message: message
message: message,
submission_id: submission_id
}
},
url: $('#editor').data('errors-url')
@ -528,10 +779,7 @@ $(function() {
var showFirstFile = function() {
var frame = $('.frame[data-role="main_file"]').isPresent() ? $('.frame[data-role="main_file"]') : $('.frame').first();
var file_id = frame.find('.editor').data('file-id');
active_file = {
filename: frame.data('filename'),
id: file_id
};
setActiveFile(frame.data('filename'), file_id);
$('#files').jstree().select_node(file_id);
showFrame(frame);
toggleButtonStates();
@ -667,19 +915,55 @@ $(function() {
$('#test').toggle(isActiveFileTestable());
};
if ($('#editor').isPresent()) {
if (isBrowserSupported()) {
$('.score, #development-environment').show();
configureEditors();
initializeEditors();
initializeEventHandlers();
initializeFileTree();
initializeTooltips();
renderScore();
showFirstFile();
showRequestedTab();
} else {
$('#alert').show();
var requestComments = function(e) {
var user_id = $('#editor').data('user-id')
var exercise_id = $('#editor').data('exercise-id')
var file_id = $('.editor').data('id')
$.ajax({
method: 'POST',
url: '/request_for_comments',
data: {
request_for_comment: {
requestorid: user_id,
exerciseid: exercise_id,
fileid: file_id,
"requested_at(1i)": 2015,
"requested_at(2i)":3,
"requested_at(3i)":27,
"requested_at(4i)":17,
"requested_at(5i)":06
}
}
})
}
var initializeCodePilot = function() {
if ($('#questions-column').isPresent() && QaApi.isBrowserSupported()) {
$('#editor-column').addClass('col-md-8').removeClass('col-md-10');
$('#questions-column').addClass('col-md-3');
var node = document.getElementById('questions-holder');
var url = $('#questions-holder').data('url');
qa_api = new QaApi(node, url);
}
}
if ($('#editor').isPresent()) {
if (isBrowserSupported()) {
initializeCodePilot();
$('.score, #development-environment').show();
configureEditors();
initializeEditors();
initializeEventHandlers();
initializeFileTree();
initializeTooltips();
renderScore();
showFirstFile();
showRequestedTab();
} else {
$('#alert').show();
}
}
});

View File

@ -1,5 +1,10 @@
h1 {
margin-bottom: 1em;
font-size: 25px;
margin-bottom: 0.5em;
}
.lead {
font-size: 16px;
}
i.fa {

View File

@ -0,0 +1,8 @@
// Place all the styles related to the Comments controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
.ace_gutter-cell.code-ocean_comment {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wIUDTMn077U+gAAANhJREFUOMvV0jFOQkEURuEPfCFKaChwASQWhsIOaxYgW7Ci0c4VuBBM6GmsWIC2JsbCykJiRSD0GMVHMy+ZTPSBlfHvZu7NyZ1zh79O5Zu7Bi7RRz30TDHC7TbACB1UkSe1Kt5xg2FxuRc1jHFcMm0e+k/xgceCCmc4wtcOz17jCs0YMMDnL9ytcBgDVj8ILZO/jgHXiY9t2cdbLHGBFk4KcklqYcXLdAt3wXQ3kVlBhgM84AKvRTFL6O0gM8MTZuH8ggnmZaP18Ix7nO8qI0t+Wi/4yP2bbAA4rSby6Nz4AwAAAABJRU5ErkJggg==");
background-position: 2px center;
}

View File

@ -54,7 +54,7 @@ button i.fa-spin {
}
#files {
overflow: scroll;
overflow: auto;
}
#hint {

View File

@ -0,0 +1,4 @@
#commentitor {
margin-top: 2rem;
height: 600px;
}

View File

@ -0,0 +1,125 @@
class CommentsController < ApplicationController
before_action :set_comment, only: [:show, :edit, :update, :destroy_by_id]
# to disable authorization check: comment the line below back in
# skip_after_action :verify_authorized
def authorize!
authorize(@comment || @comments)
end
private :authorize!
# GET /comments
# GET /comments.json
def index
#@comments = Comment.all
#if admin, show all comments.
#check whether user is the author of the passed file_id, if so, show all comments. otherwise, only show comments of auther and own comments
file = CodeOcean::File.find(params[:file_id])
submission = Submission.find(file.context_id)
is_admin = false
if current_user.respond_to? :external_id
user_id = current_user.external_id
else
user_id = current_user.id
is_admin = current_user.role == 'admin'
end
if(is_admin || user_id == submission.user_id)
# fetch all comments for this file
@comments = Comment.where(file_id: params[:file_id])
else
@comments = Comment.where(file_id: params[:file_id], user_id: user_id)
end
#@comments = Comment.where(file_id: params[:file_id])
#add names to comments
@comments.map{|comment| comment.username = Xikolo::UserClient.get(comment.user_id.to_s)[:display_name]}
authorize!
end
# GET /comments/1
# GET /comments/1.json
def show
authorize!
end
# GET /comments/new
def new
@comment = Comment.new
authorize!
end
# GET /comments/1/edit
def edit
authorize!
end
# POST /comments
# POST /comments.json
def create
@comment = Comment.new(comment_params.merge(user_type: 'InternalUser'))
respond_to do |format|
if @comment.save
format.html { redirect_to @comment, notice: 'Comment was successfully created.' }
format.json { render :show, status: :created, location: @comment }
else
format.html { render :new }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
end
authorize!
end
# PATCH/PUT /comments/1
# PATCH/PUT /comments/1.json
def update
respond_to do |format|
if @comment.update(comment_params)
format.html { head :no_content, notice: 'Comment was successfully updated.' }
format.json { render :show, status: :ok, location: @comment }
else
format.html { render :edit }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
end
authorize!
end
# DELETE /comments/1
# DELETE /comments/1.json
def destroy_by_id
@comment.destroy
respond_to do |format|
format.html { head :no_content, notice: 'Comment was successfully destroyed.' }
format.json { head :no_content }
end
end
def destroy
@comments = Comment.where(file_id: params[:file_id], row: params[:row])
@comments.delete_all
respond_to do |format|
#format.html { redirect_to comments_url, notice: 'Comments were successfully destroyed.' }
format.html { head :no_content, notice: 'Comments were successfully destroyed.' }
format.json { head :no_content }
end
authorize!
end
private
# Use callbacks to share common setup or constraints between actions.
def set_comment
@comment = Comment.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def comment_params
#params.require(:comment).permit(:user_id, :file_id, :row, :column, :text)
# fuer production mode, damit böse menschen keine falsche user_id uebergeben:
params.require(:comment).permit(:file_id, :row, :column, :text).merge(user_id: current_user.id)
end
end

View File

@ -22,7 +22,7 @@ class ErrorsController < ApplicationController
end
def error_params
params[:error].permit(:message).merge(execution_environment_id: @execution_environment.id)
params[:error].permit(:message, :submission_id).merge(execution_environment_id: @execution_environment.id)
end
private :error_params

View File

@ -86,6 +86,12 @@ class ExercisesController < ApplicationController
@submission = current_user.submissions.where(exercise_id: @exercise.id).order('created_at DESC').first
@files = (@submission ? @submission.collect_files : @exercise.files).select(&:visible).sort_by(&:name_with_extension)
@paths = collect_paths(@files)
if current_user.respond_to? :external_id
@user_id = current_user.external_id
else
@user_id = current_user.id
end
end
def index

View File

@ -0,0 +1,94 @@
class RequestForCommentsController < ApplicationController
before_action :set_request_for_comment, only: [:show, :edit, :update, :destroy]
skip_after_action :verify_authorized
def authorize!
authorize(@request_for_comments || @request_for_comment)
end
private :authorize!
# GET /request_for_comments
# GET /request_for_comments.json
def index
# @request_for_comments = RequestForComment.all
@request_for_comments = RequestForComment.all.order('created_at DESC').limit(50)
authorize!
end
# GET /request_for_comments/1
# GET /request_for_comments/1.json
def show
authorize!
end
# GET /request_for_comments/new
def new
@request_for_comment = RequestForComment.new
authorize!
end
# GET /request_for_comments/1/edit
def edit
end
# POST /request_for_comments
# POST /request_for_comments.json
def create
file = CodeOcean::File.find(request_for_comment_params[:fileid])
# get newest version of the file. this method is only called if there is at least one submission (prevented in frontend otherwise)
# find newest submission for that exercise and user, use the file with the same filename for that.
# this is necessary because the passed params are not up to date since the data attributes are not updated upon submission creation.
# if we stat from the template, the context type is exercise. we find the newest submission based on the context_id and the current_user.id
if(file.context_type =='Exercise')
newest_submission = Submission.where(exercise_id: file.context_id, user_id: current_user.id).order('created_at DESC').first
else
# else we start from a submission. we find it it by the given context_id and retrieve the newest submission with the info of the known submission.
submission = Submission.find(file.context_id)
newest_submission = Submission.where(exercise_id: submission.exercise_id, user_id: submission.user_id).order('created_at DESC').first
end
newest_file = CodeOcean::File.where(context_id: newest_submission.id, name: file.name).first
#finally, correct the fileid and create the request for comment
request_for_comment_params[:fileid]=newest_file.id
@request_for_comment = RequestForComment.new(request_for_comment_params)
respond_to do |format|
if @request_for_comment.save
format.json { render :show, status: :created, location: @request_for_comment }
else
format.html { render :new }
format.json { render json: @request_for_comment.errors, status: :unprocessable_entity }
end
end
authorize!
end
# DELETE /request_for_comments/1
# DELETE /request_for_comments/1.json
def destroy
@request_for_comment.destroy
respond_to do |format|
format.html { redirect_to request_for_comments_url, notice: 'Request for comment was successfully destroyed.' }
format.json { head :no_content }
end
authorize!
end
private
# Use callbacks to share common setup or constraints between actions.
def set_request_for_comment
@request_for_comment = RequestForComment.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def request_for_comment_params
params.require(:request_for_comment).permit(:requestorid, :exerciseid, :fileid, :requested_at)
end
end

View File

@ -20,9 +20,32 @@ class SubmissionsController < ApplicationController
def create
@submission = Submission.new(submission_params)
authorize!
copy_comments
create_and_respond(object: @submission)
end
def copy_comments
# copy each annotation and set the target_file.id
unless(params[:annotations_arr].nil?)
params[:annotations_arr].each do | annotation |
comment = Comment.new(:user_id => annotation[1][:user_id], :file_id => annotation[1][:file_id], :user_type => 'InternalUser', :row => annotation[1][:row], :column => annotation[1][:column], :text => annotation[1][:text])
source_file = CodeOcean::File.find(annotation[1][:file_id])
#comment = Comment.new(annotation[1].permit(:user_id, :file_id, :user_type, :row, :column, :text, :created_at, :updated_at))
target_file = @submission.files.detect do |file|
# file_id has to be that of a the former iteration OR of the initial file (if this is the first run)
file.file_id == source_file.file_id || file.file_id == source_file.id #seems to be needed here: (check this): || file.file_id == source_file.id
end
#save to assign an id
target_file.save!
comment.file_id = target_file.id
comment.save!
end
end
end
def download_file
if @file.native_file?
send_file(@file.native_file.path)

View File

@ -2,4 +2,17 @@ module ExerciseHelper
def embedding_parameters(exercise)
"locale=#{I18n.locale}&token=#{exercise.token}"
end
def qa_js_tag
javascript_include_tag qa_url + "/assets/qa_api.js"
end
def qa_url
config = CodeOcean::Config.new(:code_ocean)
enabled = config.read[:code_pilot][:enabled]
if enabled
config.read[:code_pilot][:url]
end
end
end

View File

@ -0,0 +1,2 @@
module RequestForCommentsHelper
end

7
app/models/comment.rb Normal file
View File

@ -0,0 +1,7 @@
class Comment < ActiveRecord::Base
# inherit the creation module: encapsulates that this is a polymorphic user, offers some aliases and makes sure that all necessary attributes are set.
include Creation
attr_accessor :username
belongs_to :file, class: CodeOcean::File
end

View File

@ -0,0 +1,7 @@
class RequestForComment < ActiveRecord::Base
before_create :set_requested_timestamp
def set_requested_timestamp
self.requested_at = Time.now
end
end

View File

@ -0,0 +1,22 @@
class CommentPolicy < ApplicationPolicy
def author?
@user == @record.author
end
private :author?
def create?
everyone
end
[:new?, :show?, :destroy?].each do |action|
define_method(action) { admin? || author? }
end
def edit?
admin?
end
def index?
everyone
end
end

View File

@ -0,0 +1,23 @@
class RequestForCommentPolicy < ApplicationPolicy
def create?
everyone
end
def show?
everyone
end
[:destroy?].each do |action|
define_method(action) { admin? }
end
def edit?
admin?
end
def index?
everyone
end
end

View File

@ -0,0 +1,37 @@
<%= form_for(@comment) do |f| %>
<% if @comment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
<ul>
<% @comment.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :user_id %><br>
<%= f.text_field :user_id %>
</div>
<div class="field">
<%= f.label :file_id %><br>
<%= f.text_field :file_id %>
</div>
<div class="field">
<%= f.label :row %><br>
<%= f.number_field :row %>
</div>
<div class="field">
<%= f.label :column %><br>
<%= f.number_field :column %>
</div>
<div class="field">
<%= f.label :text %><br>
<%= f.text_field :text %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@ -0,0 +1,6 @@
<h1>Editing comment</h1>
<%= render 'form' %>
<%= link_to 'Show', @comment %> |
<%= link_to 'Back', comments_path %>

View File

@ -0,0 +1,33 @@
<h1>Listing comments</h1>
<table>
<thead>
<tr>
<th>User</th>
<th>File</th>
<th>Row</th>
<th>Column</th>
<th>Text</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @comments.each do |comment| %>
<tr>
<td><%= comment.user %></td>
<td><%= comment.file %></td>
<td><%= comment.row %></td>
<td><%= comment.column %></td>
<td><%= comment.text %></td>
<td><%= link_to 'Show', comment %></td>
<td><%= link_to 'Edit', edit_comment_path(comment) %></td>
<td><%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Comment', new_comment_path %>

View File

@ -0,0 +1,4 @@
json.array!(@comments) do |comment|
json.extract! comment, :id, :user_id, :file_id, :row, :column, :text, :username
json.url comment_url(comment, format: :json)
end

View File

@ -0,0 +1,5 @@
<h1>New comment</h1>
<%= render 'form' %>
<%= link_to 'Back', comments_path %>

View File

@ -0,0 +1,29 @@
<p id="notice"><%= notice %></p>
<p>
<strong>User:</strong>
<%= @comment.user %>
</p>
<p>
<strong>File:</strong>
<%= @comment.file %>
</p>
<p>
<strong>Row:</strong>
<%= @comment.row %>
</p>
<p>
<strong>Column:</strong>
<%= @comment.column %>
</p>
<p>
<strong>Text:</strong>
<%= @comment.text %>
</p>
<%= link_to 'Edit', edit_comment_path(@comment) %> |
<%= link_to 'Back', comments_path %>

View File

@ -0,0 +1 @@
json.extract! @comment, :id, :user_id, :file_id, :row, :column, :text, :created_at, :updated_at

View File

@ -0,0 +1,9 @@
h5 =t('exercises.implement.comment.others')
pre#other-comments
h5 =t('exercises.implement.comment.addyours')
textarea.form-control(style='resize:none;')
p = ''
button#addCommentButton.btn.btn-block.btn-primary(type='button') =t('exercises.implement.comment.addComment')
button#removeAllButton.btn.btn-block.btn-warning(type='button') =t('exercises.implement.comment.removeAllOnLine')

View File

@ -1,4 +1,4 @@
#editor.row data-exercise-id=exercise.id data-message-timeout=t('exercises.editor.timeout', permitted_execution_time: @exercise.execution_environment.permitted_execution_time) data-errors-url=execution_environment_errors_path(exercise.execution_environment) data-submissions-url=submissions_path
#editor.row data-exercise-id=exercise.id data-message-timeout=t('exercises.editor.timeout', permitted_execution_time: @exercise.execution_environment.permitted_execution_time) data-errors-url=execution_environment_errors_path(exercise.execution_environment) data-submissions-url=submissions_path data-user-id=@current_user.id
.col-sm-3 = render('editor_file_tree', files: @files)
#frames.col-sm-9
- @files.each do |file|
@ -33,3 +33,5 @@
i.fa.fa-rocket
= t('exercises.editor.test')
= render('editor_button', data: {:'data-placement' => 'top', :'data-tooltip' => true}, icon: 'fa fa-trophy', id: 'assess', label: t('exercises.editor.score'), title: t('shared.tooltips.shortcut', shortcut: 'ALT + s'))
= render('shared/modal', id: 'comment-modal', title: t('exercises.implement.comment.dialogtitle'), template: 'exercises/_comment_dialogcontent')

View File

@ -5,5 +5,6 @@ hr
= render('editor_button', classes: 'btn-block btn-primary btn-xs', data: {:'data-cause' => 'file'}, icon: 'fa fa-plus', id: 'create-file', label: t('exercises.editor.create_file'))
= render('editor_button', classes: 'btn-block btn-warning btn-xs', data: {:'data-cause' => 'file', :'data-message-confirm' => t('shared.confirm_destroy')}, icon: 'fa fa-times', id: 'destroy-file', label: t('exercises.editor.destroy_file'))
= render('editor_button', classes: 'btn-block btn-primary btn-xs', icon: 'fa fa-download', id: 'download', label: t('exercises.editor.download'))
= render('editor_button', classes: 'btn-block btn-primary btn-xs', icon: 'fa fa-bullhorn', id: 'request-for-comments', label: 'Request comments')
= render('shared/modal', id: 'modal-file', template: 'code_ocean/files/_form', title: t('exercises.editor.create_file'))

View File

@ -11,4 +11,5 @@
- else
= link_to(file.native_file.file.name_with_extension, file.native_file.url)
- else
.editor data-file-id=file.ancestor_id data-indent-size=file.file_type.indent_size data-mode=file.file_type.editor_mode data-read-only=file.read_only = file.content
.editor-content.hidden data-file-id=file.ancestor_id = file.content
.editor data-file-id=file.ancestor_id data-indent-size=file.file_type.indent_size data-mode=file.file_type.editor_mode data-read-only=file.read_only data-id=file.id

View File

@ -1,73 +1,79 @@
h1 = @exercise
.row
#editor-column.col-md-10.col-md-offset-1
h1 = @exercise
span.badge.pull-right.score
span.badge.pull-right.score
p.lead = @exercise.description
p.lead = @exercise.description
#alert.alert.alert-danger role='alert'
h4 = t('.alert.title')
p = t('.alert.text', application_name: application_name)
#alert.alert.alert-danger role='alert'
h4 = t('.alert.title')
p = t('.alert.text', application_name: application_name)
#development-environment
ul.nav.nav-justified.nav-tabs role='tablist'
li.active
a data-placement='top' data-toggle='tab' data-tooltip=true href='#instructions' role='tab' title=t('shared.tooltips.shortcut', shortcut: 'ALT + 1')
i.fa.fa-question
= t('activerecord.attributes.exercise.instructions')
li
a data-placement='top' data-toggle='tab' data-tooltip=true href='#workspace' role='tab' title=t('shared.tooltips.shortcut', shortcut: 'ALT + 2')
i.fa.fa-code
= t('.workspace')
li
a data-placement='top' data-toggle='tab' data-tooltip=true href='#outputInformation' role='tab' title=t('shared.tooltips.shortcut', shortcut: 'ALT + 3')
i.fa.fa-terminal
= t('.output')
li
a data-placement='top' data-toggle='tab' data-tooltip=true href='#progress' role='tab' title=t('shared.tooltips.shortcut', shortcut: 'ALT + 4')
i.fa.fa-line-chart
= t('.progress')
#development-environment
ul.nav.nav-justified.nav-tabs role='tablist'
li.active
a data-placement='top' data-toggle='tab' data-tooltip=true href='#instructions' role='tab' title=t('shared.tooltips.shortcut', shortcut: 'ALT + 1')
i.fa.fa-question
= t('activerecord.attributes.exercise.instructions')
li
a data-placement='top' data-toggle='tab' data-tooltip=true href='#workspace' role='tab' title=t('shared.tooltips.shortcut', shortcut: 'ALT + 2')
i.fa.fa-code
= t('.workspace')
li
a data-placement='top' data-toggle='tab' data-tooltip=true href='#outputInformation' role='tab' title=t('shared.tooltips.shortcut', shortcut: 'ALT + 3')
i.fa.fa-terminal
= t('.output')
li
a data-placement='top' data-toggle='tab' data-tooltip=true href='#progress' role='tab' title=t('shared.tooltips.shortcut', shortcut: 'ALT + 4')
i.fa.fa-line-chart
= t('.progress')
hr
hr
.tab-content
#instructions.tab-pane.active
p = render_markdown(@exercise.instructions)
br
p.text-center
a#start.btn.btn-lg.btn-success
i.fa.fa-code
= t('.start')
#workspace.tab-pane = render('editor', exercise: @exercise, files: @files, submission: @submission)
#outputInformation.tab-pane data-message-no-output=t('.no_output')
#hint
.panel.panel-warning
.panel-heading = t('.hint')
.panel-body
#output
pre = t('.no_output_yet')
- if CodeOcean::Config.new(:code_ocean).read[:flowr][:enabled]
#flowrHint.panel.panel-info data-url=CodeOcean::Config.new(:code_ocean).read[:flowr][:url] role='tab'
.panel-heading = 'Gain more insights here'
.panel-body
#progress.tab-pane
#results
h2 = t('.results')
p.test-count == t('.test_count', count: 0)
ul.list-unstyled
ul#dummies.hidden.list-unstyled
li.panel.panel-default
.panel-heading
h3.panel-title == t('.file', filename: '', number: 0)
.panel-body
= row(label: '.passed_tests', value: t('shared.out_of', maximum_value: 0, value: 0).html_safe)
= row(label: 'activerecord.attributes.submission.score', value: t('shared.out_of', maximum_value: 0, value: 0).html_safe)
= row(label: '.feedback')
= row(label: '.output', value: link_to(t('shared.show'), '#'))
#score data-maximum-score=@exercise.maximum_score data-score=@submission.try(:score)
h4
span == "#{t('activerecord.attributes.submission.score')}:&nbsp;"
span.score
.progress
.progress-bar role='progressbar'
br
p.text-center = render('editor_button', classes: 'btn-lg btn-success', data: {:'data-message-confirm' => t('exercises.editor.confirm_submit'), :'data-url' => submit_exercise_path(@exercise)}, icon: 'fa fa-send', id: 'submit', label: t('exercises.editor.submit'))
.tab-content
#instructions.tab-pane.active
p = render_markdown(@exercise.instructions)
br
p.text-center
a#start.btn.btn-lg.btn-success
i.fa.fa-code
= t('.start')
#workspace.tab-pane = render('editor', exercise: @exercise, files: @files, submission: @submission)
#outputInformation.tab-pane data-message-no-output=t('.no_output')
#hint
.panel.panel-warning
.panel-heading = t('.hint')
.panel-body
#output
pre = t('.no_output_yet')
- if CodeOcean::Config.new(:code_ocean).read[:flowr][:enabled]
#flowrHint.panel.panel-info data-url=CodeOcean::Config.new(:code_ocean).read[:flowr][:url] role='tab'
.panel-heading = 'Gain more insights here'
.panel-body
#progress.tab-pane
#results
h2 = t('.results')
p.test-count == t('.test_count', count: 0)
ul.list-unstyled
ul#dummies.hidden.list-unstyled
li.panel.panel-default
.panel-heading
h3.panel-title == t('.file', filename: '', number: 0)
.panel-body
= row(label: '.passed_tests', value: t('shared.out_of', maximum_value: 0, value: 0).html_safe)
= row(label: 'activerecord.attributes.submission.score', value: t('shared.out_of', maximum_value: 0, value: 0).html_safe)
= row(label: '.feedback')
= row(label: '.output', value: link_to(t('shared.show'), '#'))
#score data-maximum-score=@exercise.maximum_score data-score=@submission.try(:score)
h4
span == "#{t('activerecord.attributes.submission.score')}:&nbsp;"
span.score
.progress
.progress-bar role='progressbar'
br
p.text-center = render('editor_button', classes: 'btn-lg btn-success', data: {:'data-message-confirm' => t('exercises.editor.confirm_submit'), :'data-url' => submit_exercise_path(@exercise)}, icon: 'fa fa-send', id: 'submit', label: t('exercises.editor.submit'))
- if qa_url
#questions-column
#questions-holder data-url="#{qa_url}/qa/index/#{@exercise.id}/#{@user_id}"
= qa_js_tag

View File

@ -40,4 +40,4 @@ h1 = Exercise.model_name.human(count: 2)
td = link_to(t('shared.statistics'), statistics_exercise_path(exercise))
= render('shared/pagination', collection: @exercises)
p = render('shared/new_button', model: Exercise)
p = render('shared/new_button', model: Exercise)

View File

@ -34,6 +34,12 @@ html lang='en'
.container data-controller=controller_name
= render('breadcrumbs')
= render('flash')
= yield
- if (controller_name == "exercises" && action_name == "implement")
.container-fluid
= yield
- else
.container
= yield
- template_variables = {execution_environment: @exercise.execution_environment} if action_name == 'implement'
= render('shared/modal', classes: 'modal-lg', id: 'modal-help', template: 'application/help', template_variables: template_variables, title: t('shared.help.headline'))

View File

@ -0,0 +1,33 @@
<%= form_for(@request_for_comment) do |f| %>
<% if @request_for_comment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@request_for_comment.errors.count, "error") %> prohibited this request_for_comment from being saved:</h2>
<ul>
<% @request_for_comment.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :requestorid %><br>
<%= f.number_field :requestorid %>
</div>
<div class="field">
<%= f.label :exerciseid %><br>
<%= f.number_field :exerciseid %>
</div>
<div class="field">
<%= f.label :fileid %><br>
<%= f.number_field :fileid %>
</div>
<div class="field">
<%= f.label :requested_at %><br>
<%= f.datetime_select :requested_at %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@ -0,0 +1,12 @@
<h1><%= t('exercises.implement.comment.listing') %></h1>
<div class="list-group">
<% @request_for_comments.each do |request_for_comment| %>
<a href="<%= request_for_comment_path(request_for_comment) %>" class="list-group-item">
<h4 class="list-group-item-heading"><%= Exercise.find(request_for_comment.exerciseid) %></h4>
<p class="list-group-item-text">
<%= InternalUser.find(request_for_comment.requestorid) %> | <%= request_for_comment.requested_at %>
</p>
</a>
<% end %>
</div>

View File

@ -0,0 +1,4 @@
json.array!(@request_for_comments) do |request_for_comment|
json.extract! request_for_comment, :id, :requestorid, :exerciseid, :fileid, :requested_at
json.url request_for_comment_url(request_for_comment, format: :json)
end

View File

@ -0,0 +1,89 @@
<div class="list-group">
<h4 class="list-group-item-heading"><%= Exercise.find(@request_for_comment.exerciseid) %></h4>
<p class="list-group-item-text">
<%= InternalUser.find(@request_for_comment.requestorid) %> | <%= @request_for_comment.requested_at %>
</p>
</div>
<form class="form-inline">
<div class="form-group">
<p style='display:inline-block'><%= t('exercises.implement.comment.line') %></p>
<input type="number" class="form-control" id="lineInput" placeholder="1" required>
</div>
<div class="form-group">
<p style='display:inline-block'><%= t('exercises.implement.comment.a_comment') %></p>
<input type="text" class="form-control" id="commentInput" placeholder="I'd suggest a variable here" required>
</div>
<button id='submitComment' type="submit" class="btn btn-default"><%= t('exercises.implement.comment.addComment') %>!</button>
</form>
<div id='commentitor' class='editor' data-read-only='true' data-file-id='<%=@request_for_comment.fileid%>'>
<%= CodeOcean::File.find(@request_for_comment.fileid).content %>
</div>
<script type="text/javascript">
//(function() {
var commentitor = $('#commentitor');
var userid = commentitor.data('user-id');
var fileid = commentitor.data('file-id');
var lineInput = $('#lineInput');
var commentInput = $('#commentInput');
commentitor = ace.edit(commentitor[0]);
commentitor.setReadOnly(true);
$('#submitComment').click(addComment);
setAnnotations();
function setAnnotations() {
var session = commentitor.getSession()
var jqrequest = $.ajax({
dataType: 'json',
method: 'GET',
url: '/comments',
data: {
file_id: fileid
}
});
jqrequest.done(function(response){
$.each(response, function(index, comment) {
comment.className = "code-ocean_comment"
comment.text = comment.username + ": " + comment.text
})
commentitor.getSession().setAnnotations(response)
})
}
function addComment() {
var line = lineInput.val()
var comment = commentInput.val()
if (line == '' || comment == '') {
return
} else {
line = parseInt(line) - 1
}
var jqxhr = $.ajax({
data: {
comment: {
user_id: userid,
file_id: fileid,
row: line,
column: 0,
text: comment
}
},
dataType: 'json',
method: 'POST',
url: "/comments"
})
jqxhr.done(setAnnotations)
lineInput.val(''); commentInput.val('');
}
//})()
</script>

View File

@ -0,0 +1 @@
json.extract! @request_for_comment, :id, :requestorid, :exerciseid, :fileid, :requested_at, :created_at, :updated_at

View File

@ -1,11 +1,16 @@
default: &default
flowr:
enabled: false
code_pilot:
enabled: false
development:
flowr:
enabled: true
url: http://example.org:3000/api/exceptioninfo?id=&lang=auto
code_pilot:
enabled: false
url: //localhost:3000
production:
<<: *default

View File

@ -1,3 +1,5 @@
test:
flowr:
enabled: false
code_pilot:
enabled: false

View File

@ -209,6 +209,15 @@ de:
start: Mit dem Programmieren beginnen
test_count: '<span class="number">%{count}</span> Test-Dateien wurden ausgeführt.'
workspace: Arbeitsbereich
comment:
a_comment: Kommentar
line: Zeile
dialogtitle: Kommentieren Sie diese Zeile!
others: Andere Kommentare auf dieser Zeile
addyours: Fügen Sie Ihren Kommentar hinzu
addComment: Kommentieren
removeAllOnLine: Alle Kommentare auf dieser Zeile löschen
listing: Die neuesten Kommentaranfragen
index:
clone: Duplizieren
implement: Implementieren

View File

@ -209,6 +209,15 @@ en:
start: Start Coding
test_count: '<span class="number">%{count}</span> test files have been executed.'
workspace: Workspace
comment:
a_comment: comment
line: line
dialogtitle: Comment on this line!
others: Other comments on this line
addyours: Add your comment
addComment: Comment this
removeAllOnLine: Remove all comments on this line
listing: Listing the newest comment requests
index:
clone: Duplicate
implement: Implement

View File

@ -1,6 +1,16 @@
FILENAME_REGEXP = /[\w\.]+/ unless Kernel.const_defined?(:FILENAME_REGEXP)
Rails.application.routes.draw do
resources :request_for_comments
resources :comments, except: [:destroy] do
collection do
delete :destroy
end
end
delete '/comment_by_id', to: 'comments#destroy_by_id'
put '/comments', to: 'comments#update'
root to: 'application#welcome'
namespace :admin do

View File

@ -0,0 +1,14 @@
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.references :user, index: true
t.references :file, index: true
t.string :user_type
t.integer :row
t.integer :column
t.string :text
t.timestamps
end
end
end

View File

@ -0,0 +1,12 @@
class CreateRequestForComments < ActiveRecord::Migration
def change
create_table :request_for_comments do |t|
t.integer :requestorid, :null => false
t.integer :exerciseid, :null => false
t.integer :fileid, :null => false
t.timestamp :requested_at
t.timestamps
end
end
end

View File

@ -0,0 +1,5 @@
class AddSubmissionToError < ActiveRecord::Migration
def change
add_reference :errors, :submission, index: true
end
end

View File

@ -11,11 +11,25 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150317115338) do
ActiveRecord::Schema.define(version: 20150408155923) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "comments", force: true do |t|
t.integer "user_id"
t.integer "file_id"
t.string "user_type"
t.integer "row"
t.integer "column"
t.string "text"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "comments", ["file_id"], name: "index_comments_on_file_id", using: :btree
add_index "comments", ["user_id"], name: "index_comments_on_user_id", using: :btree
create_table "consumers", force: true do |t|
t.string "name"
t.datetime "created_at"
@ -29,8 +43,11 @@ ActiveRecord::Schema.define(version: 20150317115338) do
t.text "message"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "submission_id"
end
add_index "errors", ["submission_id"], name: "index_errors_on_submission_id", using: :btree
create_table "execution_environments", force: true do |t|
t.string "docker_image"
t.string "name"
@ -151,6 +168,15 @@ ActiveRecord::Schema.define(version: 20150317115338) do
add_index "internal_users_teams", ["internal_user_id"], name: "index_internal_users_teams_on_internal_user_id", using: :btree
add_index "internal_users_teams", ["team_id"], name: "index_internal_users_teams_on_team_id", using: :btree
create_table "request_for_comments", force: true do |t|
t.integer "requestorid", null: false
t.integer "exerciseid", null: false
t.integer "fileid", null: false
t.datetime "requested_at"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "submissions", force: true do |t|
t.integer "exercise_id"
t.float "score"

59
lib/xikolo/client.rb Normal file
View File

@ -0,0 +1,59 @@
class Xikolo::Client
def self.get_user(user_id)
params = {:user_id => user_id}
response = get_request(user_profile_url(user_id), params)
if response
return JSON.parse(response)
else
return nil
end
end
def self.user_profile_url(user_id)
return url + 'users/' + user_id
end
def self.post_request(url, params)
begin
return RestClient.post url, params, http_header
rescue
return nil
end
end
def self.get_request(url, params)
begin
return RestClient.get url, {:params => params}.merge(http_header)
rescue
return nil
end
end
def self.http_header
return {:accept => accept, :authorization => token}
end
def self.url
'http://localhost:2000/api/'
end
def self.accept
'application/vnd.xikolo.v1, application/json'
end
def self.token
'Token token="'+Rails.application.config.xikolo[:token]+'"'
end
private
def authenticate_with_user
params = {:email => "admin@openhpi.de", :password => "admin"}
response = post_request(authentication_url, params)
@token = 'Token token="'+JSON.parse(response)['token']+'"'
end
def self.authentication_url
return @url + 'authenticate'
end
end

12
lib/xikolo/user_client.rb Normal file
View File

@ -0,0 +1,12 @@
class Xikolo::UserClient
def self.get(user_id)
user = Xikolo::Client.get_user(user_id)
# return default values if user is not found or if there is a server issue:
if user
return {display_name: user['first_name'], user_visual: user['user_visual'], language: user['language']}
else
return {display_name: "Name" + user_id, user_visual: ActionController::Base.helpers.image_path('default.png'), language: "DE"}
end
end
end

View File

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

File diff suppressed because one or more lines are too long