Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions app/controllers/new_design_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def explore
@duration = params[:duration]
@min_rating = params[:min_rating]
@city_name = params[:city_name]
@tag = params[:tag]
@origin = params[:origin]
@audio_support = params[:audio_support] == "true"
@accessible = params[:accessible] == "true"
Expand Down Expand Up @@ -115,6 +116,13 @@ def explore
.pluck(:city)
.sort

# Load tags for filter dropdown
@tags = Location.not_archived.where.not(tags: [ nil, [] ])
.pluck(:tags)
.flatten
.uniq
.sort

# Load categories for filter dropdown
@experience_categories = ExperienceCategory.active.ordered

Expand Down Expand Up @@ -146,6 +154,7 @@ def build_browse_queries(search_types)
# Build base Browse query with common filters
base_browse = Browse.smart_search(@query)
base_browse = base_browse.by_city_name(@city_name) if @city_name.present?
base_browse = base_browse.by_tag(@tag) if @tag.present?
base_browse = base_browse.by_min_rating(@min_rating) if @min_rating.present?
base_browse = base_browse.by_season(@season) if @season.present?
base_browse = base_browse.by_budget(@budget) if @budget.present?
Expand Down Expand Up @@ -240,15 +249,15 @@ def lead_own_with_named(scope)
# asked for. id, partial and the *_page keys stay out — loadMore sets its own
# page, and an id would re-name a moment on every fetch.
def filter_params
params.permit(:q, :season, :budget, :duration, :min_rating, :city_name,
params.permit(:q, :season, :budget, :duration, :min_rating, :city_name, :tag,
:origin, :audio_support, :lat, :lng, :radius, :sort, types: [])
.to_h.reject { |_, value| value.blank? }
end

# Unfiltered, a traveller keeps seeing every moment they own, including ones
# at places since retired that browse no longer indexes.
def filters_active?
@query.present? || @city_name.present? || @season.present? || @budget.present? ||
@query.present? || @city_name.present? || @tag.present? || @season.present? || @budget.present? ||
@min_rating.present? || @origin.present? || (@lat.present? && @lng.present?)
end

Expand Down
12 changes: 12 additions & 0 deletions app/javascript/controllers/explore_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class extends Controller {
"typeCheckbox",
"filterInput",
"citySelect",
"tagSelect",
"audioToggle",
"accessibleToggle",
"nearbyButton",
Expand Down Expand Up @@ -207,6 +208,11 @@ export default class extends Controller {
formData.append("city_name", this.citySelectTarget.value)
}

// Tag filter
if (this.hasTagSelectTarget && this.tagSelectTarget.value) {
formData.append("tag", this.tagSelectTarget.value)
}

// Audio support filter
if (this.hasAudioToggleTarget && this.audioToggleTarget.checked) {
formData.append("audio_support", "true")
Expand Down Expand Up @@ -324,6 +330,9 @@ export default class extends Controller {
// Count city select
if (this.hasCitySelectTarget && this.citySelectTarget.value) count++

// Count tag select
if (this.hasTagSelectTarget && this.tagSelectTarget.value) count++

// Count toggles
if (this.hasAudioToggleTarget && this.audioToggleTarget.checked) count++
if (this.hasAccessibleToggleTarget && this.accessibleToggleTarget.checked) count++
Expand Down Expand Up @@ -363,6 +372,9 @@ export default class extends Controller {
// Reset city select
if (this.hasCitySelectTarget) this.citySelectTarget.value = ""

// Reset tag select
if (this.hasTagSelectTarget) this.tagSelectTarget.value = ""

// Clear toggles
if (this.hasAudioToggleTarget) this.audioToggleTarget.checked = false
if (this.hasAccessibleToggleTarget) this.accessibleToggleTarget.checked = false
Expand Down
49 changes: 49 additions & 0 deletions app/models/browse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,55 @@ class Browse < ApplicationRecord
where("category_keys @> ?", [ category_key ].to_json)
}

# Filter by tag - only locations carry tags, so a tag's experiences, plans
# and moments are the ones that reach a tagged location (mirrors by_city_name)
scope :by_tag, ->(tag) {
return all if tag.blank?

tagged_location_ids = Location
.where("EXISTS (SELECT 1 FROM jsonb_array_elements_text(tags) AS tag WHERE lower(tag) = lower(?))", tag.to_s.strip)
.pluck(:id)
return none if tagged_location_ids.empty?

experience_ids = ExperienceLocation
.where(location_id: tagged_location_ids)
.pluck(:experience_id)
.uniq

plan_ids = PlanExperience
.joins(experience: :experience_locations)
.where(experience_locations: { location_id: tagged_location_ids })
.pluck(:plan_id)
.uniq

moment_ids = Moment
.where(location_id: tagged_location_ids)
.pluck(:id)

conditions = []
values = []

conditions << "(browsable_type = 'Location' AND browsable_id IN (?))"
values << tagged_location_ids

if experience_ids.any?
conditions << "(browsable_type = 'Experience' AND browsable_id IN (?))"
values << experience_ids
end

if plan_ids.any?
conditions << "(browsable_type = 'Plan' AND browsable_id IN (?))"
values << plan_ids
end

if moment_ids.any?
conditions << "(browsable_type = 'Moment' AND browsable_id IN (?))"
values << moment_ids
end

where(conditions.join(" OR "), *values)
}

# Filter by AI generated / Human made
scope :ai_generated, -> { where(ai_generated: true) }
scope :human_made, -> { where(ai_generated: false) }
Expand Down
12 changes: 12 additions & 0 deletions app/views/new_design/explore.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,18 @@
{ class: "rounded-full border-0 bg-white dark:bg-gray-700 py-2 pl-3 pr-8 text-sm text-gray-900 dark:text-white shadow-sm ring-1 ring-inset ring-gray-200 dark:ring-gray-600 focus:ring-2 focus:ring-inset focus:ring-blue-600 dark:focus:ring-yellow-500",
data: { explore_target: "citySelect", action: "change->explore#onFilterChange" } } %>
</div>

<%# Tag Filter - Keep as select for curated tag sets %>
<div class="flex items-center gap-2">
<svg class="w-4 h-4 text-gray-500 dark:text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 7h.01M7 3h5.586a1 1 0 01.707.293l7 7a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-7-7A1 1 0 017 8.586V4a1 1 0 011-1z"></path>
</svg>
<%= f.select :tag,
options_for_select([[t("explore.tags.any"), ""]] + @tags.map { |tag| [tag, tag] }, @tag),
{},
{ class: "rounded-full border-0 bg-white dark:bg-gray-700 py-2 pl-3 pr-8 text-sm text-gray-900 dark:text-white shadow-sm ring-1 ring-inset ring-gray-200 dark:ring-gray-600 focus:ring-2 focus:ring-inset focus:ring-blue-600 dark:focus:ring-yellow-500",
data: { explore_target: "tagSelect", action: "change->explore#onFilterChange" } } %>
</div>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/bs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ bs:
audio_support: Audio ture
accessible: "♿ Pristupačno"
origin: Porijeklo
tag: Oznaka
accessible_aria: Prikaži samo lokacije pristupačne za invalidska kolica
origins:
ai: AI Generirano
Expand Down Expand Up @@ -150,6 +151,8 @@ bs:
name: Naziv
cities:
any: Sva mjesta
tags:
any: Sve oznake
loading: Učitavanje...
load_more: Učitaj više
results_count: Pronađeno %{count} rezultata
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ en:
audio_support: Audio tours
accessible: "♿ Accessible"
origin: Origin
tag: Tag
accessible_aria: Show only wheelchair accessible places
origins:
ai: AI Generated
Expand Down Expand Up @@ -152,6 +153,8 @@ en:
name: Name
cities:
any: All places
tags:
any: All tags
loading: Loading...
load_more: Load More
results_count: '%{count} results found'
Expand Down
18 changes: 18 additions & 0 deletions test/controllers/new_design_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,24 @@ class NewDesignControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end

test "explore filters by tag" do
@location.update!(tags: [ "historic" ])
@mostar_location.update!(tags: [ "food" ])

get explore_path, params: { types: [ "location" ], tag: "historic" }

assert_response :success
assert_select "a[href=?]", location_path(@location), minimum: 1
assert_select "a[href=?]", location_path(@mostar_location), count: 0
end

test "explore with a tag nobody carries finds nothing" do
get explore_path, params: { types: [ "location" ], tag: "nonexistent" }

assert_response :success
assert_select "a[href=?]", location_path(@location), count: 0
end

test "explore filters by origin ai" do
get explore_path, params: { origin: "ai" }

Expand Down
29 changes: 29 additions & 0 deletions test/system/explore_tag_filter_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "application_system_test_case"

# The tag select on explore in a real browser: choosing a tag reloads the
# results with only the places carrying it, and the url says which tag.
class ExploreTagFilterTest < ApplicationSystemTestCase
setup do
@historic = Location.create!(name: "Tag Fortress", city: "Jajce", lat: 44.34, lng: 17.27, tags: [ "historic" ])
@food = Location.create!(name: "Tag Kafana", city: "Mostar", lat: 43.34, lng: 17.81, tags: [ "food" ])
[ @historic, @food ].each { |location| Browse.sync_record(location) }
end

teardown do
[ @historic, @food ].each { |location| location&.destroy }
end

test "choosing a tag narrows explore to the places carrying it" do
visit explore_path(types: [ "location" ])
assert_text "Tag Fortress"
assert_text "Tag Kafana"

click_once_wired("[data-explore-target='filterToggle']", "explore")
find("[data-explore-target='tagSelect']").select("historic")

assert_current_path(/tag=historic/)
assert_text "Tag Fortress"
assert_no_text "Tag Kafana"
assert_equal "historic", find("[data-explore-target='tagSelect']", visible: :all).value
end
end
4 changes: 2 additions & 2 deletions wiki/initiatives/open-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Open issues
kind: reference
status: living
updated: 2026-09-29
updated: 2026-10-08
repos:
- usput.ba
confidence: medium
Expand Down Expand Up @@ -48,7 +48,7 @@ The 17 open GitHub issues on misabegovic/usput.ba as of 2026-09-29, grouped by t

## Explore, search and maps

- [#111](https://github.com/misabegovic/usput.ba/issues/111) **Improve explore page filters** (filter on tags). Partly addressed: explore now filters by type, season, budget, duration, rating, city, origin, audio and accessibility (`app/controllers/new_design_controller.rb`), but not by tag. Tags reach search only as full text.
- [#111](https://github.com/misabegovic/usput.ba/issues/111) **Improve explore page filters** (filter on tags). Addressed: explore now filters by type, season, budget, duration, rating, city, tag, origin, audio and accessibility (`app/controllers/new_design_controller.rb`; `app/models/browse.rb`, `by_tag`). Tags also reach full text search through the composed browse description (`app/services/browse_adapter.rb`).
- [#86](https://github.com/misabegovic/usput.ba/issues/86) **Map view** for exploring and for plan, experience and location pages, with nearby places. Largely addressed: a location map (#163), map points and a map panel on places, a route page, and map cards on the plan walk (#164) and the Explore Bosnia deck (#165) (`config/routes.rb`). A map on experience pages is (unverified, 2026-09-29).
- [#153](https://github.com/misabegovic/usput.ba/issues/153) **Cycling trails** (experiences for cyclists). Not addressed: no cycling experience type or trail data exists.
- [#29](https://github.com/misabegovic/usput.ba/issues/29) **Area information**: live conditions for planning (roads, accidents, weather, ice). Not addressed.
Expand Down
4 changes: 2 additions & 2 deletions wiki/product/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Feature inventory
kind: reference
status: living
updated: 2026-09-30
updated: 2026-10-08
repos:
- usput.ba
confidence: medium
Expand Down Expand Up @@ -99,7 +99,7 @@ This is what Usput.ba ships as of 2026-09-29, grouped by what a person does with
## Explore and search

- **Home page.** Shows positive reviews (rating 3 or more), the newest approved public moments, and trending locations and experiences with a rating of at least 3.5 (`app/controllers/new_design_controller.rb`, `home`).
- **Explore.** `/explore` searches one index, `Browse`, across locations, experiences, public plans and approved public moments. Filters: type, city, budget, minimum rating, season, duration, AI or human origin, audio support, accessibility and a nearby radius, with a sort order. Results page with load-more. A search that matches a single place expands to nearby items (`new_design_controller.rb`, `explore`, `build_browse_queries`; `app/models/browse.rb`). The most liked moments rank first ([#167](https://github.com/misabegovic/usput.ba/pull/167)).
- **Explore.** `/explore` searches one index, `Browse`, across locations, experiences, public plans and approved public moments. Filters: type, city, budget, minimum rating, season, duration, tag, AI or human origin, audio support, accessibility and a nearby radius, with a sort order. Results page with load-more. A search that matches a single place expands to nearby items (`new_design_controller.rb`, `explore`, `build_browse_queries`; `app/models/browse.rb`). The most liked moments rank first ([#167](https://github.com/misabegovic/usput.ba/pull/167)).
- **Explore Bosnia deck.** `/explore-bosnia` deals places as a deck of cards, nearest first. Position orders the deck but does not bound it, so a traveller anywhere gets the whole country. Paging uses a keyset cursor because a check-in removes a place from the set. Categories combine, and a filter turned off stays off. Places already reached drop out, and an empty deck says whether nothing is here or everything has been visited. Without a browser location the deck is ordered from the city the request's IP suggests ([#165](https://github.com/misabegovic/usput.ba/pull/165); `app/controllers/explore_bosnia_controller.rb`).
- **Retired places stay hidden.** An archived location leaves Browse and the traveller-facing scopes ([#167](https://github.com/misabegovic/usput.ba/pull/167); `app/models/location.rb`, `places`).

Expand Down
4 changes: 2 additions & 2 deletions wiki/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Product state
kind: reference
status: living
updated: 2026-09-30
updated: 2026-10-08
repos:
- usput.ba
confidence: medium
Expand Down Expand Up @@ -62,7 +62,7 @@ Where Usput.ba has been, what is true in the code today, what the older planning
## Now

- **Stack.** Rails 8.1 on PostgreSQL (PostGIS only offline, to build the Mine Checker's static artifacts, per `docs/mine_checker/README.md`), Hotwire, Tailwind, Solid Queue; two databases (`db/schema.rb`, `sources/planning/decisions/2026-02-03-remove-platform-database.md`).
- **Public product.** Home, explore (the Browse-backed search with filters for type, season, budget, duration, rating, city, origin, audio and accessibility), Explore Bosnia (a deck of places, nearest first), location, experience and plan pages, the plan wizard, walking a plan with check-ins, moments with likes, a travel profile that works without an account, reviews, `/mine-check` and the minesweeper game (`config/routes.rb`).
- **Public product.** Home, explore (the Browse-backed search with filters for type, season, budget, duration, rating, city, tag, origin, audio and accessibility), Explore Bosnia (a deck of places, nearest first), location, experience and plan pages, the plan wizard, walking a plan with check-ins, moments with likes, a travel profile that works without an account, reviews, `/mine-check` and the minesweeper game (`config/routes.rb`).
- **Accounts.** Devise with sign-in by email, confirmation within three days, reset by email through Postmark, an account page, and one token that ends every session on a password change, a block or a button; #171's session rows are gone ([decision](decisions/accounts-through-devise.md)). A database holding accounts without an email cannot migrate, by design: the rebuild starts empty.
- **Admin.** Avo 4 Community at `/admin`, open only to curators and admins, checked in the route and again inside Avo; users page for admins, with role changes and blocks, places, experiences and plans with all 16 languages editable, plans limited to curated ones and travellers' public ones, and audio tours ([Avo admin and roles](initiatives/avo-admin-and-roles.md)). Curators create and edit there directly; there are no proposals. What is left of the old curator dashboard runs beside it until each Avo slice replaces a part.
- **Curator dashboard.** What remains at `/curator` is the start page with counts and recent activity, whose links now open the admin, the moments queue (`Moment` enum `moderation_status`), the reviews list, where only an admin removes a review, and the old users pages. Proposals (`ContentChange`, its contributions and curator reviews) and the curator pages for places, experiences, plans and audio tours were removed on 2026-09-30 ([removal plan](initiatives/remove-curator-dashboard.md)).
Expand Down
Loading