Filter classified listings by published status for mods (#7432)
* Filter classified listings by published status for mods * Change checkbox label, invert logic, respect checked status
This commit is contained in:
parent
4ab202ab0a
commit
f791e84f2d
3 changed files with 26 additions and 2 deletions
|
|
@ -7,6 +7,7 @@ class Internal::ClassifiedListingsController < Internal::ApplicationController
|
|||
ClassifiedListing.includes(%i[user classified_listing_category]).
|
||||
page(params[:page]).order("bumped_at DESC").per(50)
|
||||
|
||||
@classified_listings = @classified_listings.published unless include_unpublished?
|
||||
@classified_listings = @classified_listings.where(category: params[:filter]) if params[:filter].present?
|
||||
end
|
||||
|
||||
|
|
@ -46,4 +47,8 @@ class Internal::ClassifiedListingsController < Internal::ApplicationController
|
|||
unpublish_listing if listing_params[:published] == "0"
|
||||
publish_listing if listing_params[:published] == "1"
|
||||
end
|
||||
|
||||
def include_unpublished?
|
||||
params[:include_unpublished] == "1"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,7 +11,12 @@
|
|||
</div>
|
||||
<div class="form-group">
|
||||
<%= label_tag(:filter, "Category") %>
|
||||
<%= select_tag(:filter, options_for_select([""] + ClassifiedListing.categories_available.keys, params[:filter])) %>
|
||||
<%= select_tag(:filter, options_for_select(ClassifiedListing.categories_available.keys, params[:filter]), include_blank: true) %>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<%= label_tag(:include_unpublished, "Include unpublished listings") %>
|
||||
<%= hidden_field_tag(:include_unpublished, 0) %>
|
||||
<%= check_box_tag(:include_unpublished, 1, params[:include_unpublished] == "1") %>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<%= submit_tag("Filter") %>
|
||||
|
|
|
|||
|
|
@ -11,11 +11,25 @@ RSpec.describe "/internal/listings", type: :request do
|
|||
end
|
||||
|
||||
it "clears listing cache" do
|
||||
put "/internal/listings/#{classified_listing.id}", params: {
|
||||
put internal_listing_path(id: classified_listing.id), params: {
|
||||
classified_listing: { title: "updated" }
|
||||
}
|
||||
sidekiq_perform_enqueued_jobs
|
||||
expect(CacheBuster).to have_received(:bust_classified_listings)
|
||||
end
|
||||
|
||||
describe "GET /internal/listings" do
|
||||
let(:unpublished_listing) { create(:classified_listing, published: false) }
|
||||
|
||||
it "filters unpublished listings by default" do
|
||||
get internal_listings_path
|
||||
expect(response.body).not_to match(unpublished_listing.title)
|
||||
end
|
||||
|
||||
it "includes unpublished listings when asked to" do
|
||||
get internal_listings_path, params: { include_unpublished: "1" }
|
||||
expect(response.body).to match(unpublished_listing.title)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue