diff --git a/Gemfile.lock b/Gemfile.lock index 036aa3f74..13774c4cf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -539,9 +539,8 @@ GEM thread_safe (0.3.6) tilt (2.4.0) timeout (0.4.1) - turbo-rails (2.0.6) + turbo-rails (2.0.8) actionpack (>= 6.0.0) - activejob (>= 6.0.0) railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) diff --git a/app/components/ChangelogEntries/object_list_component.rb b/app/components/ChangelogEntries/object_list_component.rb new file mode 100644 index 000000000..6ce29caee --- /dev/null +++ b/app/components/ChangelogEntries/object_list_component.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module ChangelogEntries + class ObjectListComponent < ApplicationComponent + include Turbo::FramesHelper + + erb_template <<~ERB + <%= turbo_frame_tag("changelog-entries", loading: :lazy, src: object_changelog_path, **@html_options) do %> +
+ <%= t("changelog_entries.object_list_component.loading") %> + +
+ <% end %> + ERB + + def initialize(object, **html_options) + @object = object + @html_options = html_options + + raise ArgumentError, "@object could not be nil" unless @object + + super() + end + + private + + def object_changelog_path + object_changelog_entries_path(@object.model_name.plural, @object.id) + end + end +end diff --git a/app/controllers/changelog_entries_controller.rb b/app/controllers/changelog_entries_controller.rb index 4007068bb..4acca6da3 100644 --- a/app/controllers/changelog_entries_controller.rb +++ b/app/controllers/changelog_entries_controller.rb @@ -1,6 +1,6 @@ class ChangelogEntriesController < ApplicationController def index - @changelog_entries = sorted changelog_scope.order(created_at: :desc).page(params[:page]).per(100) + @changelog_entries = sorted changelog_scope.order(created_at: :desc).page(params[:page]).per(per_page) end def show @@ -28,4 +28,8 @@ def changelog_scope ChangelogEntry.all end + + def per_page + @per_page ||= turbo_frame_request? ? 10 : 50 + end end diff --git a/app/views/air_conditioners/show.html.erb b/app/views/air_conditioners/show.html.erb index c3117878a..54b86e6b7 100644 --- a/app/views/air_conditioners/show.html.erb +++ b/app/views/air_conditioners/show.html.erb @@ -52,3 +52,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@air_conditioner) %> diff --git a/app/views/architectures/show.html.erb b/app/views/architectures/show.html.erb index 649ee82ea..18c7960fc 100644 --- a/app/views/architectures/show.html.erb +++ b/app/views/architectures/show.html.erb @@ -28,3 +28,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@architecture) %> diff --git a/app/views/bays/show.html.erb b/app/views/bays/show.html.erb index ee67d364f..005eefac7 100644 --- a/app/views/bays/show.html.erb +++ b/app/views/bays/show.html.erb @@ -35,3 +35,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@bay) %> diff --git a/app/views/card_types/show.html.erb b/app/views/card_types/show.html.erb index c9b3ac32f..be3f3e144 100644 --- a/app/views/card_types/show.html.erb +++ b/app/views/card_types/show.html.erb @@ -26,3 +26,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@card_type) %> diff --git a/app/views/categories/show.html.erb b/app/views/categories/show.html.erb index dec652035..dcd5c230d 100644 --- a/app/views/categories/show.html.erb +++ b/app/views/categories/show.html.erb @@ -28,3 +28,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@category) %> diff --git a/app/views/changelog_entries/index.html.erb b/app/views/changelog_entries/index.html.erb index 8c9299850..6963f47d0 100644 --- a/app/views/changelog_entries/index.html.erb +++ b/app/views/changelog_entries/index.html.erb @@ -1,52 +1,63 @@ -<% provide(:title, t("changelog_entries.title")) %> -<%= render "layouts/breadcrumb", breadcrumb_steps: { +<% + provide(:title, t("changelog_entries.title")) + + breadcrumb = {} + + if @scoped_object + breadcrumb[@scoped_object.model_name.human.pluralize] = polymorphic_path(@scoped_object.class) + breadcrumb[@scoped_object] = polymorphic_path(@scoped_object) + end +%> +<%= render "layouts/breadcrumb", breadcrumb_steps: breadcrumb.merge({ t("changelog_entries.title") => "" -} %> +}) %> -
-

<%= t("changelog_entries.title") %>

+<%= turbo_frame_tag "changelog-entries" do %> +
+

<%= t("changelog_entries.title") %>

