Skip to content

Commit

Permalink
Merge pull request #275 from diegosteiner/feature/searchbar
Browse files Browse the repository at this point in the history
feature: global searchbar
  • Loading branch information
diegosteiner authored Dec 6, 2023
2 parents 02d311c + 575077c commit 3da84ef
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 38 deletions.
12 changes: 12 additions & 0 deletions app/javascript/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,15 @@ tr.disabled {
}
}
}

#searchbar {
opacity: 0.5;

&>input {
flex-grow: 1;
}

&:has(input:focus) {
opacity: 1;
}
}
17 changes: 7 additions & 10 deletions app/models/booking/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

class Booking
class Filter < ApplicationFilter
attribute :ref
attribute :tenant
attribute :q
attribute :categories
attribute :homes, default: -> { [] }
attribute :occupiables, default: -> { [] }
Expand Down Expand Up @@ -33,10 +32,6 @@ class Filter < ApplicationFilter
bookings.where(occupancy_type:) if occupancy_type.present?
end

filter :ref do |bookings|
bookings.where(Booking.arel_table[:ref].matches("%#{ref.strip}%")) if ref.present?
end

filter :homes do |bookings|
relevant_homes = Array.wrap(homes).compact_blank
bookings.joins(:occupancies).where(home_id: relevant_homes) if relevant_homes.present?
Expand All @@ -57,12 +52,14 @@ class Filter < ApplicationFilter
bookings.where(booking_category_id: category_ids)
end

filter :tenant do |bookings|
next bookings if tenant.blank?
filter :q do |bookings|
next bookings if q.blank?

match = "%#{q.strip}%"
bookings.joins(:tenant)
.where(Tenant.arel_table[:search_cache].matches("%#{tenant}%")
.or(Booking.arel_table[:tenant_organisation].matches("%#{tenant}%")))
.where(Tenant.arel_table[:search_cache].matches(match)
.or(Booking.arel_table[:tenant_organisation].matches(match))
.or(Booking.arel_table[:ref].matches("#{q.strip}%")))
end

filter :has_booking_state do |bookings|
Expand Down
2 changes: 1 addition & 1 deletion app/params/manage/booking_filter_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Manage
class BookingFilterParams < ApplicationParams
def self.permitted_keys
%i[tenant ref begins_at_before begins_at_after ends_at_before ends_at_after at_date] +
%i[q begins_at_before begins_at_after ends_at_before ends_at_after at_date] +
[current_booking_states: [], previous_booking_states: [], homes: [], occupiables: []]
end
end
Expand Down
42 changes: 26 additions & 16 deletions app/views/layouts/_top_navigation.html.slim
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
nav#navbar-top.navbar.fixed-top.navbar-light.navbar-expand-lg
.container-fluid
= link_to home_path, class: 'navbar-brand' do
= image_tag asset_pack_path('static/images/logo.svg'), class: "d-inline-block align-top", width: 90

ul.navbar-nav.ms-auto
- if current_user.present?
li.nav-item.dropdown
a.nav-link.dropdown-toggle aria-expanded="false" aria-haspopup="true" data-bs-toggle="dropdown" href="#"
i.fa.fa-user
=<> current_user&.email || t(:'nav.sign_in')
.dropdown-menu aria-labelledby="navbarDropdownMenuLink"
= link_to t(:'nav.manage'), manage_root_path(org: current_organisation), class: 'dropdown-item' if current_organisation
= link_to t(:'nav.edit_account'), edit_account_path, class: 'dropdown-item'
= link_to t(:'nav.sign_out'), destroy_user_session_path, :method=>'delete', class: 'dropdown-item'
- else
li.nav-item
= link_to t(:'nav.sign_in'), new_user_session_path, class: 'nav-link'
.col-md-3.col-12
= link_to home_path, class: 'navbar-brand' do
= image_tag asset_pack_path('static/images/logo.svg'), class: "d-inline-block align-top", width: 90

- if current_user.present?
.col-md-4.offset-md-1.col-12
= form_with(url: manage_bookings_path, method: :get, id: 'searchbar', class: 'input-group d-flex') do |f|
button.btn.bg-white.border-0[type="submit"]
span.fa.fa-search
input.d-none[name="filter[current_booking_states]" value="" type="hidden"]
input.form-control.bg-white.border-0[name="filter[q]" type="search" tabindex=1 value=params.dig(:filter, :q).presence placeholder=Booking::Filter.human_attribute_name(:q)]

.col-md-3.col-12
ul.navbar-nav.justify-content-end
- if current_user.present?
li.nav-item.dropdown
a.nav-link.dropdown-toggle aria-expanded="false" aria-haspopup="true" data-bs-toggle="dropdown" href="#"
i.fa.fa-user
=<> current_user&.email || t(:'nav.sign_in')
.dropdown-menu aria-labelledby="navbarDropdownMenuLink"
= link_to t(:'nav.manage'), manage_root_path(org: current_organisation), class: 'dropdown-item' if current_organisation
= link_to t(:'nav.edit_account'), edit_account_path, class: 'dropdown-item'
= link_to t(:'nav.sign_out'), destroy_user_session_path, :method=>'delete', class: 'dropdown-item'
- else
li.nav-item
= link_to t(:'nav.sign_in'), new_user_session_path, class: 'nav-link'
4 changes: 1 addition & 3 deletions app/views/manage/bookings/_filter_fields.html.slim
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/ h3.my-2.text-center= Booking:.model_name.human
.row.mt-3
.col
= f.text_field :ref
.col
= f.text_field :tenant
= f.text_field :q
.row
.col
= f.datetime_field :begins_at_after, include_blank: true
Expand Down
3 changes: 1 addition & 2 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ de:
occupiables: Mietobjekte
only_inconcluded: nur offene Buchungen
previous_booking_states: Vergangene Status
ref: Buchungsreferenz
tenant: Mieter
q: Buchungsreferenz, Mieter, Organisation
invoice/filter:
invoice_type: Rechungsart
issued_at_after: Rechnungsdatum nach
Expand Down
2 changes: 0 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ en:
occupiables: Mietobjekte
only_inconcluded: nur offene Buchungen
previous_booking_states: Vergangene Status
ref: Buchungsreferenz
tenant: Mieter
invoice/filter:
invoice_type: Rechungsart
issued_at_after: Rechnungsdatum nach
Expand Down
2 changes: 0 additions & 2 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ fr:
occupiables: Objet de location
only_inconcluded: Uniquement les réservations ouvertes/libres (?)
previous_booking_states: Anciens statuts
ref: "(Numéro de) Référence de location"
tenant: Locataire
invoice/filter:
invoice_type: Type de facture/facturation
issued_at_after: Délai de paiement après le
Expand Down
2 changes: 0 additions & 2 deletions config/locales/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ it:
occupiables: Proprietà in affitto
only_inconcluded: solo prenotazioni aperte
previous_booking_states: Stato passato
ref: Riferimento di prenotazione
tenant: Inquilino
invoice/filter:
invoice_type: Tipo di fattura
issued_at_after: Data di fatturazione dopo
Expand Down

0 comments on commit 3da84ef

Please sign in to comment.