From c44c9ccabaea25ea361712ae356f9a984ed601ae Mon Sep 17 00:00:00 2001 From: david Date: Sat, 20 Jul 2024 22:32:35 +0200 Subject: [PATCH] Avoid full page reloads on report#show --- app/controllers/elements_controller.rb | 5 ++++- app/views/elements/_form.html.erb | 2 +- app/views/elements/create.turbo_stream.erb | 2 ++ app/views/elements/edit.html.erb | 3 +++ app/views/reports/_new_element_button.html.erb | 1 + app/views/reports/show.html.erb | 14 ++++++++------ public/favicon.ico | Bin 0 -> 4286 bytes 7 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 app/views/elements/create.turbo_stream.erb create mode 100644 app/views/reports/_new_element_button.html.erb diff --git a/app/controllers/elements_controller.rb b/app/controllers/elements_controller.rb index 3ffdf98..261e359 100644 --- a/app/controllers/elements_controller.rb +++ b/app/controllers/elements_controller.rb @@ -31,7 +31,10 @@ class ElementsController < ApplicationController @element.success_criteria.create!(title: check.name, description_html: check.success_criterion_html, level: check.level) end - redirect_to @element.report, notice: 'Element was successfully created.' + respond_to do |format| + format.html { redirect_to @element.report, notice: 'Element was successfully created.' } + format.turbo_stream + end else render :new, status: :unprocessable_entity end diff --git a/app/views/elements/_form.html.erb b/app/views/elements/_form.html.erb index 4ec0cee..000bcbe 100644 --- a/app/views/elements/_form.html.erb +++ b/app/views/elements/_form.html.erb @@ -1,4 +1,4 @@ -<%= bootstrap_form_with(model: element, data: { turbo_frame: "_top" }) do |form| %> +<%= bootstrap_form_with(model: element, data: element.persisted? || { turbo_frame: "_top" }) do |form| %> <%= form.hidden_field :report_id %>
diff --git a/app/views/elements/create.turbo_stream.erb b/app/views/elements/create.turbo_stream.erb new file mode 100644 index 0000000..458bd31 --- /dev/null +++ b/app/views/elements/create.turbo_stream.erb @@ -0,0 +1,2 @@ +<%= turbo_stream.update "new_element_frame", partial: "reports/new_element_button", locals: { report: @element.report } %> +<%= turbo_stream.append "element_list", @element %> \ No newline at end of file diff --git a/app/views/elements/edit.html.erb b/app/views/elements/edit.html.erb index dbdcb3a..0ce1dc1 100644 --- a/app/views/elements/edit.html.erb +++ b/app/views/elements/edit.html.erb @@ -7,6 +7,9 @@ <%= @element.title %> +
+ <%= @element.path %> +
<%= link_to(tag.i(class: "bi bi-pencil"), @element, class: "btn btn-link text-warning") %>
diff --git a/app/views/reports/_new_element_button.html.erb b/app/views/reports/_new_element_button.html.erb new file mode 100644 index 0000000..29f71b1 --- /dev/null +++ b/app/views/reports/_new_element_button.html.erb @@ -0,0 +1 @@ +<%= link_to "#{tag.i(class: "bi bi-plus-lg")} Neues Element".html_safe, new_element_path(report_id: report.id), class: "btn btn-primary" %> diff --git a/app/views/reports/show.html.erb b/app/views/reports/show.html.erb index 4f66dcf..ad8b9ae 100644 --- a/app/views/reports/show.html.erb +++ b/app/views/reports/show.html.erb @@ -12,15 +12,17 @@
<%= turbo_frame_tag "new_element_frame" do %> - <%= link_to "#{tag.i(class: "bi bi-plus-lg")} Neues Element".html_safe, new_element_path(report_id: @report.id), class: "btn btn-primary" %> + <%= render partial: "reports/new_element_button", locals: { report: @report } %> <% end %>
- <% @report.elements.each do |element| %> - <%= turbo_frame_tag dom_id(element, :frame) do %> - <%= render element %> - <% end %> - <% end %> +
+ <% @report.elements.each do |element| %> + <%= turbo_frame_tag dom_id(element, :frame) do %> + <%= render element %> + <% end %> + <% end %> +
diff --git a/public/favicon.ico b/public/favicon.ico index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..98424e7d7c3b6a94f2bf4888d11062fb14c70c5b 100644 GIT binary patch literal 4286 zcmeH}yKWOf6o!W&#HE2M6bO+L5Fo(|kR}fR6;&t#ya9d$TtI;c1+-8EK~ICj&RD`Y z_J)gSh>*AlaZxG+2PB>quDiP3;$+jjQ=)w_82p5 zj5)}lWM&y&FFvd__YYzq7z1G9=v&-oyng-&)A7D;3wv{mH>}@^Yg+TtAN>qxVo$G; z4ZkL?Y0c^Xv|u<~jy-!BuJ{_`NnF#K_biqRh672XzZ-Q|)>?5*Yfk@r1;gSSJ*NWS zDe7O#+TB2(xVI+RL;ss41FH^)WKXw^!=kefZiud(dk)PZ$6;RlbBD8{v;QuMuARwf z2#5Ka`1c(a1O1}t+Bwf~PB`qv$Kp?ZS9FdSMAyzd|IpjFtS+AW}+c-ADvN+H4z7T5c#iQC>@#`#OU&!M4Wf}h7E5fgl z_1c-g^)BJ0a;Jlx+T74D#T7kVTgO;9sayv$^h|L@57*W)7EUVH!3;f9T+zd|b&Q3R z%5^Y9&lFemaP4NsS%w|FUysmdj(6HTbA!*DtISJ$*0h<|7~dJgyCyOAYu3s=OQlDn z^qljISNE|!{@=LgMZ)h-yiM2nj__=Z@6h^Nd~zPd{QvXO_vxzhD4s)ucdm7wtnq_O_NdOMfS%rzQu>CJ(@MLKW)JOtjVbI`q$^L+JEo)8Xv~HCJ@J4 ZUYBuv*$pJZ8nab`=Q#NMIsj}CzX6+b#sL5T literal 0 HcmV?d00001