diff --git a/app/controllers/admin/hackathons_controller.rb b/app/controllers/admin/hackathons_controller.rb index a7c7e7dd..555ed31e 100644 --- a/app/controllers/admin/hackathons_controller.rb +++ b/app/controllers/admin/hackathons_controller.rb @@ -2,7 +2,15 @@ class Admin::HackathonsController < Admin::BaseController before_action :set_hackathon, except: :index def index - @pagy, @hackathons = pagy(Hackathon.all.order(created_at: :desc)) + @hackathons = Hackathon.all.order(created_at: :desc) + + @query = params[:q] + @status = params[:status] + + @hackathons = @hackathons.where("name ILIKE ?", "%#{Hackathon.sanitize_sql_like(@query)}%") if @query.present? + @hackathons = @hackathons.where(status: @status) if @status.present? + + @pagy, @hackathons = pagy(@hackathons) end def show diff --git a/app/views/admin/hackathons/_filters.html.erb b/app/views/admin/hackathons/_filters.html.erb new file mode 100644 index 00000000..47a6a60b --- /dev/null +++ b/app/views/admin/hackathons/_filters.html.erb @@ -0,0 +1,15 @@ +
+ <%= form_with method: :get, class: "simple_form mb3" do |form| %> + <%= form.hidden_field :status, value: @status if @status.present? %> + +
+ <%= form.text_field :q, placeholder: "Search", value: @query, style: "flex: 1", class: "mr2" %> + +
+ <% end %> + + <%= link_to "All", params.permit(:q).merge(status: nil), class: "mr2", style: ("color: var(--muted); text-decoration: none" unless @status.nil?) %> + <% Hackathon.statuses.keys.each do |status| %> + <%= link_to status.humanize, params.permit(:q).merge(status:), class: "mr2", style: ("color: var(--muted); text-decoration: none" unless @status == status) %> + <% end %> +
diff --git a/app/views/admin/hackathons/index.html.erb b/app/views/admin/hackathons/index.html.erb index f4995f79..1dfc3bdf 100644 --- a/app/views/admin/hackathons/index.html.erb +++ b/app/views/admin/hackathons/index.html.erb @@ -2,6 +2,11 @@ <% @nav_active_item = admin_hackathons_path %>

Hackathons

-<%= render partial: "snippet", collection: @hackathons, as: :hackathon %> +<%= render "filters" %> +<% if @hackathons.any? %> + <%= render partial: "snippet", collection: @hackathons, as: :hackathon %> +<% else %> +

No hackathons to show.

+<% end %> <%== pagy_nav(@pagy) %>