Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-6539 Update user creation summary h3s and pagination behavior #4897

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 7 additions & 4 deletions app/views/admin/admin_users/_user_creations_summary.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<% unless @works.empty? %>
<% unless @user.works.empty? %>
<%# Checking @user.items.empty? rather than @items.empty? allows us to display
# an empty listbox with pagination if the admin manually enters the wrong URL.
# This is consistent with pagination on other site pages. %>
<div class="work listbox group" id="works-summary">
<h3 class="heading"><%= t(".works", count: works.size) %></h3>
<h3 class="heading"><%= search_header(@works, nil, "Work") %></h3>
<%= render "works/work_abbreviated_list", works: works %>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just call pluralize on the string passed here, which is... oof. A problem for future us.

def search_header(collection, search, item_name, parent=nil)
header = []
if !collection.respond_to?(:total_pages)
header << ts("Recent #{item_name.pluralize}")
elsif collection.total_pages < 2
header << pluralize(collection.total_entries, item_name)
else
total_entries = collection.total_entries
total_entries = collection.unlimited_total_entries if collection.respond_to?(:unlimited_total_entries)
header << ts(" %{start_number} - %{end_number} of %{total} %{things}",
start_number: number_with_delimiter(collection.offset + 1),
end_number: number_with_delimiter(collection.offset + collection.length),
total: number_with_delimiter(total_entries),
things: item_name.pluralize)
end
header << ts("found") if search.present? && search.query.present?
case parent
when Collection
header << ts("in %{collection_link}", collection_link: link_to(parent.title, parent))
when Pseud
header << ts("by %{byline}", byline: parent.byline)
when User
header << ts("by %{username}", username: parent.login)
when Language
header << ts("in %{language}", language: parent.name)
end
header << ts("in %{tag_link}", tag_link: link_to_tag_with_text(parent, parent.name)) if parent.is_a?(Tag)
# The @fandom version is used when following a fandom link from a user's dashboard, which
# which will take you to a URL like /users/username/works?fandom_id=123.
header << ts("in %{fandom_link}", fandom_link: link_to_tag(@fandom)) if @fandom.present?
header.join(" ").html_safe
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱

<%= will_paginate(works, param_name: "works_page", params: { anchor: "works-summary" }) %>
</div>
<% end %>

<% unless @comments.empty? %>
<% unless @user.comments.empty? %>
<%# We use comments rather than comment as the class because .comment:after
# create a clear that causes wonky styling when there are only a few
# comments. %>
<div class="comments listbox group" id="comments-summary">
<h3 class="heading"><%= t(".comments", count: comments.size) %></h3>
<h3 class="heading"><%= search_header(@comments, nil, "Comment") %></h3>
<%= render "comments/comment_abbreviated_list", comments: comments %>
<%= will_paginate(comments, param_name: "comments_page", params: { anchor: "comments-summary" }) %>
</div>
Expand Down
9 changes: 6 additions & 3 deletions app/views/admin/admin_users/creations.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
<!--/descriptions-->

<!--subnav-->
<ul class="navigation actions" role="navigation">
<ul class="navigation actions">
<li>
<%= link_to t(".admin_user"), admin_user_path(@user) %>
<%= span_if_current(t(".navigation.creations"), creations_admin_user_path(@user)) %>
</li>
<li>
<%= span_if_current(t(".navigation.admin_user"), admin_user_path(@user)) %>
</li>
</ul>
<!--/subnav-->

<!--main content-->
<% if @works.empty? && @comments.empty? %>
<% if @user.works.empty? && @user.comments.empty? %>
<p class="notes"><%= t(".no_creations") %></p>
<% else %>
<%= render "user_creations_summary", works: @works, comments: @comments %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/admin_users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!--/descriptions-->

<!--subnav-->
<ul class="navigation actions" role="navigation">
<ul class="navigation actions">
<li>
<%= link_to t(".navigation.invitations.manage"), manage_user_invitations_path(user_id: @user.login) %>
</li>
Expand Down
7 changes: 3 additions & 4 deletions config/locales/views/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ en:
page_heading: Delete Spammer Creations
submit: Yes, Delete All Spammer Creations
creations:
admin_user: User Administration
navigation:
admin_user: User Administration
creations: Creations
no_creations: This user has no works or comments.
page_heading: Works and Comments by %{user}
page_title: "%{login} - User Creations"
Expand Down Expand Up @@ -188,9 +190,6 @@ en:
required: Required when adding or removing a warning or suspension to an account.
submit: Update
heading: Record Warnings, Suspensions, or Notes
user_creations_summary:
comments: Comments (%{count})
works: Works (%{count})
api:
edit:
page_title: Edit API Token
Expand Down
8 changes: 5 additions & 3 deletions features/admins/users/admin_manage_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ Feature: Admin Actions to manage users
Then I should see the invitation id for the user "user2"

Scenario: An admin can access a user's creations from their administration page
Given the user "lurker" exists and is activated
Given there is 1 user creation per page
And the user "lurker" exists and is activated
And I am logged in as "troll"
And I post the work "Creepy Gift"
And I post the work "NFW"
And I post the comment "Neener" on the work "Creepy Gift"
When I am logged in as a "support" admin
And I go to the user administration page for "lurker"
Expand All @@ -103,8 +105,8 @@ Feature: Admin Actions to manage users
When I go to the user administration page for "troll"
And I follow "Creations"
Then I should see "Works and Comments by troll"
And I should see "Works (1)" within "#works-summary"
And I should see "1 - 1 of 2 Works" within "#works-summary"
And I should see "Creepy Gift" within "#works-summary"
And I should see "Comments (1)" within "#comments-summary"
And I should see "1 Comment" within "#comments-summary"
And I should see "Comment on the work Creepy Gift" within "#comments-summary"
And I should see "<p>Neener</p>" within "#comments-summary"
5 changes: 5 additions & 0 deletions features/step_definitions/admin_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@
admin.unlock_access!
end

Given "there is/are {int} user creation(s) per page" do |amount|
allow(Work).to receive(:per_page).and_return(amount)
allow(Comment).to receive(:per_page).and_return(amount)
end

### WHEN

When /^I visit the last activities item$/ do
Expand Down
Loading