diff --git a/Gemfile.lock b/Gemfile.lock index 308799d93..3b4f2ac2a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -120,7 +120,7 @@ GEM debug_inspector (>= 1.2.0) bootsnap (1.18.6) msgpack (~> 1.2) - brakeman (7.1.1) + brakeman (7.1.2) racc builder (3.3.0) bundler-audit (0.9.2) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index c95169456..8f59d780d 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,23 +1,27 @@ class TagsController < ApplicationController - def index - @sectors = - Sector - .includes(:sectorable_items) - .references(:sectorable_items) - .published - .distinct - .order(:name) + def index + end - categories = - Category - .includes(:category_type, :categorizable_items) - .references(:category_type, :categorizable_items) - .published - .select("categories.*, metadata.name AS category_type_name") - .distinct - .order("category_type_name ASC, categories.name ASC") + def sectors + @sectors = + Sector + .includes(:sectorable_items) + .references(:sectorable_items) + .published + .distinct + .order(:name) + end - @categories_by_type = categories.group_by(&:category_type_name) - end + def categories + categories = + Category + .includes(:category_type, :categorizable_items) + .references(:category_type, :categorizable_items) + .published + .select("categories.*, metadata.name AS category_type_name") + .distinct + .order("category_type_name ASC, categories.name ASC") + @categories_by_type = categories.group_by(&:category_type_name) + end end diff --git a/app/views/tags/_loading.html.erb b/app/views/tags/_loading.html.erb new file mode 100644 index 000000000..6370e5d26 --- /dev/null +++ b/app/views/tags/_loading.html.erb @@ -0,0 +1,3 @@ +
+ +
diff --git a/app/views/tags/categories.html.erb b/app/views/tags/categories.html.erb new file mode 100644 index 000000000..d3f0aedef --- /dev/null +++ b/app/views/tags/categories.html.erb @@ -0,0 +1,19 @@ +<%= turbo_frame_tag :categories_tags do %> +
+ <% @categories_by_type.each do |type, categories| %> +
+
<%= type.titleize %>
+ +
+ <% categories.each do |category| %> + <%= render "categories/tagging_label", + category: category, + name_only: true, + bg_color: "bg-white", + bg_hover_color: "bg-lime-200" %> + <% end %> +
+
+ <% end %> +
+<% end %> diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index be31eb56a..407a15957 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -1,5 +1,4 @@
-
@@ -15,94 +14,73 @@ <%# if current_user.super_user? %> - - <%#= link_to "Manage sectors", - authenticated_root_path, - class: "whitespace-nowrap btn btn-secondary-outline" %> - <%#= link_to "Manage categories", - authenticated_root_path, - class: "whitespace-nowrap btn btn-secondary-outline" %> - + + <%# + = link_to "Manage sectors", + authenticated_root_path, + class: "whitespace-nowrap btn btn-secondary-outline" + %> + <%# + = link_to "Manage categories", + authenticated_root_path, + class: "whitespace-nowrap btn btn-secondary-outline" + %> + <%# end %>
- - -
-
-
-

- Service Populations -

-

- Who this content is intended to support -

-
- - <% if current_user.super_user? %> -
- <%= link_to "Manage sectors", - authenticated_root_path, - class: "admin-only bg-blue-100 btn btn-secondary-outline whitespace-nowrap" %> -
- <% end %> -
- -
- <% @sectors.each do |sector| %> - <%= render "sectors/tagging_label", - sector: sector, - bg_color: "bg-white", - bg_hover_color: "bg-lime-200" %> - <% end %> + +
+
+
+

+ Service Populations +

+

+ Who this content is intended to support +

-
- - -
-
-
-

- Categories -

-

- Themes and topics represented across content -

-
- - <% if current_user.super_user? %> -
- <%= link_to "Manage categories", + <% if current_user.super_user? %> +
+ <%= link_to "Manage sectors", authenticated_root_path, class: "admin-only bg-blue-100 btn btn-secondary-outline whitespace-nowrap" %> -
- <% end %> -
+
+ <% end %> +
-
- <% @categories_by_type.each do |type, categories| %> -
-
- <%= type.titleize %> -
+ <%= turbo_frame_tag :sectors_tags, src: tags_sectors_path do %> + <% render "loading" %> + <% end %> +
-
- <% categories.each do |category| %> - <%= render "categories/tagging_label", - category: category, - name_only: true, - bg_color: "bg-white", - bg_hover_color: "bg-lime-200" %> - <% end %> -
-
- <% end %> + +
+
+
+

+ Categories +

+

+ Themes and topics represented across content +

