diff --git a/app.rb b/app.rb index b127fca..09ab729 100644 --- a/app.rb +++ b/app.rb @@ -362,7 +362,7 @@ class App < Sinatra::Base if @record.notes.create!(body: params[:body]) flash[:success] = "Note added successfully." else - flash[:danger] = "Something went wrong!" + flash[:danger] = "Failed to create Note." end redirect "/db/#{name}/#{params[:id]}" diff --git a/public/javascript/notes.js b/public/javascript/notes.js new file mode 100644 index 0000000..183a320 --- /dev/null +++ b/public/javascript/notes.js @@ -0,0 +1,28 @@ +const Notes = { + init() { + (document.querySelectorAll('.delete-note') || []).forEach(button => { + button.addEventListener('click', () => { + const noteId = button.getAttribute('data-note-id'); + Notes.delete(noteId, button) + }); + }); + }, + + delete(noteId, button) { + fetch(`${document.location}/notes/${noteId}`, { + method: 'DELETE' + }) + .then(response => { + if (response.ok) { + button.parentElement.parentElement.remove(); + } else { + console.error('Failed to delete note'); + } + }) + .catch(error => { + console.error('Error:', error); + }); + } +}; + +ready(Notes.init); diff --git a/views/_notes.erb b/views/_notes.erb index 2fec729..ef5199c 100644 --- a/views/_notes.erb +++ b/views/_notes.erb @@ -1,4 +1,6 @@ -<% if notes.present? %> + + +<% unless notes.empty? %>

Notes

<% notes.each do |note| %>
@@ -15,29 +17,4 @@ <% end %> <% end %> - \ No newline at end of file +<%= partial(:add_note) %> diff --git a/views/db/advisories/show.erb b/views/db/advisories/show.erb index ed11e42..768f468 100644 --- a/views/db/advisories/show.erb +++ b/views/db/advisories/show.erb @@ -100,5 +100,3 @@ <%= partial(:notes, notes: @advisory.notes) %> - -<%= partial(:add_note, parent: @advisory) %> diff --git a/views/db/credentials/show.erb b/views/db/credentials/show.erb index ba18d30..582dd4f 100644 --- a/views/db/credentials/show.erb +++ b/views/db/credentials/show.erb @@ -46,5 +46,3 @@ <%= partial(:notes, notes: @credential.notes) %> - -<%= partial(:add_note, parent: @credential) %> \ No newline at end of file diff --git a/views/db/email_addresses/show.erb b/views/db/email_addresses/show.erb index 7cf7a17..3e2a1e5 100644 --- a/views/db/email_addresses/show.erb +++ b/views/db/email_addresses/show.erb @@ -39,5 +39,3 @@ <%= partial(:notes, notes: @email_address.notes) %> - -<%= partial(:add_note, parent: @email_address) %> \ No newline at end of file diff --git a/views/db/host_names/show.erb b/views/db/host_names/show.erb index 6ea8a12..7bd1aa9 100644 --- a/views/db/host_names/show.erb +++ b/views/db/host_names/show.erb @@ -47,5 +47,3 @@ <%= partial(:notes, notes: @host_name.notes) %> - -<%= partial(:add_note, parent: @host_name) %> \ No newline at end of file diff --git a/views/db/ip_addresses/show.erb b/views/db/ip_addresses/show.erb index 60b0607..143d4fe 100644 --- a/views/db/ip_addresses/show.erb +++ b/views/db/ip_addresses/show.erb @@ -93,5 +93,3 @@ <%= partial(:notes, notes: @ip_address.notes) %> - -<%= partial(:add_note, parent: @ip_address) %> \ No newline at end of file diff --git a/views/db/mac_addresses/show.erb b/views/db/mac_addresses/show.erb index 45758ff..e5ccea2 100644 --- a/views/db/mac_addresses/show.erb +++ b/views/db/mac_addresses/show.erb @@ -57,4 +57,3 @@ <%= partial(:notes, notes: @mac_address.notes) %> -<%= partial(:add_note, parent: @mac_address) %> diff --git a/views/db/open_ports/show.erb b/views/db/open_ports/show.erb index c650af7..6801d0b 100644 --- a/views/db/open_ports/show.erb +++ b/views/db/open_ports/show.erb @@ -82,5 +82,3 @@ <%= partial(:notes, notes: @open_port.notes) %> - -<%= partial(:add_note, parent: @open_port) %> \ No newline at end of file diff --git a/views/db/passwords/show.erb b/views/db/passwords/show.erb index 95b7c18..6f57785 100644 --- a/views/db/passwords/show.erb +++ b/views/db/passwords/show.erb @@ -47,5 +47,3 @@ <%= partial(:notes, notes: @password.notes) %> - -<%= partial(:add_note, parent: @password) %> \ No newline at end of file diff --git a/views/db/ports/show.erb b/views/db/ports/show.erb index db7cd01..f8cafe7 100644 --- a/views/db/ports/show.erb +++ b/views/db/ports/show.erb @@ -65,4 +65,3 @@ <%= partial(:notes, notes: @port.notes) %> -<%= partial(:add_note, parent: @port) %> diff --git a/views/db/services/show.erb b/views/db/services/show.erb index eed8ece..4598362 100644 --- a/views/db/services/show.erb +++ b/views/db/services/show.erb @@ -60,4 +60,3 @@ <%= partial(:notes, notes: @service.notes) %> -<%= partial(:add_note, parent: @service) %> diff --git a/views/db/urls/show.erb b/views/db/urls/show.erb index e5effbd..48426d8 100644 --- a/views/db/urls/show.erb +++ b/views/db/urls/show.erb @@ -98,5 +98,3 @@ <%= partial(:notes, notes: @url.notes) %> - -<%= partial(:add_note, parent: @url) %> \ No newline at end of file diff --git a/views/db/user_names/show.erb b/views/db/user_names/show.erb index 1e2f6c4..5c2b12b 100644 --- a/views/db/user_names/show.erb +++ b/views/db/user_names/show.erb @@ -43,5 +43,3 @@ <%= partial(:notes, notes: @user_name.notes) %> - -<%= partial(:add_note, parent: @user_name) %> \ No newline at end of file