diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb
index 781649d38..3324c203e 100644
--- a/app/controllers/admin/base_controller.rb
+++ b/app/controllers/admin/base_controller.rb
@@ -4,10 +4,16 @@ class BaseController < ApplicationController
before_action :require_staff
before_action :load_requested_renewal_request_count
- layout "admin"
+ layout :custom_layout
private
+ def custom_layout
+ return "turbo_rails/frame" if turbo_frame_request?
+
+ "admin"
+ end
+
def require_staff
unless current_user.roles.include?(:staff)
redirect_to root_url, warning: "You do not have access to that page."
diff --git a/app/controllers/admin/items/notes_controller.rb b/app/controllers/admin/items/notes_controller.rb
new file mode 100644
index 000000000..a5f2aaa25
--- /dev/null
+++ b/app/controllers/admin/items/notes_controller.rb
@@ -0,0 +1,58 @@
+module Admin
+ module Items
+ class NotesController < BaseController
+ include ActionView::RecordIdentifier
+
+ before_action :load_item
+
+ def create
+ @note = @item.notes.create(note_params.merge(creator: current_user))
+
+ if @note.save
+ respond_to do |format|
+ format.turbo_stream
+ end
+ else
+ render :new, status: :unprocessable_entity
+ end
+ end
+
+ def update
+ load_note
+
+ if @note.update(note_params)
+ redirect_to [:admin, @item, anchor: dom_id(@note)], status: :see_other
+ else
+ render :edit, status: :unprocessable_entity
+ end
+ end
+
+ def new
+ @note = @item.notes.new
+ end
+
+ def edit
+ load_note
+ end
+
+ def show
+ load_note
+ end
+
+ def destroy
+ load_note
+ @note.destroy!
+ end
+
+ private
+
+ def note_params
+ params.require(:note).permit(:body)
+ end
+
+ def load_note
+ @note = @item.notes.find(params[:id])
+ end
+ end
+ end
+end
diff --git a/app/controllers/admin/items_controller.rb b/app/controllers/admin/items_controller.rb
index 9cde6eb09..86edffc98 100644
--- a/app/controllers/admin/items_controller.rb
+++ b/app/controllers/admin/items_controller.rb
@@ -25,6 +25,7 @@ def index
end
def show
+ @notes = @item.notes.with_all_rich_text
end
def number
diff --git a/app/controllers/admin/members/notes_controller.rb b/app/controllers/admin/members/notes_controller.rb
new file mode 100644
index 000000000..b1474b966
--- /dev/null
+++ b/app/controllers/admin/members/notes_controller.rb
@@ -0,0 +1,58 @@
+module Admin
+ module Members
+ class NotesController < BaseController
+ include ActionView::RecordIdentifier
+
+ before_action :load_member
+
+ def create
+ @note = @member.notes.create(note_params.merge(creator: current_user))
+
+ if @note.save
+ respond_to do |format|
+ format.turbo_stream
+ end
+ else
+ render :new, status: :unprocessable_entity
+ end
+ end
+
+ def update
+ load_note
+
+ if @note.update(note_params)
+ redirect_to [:admin, @member, anchor: dom_id(@note)], status: :see_other
+ else
+ render :edit, status: :unprocessable_entity
+ end
+ end
+
+ def new
+ @note = @member.notes.new
+ end
+
+ def edit
+ load_note
+ end
+
+ def show
+ load_note
+ end
+
+ def destroy
+ load_note
+ @note.destroy!
+ end
+
+ private
+
+ def note_params
+ params.require(:note).permit(:body)
+ end
+
+ def load_note
+ @note = @member.notes.find(params[:id])
+ end
+ end
+ end
+end
diff --git a/app/controllers/admin/notes_controller.rb b/app/controllers/admin/notes_controller.rb
deleted file mode 100644
index 2016652d0..000000000
--- a/app/controllers/admin/notes_controller.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-module Admin
- class NotesController < BaseController
- include ActionView::RecordIdentifier
- include PortalRendering
-
- before_action :load_parent
-
- def create
- @note = @parent.notes.create(note_params.merge(creator: current_user))
-
- if @note.save
- redirect_to [:admin, @parent, anchor: dom_id(@note)], status: :see_other
- else
- render_to_portal "form", locals: {parent: @parent, note: @note}, status: 422
- end
- end
-
- def update
- @note = @parent.notes.find(params[:id])
-
- if @note.update(note_params)
- redirect_to [:admin, @parent, anchor: dom_id(@note)], status: :see_other
- else
- render_to_portal "form", locals: {parent: @parent, note: @note}, status: 422
- end
- end
-
- def new
- @note = @parent.notes.new
- end
-
- def edit
- @note = @parent.notes.find(params[:id])
-
- if @parent.is_a?(Member)
- render "_form", locals: {parent: @parent, note: @note}, status: :see_other
- else
- render_to_portal "form", locals: {parent: @parent, note: @note}
- end
- end
-
- def show
- @note = @parent.notes.find(params[:id])
- render_to_portal "show", locals: {parent: @parent, note: @note}
- end
-
- def destroy
- @parent.notes.find(params[:id]).destroy!
- redirect_to [:admin, @parent], flash: {success: "Note has been deleted."}, status: :see_other
- end
-
- private
-
- def note_params
- params.require(:note).permit(:body)
- end
-
- def load_parent
- if params[:item_id]
- @parent = Item.find(params[:item_id])
- elsif params[:member_id]
- @parent = Member.find(params[:member_id])
- end
- raise ActiveRecord::RecordNotFound unless @parent
- end
- end
-end
diff --git a/app/models/item.rb b/app/models/item.rb
index 1f47348fe..291953ec9 100644
--- a/app/models/item.rb
+++ b/app/models/item.rb
@@ -119,6 +119,10 @@ def self.find_by_complete_number(complete_number)
joins(:borrow_policy).find_by(borrow_policies: {code: code}, number: number.to_i)
end
+ def hello
+ 10
+ end
+
def assign_number
if number.blank?
return unless borrow_policy
diff --git a/app/views/admin/items/notes/_form.html.erb b/app/views/admin/items/notes/_form.html.erb
new file mode 100644
index 000000000..fb7126d4e
--- /dev/null
+++ b/app/views/admin/items/notes/_form.html.erb
@@ -0,0 +1,25 @@
+
+ <%= form_with(model: note, url: [:admin, item, note], builder: SpectreFormBuilder) do |form| %>
+ <%= form.errors %>
+
+ <%= form.rich_text_area :body, label: (note.new_record? ? "Add a note" : "Edit note") %>
+
+ <%= form.actions do %>
+ <%= form.submit class: "btn btn-primary" %>
+
+ or
+ <% if note.new_record? %>
+ <%= link_to "Cancel", [:admin, item], data: {"turbo-frame" => "_top"} %>
+ <% else %>
+ <%= link_to "Cancel", [:admin, item, note] %>
+ <% end %>
+
+ <% end %>
+ <% end %>
+ <% unless note.new_record? %>
+
+ <%= tag.div class: "notes-actions" do %>
+ <%= button_to "Delete Note", [:admin, item, note], method: :delete, class: "btn btn-link", data: { 'turbo-confirm': 'Are you sute you want to delete this note?'} %>
+ <% end %>
+ <% end %>
+
diff --git a/app/views/admin/items/notes/_list.html.erb b/app/views/admin/items/notes/_list.html.erb
new file mode 100644
index 000000000..c3e027613
--- /dev/null
+++ b/app/views/admin/items/notes/_list.html.erb
@@ -0,0 +1,7 @@
+
+ <% @notes.by_creation_date.each do |note| %>
+ <%= render partial: "admin/items/notes/note", locals: { note: note, item: @item } %>
+ <% end %>
+
+
+<%= render partial: "admin/items/notes/new_button", locals: { item: @item } %>
diff --git a/app/views/admin/items/notes/_new_button.html.erb b/app/views/admin/items/notes/_new_button.html.erb
new file mode 100644
index 000000000..b4156a89f
--- /dev/null
+++ b/app/views/admin/items/notes/_new_button.html.erb
@@ -0,0 +1,5 @@
+<%= turbo_frame_tag "new-note" do %>
+ <%= link_to new_admin_item_note_url(item), class: "btn" do %>
+ <%= feather_icon "message-square" %>Add a Note
+ <% end %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/admin/items/notes/_note.html.erb b/app/views/admin/items/notes/_note.html.erb
new file mode 100644
index 000000000..a01ebd266
--- /dev/null
+++ b/app/views/admin/items/notes/_note.html.erb
@@ -0,0 +1,10 @@
+<%= turbo_frame_tag note do %>
+ <%= tag.blockquote class: "note" do %>
+ <%= note.body %>
+
+
+ <%= tag.div class: "notes-actions" do %>
+ <%= link_to "Edit Note", [:edit, :admin, item, note], method: :get, remote: true, class: "btn btn-sm" %>
+ <% end %>
+ <% end %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/admin/items/notes/create.turbo_stream.erb b/app/views/admin/items/notes/create.turbo_stream.erb
new file mode 100644
index 000000000..d1582efd1
--- /dev/null
+++ b/app/views/admin/items/notes/create.turbo_stream.erb
@@ -0,0 +1,11 @@
+
+
+ <%= render partial: "admin/items/notes/note", formats: [:html], locals: { note: @note, item: @item } %>
+
+
+
+
+
+ <%= render partial: "admin/items/notes/new_button", formats: [:html], locals: { item: @item } %>
+
+
\ No newline at end of file
diff --git a/app/views/admin/items/notes/destroy.html.erb b/app/views/admin/items/notes/destroy.html.erb
new file mode 100644
index 000000000..fd05290ab
--- /dev/null
+++ b/app/views/admin/items/notes/destroy.html.erb
@@ -0,0 +1 @@
+<%= turbo_frame_tag @note do %><% end %>
\ No newline at end of file
diff --git a/app/views/admin/items/notes/edit.html.erb b/app/views/admin/items/notes/edit.html.erb
new file mode 100644
index 000000000..1a4719341
--- /dev/null
+++ b/app/views/admin/items/notes/edit.html.erb
@@ -0,0 +1,3 @@
+<%= turbo_frame_tag @note do %>
+ <%= render partial: "form", locals: {note: @note, item: @item} %>
+<% end %>
diff --git a/app/views/admin/items/notes/new.html.erb b/app/views/admin/items/notes/new.html.erb
new file mode 100644
index 000000000..592928914
--- /dev/null
+++ b/app/views/admin/items/notes/new.html.erb
@@ -0,0 +1,3 @@
+<%= turbo_frame_tag "new-note" do %>
+ <%= render partial: "form", locals: {note: @note, item: @item} %>
+<% end %>
diff --git a/app/views/admin/items/notes/show.html.erb b/app/views/admin/items/notes/show.html.erb
new file mode 100644
index 000000000..383612e25
--- /dev/null
+++ b/app/views/admin/items/notes/show.html.erb
@@ -0,0 +1 @@
+<%= render partial: "admin/items/notes/note", locals: { note: @note, item: @item } %>
\ No newline at end of file
diff --git a/app/views/admin/items/show.html.erb b/app/views/admin/items/show.html.erb
index 6b7010c44..3eb518d06 100644
--- a/app/views/admin/items/show.html.erb
+++ b/app/views/admin/items/show.html.erb
@@ -12,5 +12,5 @@
<% end %>
- <%= render partial: "admin/notes/list", locals: {parent: @item} %>
+ <%= render partial: "admin/items/notes/list", locals: { item: @item } %>
<% end %>
diff --git a/app/views/admin/members/_profile.html.erb b/app/views/admin/members/_profile.html.erb
index 5dd6a3e9b..5108ab561 100644
--- a/app/views/admin/members/_profile.html.erb
+++ b/app/views/admin/members/_profile.html.erb
@@ -1,7 +1,7 @@
<% content_for :header do %>
<%= index_header preferred_or_default_name(@member) do %>
<%= link_to "Edit Member", edit_admin_member_path(@member), class: "btn" %>
- <%= link_to "Add Note to Member", new_admin_member_note_path(@member), class: "btn" %>
+ <%= link_to "Add Note to Member", new_admin_member_note_path(@member), class: "btn", data: {turbo_frame: 'new-note'} %>
<%# <%= link_to 'Record Payment', new_admin_member_payment_path(@member), class: "btn" %>
<% end %>
<% end %>
@@ -22,18 +22,9 @@
<% end %>
+
- <% @member.notes.newest_first.each do |note| %>
-
- <%= link_to "Edit Note", [:edit, :admin, @member, note], method: :get, class: "btn btn-sm edit-button" %>
-
- <%= note.body -%>
-
-
- - <%= note.creator.member.preferred_name %>, <%= time_ago_in_words(note.created_at) %> ago
-
-
- <% end %>
+ <%= render partial: "admin/members/notes/list", locals: { member: @member } %>
diff --git a/app/views/admin/members/notes/_form.html.erb b/app/views/admin/members/notes/_form.html.erb
new file mode 100644
index 000000000..46791e24f
--- /dev/null
+++ b/app/views/admin/members/notes/_form.html.erb
@@ -0,0 +1,25 @@
+
+ <%= form_with(model: note, url: [:admin, member, note], builder: SpectreFormBuilder) do |form| %>
+ <%= form.errors %>
+
+ <%= form.rich_text_area :body, label: (note.new_record? ? "Add a note" : "Edit note") %>
+
+ <%= form.actions do %>
+ <%= form.submit class: "btn btn-primary" %>
+
+ or
+ <% if note.new_record? %>
+ <%= link_to "Cancel", [:admin, member], data: {"turbo-frame" => "_top"} %>
+ <% else %>
+ <%= link_to "Cancel", [:admin, member, note] %>
+ <% end %>
+
+ <% end %>
+ <% end %>
+ <% unless note.new_record? %>
+
+ <%= tag.div class: "notes-actions" do %>
+ <%= button_to "Delete Note", [:admin, member, note], method: :delete, class: "btn btn-link", data: { 'turbo-confirm': 'Are you sute you want to delete this note?'} %>
+ <% end %>
+ <% end %>
+
diff --git a/app/views/admin/members/notes/_list.html.erb b/app/views/admin/members/notes/_list.html.erb
new file mode 100644
index 000000000..9d16d4759
--- /dev/null
+++ b/app/views/admin/members/notes/_list.html.erb
@@ -0,0 +1,7 @@
+<%= turbo_frame_tag "new-note" do %><% end %>
+
+
+ <% @member.notes.with_all_rich_text.by_creation_date.each do |note| %>
+ <%= render partial: "admin/members/notes/note", locals: { note: note, member: @member } %>
+ <% end %>
+
\ No newline at end of file
diff --git a/app/views/admin/members/notes/_note.html.erb b/app/views/admin/members/notes/_note.html.erb
new file mode 100644
index 000000000..23d70e4ed
--- /dev/null
+++ b/app/views/admin/members/notes/_note.html.erb
@@ -0,0 +1,10 @@
+<%= turbo_frame_tag note do %>
+ <%= tag.blockquote class: "note" do %>
+ <%= note.body %>
+
+
+ <%= tag.div class: "notes-actions" do %>
+ <%= link_to "Edit Note", [:edit, :admin, member, note], method: :get, remote: true, class: "btn btn-sm" %>
+ <% end %>
+ <% end %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/admin/members/notes/create.turbo_stream.erb b/app/views/admin/members/notes/create.turbo_stream.erb
new file mode 100644
index 000000000..867325df7
--- /dev/null
+++ b/app/views/admin/members/notes/create.turbo_stream.erb
@@ -0,0 +1,11 @@
+
+
+ <%= render partial: "admin/members/notes/note", formats: [:html], locals: { note: @note, member: @member } %>
+
+
+
+
+
+ <%= turbo_frame_tag "new-note" do %><% end %>
+
+
\ No newline at end of file
diff --git a/app/views/admin/members/notes/destroy.html.erb b/app/views/admin/members/notes/destroy.html.erb
new file mode 100644
index 000000000..fd05290ab
--- /dev/null
+++ b/app/views/admin/members/notes/destroy.html.erb
@@ -0,0 +1 @@
+<%= turbo_frame_tag @note do %><% end %>
\ No newline at end of file
diff --git a/app/views/admin/members/notes/edit.html.erb b/app/views/admin/members/notes/edit.html.erb
new file mode 100644
index 000000000..8d450dd79
--- /dev/null
+++ b/app/views/admin/members/notes/edit.html.erb
@@ -0,0 +1,3 @@
+<%= turbo_frame_tag @note do %>
+ <%= render partial: "form", locals: {note: @note, member: @member} %>
+<% end %>
diff --git a/app/views/admin/members/notes/new.html.erb b/app/views/admin/members/notes/new.html.erb
new file mode 100644
index 000000000..2b3bf2c4f
--- /dev/null
+++ b/app/views/admin/members/notes/new.html.erb
@@ -0,0 +1,3 @@
+<%= turbo_frame_tag "new-note" do %>
+ <%= render partial: "form", locals: {note: @note, member: @member} %>
+<% end %>
diff --git a/app/views/admin/members/notes/show.html.erb b/app/views/admin/members/notes/show.html.erb
new file mode 100644
index 000000000..4a34c9de8
--- /dev/null
+++ b/app/views/admin/members/notes/show.html.erb
@@ -0,0 +1 @@
+<%= render partial: "admin/members/notes/note", locals: { note: @note, member: @member } %>
\ No newline at end of file
diff --git a/app/views/admin/notes/_form.html.erb b/app/views/admin/notes/_form.html.erb
deleted file mode 100644
index 1cada8095..000000000
--- a/app/views/admin/notes/_form.html.erb
+++ /dev/null
@@ -1,28 +0,0 @@
-
- <%- note ||= parent.notes.new %>
- <%= form_with(model: note, url: [:admin, parent, note], builder: SpectreFormBuilder) do |form| %>
- <%= form.errors %>
-
- <%= form.rich_text_area :body, label: (note.new_record? ? "Add a note" : "Edit note") %>
-
- <%= form.actions do %>
- <%= form.submit class: "btn btn-primary" %>
- <% if note.new_record? %>
- or
- <%= link_to "Cancel", nil, data: {action: "click->toggle#toggle"} %>
- <% else %>
- <% if parent.is_a?(Item) %>
- or
- <%= link_to "Cancel", [:admin, parent, note], method: :get, remote: true %>
- <% end %>
- <% end %>
-
-
- <% unless note.new_record? %>
- <%= tag.div class: "notes-actions" do %>
- <%= link_to "Delete Note", [:admin, parent, note], method: :delete, remote: true, class: "btn btn-link" %>
- <% end %>
- <% end %>
- <% end %>
- <% end %>
-
diff --git a/app/views/admin/notes/_index.html.erb b/app/views/admin/notes/_index.html.erb
deleted file mode 100644
index ff5993969..000000000
--- a/app/views/admin/notes/_index.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= turbo_frame_tag "admin_item_notes" do %>
- <%= render @notes %>
-<% end %>
\ No newline at end of file
diff --git a/app/views/admin/notes/_list.html.erb b/app/views/admin/notes/_list.html.erb
deleted file mode 100644
index 81deee0a3..000000000
--- a/app/views/admin/notes/_list.html.erb
+++ /dev/null
@@ -1,17 +0,0 @@
-<% parent.notes.by_creation_date.each do |note| %>
- <%= portal do %>
- <%= render partial: "admin/notes/show", locals: {note: note, parent: parent} %>
- <% end %>
-<% end %>
-
-
-
-
-
- <%= portal do %>
- <%= render partial: "admin/notes/form", locals: {parent: parent} %>
- <% end %>
-
-
diff --git a/app/views/admin/notes/_note.html.erb b/app/views/admin/notes/_note.html.erb
deleted file mode 100644
index 42d249699..000000000
--- a/app/views/admin/notes/_note.html.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-
-<%= turbo_frame_tag note do %>
-
- <%= tag.blockquote class: "note" do %>
- <%= note.body %>
-
-
- <%= turbo_frame_tag "add_new_note_form" do %>
- <%= link_to " Edit Note", edit_admin_item_note_path(@item.id, note.id), class: "btn btn-sm" %>
- <% end %>
- <% end %>
-
-<% end %>
\ No newline at end of file
diff --git a/app/views/admin/notes/_show.html.erb b/app/views/admin/notes/_show.html.erb
deleted file mode 100644
index ffbefa636..000000000
--- a/app/views/admin/notes/_show.html.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-<%= tag.blockquote class: "note", id: dom_id(note) do %>
- <%= note.body %>
-
-
- <%= tag.div class: "notes-actions" do %>
- <%= link_to "Edit Note", [:edit, :admin, parent, note], method: :get, remote: true, class: "btn btn-sm" %>
- <% end %>
-
-<% end %>
diff --git a/app/views/admin/notes/new.html.erb b/app/views/admin/notes/new.html.erb
deleted file mode 100644
index b22b77490..000000000
--- a/app/views/admin/notes/new.html.erb
+++ /dev/null
@@ -1 +0,0 @@
-<%= render partial: "form", locals: {parent: @parent, note: @note} %>
diff --git a/config/routes.rb b/config/routes.rb
index 51c9bd9dc..380813da8 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -83,6 +83,7 @@
resource :position, only: :update
end
end
+ resources :notes
if ENV["FEATURE_MAINTENANCE_WORKFLOW"] == "on"
resources :tickets do
scope module: "tickets" do
@@ -97,7 +98,6 @@
resource :loan_history, only: :show
# resource :manual_import, only: [:edit, :update]
- resources :notes
end
resources :loan_summaries, only: :index
resources :loans, only: [:index, :create, :update, :destroy]
@@ -119,8 +119,8 @@
resources :notifications, only: :index
resources :loan_summaries, only: :index
+ resources :notes
end
- resources :notes
end
namespace :reports do