-
+ <% if current_user.super_user? %> +
+ <%= link_to "Manage categories", + authenticated_root_path, + class: "admin-only bg-blue-100 btn btn-secondary-outline whitespace-nowrap" %> +
+ <% end %> +
-
+ <%= turbo_frame_tag :categories_tags, src: tags_categories_path do %> + <%= render "loading" %> + <% end %> + + diff --git a/app/views/tags/sectors.html.erb b/app/views/tags/sectors.html.erb new file mode 100644 index 000000000..c235b0743 --- /dev/null +++ b/app/views/tags/sectors.html.erb @@ -0,0 +1,10 @@ +<%= turbo_frame_tag :sectors_tags do %> +
+ <% @sectors.each do |sector| %> + <%= render "sectors/tagging_label", + sector: sector, + bg_color: "bg-white", + bg_hover_color: "bg-lime-200" %> + <% end %> +
+<% end %> diff --git a/config/routes.rb b/config/routes.rb index de71b048b..b9ba66d6c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,9 +27,11 @@ get 'dashboard/help', to: 'dashboard#help' get "image_migration_audit", to: "image_migration_audit#index" - get "taggings", to: 'taggings#index', as: 'taggings' - get "taggings/matrix", to: 'taggings#matrix', as: 'taggings_matrix' - get "tags", to: 'tags#index', as: 'tags' + get "taggings", to: "taggings#index", as: "taggings" + get "taggings/matrix", to: "taggings#matrix", as: "taggings_matrix" + get "tags", to: "tags#index", as: "tags" + get "tags/sectors", to: "tags#sectors", as: "tags_sectors" + get "tags/categories", to: "tags#categories", as: "tags_categories" resources :banners resources :bookmarks do diff --git a/spec/requests/tags_spec.rb b/spec/requests/tags_spec.rb index 347cbbaf5..b582104ab 100644 --- a/spec/requests/tags_spec.rb +++ b/spec/requests/tags_spec.rb @@ -1,77 +1,64 @@ -# spec/requests/tags_spec.rb require "rails_helper" RSpec.describe "Tags index", type: :request do - let!(:sector) do - create(:sector, :published, name: "Youth") - end + let!(:sector) { create(:sector, :published, name: "Youth") } + let!(:category_type) { create(:category_type, name: "Theme") } + let!(:category) { create(:category, :published, name: "Healing", category_type: category_type) } - let!(:category_type) do - create(:category_type, name: "Theme") - end + describe "as a regular user" do + let(:user) { create(:user) } - let!(:category) do - create( - :category, - :published, - name: "Healing", - category_type: category_type - ) - end + before { sign_in user } - describe "as a regular user" do - let(:user) { create(:user) } + it "renders Service Populations and Categories skeleton" do + get tags_path + expect(response).to have_http_status(:ok) + expect(response.body).to include("Service Populations") + expect(response.body).to include("Categories") + end - before do - sign_in user - get tags_path - end + it "renders sectors frame" do + get tags_sectors_path + expect(response).to have_http_status(:ok) + expect(response.body).to include("Youth") + end - it "renders successfully" do - expect(response).to have_http_status(:ok) - end + it "renders categories frame" do + get tags_categories_path + expect(response).to have_http_status(:ok) + expect(response.body).to include("Healing") + end - it "shows published sectors" do - expect(response.body).to include("Youth") - end + it "does NOT show admin-only controls" do + get tags_path + expect(response).to have_http_status(:ok) + expect(response.body).not_to include("Manage sectors") + expect(response.body).not_to include("Manage categories") + end + end - it "shows published categories" do - expect(response.body).to include("Healing") - end + describe "as a super user (admin)" do + let(:admin) { create(:user, :admin) } - it "does NOT show admin-only controls" do - expect(response.body).not_to include("Manage sectors") - expect(response.body).not_to include("Manage categories") - end - end + before { sign_in admin } - describe "as a super user (admin)" do - let(:admin) { create(:user, :admin) } + it "renders sectors frame with admin controls" do + get tags_path + expect(response).to have_http_status(:ok) + expect(response.body).to include("Manage sectors") + end - before do - sign_in admin - get tags_path - end + it "renders categories frame with admin controls" do + get tags_path + expect(response).to have_http_status(:ok) + expect(response.body).to include("Manage categories") + end + end - it "renders successfully" do - expect(response).to have_http_status(:ok) - end - - it "shows admin controls" do - expect(response.body).to include("Manage sectors") - expect(response.body).to include("Manage categories") - end - - it "still shows sectors and categories" do - expect(response.body).to include("Youth") - expect(response.body).to include("Healing") - end - end - - describe "when not signed in" do - it "redirects to sign-in" do - get tags_path - expect(response).to redirect_to(new_user_session_path) - end - end + describe "when not signed in" do + it "redirects to sign-in" do + get tags_path + expect(response).to redirect_to(new_user_session_path) + end + end end