Skip to content
2 changes: 1 addition & 1 deletion app/controllers/fandoms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class FandomsController < ApplicationController

def index
if @collection
@media = Media.canonical.by_name - [Media.find_by(name: ArchiveConfig.MEDIA_NO_TAG_NAME)] - [Media.find_by(name: ArchiveConfig.MEDIA_UNCATEGORIZED_NAME)]
@media = Media.canonical.by_name.where.not(name: [ArchiveConfig.MEDIA_UNCATEGORIZED_NAME, ArchiveConfig.MEDIA_NO_TAG_NAME]) + [Media.uncategorized]
@page_subtitle = t(".collection_page_title", collection_title: @collection.title)
@medium = Media.find_by_name(params[:media_id]) if params[:media_id]
@counts = SearchCounts.fandom_ids_for_collection(@collection)
Expand Down
15 changes: 12 additions & 3 deletions app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,21 @@ def show
# if tag is NOT wrangled, prepare to show works, collections, and bookmarks that are using it
if !@tag.canonical && !@tag.merger
@works = if logged_in? # current_user.is_a?User
@tag.works.visible_to_registered_user.paginate(page: params[:page])
@tag.works.visible_to_registered_user
elsif logged_in_as_admin?
@tag.works.visible_to_admin.paginate(page: params[:page])
@tag.works.visible_to_admin
else
@tag.works.visible_to_all.paginate(page: params[:page])
@tag.works.visible_to_all
end
@bookmarks = @tag.bookmarks.visible
@collections = @tag.collections
# if from a collection, only show items from that collection
if @collection.present?
@works &= @collection.works
@bookmarks &= @collection.bookmarks
@collections &= @collection.children
end
@works = @works.paginate(page: params[:page])
@bookmarks = @tag.bookmarks.visible.paginate(page: params[:page])
@collections = @tag.collections.paginate(page: params[:page])
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ def load_owner
else
redirect_to(tag_works_path(@tag.merger)) && return
end
elsif @collection.present?
redirect_to(collection_tag_path(@collection, @tag)) && return
else
redirect_to(tag_path(@tag)) && return
end
Expand Down
16 changes: 14 additions & 2 deletions app/models/search/search_counts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def bookmarkable_count_for_collection(collection)
def fandom_count_for_collection(collection)
Rails.cache.fetch(collection_cache_key(collection, :fandom_count),
collection_cache_options) do
collection_works_query(collection).field_count(:fandom_ids)
get_fandom_hash(collection_works_query(collection)).count
end
end

def fandom_ids_for_collection(collection)
Rails.cache.fetch(collection_cache_key(collection, :fandom_ids),
collection_cache_options) do
collection_works_query(collection).field_values(:fandom_ids)
get_fandom_hash(collection_works_query(collection))
end
end

Expand Down Expand Up @@ -114,6 +114,18 @@ def logged_in
User.current_user ? :logged_in : :logged_out
end

# Helper function to get both categorized and uncategorized fandoms from a WorkQuery object
def get_fandom_hash(query)
list = []
query.search_results.each do |work|
list |= work.fandom_ids if work.fandom_ids.present?
work.tag_groups["Fandom"].each do |fandom|
list.push(fandom.id) if fandom.unwrangled?
end
end
list.tally
end

######################################################################
# CACHE OPTIONS
######################################################################
Expand Down
43 changes: 43 additions & 0 deletions features/collections/collection_navigation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,49 @@ Feature: Basic collection navigation
Then I should not see "High School Musical"
And I should see "Steven's Universe"

Scenario: Uncategorized Fandoms should appear in Collection's Fandoms
Given I have the collection "Categoric" with name "categoric"
And the tag "Unrelated Fandom" does not exist
And I have a canonical "Video Games" fandom tag named "Undertale"
When I am logged in as "Frisk"
And I post the work "Categoric Sans" with fandom "Undertale" in the collection "Categoric"
And I post the work "Categoric Papyrus" with fandom "Undertale"
And I post the work "Uncategoric Sans" with fandom "Unrelated Fandom" in the collection "Categoric"
And I post the work "Uncategoric Papyrus" with fandom "Unrelated Fandom"
And I go to "Categoric" collection's page
Then I should see "Fandoms (2)"
When I follow "Fandoms (2)"
Then I should see "Unrelated Fandom"
And I should see "Undertale"
When I select "Uncategorized Fandoms" from "media_id"
And I press "Show"
Then I should see "Unrelated Fandom"
And I should not see "Undertale"

# From collection we only see the works in the collection
When I follow "Unrelated Fandom"
Then I should see "Sans"
And I should not see "Papyrus"

# Else we see all
When I follow "Uncategorized Fandoms" within "#header"
And I follow "Unrelated Fandom"
Then I should see "Sans"
And I should see "Papyrus"

Scenario: Non-Canonical Fandoms are not double counted
Given I have the collection "Canons" with name "canon"
And I have a canonical "TV Shows" fandom tag named "TV"
And a synonym "Television" of the tag "TV"
When I am logged in as "Screen"
And I post the work "Full name" with fandom "Television" in the collection "Canons"
And I post the work "Small name" with fandom "TV" in the collection "Canons"
And I go to "Canons" collection's page
Then I should see "Fandoms (1)"
And I should see "Television"
When I follow "Fandoms (1)"
Then I should not see "Television"

Scenario: Browse tags within a collection (or not)
Given I have a collection "Randomness"
And a canonical fandom "Naruto"
Expand Down
Loading