Skip to content

Commit 44d7fee

Browse files
committed
feat: add submission notification
1 parent 43ecaaa commit 44d7fee

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

webapp/public/js/domjudge.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ function toggleRefresh($url, $after, usingAjax) {
660660
$('#refresh-toggle').text(text);
661661
}
662662

663-
function updateClarifications()
663+
function updateTeamNotifications()
664664
{
665665
$.ajax({
666666
url: $('#menuDefault').data('update-url'),
@@ -677,6 +677,14 @@ function updateClarifications()
677677
'link': domjudge_base_url + '/team/clarifications/'+data[i].clarid,
678678
'body': data[i].body });
679679
}
680+
data = json['unread_submissions'];
681+
num = data.length;
682+
for (let i = 0; i < num; i++) {
683+
sendNotification(`Submission ${data[i].submissionid}: ${data[i].result}`,
684+
{'tag': 'sub_' + data[i].submissionid + '_judge_' + data[i].judgingid,
685+
'link': domjudge_base_url + '/team/submission/'+data[i].submissionid,
686+
'body': `Submission ${data[i].submissionid} received a new result: ${data[i].result}` });
687+
}
680688
}
681689
})
682690
}

webapp/src/Controller/Team/MiscController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ public function homeAction(Request $request): Response
143143
#[Route(path: '/updates', methods: ['GET'], name: 'team_ajax_updates')]
144144
public function updatesAction(): JsonResponse
145145
{
146-
return $this->json(['unread_clarifications' => $this->dj->getUnreadClarifications()]);
146+
return $this->json([
147+
'unread_clarifications' => $this->dj->getUnreadClarifications(),
148+
'unread_submissions' => $this->dj->getUnreadJudgements(),
149+
]);
147150
}
148151

149152
#[Route(path: '/change-contest/{contestId<-?\d+>}', name: 'team_change_contest')]

webapp/src/Service/DOMJudgeService.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,53 @@ public function getUnreadClarifications(): array
322322
return $unreadClarifications;
323323
}
324324

325+
/**
326+
* @return array<array{submissionid: int, judgingid: int, result: string}>
327+
*/
328+
329+
public function getUnreadJudgements(): array
330+
{
331+
$user = $this->getUser();
332+
$team = $user->getTeam();
333+
$contest = $this->getCurrentContest($team->getTeamId());
334+
$unreadJudgements = [];
335+
if ($contest === null) {
336+
return $unreadJudgements;
337+
}
338+
339+
$queryBuilder = $this->em->createQueryBuilder()
340+
->from(Judging::class, 'j')
341+
->select('j, c, s')
342+
->leftJoin('j.contest', 'c')
343+
->leftJoin('j.submission', 's')
344+
->groupBy('j.judgingid')
345+
->orderBy('j.judgingid')
346+
->andWhere('j.contest = :cid')
347+
->setParameter('cid', $contest->getCid())
348+
->andWhere('j.result IS NOT NULL')
349+
->andWhere('s.team = :team')
350+
->setParameter('team', $team)
351+
->andWhere('s.submittime < c.endtime')
352+
->andWhere('j.valid = 1')
353+
->andWhere('j.seen = 0');
354+
355+
if ($this->config->get('verification_required')) {
356+
$queryBuilder->andWhere('j.verified = 1');
357+
}
358+
359+
/** @var Judging[] $judgings */
360+
$judgings = $queryBuilder->getQuery()->getResult();
361+
362+
foreach ($judgings as $j) {
363+
$unreadJudgements[] = [
364+
'submissionid' => $j->getSubmissionId(),
365+
'judgingid' => $j->getJudgingid(),
366+
'result' => $j->getResult()
367+
];
368+
}
369+
return $unreadJudgements;
370+
}
371+
325372
/**
326373
* @return array{clarifications: array<array{clarid: int, body: string}>,
327374
* judgehosts: array<array{hostname: string, polltime: float}>,

webapp/templates/team/base.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
$('#notify_disable').removeClass('d-none');
4444
}
4545
}
46-
updateClarifications();
47-
setInterval(updateClarifications, 20000);
46+
updateTeamNotifications();
47+
setInterval(updateTeamNotifications, 20000);
4848
});
4949
5050
</script>

0 commit comments

Comments
 (0)