From 84a01a3174d1383e85584f0d6689d4e07a4b6bed Mon Sep 17 00:00:00 2001 From: Emin Kocan Date: Wed, 16 Oct 2024 17:44:47 +0200 Subject: [PATCH] Use turbo for filtering on select without refreshing the whole page --- app/views/notes/index.html.erb | 117 +++++++++++++++++---------------- 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/app/views/notes/index.html.erb b/app/views/notes/index.html.erb index 639fcc6146..2ab73b4fbc 100644 --- a/app/views/notes/index.html.erb +++ b/app/views/notes/index.html.erb @@ -7,68 +7,69 @@ :commented => tag.span(t(".subheading_commented"), :class => "px-2 py-1 bg-body") %>

<% end %> -<% if @notes.empty? %> -

<%= t ".no_notes" %>

-<% else %> - <%= form_tag(url_for("controller" => "notes", "action" => "index"), "method" => :get, "data" => { "turbo" => true, "turbo-frame" => "pagination", "turbo-action" => "advance" }) do %> -
-
- <%= label_tag :status, t(".status") %> - <%= select_tag :status, - options_for_select([[t(".all"), "all"], [t(".open"), "open"], [t(".closed"), "closed"]], params[:status] || "all"), - :class => "form-select" %> -
-
- <%= label_tag :note_type, t(".interaction_type") %> - <%= select_tag :note_type, - options_for_select([[t(".all"), ""], [t(".submitted"), "submitted"], [t(".commented"), "commented"]], params[:note_type] || "all"), - :class => "form-select" %> +<%= form_tag(url_for("controller" => "notes", "action" => "index"), "method" => :get, "data" => { "turbo" => true, "turbo-frame" => "pagination", "turbo-action" => "advance" }) do %> +
+
+ <%= label_tag :status, t(".status") %> + <%= select_tag :status, + options_for_select([[t(".all"), "all"], [t(".open"), "open"], [t(".closed"), "closed"]], params[:status] || "all"), + :class => "form-select", + :onchange => "this.form.requestSubmit()" %>
-
- <%= label_tag :from, t(".from") %> - <%= date_field_tag :from, params[:from], :placeholder => t(".from"), :class => "form-control", :autocomplete => "off" %> -
-
- <%= label_tag :to, t(".to") %> - <%= date_field_tag :to, params[:to], :placeholder => t(".to"), :class => "form-control", :autocomplete => "off" %> -
-
- <%= submit_tag t(".filter"), :class => "btn btn-primary" %> -
+
+ <%= label_tag :note_type, t(".interaction_type") %> + <%= select_tag :note_type, + options_for_select([[t(".all"), ""], [t(".submitted"), "submitted"], [t(".commented"), "commented"]], params[:note_type] || "all"), + :class => "form-select", + :onchange => "this.form.requestSubmit()" %> +
+
+ <%= label_tag :from, t(".from") %> + <%= date_field_tag :from, params[:from], :placeholder => t(".from"), :class => "form-control", :autocomplete => "off", :onchange => "this.form.requestSubmit()" %>
- <% end %> +
+ <%= label_tag :to, t(".to") %> + <%= date_field_tag :to, params[:to], :placeholder => t(".to"), :class => "form-control", :autocomplete => "off", :onchange => "this.form.requestSubmit()" %> +
+
+ <%= submit_tag t(".filter"), :class => "btn btn-primary" %> +
+
- <%= render :partial => "notes_paging_nav" %> + <% if @notes.empty? %> +

<%= t ".no_notes" %>

+ <% else %> + <%= render :partial => "notes_paging_nav" %> - - - - - - - - - +
<%= t ".id" %><%= t ".creator" %><%= t ".description" %><%= t ".created_at" %><%= t ".last_changed" %>
+ + + + + + + + + + + <% @notes.each do |note| -%> + class="table-primary"<% end %>> + + + + + + - - <% @notes.each do |note| -%> - class="table-primary"<% end %>> - - - - - - - - <% end -%> -
<%= t ".id" %><%= t ".creator" %><%= t ".description" %><%= t ".created_at" %><%= t ".last_changed" %>
+ <% if note.closed? %> + <%= image_tag("closed_note_marker.svg", :alt => "closed", :width => 25, :height => 40) %> + <% else %> + <%= image_tag("open_note_marker.svg", :alt => "open", :width => 25, :height => 40) %> + <% end %> + <%= link_to note.id, note %><%= note_author(note.author) %><%= note.comments.first.body.to_html %><%= friendly_date_ago(note.created_at) %><%= friendly_date_ago(note.updated_at) %>
- <% if note.closed? %> - <%= image_tag("closed_note_marker.svg", :alt => "closed", :width => 25, :height => 40) %> - <% else %> - <%= image_tag("open_note_marker.svg", :alt => "open", :width => 25, :height => 40) %> - <% end %> - <%= link_to note.id, note %><%= note_author(note.author) %><%= note.comments.first.body.to_html %><%= friendly_date_ago(note.created_at) %><%= friendly_date_ago(note.updated_at) %>
- - <%= render :partial => "notes_paging_nav" %> + <% end -%> + + <%= render :partial => "notes_paging_nav" %> + <% end %> <% end -%>