From b8ec3edef26c5ad84191f047c4aa435f33b57ee1 Mon Sep 17 00:00:00 2001 From: Felix Wolff Date: Fri, 27 Mar 2015 18:10:47 +0100 Subject: [PATCH] Show requests for comments and begin work on a view for executing them --- app/assets/javascripts/editor.js | 35 ++++++++-- app/assets/stylesheets/scaffolds.css.scss | 69 +++++++++++++++++++ .../request_for_comments_controller.rb | 62 +++++++++++++++++ app/helpers/request_for_comments_helper.rb | 2 + app/models/request_for_comment.rb | 7 ++ app/views/exercises/_editor.html.slim | 2 +- .../exercises/_editor_file_tree.html.slim | 1 + app/views/exercises/index.html.slim | 2 +- app/views/request_for_comments/_form.html.erb | 33 +++++++++ app/views/request_for_comments/index.html.erb | 12 ++++ .../request_for_comments/index.json.jbuilder | 4 ++ app/views/request_for_comments/show.html.erb | 9 +++ .../request_for_comments/show.json.jbuilder | 1 + config/routes.rb | 1 + db/schema.rb | 11 ++- 15 files changed, 241 insertions(+), 10 deletions(-) create mode 100644 app/assets/stylesheets/scaffolds.css.scss create mode 100644 app/controllers/request_for_comments_controller.rb create mode 100644 app/helpers/request_for_comments_helper.rb create mode 100644 app/models/request_for_comment.rb create mode 100644 app/views/request_for_comments/_form.html.erb create mode 100644 app/views/request_for_comments/index.html.erb create mode 100644 app/views/request_for_comments/index.json.jbuilder create mode 100644 app/views/request_for_comments/show.html.erb create mode 100644 app/views/request_for_comments/show.json.jbuilder diff --git a/app/assets/javascripts/editor.js b/app/assets/javascripts/editor.js index c5b0f0ad..184e1043 100644 --- a/app/assets/javascripts/editor.js +++ b/app/assets/javascripts/editor.js @@ -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(); diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 00000000..6ec6a8ff --- /dev/null +++ b/app/assets/stylesheets/scaffolds.css.scss @@ -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; + } +} diff --git a/app/controllers/request_for_comments_controller.rb b/app/controllers/request_for_comments_controller.rb new file mode 100644 index 00000000..fc0ab7b0 --- /dev/null +++ b/app/controllers/request_for_comments_controller.rb @@ -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 diff --git a/app/helpers/request_for_comments_helper.rb b/app/helpers/request_for_comments_helper.rb new file mode 100644 index 00000000..f46a73e4 --- /dev/null +++ b/app/helpers/request_for_comments_helper.rb @@ -0,0 +1,2 @@ +module RequestForCommentsHelper +end diff --git a/app/models/request_for_comment.rb b/app/models/request_for_comment.rb new file mode 100644 index 00000000..a22a7246 --- /dev/null +++ b/app/models/request_for_comment.rb @@ -0,0 +1,7 @@ +class RequestForComment < ActiveRecord::Base + before_create :set_requested_timestamp + + def set_requested_timestamp + self.requested_at = Time.now + end +end diff --git a/app/views/exercises/_editor.html.slim b/app/views/exercises/_editor.html.slim index ad637a36..b8450c29 100644 --- a/app/views/exercises/_editor.html.slim +++ b/app/views/exercises/_editor.html.slim @@ -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| diff --git a/app/views/exercises/_editor_file_tree.html.slim b/app/views/exercises/_editor_file_tree.html.slim index cad3c845..36ba8c37 100644 --- a/app/views/exercises/_editor_file_tree.html.slim +++ b/app/views/exercises/_editor_file_tree.html.slim @@ -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')) diff --git a/app/views/exercises/index.html.slim b/app/views/exercises/index.html.slim index 9cc44d32..d6e37ca9 100644 --- a/app/views/exercises/index.html.slim +++ b/app/views/exercises/index.html.slim @@ -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) \ No newline at end of file diff --git a/app/views/request_for_comments/_form.html.erb b/app/views/request_for_comments/_form.html.erb new file mode 100644 index 00000000..a8d037e9 --- /dev/null +++ b/app/views/request_for_comments/_form.html.erb @@ -0,0 +1,33 @@ +<%= form_for(@request_for_comment) do |f| %> + <% if @request_for_comment.errors.any? %> +
+

<%= pluralize(@request_for_comment.errors.count, "error") %> prohibited this request_for_comment from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :requestorid %>
+ <%= f.number_field :requestorid %> +
+
+ <%= f.label :exerciseid %>
+ <%= f.number_field :exerciseid %> +
+
+ <%= f.label :fileid %>
+ <%= f.number_field :fileid %> +
+
+ <%= f.label :requested_at %>
+ <%= f.datetime_select :requested_at %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/request_for_comments/index.html.erb b/app/views/request_for_comments/index.html.erb new file mode 100644 index 00000000..d64d832a --- /dev/null +++ b/app/views/request_for_comments/index.html.erb @@ -0,0 +1,12 @@ +

Listing comment requests

+ +
+ <% @request_for_comments.each do |request_for_comment| %> + +

<%= Exercise.find(request_for_comment.exerciseid) %>

+

+ <%= InternalUser.find(request_for_comment.requestorid) %> | <%= request_for_comment.requested_at %> +

+
+ <% end %> +
diff --git a/app/views/request_for_comments/index.json.jbuilder b/app/views/request_for_comments/index.json.jbuilder new file mode 100644 index 00000000..26b37b67 --- /dev/null +++ b/app/views/request_for_comments/index.json.jbuilder @@ -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 diff --git a/app/views/request_for_comments/show.html.erb b/app/views/request_for_comments/show.html.erb new file mode 100644 index 00000000..5a785a5e --- /dev/null +++ b/app/views/request_for_comments/show.html.erb @@ -0,0 +1,9 @@ +
+

<%= Exercise.find(@request_for_comment.exerciseid) %>

+

+ <%= InternalUser.find(@request_for_comment.requestorid) %> | <%= @request_for_comment.requested_at %> +

+
+ +
+
\ No newline at end of file diff --git a/app/views/request_for_comments/show.json.jbuilder b/app/views/request_for_comments/show.json.jbuilder new file mode 100644 index 00000000..27897168 --- /dev/null +++ b/app/views/request_for_comments/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @request_for_comment, :id, :requestorid, :exerciseid, :fileid, :requested_at, :created_at, :updated_at diff --git a/config/routes.rb b/config/routes.rb index 1645a919..a20b8fef 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 7006b710..e1aed2ef 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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"