Skip to content

Commit 5b6c375

Browse files
authored
Merge pull request #11979 from nanaya/team-info-stats
Show statistics on team page
2 parents cb12fb1 + 3503fc4 commit 5b6c375

File tree

12 files changed

+187
-88
lines changed

12 files changed

+187
-88
lines changed

app/Http/Controllers/TeamsController.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,26 @@ public function part(string $id): Response
122122
return ujs_redirect(route('teams.show', ['team' => $team]));
123123
}
124124

125-
public function show(string $id): Response
125+
public function show(string $id, ?string $ruleset = null): Response
126126
{
127127
$team = Team
128128
::with(array_map(
129129
fn (string $preload): string => "members.user.{$preload}",
130130
UserCompactTransformer::CARD_INCLUDES_PRELOAD,
131131
))->findOrFail($id);
132132

133-
return ext_view('teams.show', compact('team'));
133+
if ($ruleset === null) {
134+
$rulesetId = $team->default_ruleset_id;
135+
} else {
136+
$rulesetId = Beatmap::MODES[$ruleset] ?? null;
137+
138+
if ($rulesetId === null) {
139+
abort(422, 'invalid ruleset name');
140+
}
141+
}
142+
$statistics = $team->statistics()->firstOrNew(['ruleset_id' => $rulesetId]);
143+
144+
return ext_view('teams.show', compact('rulesetId', 'statistics', 'team'));
134145
}
135146

136147
public function store(): Response

app/Models/TeamStatistics.php

+18-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@
1212

1313
class TeamStatistics extends Model
1414
{
15+
private const DEFAULT_ATTRIBUTES = [
16+
'performance' => 0,
17+
'play_count' => 0,
18+
'ranked_score' => 0,
19+
];
20+
1521
public $incrementing = false;
1622

23+
protected $attributes = self::DEFAULT_ATTRIBUTES;
1724
protected $primaryKey = ':composite';
1825
protected $primaryKeys = ['team_id', 'ruleset_id'];
1926

@@ -27,6 +34,16 @@ public function members(): HasMany
2734
return $this->hasMany(TeamMember::class, 'team_id', 'team_id');
2835
}
2936

37+
public function getRank(): ?int
38+
{
39+
return $this->performance === 0
40+
? null
41+
: 1 + static
42+
::where('ruleset_id', $this->ruleset_id)
43+
->where('performance', '>', $this->performance)
44+
->count();
45+
}
46+
3047
public function recalculate(): void
3148
{
3249
$userIdsQuery = TeamMember
@@ -42,11 +59,7 @@ public function recalculate(): void
4259
->first();
4360

4461
if ($statistics === null) {
45-
$this->update([
46-
'performance' => 0,
47-
'ranked_score' => 0,
48-
'play_count' => 0,
49-
]);
62+
$this->update(static::DEFAULT_ATTRIBUTES);
5063

5164
return;
5265
}

resources/css/bem-index.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@
385385
@import "bem/supporter-quote";
386386
@import "bem/supporter-status";
387387
@import "bem/team-action-button";
388+
@import "bem/team-info";
388389
@import "bem/team-info-entries";
389390
@import "bem/team-info-entry";
390391
@import "bem/team-members";
@@ -393,7 +394,6 @@
393394
@import "bem/team-members-manage";
394395
@import "bem/team-settings";
395396
@import "bem/team-settings-description-preview";
396-
@import "bem/team-summary";
397397
@import "bem/textual-button";
398398
@import "bem/title";
399399
@import "bem/tooltip-achievement";

resources/css/bem/team-info-entries.less

-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
.team-info-entries {
55
display: grid;
66
gap: 10px;
7-
margin-bottom: 20px;
87
}

resources/css/bem/team-info-entry.less

+4
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@
77
&__value {
88
color: hsl(var(--hsl-c2));
99
min-width: 0;
10+
11+
&--large {
12+
font-size: 2em;
13+
}
1014
}
1115
}

resources/css/bem/team-info.less

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
2+
// See the LICENCE file in the repository root for full licence text.
3+
4+
.team-info {
5+
display: grid;
6+
align-items: start;
7+
gap: 20px;
8+
9+
@media @desktop {
10+
grid-template-columns: 1fr auto 2fr;
11+
}
12+
13+
&__separator {
14+
--size: 2px;
15+
background-color: hsl(var(--hsl-b6));
16+
height: var(--size);
17+
18+
@media @desktop {
19+
height: 100%;
20+
width: var(--size);
21+
}
22+
}
23+
}

resources/css/bem/team-summary.less

-36
This file was deleted.

resources/js/beatmapsets-show/scoreboard/table-row.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default class ScoreboardTableRow extends React.Component<Props> {
117117
<td className={`${bn}__cell u-relative`}>
118118
<span className={`${classWithModifiers(`${bn}__cell-content`, 'user-link')}`}>
119119
{score.user.team != null &&
120-
<a className='u-contents' href={route('teams.show', { id: score.user.team.id })}>
120+
<a className='u-contents' href={route('teams.show', { team: score.user.team.id })}>
121121
<FlagTeam team={score.user.team} />
122122
</a>
123123
}

resources/lang/en/teams.php

+6
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,15 @@
137137
],
138138

139139
'sections' => [
140+
'about' => 'About Us!',
140141
'info' => 'Info',
141142
'members' => 'Members',
142143
],
144+
145+
'statistics' => [
146+
'rank' => 'Rank',
147+
'leader' => 'Team Leader',
148+
],
143149
],
144150

145151
'store' => [

resources/views/objects/_ruleset_selector.blade.php

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ class="{{ class_with_modifiers('game-mode-link', ['active' => $ruleset === $curr
1414
class="fal fa-extra-mode-{{ $ruleset }}"
1515
title="{{ osu_trans("beatmaps.mode.{$ruleset}") }}"
1616
></span>
17+
@if (isset($defaultRuleset) && $ruleset === $defaultRuleset)
18+
<span
19+
class="game-mode-link__icon"
20+
title="{{ osu_trans('users.show.edit.default_playmode.is_default_tooltip') }}"
21+
>
22+
<span class="fas fa-star"></span>
23+
</span>
24+
@endif
1725
</a>
1826
</li>
1927
@endforeach

0 commit comments

Comments
 (0)