From 901b037d200d786ef8dad52dd40031b8b6e39853 Mon Sep 17 00:00:00 2001 From: Mike Sanders Date: Fri, 20 Dec 2024 10:53:48 +0100 Subject: [PATCH] do not show disabled materials on material index and provider show --- app/models/material.rb | 8 ++++++++ app/views/content_providers/_content_provider.html.erb | 2 +- app/views/content_providers/show.html.erb | 4 ++-- lib/facets.rb | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/models/material.rb b/app/models/material.rb index c99ea659a..b88055a00 100644 --- a/app/models/material.rb +++ b/app/models/material.rb @@ -142,6 +142,14 @@ def self.facet_fields field_list end + def self.not_disabled + where('materials.visible is true') + end + + def self.disabled + where('materials.visible is false') + end + def self.check_exists(material_params) given_material = material_params.is_a?(Material) ? material_params : new(material_params) material = nil diff --git a/app/views/content_providers/_content_provider.html.erb b/app/views/content_providers/_content_provider.html.erb index a90139c39..78ba2b857 100644 --- a/app/views/content_providers/_content_provider.html.erb +++ b/app/views/content_providers/_content_provider.html.erb @@ -10,7 +10,7 @@ <% if content_provider.materials.length > 0 %> -
<%= pluralize(content_provider.materials.length, 'training material') %>
+
<%= pluralize(content_provider.materials.not_disabled.length, 'training material') %>
<% end %> <% if content_provider.events.length > 0 %> diff --git a/app/views/content_providers/show.html.erb b/app/views/content_providers/show.html.erb index 8d4cd1509..9b8db168d 100644 --- a/app/views/content_providers/show.html.erb +++ b/app/views/content_providers/show.html.erb @@ -21,8 +21,8 @@
<% resource_limit = 30 %> - <% materials = @content_provider.materials.from_verified_users.limit(resource_limit) %> - <% materials_count = @content_provider.materials.from_verified_users.count %> + <% materials = @content_provider.materials.from_verified_users.not_disabled.limit(resource_limit) %> + <% materials_count = @content_provider.materials.from_verified_users.not_disabled.count %> <% upcoming_events = @content_provider.events.from_verified_users.not_finished.not_disabled.order(start: :asc) %> <% past_events = @content_provider.events.from_verified_users.finished.not_disabled %> <% events = upcoming_events.limit(resource_limit) %> diff --git a/lib/facets.rb b/lib/facets.rb index bfc45e3f0..98f11142a 100644 --- a/lib/facets.rb +++ b/lib/facets.rb @@ -1,7 +1,7 @@ module Facets SPECIAL = { include_expired: ->(c) { c.name == 'Event' }, - include_disabled: ->(c) { c.name == 'Event' }, + include_disabled: ->(c) { c.name == 'Event' || c.name == 'Material' }, include_archived: ->(c) { c.name == 'Material' || c.name == 'LearningPath' }, days_since_scrape: ->(c) { c.method_defined?(:last_scraped) }, elixir: ->(c) { %w[Event Material ContentProvider].include?(c.name) },