Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 14 additions & 5 deletions app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,23 @@ def show
# if tag is NOT wrangled, prepare to show works, collections, and bookmarks that are using it
if [email protected] && [email protected]
@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.paginate(page: params[:page])
@collections = @tag.collections.paginate(page: params[:page])
@bookmarks = @tag.bookmarks.visible
@collections = @tag.collections
# if from a collection, only show works from that collection
if @collection.present?
@works &= @collection.works
@bookmarks = []
@collections = []
end
@works = @works.paginate(page: params[:page])
@bookmarks = @bookmarks.paginate(page: params[:page])
@collections = @collections.paginate(page: params[:page])
end
# cache the children, since it's a possibly massive query
@tag_children = Rails.cache.fetch "views/tags/#{@tag.cache_key}/children" do
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
19 changes: 17 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,21 @@ 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|
work.fandoms.each do |fandom|
if fandom.unwrangled? || fandom.canonical?
list.push(fandom.id)
else
list.push(fandom.merger_id)
end
end
end
list.tally
end

######################################################################
# CACHE OPTIONS
######################################################################
Expand Down
8 changes: 7 additions & 1 deletion app/views/tags/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@
<p><%= ts("This tag has not been marked common and can't be filtered on (yet).") %></p>
<% unless @works.blank? %>
<div class="work listbox group">
<h3 class="heading"><%= ts('Works which have used it as a tag') %>:</h3>
<h3 class="heading">
<% if @collection.present? %>
<%= t(".unwrangled.header.collection") %>
<% else %>
<%= t(".unwrangled.header.generic") %>
<% end %>
</h3>
<%= paginated_section @works do %>
<ul class="index group">
<% for work in @works %>
Expand Down
4 changes: 4 additions & 0 deletions config/locales/views/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2405,6 +2405,10 @@ en:
filter_bookmarks: filter bookmarks
filter_works: filter works
list_fandom_tags_html: You can also access a list of %{fandom_relationship_tags_link}.
unwrangled:
header:
collection: Works in this collection which have used it as a tag
generic: Works which have used it as a tag
wrangle:
manage:
comments: Comments (%{count})
Expand Down
48 changes: 48 additions & 0 deletions features/collections/collection_navigation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,54 @@ Feature: Basic collection navigation
Then I should not see "High School Musical"
And I should see "Steven's Universe"

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 the collection counts have expired
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"

@disable_caching
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 bookmark the work "Uncategoric Sans" with the note "Secret Sans" with the tags "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"
And I should not see "Secret Sans"

# 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"
And I should see "Secret Sans"

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