- <%= render List::DataTableComponent.new(decorate(@changelog_entries)) do |table| %> + <%= render List::DataTableComponent.new(decorate(@changelog_entries)) do |table| %> - <% table.with_column(ChangelogEntry.human_attribute_name(:action), sort_by: :action) do |changelog_entry| %> - <%= render changelog_entry.action_label_to_component %> - <% end %> + <% table.with_column(ChangelogEntry.human_attribute_name(:action), sort_by: :action) do |changelog_entry| %> + <%= render changelog_entry.action_label_to_component %> + <% end %> - <% table.with_column(ChangelogEntry.human_attribute_name(:author), sort_by: :author_id) do |changelog_entry| %> - <%= link_to_if changelog_entry.author_id?, changelog_entry.author_display_name, changelog_entry.author %> - <% end %> + <% table.with_column(ChangelogEntry.human_attribute_name(:author), sort_by: :author_id) do |changelog_entry| %> + <%= link_to_if changelog_entry.author_id?, changelog_entry.author_display_name, changelog_entry.author, target: :_top %> + <% end %> - <% table.with_column(ChangelogEntry.human_attribute_name(:object), sort_by: :object_id) do |changelog_entry| %> - <% begin %> - <%= link_to changelog_entry.object_display_name, changelog_entry.object %> - <% rescue NoMethodError %> - <%= changelog_entry.object_display_name %> + <% table.with_column(ChangelogEntry.human_attribute_name(:object), sort_by: :object_id) do |changelog_entry| %> + <% begin %> + <%= link_to changelog_entry.object_display_name, changelog_entry.object, target: :_top %> + <% rescue NoMethodError %> + <%= changelog_entry.object_display_name %> + <% end %> <% end %> - <% end %> - <% table.with_column(ChangelogEntry.human_attribute_name(:attributes)) do |changelog_entry| %> -
-
- <%= sanitize changelog_entry.split_diff.left %> -
-
- <%= sanitize changelog_entry.split_diff.right %> + <% table.with_column(ChangelogEntry.human_attribute_name(:attributes)) do |changelog_entry| %> +
+
+ <%= sanitize changelog_entry.split_diff.left %> +
+
+ <%= sanitize changelog_entry.split_diff.right %> +
-
- <% end %> + <% end %> - <% table.with_column(t("label_date"), sort_by: :created_at) do |changelog_entry| %> - <%= l changelog_entry.created_at %> - <% end %> + <% table.with_column(t("label_date"), sort_by: :created_at) do |changelog_entry| %> + <%= l changelog_entry.created_at %> + <% end %> - <% table.with_column(t("label_details")) do |changelog_entry| %> - <%= link_to changelog_entry_path(changelog_entry), class: "btn btn-primary" do %> - - <%= t("action.show") %> + <% table.with_column(t("label_details")) do |changelog_entry| %> + <%= link_to changelog_entry_path(changelog_entry), class: "btn btn-primary", target: :_top do %> + + <%= t("action.show") %> + <% end %> <% end %> <% end %> - <% end %> -
+
-<%= paginate @changelog_entries %> + <%= paginate @changelog_entries %> +<% end %> diff --git a/app/views/clusters/show.html.erb b/app/views/clusters/show.html.erb index 77273a948..1814fd67b 100644 --- a/app/views/clusters/show.html.erb +++ b/app/views/clusters/show.html.erb @@ -35,3 +35,5 @@
+ +<%= render ChangelogEntries::ObjectListComponent.new(@cluster) %> diff --git a/app/views/colors/show.html.erb b/app/views/colors/show.html.erb index 358b04977..1feb8fb04 100644 --- a/app/views/colors/show.html.erb +++ b/app/views/colors/show.html.erb @@ -29,3 +29,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@color) %> diff --git a/app/views/contract_types/show.html.erb b/app/views/contract_types/show.html.erb index ef664fa0d..330e1283f 100644 --- a/app/views/contract_types/show.html.erb +++ b/app/views/contract_types/show.html.erb @@ -28,3 +28,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@contract_type) %> diff --git a/app/views/disk_types/show.html.erb b/app/views/disk_types/show.html.erb index a181356cb..c94387829 100644 --- a/app/views/disk_types/show.html.erb +++ b/app/views/disk_types/show.html.erb @@ -28,3 +28,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@disk_type) %> diff --git a/app/views/domaines/show.html.erb b/app/views/domaines/show.html.erb index bc237b4ba..05aecf0db 100644 --- a/app/views/domaines/show.html.erb +++ b/app/views/domaines/show.html.erb @@ -35,3 +35,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@domaine) %> diff --git a/app/views/frames/show.html.erb b/app/views/frames/show.html.erb index 734ef5f15..6a7273812 100644 --- a/app/views/frames/show.html.erb +++ b/app/views/frames/show.html.erb @@ -36,3 +36,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@frame) %> diff --git a/app/views/gestions/show.html.erb b/app/views/gestions/show.html.erb index ccb201e39..dac541172 100644 --- a/app/views/gestions/show.html.erb +++ b/app/views/gestions/show.html.erb @@ -35,3 +35,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@gestion) %> diff --git a/app/views/islets/show.html.erb b/app/views/islets/show.html.erb index ad12683d9..b03ab40c8 100644 --- a/app/views/islets/show.html.erb +++ b/app/views/islets/show.html.erb @@ -28,3 +28,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@islet) %> diff --git a/app/views/maintainers/show.html.erb b/app/views/maintainers/show.html.erb index e34d54e43..d7b8bb2ea 100644 --- a/app/views/maintainers/show.html.erb +++ b/app/views/maintainers/show.html.erb @@ -28,3 +28,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@maintainer) %> diff --git a/app/views/manufacturers/show.html.erb b/app/views/manufacturers/show.html.erb index ac8e40036..9d5c358fd 100644 --- a/app/views/manufacturers/show.html.erb +++ b/app/views/manufacturers/show.html.erb @@ -28,3 +28,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@manufacturer) %> diff --git a/app/views/memory_types/show.html.erb b/app/views/memory_types/show.html.erb index c9f9b9d0f..d85cf77eb 100644 --- a/app/views/memory_types/show.html.erb +++ b/app/views/memory_types/show.html.erb @@ -28,3 +28,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@memory_type) %> diff --git a/app/views/modeles/show.html.erb b/app/views/modeles/show.html.erb index 75334bb89..148fbe17b 100644 --- a/app/views/modeles/show.html.erb +++ b/app/views/modeles/show.html.erb @@ -38,3 +38,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@modele) %> diff --git a/app/views/port_types/show.html.erb b/app/views/port_types/show.html.erb index d2383b72a..0b99af99a 100644 --- a/app/views/port_types/show.html.erb +++ b/app/views/port_types/show.html.erb @@ -30,3 +30,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@port_type) %> diff --git a/app/views/rooms/show.html.erb b/app/views/rooms/show.html.erb index 9a0d6868b..dc6dbaa1b 100644 --- a/app/views/rooms/show.html.erb +++ b/app/views/rooms/show.html.erb @@ -34,3 +34,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@room) %> diff --git a/app/views/servers/show.html.erb b/app/views/servers/show.html.erb index 6ebd2f829..50294f222 100644 --- a/app/views/servers/show.html.erb +++ b/app/views/servers/show.html.erb @@ -240,4 +240,6 @@ +<%= render ChangelogEntries::ObjectListComponent.new(@server) %> + <%= render "ports/modal_edit_port" %> diff --git a/app/views/sites/show.html.erb b/app/views/sites/show.html.erb index 5b2553800..b00dc344f 100644 --- a/app/views/sites/show.html.erb +++ b/app/views/sites/show.html.erb @@ -26,3 +26,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@site) %> diff --git a/app/views/stacks/show.html.erb b/app/views/stacks/show.html.erb index 90f72eac3..12d368fe0 100644 --- a/app/views/stacks/show.html.erb +++ b/app/views/stacks/show.html.erb @@ -26,3 +26,5 @@ + +<%= render ChangelogEntries::ObjectListComponent.new(@stack) %> diff --git a/config/locales/components.en.yml b/config/locales/components.en.yml index 4e8a5a493..df7bea133 100644 --- a/config/locales/components.en.yml +++ b/config/locales/components.en.yml @@ -3,3 +3,6 @@ en: title: one: '1 error occured while saving:' other: '%{count} errors occured while saving:' + changelog_entries: + object_list_component: + loading: Loading changelog... diff --git a/config/locales/components.fr.yml b/config/locales/components.fr.yml index 3bb087c90..391cc0c53 100644 --- a/config/locales/components.fr.yml +++ b/config/locales/components.fr.yml @@ -8,3 +8,6 @@ fr: reset: Réinitialiser%{filters_count} total_with_filters: "Total: %{results_count} sur %{total_count} résultats" total: "Total: %{count}" + changelog_entries: + object_list_component: + loading: Chargement de l'historique... diff --git a/config/routes.rb b/config/routes.rb index 5cb513b79..2a92cc8d0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -123,7 +123,7 @@ get 'search', to: 'search#index' resources :changelog_entries, only: %i[index show] - get "/:object_type/:object_id/changelog_entries", to: "changelog_entries#index" + get "/:object_type/:object_id/changelog_entries", to: "changelog_entries#index", as: :object_changelog_entries mount Lookbook::Engine, at: "/lookbook" if Rails.env.development? end diff --git a/spec/components/changelog_entries/object_list_component_spec.rb b/spec/components/changelog_entries/object_list_component_spec.rb new file mode 100644 index 000000000..631d53b81 --- /dev/null +++ b/spec/components/changelog_entries/object_list_component_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe ChangelogEntries::ObjectListComponent, type: :component do + context "with object" do + let(:islet) { islets(:one) } + let(:component) { described_class.new(islet) } + let(:rendered_component) { render_inline(component) } + + it "renders component" do # rubocop:disable RSpec/ExampleLength + expect(rendered_component.to_html).to have_tag('turbo-frame', with: { + id: "changelog-entries", + src: "/islets/#{islet.id}/changelog_entries" + }) do + with_text(I18n.t("changelog_entries.object_list_component.loading")) + with_tag("span", with: { class: "spinner-border" }) + end + end + end +end