Show requests for comments and begin work on a view for executing them

This commit is contained in:
Felix Wolff
2015-03-27 18:10:47 +01:00
parent de154a6f66
commit b8ec3edef2
15 changed files with 241 additions and 10 deletions

View File

@ -318,7 +318,7 @@ $(function() {
commentModal.find('#removeAllButton').off('click')
commentModal.find('#addCommentButton').on('click', function(e){
var user_id = 18
var user_id = element.data('user-id')
var commenttext = commentModal.find('textarea').val()
if (commenttext !== "") {
@ -328,7 +328,7 @@ $(function() {
})
commentModal.find('#removeAllButton').on('click', function(e){
var user_id = 18;
var user_id = element.data('user-id')
deleteComment(user_id,file_id,row,editor);
commentModal.modal('hide')
})
@ -351,10 +351,7 @@ $(function() {
}
var setAnnotations = function (editor, file_id){
var session = editor.getSession();
// Retrieve comments for file and set them as annotations
var session = editor.getSession()
var url = "/comments";
var jqrequest = $.ajax({
@ -439,7 +436,7 @@ $(function() {
url: '/comments',
data: {
id: annotation.id,
user_id: 18,
user_id: $('#editor').data('user-id'),
comment: {
row: annotation.row,
text: annotation.text
@ -475,6 +472,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() {
@ -833,6 +831,29 @@ $(function() {
$('#test').toggle(isActiveFileTestable());
};
var requestComments = function(e) {
var user_id = $('#editor').data('user-id')
var exercise_id = $('#editor').data('exercise-id')
var file_id = $('.editor').data('file-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
}
}
})
}
if ($('#editor').isPresent()) {
if (isBrowserSupported()) {
$('.score, #development-environment').show();

View File

@ -0,0 +1,69 @@
body {
background-color: #fff;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}
a {
color: #000;
&:visited {
color: #666;
}
&:hover {
color: #fff;
background-color: #000;
}
}
div {
&.field, &.actions {
margin-bottom: 10px;
}
}
#notice {
color: green;
}
.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}
#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff;
}
ul li {
font-size: 12px;
list-style: square;
}
}

View File

@ -0,0 +1,62 @@
class RequestForCommentsController < ApplicationController
before_action :set_request_for_comment, only: [:show, :edit, :update, :destroy]
skip_after_action :verify_authorized
# GET /request_for_comments
# GET /request_for_comments.json
def index
@request_for_comments = RequestForComment.all
end
# GET /request_for_comments/1
# GET /request_for_comments/1.json
def show
end
# GET /request_for_comments/new
def new
@request_for_comment = RequestForComment.new
end
# GET /request_for_comments/1/edit
def edit
end
# POST /request_for_comments
# POST /request_for_comments.json
def create
@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
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
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

@ -0,0 +1,2 @@
module RequestForCommentsHelper
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

@ -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|

View File

@ -5,5 +5,6 @@ hr
= render('editor_button', classes: 'btn-block btn-primary btn-sm', 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-sm', 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-sm', icon: 'fa fa-download', id: 'download', label: t('exercises.editor.download'))
= render('editor_button', classes: 'btn-block btn-primary btn-sm', 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

@ -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

@ -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>Listing comment requests</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,9 @@
<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>
<div id='editor' class='editor' data-read-only='true' data-file-id='<%=@request_for_comment.fileid%>'>
</div>

View File

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

View File

@ -1,6 +1,7 @@
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

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150317115338) do
ActiveRecord::Schema.define(version: 20150327141740) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -165,6 +165,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"