-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create basic UI for saving an annotation
- Loading branch information
Showing
24 changed files
with
348 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class SavedAnnotationsController < ApplicationController | ||
before_action :set_saved_annotation, only: %i[show update destroy] | ||
|
||
def index | ||
authorize SavedAnnotation | ||
@saved_annotations = apply_scopes(policy_scope(SavedAnnotation.all)) | ||
end | ||
|
||
def show; end | ||
|
||
def create | ||
annotation = Annotation.find(params[:from]) | ||
authorize annotation, :show? | ||
@saved_annotation = SavedAnnotation.new(permitted_attributes(SavedAnnotation).merge({ user: current_user, course: annotation.course, exercise: annotation.submission.exercise })) | ||
authorize @saved_annotation | ||
respond_to do |format| | ||
if @saved_annotation.save | ||
annotation.update(saved_annotation: @saved_annotation) | ||
format.json { render :show, status: :created, location: @saved_annotation } | ||
else | ||
format.json { render json: @saved_annotation.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def update | ||
respond_to do |format| | ||
if @saved_annotation.update(args) | ||
format.json { render :show, status: :ok, location: @saved_annotation } | ||
else | ||
format.json { render json: @saved_annotation.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
@saved_annotation.destroy | ||
end | ||
|
||
private | ||
|
||
def set_saved_annotation | ||
@saved_annotation = SavedAnnotation.find(params[:id]) | ||
authorize @saved_annotation | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# == Schema Information | ||
# | ||
# Table name: saved_annotations | ||
# | ||
# id :bigint not null, primary key | ||
# title :string(255) not null | ||
# annotation_text :text(16777215) | ||
# user_id :integer not null | ||
# exercise_id :integer not null | ||
# course_id :integer not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class SavedAnnotation < ApplicationRecord | ||
validates :title, presence: true | ||
validates :annotation_text, presence: true | ||
|
||
belongs_to :user | ||
belongs_to :exercise | ||
belongs_to :course | ||
|
||
has_many :annotations, dependent: :nullify | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class SavedAnnotationPolicy < ApplicationPolicy | ||
class Scope < ApplicationPolicy::Scope | ||
def resolve | ||
if user&.zeus? | ||
scope.all | ||
elsif user | ||
scope.where(user_id: user.id) | ||
else | ||
scope.none | ||
end | ||
end | ||
end | ||
|
||
def index? | ||
user&.a_course_admin? | ||
end | ||
|
||
def create? | ||
record.course_id.present? && user&.course_admin?(record.course) | ||
end | ||
|
||
def show? | ||
record.user_id == user.id | ||
end | ||
|
||
def update? | ||
record.user_id == user.id | ||
end | ||
|
||
def destroy? | ||
record.user_id == user.id | ||
end | ||
|
||
def permitted_attributes | ||
%i[title annotation_text] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<%= form_for(model, html: { class: 'form' }) do |f| %> | ||
<%= hidden_field_tag 'from', nil, id: "save-annotation-from" %> | ||
<div class="field form-group row"> | ||
<%= f.label :title, class: "col-sm-4 col-form-label" %> | ||
<div class="col-sm-8"><%= f.text_field :title, required: true, class: "form-control" %></div> | ||
</div> | ||
<div class="field form-group row"> | ||
<%= f.label :annotation_text, class: "col-sm-4 col-form-label" %> | ||
<div class="col-sm-8"><%= f.text_area :annotation_text, required: true, class: "form-control", rows: "4", id: "save-annotation-text" %></div> | ||
<span class="help-block offset-sm-4 col-sm-8"><%= t ".annotation_text-help_html" %></span> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div class="modal fade" id="save-annotation" tabindex="-1" role="dialog"> | ||
<div class="modal-dialog" role="document"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h4 class="modal-title"><%= t ".title" %></h4> | ||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button> | ||
</div> | ||
<div class="modal-body"> | ||
<%= render 'saved_annotations/form', model: SavedAnnotation.new %> | ||
</div> | ||
<div class="modal-footer"> | ||
<button id="save-annotation-submit" type="button" class="btn btn-primary btn-text"><%= t ".save" %></button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
en: | ||
saved_annotations: | ||
form: | ||
annotation_text-help_html: '<a href="https://docs.dodona.be/en/references/exercise-description/#markdown" target="_blank">Markdown</a> is supported.' | ||
modal: | ||
save: "Save" | ||
title: "Save comment for re-use" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
nl: | ||
saved_annotations: | ||
form: | ||
annotation_text-help_html: '<a href="https://docs.dodona.be/nl/references/exercise-description/#markdown" target="_blank">Markdown</a> wordt ondersteund.' | ||
modal: | ||
save: "Opslaan" | ||
title: "Opmerking opslaan om later te hergebruiken" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class CreateSavedAnnotations < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :saved_annotations do |t| | ||
t.string :title, null: false | ||
t.text :annotation_text, size: :medium | ||
t.integer :user_id, foreign_key: true, type: :integer, null: false | ||
t.references :exercise, foreign_key: { to_table: :activities }, type: :integer, null: false | ||
t.references :course, foreign_key: true, type: :integer, null: false | ||
|
||
t.timestamps | ||
end | ||
|
||
change_table :annotations do |t| | ||
t.references :saved_annotation, foreign_key: true | ||
end | ||
end | ||
end |
Oops, something went wrong.