Skip to content

Commit 6ee27fb

Browse files
Add location to team API.
Fixes #2283. Also rename room to location in database and UI to be more consistent.
1 parent 98157a2 commit 6ee27fb

22 files changed

+104
-46
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Version 8.3.0DEV
2727
- Fix medal awards when skipping categories.
2828
- Add direct button to public page for registering when enabled.
2929
- Scale batch size of judge tasks dynamically.
30+
- Rename room to location for teams.
3031

3132
Version 8.2.0 - 6 March 2023
3233
----------------------------

doc/manual/import.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fields:
166166
- ``display_name`` (optional): the team display name. If provided, will display
167167
this instead of the team name in certain places, like the scoreboard
168168
- ``organization_id``: the ID of the team affiliation this team belongs to
169-
- ``room`` (optional): the room of the team
169+
- ``location`` (optional): the location of the team
170170

171171
If the ``data_source`` setting of DOMjudge is set to external, the ``id`` field will be the
172172
ID used for the team and the ``group_ids`` and ``organization_id`` fields are the values as
@@ -183,7 +183,7 @@ Example ``teams.json``::
183183
"group_ids": ["24"],
184184
"name": "¡i¡i¡",
185185
"organization_id": "INST-42",
186-
"room": "AUD 10"
186+
"location": "AUD 10"
187187
}, {
188188
"id": "2",
189189
"icpc_id": "447837",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* Auto-generated Migration: Please modify to your needs!
12+
*/
13+
final class Version20240112100916 extends AbstractMigration
14+
{
15+
public function getDescription(): string
16+
{
17+
return 'Change room to location for teams.';
18+
}
19+
20+
public function up(Schema $schema): void
21+
{
22+
// this up() migration is auto-generated, please modify it to your needs
23+
$this->addSql('ALTER TABLE team CHANGE room location VARCHAR(255) DEFAULT NULL COMMENT \'Physical location of team\'');
24+
}
25+
26+
public function down(Schema $schema): void
27+
{
28+
// this down() migration is auto-generated, please modify it to your needs
29+
$this->addSql('ALTER TABLE team CHANGE location room VARCHAR(255) DEFAULT NULL COMMENT \'Physical location of team\'');
30+
}
31+
32+
public function isTransactional(): bool
33+
{
34+
return false;
35+
}
36+
}

webapp/public/js/domjudge.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ function updateMenuBalloons(data)
658658
$("#num-alerts-balloons").html(num);
659659
$("#num-alerts-balloons").show();
660660
for (var i=0; i<num; i++) {
661-
var text = (data[i].room !== null) ? data[i].room+': ' : '';
661+
var text = (data[i].location !== null) ? data[i].location+': ' : '';
662662
text += data[i].pname + ' ' + data[i].name;
663663
sendNotification('New balloon:',
664664
{'tag': 'ball_' + data[i].baloonid,

webapp/src/Controller/Jury/BalloonController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ public function indexAction(BalloonService $balloonService): Response
9191
if (isset($filters['location-str'])) {
9292
/** @var Team[] $filteredLocations */
9393
$filteredLocations = $this->em->createQueryBuilder()
94-
->from(Team::class, 'a', 'a.room')
94+
->from(Team::class, 'a', 'a.location')
9595
->select('a')
96-
->where('a.room IN (:rooms)')
97-
->setParameter('rooms', $filters['location-str'])
96+
->where('a.location IN (:locations)')
97+
->setParameter('locations', $filters['location-str'])
9898
->getQuery()
9999
->getResult();
100100
}

webapp/src/Controller/Jury/JuryMiscController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ public function ajaxDataAction(Request $request, string $datatype): JsonResponse
8383
}, $affiliations);
8484
} elseif ($datatype === 'locations') {
8585
$locations = $qb->from(Team::class, 'a')
86-
->select('DISTINCT a.room')
87-
->where($qb->expr()->like('a.room', '?1'))
88-
->orderBy('a.room', 'ASC')
86+
->select('DISTINCT a.location')
87+
->where($qb->expr()->like('a.location', '?1'))
88+
->orderBy('a.location', 'ASC')
8989
->getQuery()->setParameter(1, '%' . $q . '%')
9090
->getResult();
9191

9292
$results = array_map(fn(array $location) => [
93-
'id' => $location['room'],
94-
'text' => $location['room']
93+
'id' => $location['location'],
94+
'text' => $location['location']
9595
], $locations);
9696
} elseif (!$this->isGranted('ROLE_JURY')) {
9797
throw new AccessDeniedHttpException('Permission denied');

webapp/src/Controller/Jury/TeamController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function indexAction(): Response
9393
'affiliation' => ['title' => 'affiliation', 'sort' => true,],
9494
'num_contests' => ['title' => '# contests', 'sort' => true,],
9595
'ip_address' => ['title' => 'last IP', 'sort' => true,],
96-
'room' => ['title' => 'room', 'sort' => true,],
96+
'location' => ['title' => 'location', 'sort' => true,],
9797
'status' => ['title' => '', 'sort' => false,],
9898
'stats' => ['title' => 'stats', 'sort' => true,],
9999
];

webapp/src/Controller/Team/MiscController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function printAction(Request $request): Response
184184
$teamId = (string)$team->getTeamid();
185185
}
186186
$ret = $this->dj->printFile($realfile, $originalfilename, $langid,
187-
$username, $team->getEffectiveName(), $teamId, $team->getRoom());
187+
$username, $team->getEffectiveName(), $teamId, $team->getLocation());
188188

