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

Team member leaderboard #11827

Merged
merged 4 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
30 changes: 30 additions & 0 deletions app/Http/Controllers/TeamsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

namespace App\Http\Controllers;

use App\Exceptions\InvariantException;
use App\Models\Beatmap;
use App\Models\Team;
use App\Models\User;
use App\Transformers\UserCompactTransformer;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -27,6 +30,11 @@ public static function pageLinks(string $current, Team $team): array
'title' => osu_trans('teams.header_links.show'),
'url' => route('teams.show', ['team' => $team->getKey()]),
],
[
'active' => $current === 'leaderboard',
'title' => osu_trans('teams.header_links.leaderboard'),
'url' => route('teams.leaderboard', ['team' => $team->getKey()]),
],
];

if (priv_check('TeamUpdate', $team)->can()) {
Expand Down Expand Up @@ -66,6 +74,28 @@ public function edit(string $id): Response
return ext_view('teams.edit', compact('team'));
}

public function leaderboard(string $id, ?string $ruleset = null): Response
{
$team = Team::findOrFail($id);
$ruleset ??= Beatmap::modeStr($team->default_ruleset_id);
$statisticsRelationName = User::statisticsRelationName($ruleset);
if ($statisticsRelationName === null) {
throw new InvariantException(osu_trans('beatmaps.invalid_ruleset'));
}
$leaderboard = $team
->members
->loadMissing("user.{$statisticsRelationName}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

also need to load/set the team and userGroups

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

more like too much copypaste 👀

->map(fn ($member) =>
(
$member->user->$statisticsRelationName
?? $member->user->$statisticsRelationName()->make()
)->setRelation('user', $member->user))
->sortByDesc(['rank_score', 'total_score'])
->values();

return ext_view('teams.leaderboard', compact('leaderboard', 'ruleset', 'team'));
}

public function part(string $id): Response
{
$team = Team::findOrFail($id);
Expand Down
4 changes: 4 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,10 @@ function i18n_date_auto(DateTimeInterface $date, string $skeleton): string

function i18n_number_format($number, $style = null, $pattern = null, $precision = null, $locale = null)
{
if ($number === null) {
return null;
}

if ($style === null && $pattern === null && $precision === null) {
static $formatters = [];
$locale ??= App::getLocale();
Expand Down
2 changes: 2 additions & 0 deletions resources/css/bem-index.less
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@
@import "bem/team-info-entries";
@import "bem/team-info-entry";
@import "bem/team-members";
@import "bem/team-members-leaderboard";
@import "bem/team-members-leaderboard-item";
@import "bem/team-members-manage";
@import "bem/team-settings";
@import "bem/team-settings-description-preview";
Expand Down
52 changes: 52 additions & 0 deletions resources/css/bem/team-members-leaderboard-item.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

.team-members-leaderboard-item {
--gutter: 10px;
align-items: center;
background: hsl(var(--hsl-b3));
border-radius: @border-radius--large;
display: grid;
font-size: @font-size--title-small;
gap: 10px;
grid-column: 1 / -1;
grid-template-columns: subgrid;
padding: 4px var(--gutter);

&:hover {
background: hsl(var(--hsl-b2));
}

@media @desktop {
--gutter: 20px;
}

&__avatar {
.default-border-radius();
align-items: center;
display: flex;
overflow: hidden;
width: 40px;
}

&__number {
font-size: @font-size--title-small-3;
padding: 0 var(--gutter);
}

&__number-title {
color: hsl(var(--hsl-c2));
font-size: @font-size--normal;
}

&__rank {
text-align: end;
}

&__username {
display: flex;
align-items: center;
width: max-content;
gap: 10px;
}
}
11 changes: 11 additions & 0 deletions resources/css/bem/team-members-leaderboard.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

.team-members-leaderboard {
display: grid;
margin: 0;
padding: 0;
list-style: none;
gap: 2px;
grid-template-columns: auto 1fr auto auto auto;
}
2 changes: 2 additions & 0 deletions resources/lang/en/beatmaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// See the LICENCE file in the repository root for full licence text.

return [
'invalid_ruleset' => 'Invalid ruleset specified.',

'change_owner' => [
'too_many' => 'Too many guest mappers.',
],
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/page_title.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
'teams_controller' => [
'_' => 'teams',
'edit' => 'team settings',
'leaderboard' => 'team leaderboard',
'show' => 'team info',
],
'tournaments_controller' => [
Expand Down
9 changes: 8 additions & 1 deletion resources/lang/en/teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,20 @@

'header_links' => [
'edit' => 'settings',
'leaderboard' => 'leaderboard',
'show' => 'info',

'members' => [
'index' => 'manage members',
],
],

'leaderboard' => [
'global_rank' => 'Global Rank',
'performance' => 'Performance',
'total_score' => 'Total Score',
],

'members' => [
'destroy' => [
'success' => 'Team member removed',
Expand Down Expand Up @@ -118,8 +125,8 @@
],

'sections' => [
'members' => 'Members',
'info' => 'Info',
'members' => 'Members',
],
],
];
52 changes: 52 additions & 0 deletions resources/views/teams/_members_leaderboard.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{{--
Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
See the LICENCE file in the repository root for full licence text.
--}}
<ul class="team-members-leaderboard">
@foreach ($leaderboard as $i => $stats)
<li class="team-members-leaderboard-item">
<div class="team-members-leaderboard-item__rank">
#{{ i18n_number_format($i + 1) }}
</div>
<div class="team-members-leaderboard-item__username-container">
<a
class="team-members-leaderboard-item__username js-usercard"
data-user-id="{{ $stats->user_id }}"
href="{{ route('users.show', $stats->user_id) }}"
>
<span class="team-members-leaderboard-item__avatar">
<span
class="avatar avatar--full avatar--guest"
{!! background_image($stats->user->user_avatar) !!}
></span>
</span>

{{ $stats->user->username }}
</a>
</div>
<div class="team-members-leaderboard-item__number">
<div class="team-members-leaderboard-item__number-title">
{{ osu_trans('teams.leaderboard.total_score') }}
</div>
<div>
{{ i18n_number_format($stats->total_score) }}
</div>
</div>
<div class="team-members-leaderboard-item__number">
<div class="team-members-leaderboard-item__number-title">
{{ osu_trans('teams.leaderboard.performance') }}
</div>
<div>
{{ i18n_number_format($stats->pp()) ?? '-' }}
</div>
</div>
<div class="team-members-leaderboard-item__number">
<div class="team-members-leaderboard-item__number-title">
{{ osu_trans('teams.leaderboard.global_rank') }}
</div>
<div>
{{ i18n_number_format($stats->globalRank()) ?? '-' }}
</div>
</div>
@endforeach
</ul>
30 changes: 30 additions & 0 deletions resources/views/teams/leaderboard.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{--
Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
See the LICENCE file in the repository root for full licence text.
--}}
@extends('master', [
'titlePrepend' => $team->name,
])

@section('content')
@component('layout._page_header_v4', ['params' => [
'backgroundImage' => $team->header()->url(),
'links' => App\Http\Controllers\TeamsController::pageLinks('leaderboard', $team),
'theme' => 'team',
]])
@slot('linksAppend')
@include('objects._ruleset_selector', [
'currentRuleset' => $ruleset,
'urlFn' => fn ($r) => route('teams.leaderboard', ['team' => $team->getKey(), 'ruleset' => $r]),
])
@endslot
@endcomponent

<div class="osu-page osu-page--generic-compact">
<div class="user-profile-pages user-profile-pages--no-tabs">
<div class="page-extra u-fancy-scrollbar">
@include('teams._members_leaderboard')
</div>
</div>
</div>
@endsection
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@
Route::resource('applications', 'Teams\ApplicationsController', ['only' => ['destroy', 'store']]);
Route::post('applications/{application}/accept', 'Teams\ApplicationsController@accept')->name('applications.accept');
Route::post('applications/{application}/reject', 'Teams\ApplicationsController@reject')->name('applications.reject');
Route::get('leaderboard/{ruleset?}', 'TeamsController@leaderboard')->name('leaderboard');
Route::post('part', 'TeamsController@part')->name('part');
Route::resource('members', 'Teams\MembersController', ['only' => ['destroy', 'index']]);
});
Expand Down