diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 774a5dd6..c270480b 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -44,6 +44,7 @@ class SubmissionsController < ApplicationController comment.save! end end + end def download_file if @file.native_file? diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 00000000..08fe8865 --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,6 @@ +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 + + belongs_to :file, class: CodeOcean::File +end diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb new file mode 100644 index 00000000..e076a741 --- /dev/null +++ b/app/views/comments/_form.html.erb @@ -0,0 +1,37 @@ +<%= form_for(@comment) do |f| %> + <% if @comment.errors.any? %> +
+

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

+ + +
+ <% end %> + +
+ <%= f.label :user_id %>
+ <%= f.text_field :user_id %> +
+
+ <%= f.label :file_id %>
+ <%= f.text_field :file_id %> +
+
+ <%= f.label :row %>
+ <%= f.number_field :row %> +
+
+ <%= f.label :column %>
+ <%= f.number_field :column %> +
+
+ <%= f.label :text %>
+ <%= f.text_field :text %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/comments/edit.html.erb b/app/views/comments/edit.html.erb new file mode 100644 index 00000000..12ea7f96 --- /dev/null +++ b/app/views/comments/edit.html.erb @@ -0,0 +1,6 @@ +

Editing comment

+ +<%= render 'form' %> + +<%= link_to 'Show', @comment %> | +<%= link_to 'Back', comments_path %> diff --git a/app/views/comments/index.html.erb b/app/views/comments/index.html.erb new file mode 100644 index 00000000..f9f83ff8 --- /dev/null +++ b/app/views/comments/index.html.erb @@ -0,0 +1,33 @@ +

Listing comments

+ + + + + + + + + + + + + + + <% @comments.each do |comment| %> + + + + + + + + + + + <% end %> + +
UserFileRowColumnText
<%= comment.user %><%= comment.file %><%= comment.row %><%= comment.column %><%= comment.text %><%= link_to 'Show', comment %><%= link_to 'Edit', edit_comment_path(comment) %><%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Comment', new_comment_path %> diff --git a/app/views/comments/index.json.jbuilder b/app/views/comments/index.json.jbuilder new file mode 100644 index 00000000..84a4cee0 --- /dev/null +++ b/app/views/comments/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@comments) do |comment| + json.extract! comment, :id, :user_id, :file_id, :row, :column, :text + json.url comment_url(comment, format: :json) +end diff --git a/app/views/comments/new.html.erb b/app/views/comments/new.html.erb new file mode 100644 index 00000000..07a754a8 --- /dev/null +++ b/app/views/comments/new.html.erb @@ -0,0 +1,5 @@ +

New comment

+ +<%= render 'form' %> + +<%= link_to 'Back', comments_path %> diff --git a/app/views/comments/show.html.erb b/app/views/comments/show.html.erb new file mode 100644 index 00000000..e6955fa0 --- /dev/null +++ b/app/views/comments/show.html.erb @@ -0,0 +1,29 @@ +

<%= notice %>

+ +

+ User: + <%= @comment.user %> +

+ +

+ File: + <%= @comment.file %> +

+ +

+ Row: + <%= @comment.row %> +

+ +

+ Column: + <%= @comment.column %> +

+ +

+ Text: + <%= @comment.text %> +

+ +<%= link_to 'Edit', edit_comment_path(@comment) %> | +<%= link_to 'Back', comments_path %> diff --git a/app/views/comments/show.json.jbuilder b/app/views/comments/show.json.jbuilder new file mode 100644 index 00000000..621bd9f6 --- /dev/null +++ b/app/views/comments/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @comment, :id, :user_id, :file_id, :row, :column, :text, :created_at, :updated_at