diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb
index 26d27692e5c..ed150046a08 100644
--- a/app/controllers/notes_controller.rb
+++ b/app/controllers/notes_controller.rb
@@ -18,12 +18,13 @@ class NotesController < ApplicationController
def index
param! :page, Integer, :min => 1
- @params = params.permit(:display_name)
+ @params = params.permit(:display_name, :status)
@title = t ".title", :user => @user.display_name
@page = (params[:page] || 1).to_i
@page_size = 10
@notes = @user.notes
@notes = @notes.visible unless current_user&.moderator?
+ @notes = @notes.with_status(params[:status])
@notes = @notes.order("updated_at DESC, id").distinct.offset((@page - 1) * @page_size).limit(@page_size).preload(:comments => :author)
render :layout => "site"
diff --git a/app/models/note.rb b/app/models/note.rb
index 0b0597434f0..1c6c892aac1 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -34,6 +34,16 @@ class Note < ApplicationRecord
scope :visible, -> { where.not(:status => "hidden") }
scope :invisible, -> { where(:status => "hidden") }
+ scope :with_status, lambda { |status|
+ case status
+ when "open"
+ where(:status => "open")
+ when "closed"
+ where(:status => "closed")
+ else
+ all
+ end
+ }
after_initialize :set_defaults
diff --git a/app/views/notes/index.html.erb b/app/views/notes/index.html.erb
index d5efe0d79c7..11837155a92 100644
--- a/app/views/notes/index.html.erb
+++ b/app/views/notes/index.html.erb
@@ -6,6 +6,20 @@
:commented => tag.span(t(".subheading_commented"), :class => "px-2 py-1 bg-body") %>
<% end %>
+<%= form_with :url => url_for(:controller => "notes", :action => "index"), :method => :get, :data => { :turbo => true } do %>
+
+
+ <%= label_tag :status, t(".status") %>
+ <%= select_tag :status,
+ options_for_select([[t(".all"), "all"], [t(".open"), "open"], [t(".closed"), "closed"]], params[:status] || "all"),
+ :class => "form-select" %>
+
+
+ <%= submit_tag t(".apply"), :class => "btn btn-primary" %>
+
+
+<% end %>
+
<% if @notes.empty? %>
<%= t ".no_notes" %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index f68488c09c4..3f2a4cb1408 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2966,6 +2966,11 @@ en:
description: "Description"
created_at: "Created at"
last_changed: "Last changed"
+ apply: "Apply"
+ all: "All"
+ open: "Open"
+ closed: "Closed"
+ status: "Status"
show:
title: "Note: %{id}"
description: "Description"
diff --git a/test/models/note_test.rb b/test/models/note_test.rb
index 34b16c19d5e..bf4748cb708 100644
--- a/test/models/note_test.rb
+++ b/test/models/note_test.rb
@@ -71,4 +71,25 @@ def test_lat_lon_format
assert_equal "0.0000400", note.lat.to_s
assert_equal "0.0000800", note.lon.to_s
end
+
+ def test_with_status_scope
+ open_note = create(:note, :status => "open")
+ closed_note = create(:note, :status => "closed")
+ reopened_note = create(:note, :status => "open", :closed_at => 2.days.ago)
+
+ filtered_notes = Note.with_status("open")
+ assert_includes filtered_notes, open_note
+ assert_includes filtered_notes, reopened_note
+ assert_not_includes filtered_notes, closed_note
+
+ filtered_notes = Note.with_status("closed")
+ assert_includes filtered_notes, closed_note
+ assert_not_includes filtered_notes, open_note
+ assert_not_includes filtered_notes, reopened_note
+
+ filtered_notes = Note.with_status(nil)
+ assert_includes filtered_notes, open_note
+ assert_includes filtered_notes, closed_note
+ assert_includes filtered_notes, reopened_note
+ end
end