189189
return $this->render('team/print_result.html.twig', [
190190
'success' => $ret[0],
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\DataFixtures\Test;
4+
5+
use App\Entity\Team;
6+
use Doctrine\Persistence\ObjectManager;
7+
8+
class AddLocationToTeamFixture extends AbstractTestDataFixture
9+
{
10+
public function load(ObjectManager $manager): void
11+
{
12+
$team = $manager->getRepository(Team::class)->findOneBy(['name' => 'Example teamname']);
13+
$team->setLocation('Utrecht');
14+
$manager->flush();
15+
}
16+
}

webapp/src/Entity/Team.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ class Team extends BaseApiEntity implements ExternalRelationshipEntityInterface,
8787
private ?string $publicDescription = null;
8888

8989
#[ORM\Column(nullable: true, options: ['comment' => 'Physical location of team'])]
90-
#[Serializer\Exclude]
91-
private ?string $room = null;
90+
#[OA\Property(nullable: true)]
91+
#[Serializer\Groups([ARC::GROUP_NONSTRICT])]
92+
private ?string $location = null;
9293

9394
#[ORM\Column(
9495
name: 'internalcomments',
@@ -285,15 +286,15 @@ public function getPublicDescription(): ?string
285286
return $this->publicDescription;
286287
}
287288

288-
public function setRoom(?string $room): Team
289+
public function setLocation(?string $location): Team
289290
{
290-
$this->room = $room;
291+
$this->location = $location;
291292
return $this;
292293
}
293294

294-
public function getRoom(): ?string
295+
public function getLocation(): ?string
295296
{
296-
return $this->room;
297+
return $this->location;
297298
}
298299

299300
public function setInternalComments(?string $comments): Team

webapp/src/Form/Type/TeamType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
8282
$builder->add('penalty', IntegerType::class, [
8383
'label' => 'Penalty time',
8484
]);
85-
$builder->add('room', TextType::class, [
85+
$builder->add('location', TextType::class, [
8686
'label' => 'Location',
8787
'required' => false,
8888
]);

webapp/src/Service/BalloonService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function collectBalloonTable(Contest $contest, bool $todo = false): array
9292

9393
$query = $em->createQueryBuilder()
9494
->select('b', 's.submittime', 'p.probid',
95-
't.teamid', 's', 't', 't.room',
95+
't.teamid', 's', 't', 't.location',
9696
'c.categoryid AS categoryid', 'c.name AS catname',
9797
'co.cid', 'co.shortname',
9898
'cp.shortname AS probshortname', 'cp.color',
@@ -159,7 +159,7 @@ public function collectBalloonTable(Contest $contest, bool $todo = false): array
159159
$balloondata['contestproblem'] = $balloon->getSubmission()->getContestProblem();
160160
$balloondata['team'] = $balloon->getSubmission()->getTeam();
161161
$balloondata['teamid'] = $balloonsData['teamid'];
162-
$balloondata['location'] = $balloonsData['room'];
162+
$balloondata['location'] = $balloonsData['location'];
163163
$balloondata['affiliation'] = $balloonsData['affilshort'];
164164
$balloondata['affiliationid'] = $balloonsData['affilid'];
165165
$balloondata['category'] = $balloonsData['catname'];

webapp/src/Service/DOMJudgeService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public function getUpdates(): array
410410

411411
if ($this->checkrole('balloon')) {
412412
$balloonsQuery = $this->em->createQueryBuilder()
413-
->select('b.balloonid', 't.name', 't.room', 'p.name AS pname')
413+
->select('b.balloonid', 't.name', 't.location', 'p.name AS pname')
414414
->from(Balloon::class, 'b')
415415
->leftJoin('b.submission', 's')
416416
->leftJoin('s.problem', 'p')
@@ -714,7 +714,7 @@ public function openZipFile(string $filename): ZipArchive
714714
* @param string $username Username of the print job submitter
715715
* @param string|null $teamname Teamname of the team this user belongs to, if any
716716
* @param string|null $teamid Teamid of the team this user belongs to, if any
717-
* @param string|null $location Room/place of the team, if any.
717+
* @param string|null $location Location of the team, if any.
718718
*/
719719
public function printFile(
720720
string $filename,

webapp/src/Service/ICPCCmsService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function importTeams(string $token, string $contest, ?string &$message =
115115
->setEnabled($enabled)
116116
->setInternalComments('Status: ' . $teamData['status'])
117117
->setIcpcid($teamData['teamId'])
118-
->setRoom($siteName);
118+
->setLocation($siteName);
119119
$this->em->persist($team);
120120
$this->em->flush();
121121
$username = sprintf("team%04d", $team->getTeamid());
@@ -137,7 +137,7 @@ public function importTeams(string $token, string $contest, ?string &$message =
137137
->setEnabled($enabled)
138138
->setInternalComments('Status: ' . $teamData['status'])
139139
->setIcpcid($teamData['teamId'])
140-
->setRoom($siteName);
140+
->setLocation($siteName);
141141

142142
$user = $this->em->getRepository(User::class)->findOneBy(['username' => $username]);
143143
$user?->setName($teamData['teamName']);

webapp/src/Service/ImportExportService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ public function importTeamsJson(array $data, ?string &$message = null, ?array &$
854854
'name' => @$team['name'],
855855
'display_name' => @$team['display_name'],
856856
'publicdescription' => $team['public_description'] ?? @$team['members'],
857-
'room' => @$team['room'],
857+
'location' => @$team['location'],
858858
],
859859
'team_affiliation' => [
860860
'externalid' => $team['organization_id'] ?? null,

webapp/templates/jury/balloons.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
<select id="location-filter" class="select2 form-control" multiple data-filter-field="location-str"
4747
data-ajax-url="{{ path('jury_ajax_data', {datatype: 'locations', select2: true}) }}">
4848
{%- for location in filteredLocations %}
49-
<option value="{{ location.room }}" selected>
50-
{{ location.room }}
49+
<option value="{{ location.location }}" selected>
50+
{{ location.location }}
5151
</option>
5252
{%- endfor %}
5353
</select>

webapp/templates/jury/partials/team_form.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{{ form_row(form.publicdescription) }}
1313
{{ form_row(form.affiliation) }}
1414
{{ form_row(form.penalty) }}
15-
{{ form_row(form.room) }}
15+
{{ form_row(form.location) }}
1616
{{ form_row(form.internalcomments) }}
1717
{{ form_row(form.contests) }}
1818
{{ form_row(form.enabled) }}

webapp/templates/jury/team.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@
8585
<td>{{ team.penalty }}</td>
8686
</tr>
8787
{% endif %}
88-
{% if team.room %}
88+
{% if team.location %}
8989
<tr>
9090
<th>Location</th>
91-
<td>{{ team.room }}</td>
91+
<td>{{ team.location }}</td>
9292
</tr>
9393
{% endif %}
9494
<tr>

webapp/templates/partials/team.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
</tr>
4646
{% endif %}
4747
{% endif %}
48-
{% if team.room is not empty %}
48+
{% if team.location is not empty %}
4949
<tr>
5050
<th>Location</th>
51-
<td>{{ team.room }}</td>
51+
<td>{{ team.location }}</td>
5252
</tr>
5353
{% endif %}
5454
</table>

webapp/tests/Unit/Controller/API/TeamControllerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Tests\Unit\Controller\API;
44

5+
use App\DataFixtures\Test\AddLocationToTeamFixture;
56
use Symfony\Component\HttpFoundation\BinaryFileResponse;
67
use Symfony\Component\HttpFoundation\File\UploadedFile;
78

@@ -21,9 +22,12 @@ class TeamControllerTest extends BaseTestCase
2122
'display_name' => null,
2223
'members' => null,
2324
'photo' => null,
25+
'location' => 'Utrecht',
2426
],
2527
];
2628

29+
protected static array $fixtures = [AddLocationToTeamFixture::class];
30+
2731
protected array $expectedAbsent = ['4242', 'nonexistent'];
2832

2933
public function testLogoManagement(): void

webapp/tests/Unit/Controller/Jury/TeamControllerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TeamControllerTest extends JuryControllerTestCase
1818
protected static string $className = Team::class;
1919
protected static array $DOM_elements = ['h1' => ['Teams']];
2020
protected static string $addForm = 'team[';
21-
protected static array $addEntitiesShown = ['icpcid', 'label', 'displayName', 'room'];
21+
protected static array $addEntitiesShown = ['icpcid', 'label', 'displayName', 'location'];
2222
protected static array $overviewSingleNotShown = ['addUserForTeam'];
2323
protected static array $overviewGeneralNotShown = ['icpcid'];
2424
protected static array $addEntitiesCount = ['contests'];
@@ -27,7 +27,7 @@ class TeamControllerTest extends JuryControllerTestCase
2727
'category' => '3',
2828
'publicdescription' => 'Some members',
2929
'penalty' => '0',
30-
'room' => 'The first room',
30+
'location' => 'The first room',
3131
'internalcomments' => 'This is a team without a user',
3232
'contests' => [],
3333
'enabled' => '1',
@@ -38,7 +38,7 @@ class TeamControllerTest extends JuryControllerTestCase
3838
'category' => '1',
3939
'publicdescription' => 'More members',
4040
'penalty' => '20',
41-
'room' => 'Another room',
41+
'location' => 'Another room',
4242
'internalcomments' => 'This is a team with a user',
4343
'enabled' => '1',
4444
'addUserForTeam' => Team::CREATE_NEW_USER,
@@ -57,9 +57,9 @@ class TeamControllerTest extends JuryControllerTestCase
5757
['name' => 'no_members',
5858
'publicdescription' => '',
5959
'displayName' => 'Team without members'],
60-
['name' => 'no_room',
61-
'room' => '',
62-
'displayName' => 'Team without a room'],
60+
['name' => 'no_location',
61+
'location' => '',
62+
'displayName' => 'Team without a location'],
6363
['name' => 'no_comments',
6464
'internalcomments' => '',
6565
'displayName' => 'Team without comments'],

0 commit comments

Comments
 (0)