Skip to content

Commit a25b795

Browse files
committed
Merge branch 'pull/5297'
2 parents 96ef05b + 738e66a commit a25b795

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

app/controllers/notes_controller.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ class NotesController < ApplicationController
1818
def index
1919
param! :page, Integer, :min => 1
2020

21-
@params = params.permit(:display_name)
21+
@params = params.permit(:display_name, :status)
2222
@title = t ".title", :user => @user.display_name
2323
@page = (params[:page] || 1).to_i
2424
@page_size = 10
2525
@notes = @user.notes
2626
@notes = @notes.visible unless current_user&.moderator?
27+
@notes = @notes.where(:status => params[:status]) unless params[:status] == "all" || params[:status].blank?
2728
@notes = @notes.order("updated_at DESC, id").distinct.offset((@page - 1) * @page_size).limit(@page_size).preload(:comments => :author)
2829

2930
render :layout => "site"

app/views/notes/index.html.erb

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66
:commented => tag.span(t(".subheading_commented"), :class => "px-2 py-1 bg-body") %></p>
77
<% end %>
88

9+
<%= form_with :url => user_notes_path(@user), :method => :get, :data => { :turbo => true } do %>
10+
<div class="row gx-2 align-items-end">
11+
<div class="col-sm-auto mb-3">
12+
<%= label_tag :status, t(".status") %>
13+
<%= select_tag :status,
14+
options_for_select([[t(".all"), "all"], [t(".open"), "open"], [t(".closed"), "closed"]], params[:status] || "all"),
15+
:class => "form-select" %>
16+
</div>
17+
<div class="col-sm-auto mb-3">
18+
<%= submit_tag t(".apply"), :name => nil, :class => "btn btn-primary" %>
19+
</div>
20+
</div>
21+
<% end %>
22+
923
<% if @notes.empty? %>
1024
<h4><%= t ".no_notes" %></h4>
1125

config/locales/en.yml

+5
Original file line numberDiff line numberDiff line change
@@ -2966,6 +2966,11 @@ en:
29662966
description: "Description"
29672967
created_at: "Created at"
29682968
last_changed: "Last changed"
2969+
apply: "Apply"
2970+
all: "All"
2971+
open: "Open"
2972+
closed: "Closed"
2973+
status: "Status"
29692974
show:
29702975
title: "Note: %{id}"
29712976
description: "Description"

test/controllers/notes_controller_test.rb

+34
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,38 @@ def test_new_note
184184
assert_template "notes/new"
185185
assert_select "#sidebar_content a[href='#{login_path(:referer => new_note_path)}']", :count => 0
186186
end
187+
188+
def test_index_filter_by_status
189+
user = create(:user)
190+
other_user = create(:user)
191+
192+
open_note = create(:note, :status => "open")
193+
create(:note_comment, :note => open_note, :author => user)
194+
195+
closed_note = create(:note, :status => "closed")
196+
create(:note_comment, :note => closed_note, :author => user)
197+
198+
hidden_note = create(:note, :status => "hidden")
199+
create(:note_comment, :note => hidden_note, :author => user)
200+
201+
commented_note = create(:note, :status => "open")
202+
create(:note_comment, :note => commented_note, :author => other_user)
203+
create(:note_comment, :note => commented_note, :author => user)
204+
205+
get user_notes_path(user, :status => "all")
206+
assert_response :success
207+
assert_select "table.note_list tbody tr", :count => 3
208+
209+
get user_notes_path(user, :status => "open")
210+
assert_response :success
211+
assert_select "table.note_list tbody tr", :count => 2
212+
213+
get user_notes_path(user, :status => "closed")
214+
assert_response :success
215+
assert_select "table.note_list tbody tr", :count => 1
216+
217+
get user_notes_path(user)
218+
assert_response :success
219+
assert_select "table.note_list tbody tr", :count => 3
220+
end
187221
end

0 commit comments

Comments
 (0)