Skip to content

Commit

Permalink
Move all inline style to dedicated endpoint
Browse files Browse the repository at this point in the history
We rendered the <style> within the <body> which is not valid. By moving
it to a dedicated endpoint we also save a bit of bandwith as this is
content which stays static during the contest.
  • Loading branch information
vmcj committed Dec 8, 2024
1 parent e596a3b commit a0f9cd3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/jobs/webstandard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ if [ "$TEST" = "w3cval" ]; then
unzip -q vnu.linux.zip
section_end
FLTR='--filterpattern .*autocomplete.*|.*style.*|.*role=tab.*|.*descendant.*|.*Stray.*|.*attribute.*|.*Forbidden.*|.*stream.*|.*obsolete.*'
FLTR='--filterpattern .*autocomplete.*|.*role=tab.*|.*descendant.*|.*Stray.*|.*attribute.*|.*Forbidden.*|.*stream.*|.*obsolete.*'
for typ in html css svg
do
section_start "Analyse with $typ"
Expand Down
8 changes: 8 additions & 0 deletions webapp/src/Controller/PublicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public function scoreboardDataZipAction(
return $this->dj->getScoreboardZip($request, $requestStack, $contest, $this->scoreboardService);
}

#[Route(path: '/dynamic-css', name: 'get_dynamic_css')]
public function dynamicCSS(): Response {
$response = new Response();
$response->headers->set('Content-Type', 'text/css');
$response->setContent($this->renderView('public/dynamic.css.twig', $this->dj->getDynamicCSS()));
return $response;

Check failure on line 108 in webapp/src/Controller/PublicController.php

View workflow job for this annotation

GitHub Actions / phpcs

Spaces must be used to indent lines; tabs are not allowed

Check failure on line 108 in webapp/src/Controller/PublicController.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected at least 8 spaces, found 4
}

/**
* Get the contest from the request, if any
*/
Expand Down
10 changes: 10 additions & 0 deletions webapp/src/Service/DOMJudgeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use App\Entity\Submission;
use App\Entity\Team;
use App\Entity\TeamAffiliation;
use App\Entity\TeamCategory;
use App\Entity\Testcase;
use App\Entity\User;
use App\Utils\FreezeData;
Expand Down Expand Up @@ -1532,6 +1533,15 @@ public function getScoreboardZip(
return Utils::streamZipFile($tempFilename, 'scoreboard.zip');
}

/**
* @return array{'backgroundColors', array<TeamCategory>}
*/
public function getDynamicCSS(): array {
$backgroundColors = array_map(fn($x) => ( $x->getColor() ?? '#FFFFFF' ), $this->em->getRepository(TeamCategory::class)->findAll());

Check failure on line 1540 in webapp/src/Service/DOMJudgeService.php

View workflow job for this annotation

GitHub Actions / phpcs

Spaces must be used to indent lines; tabs are not allowed

Check failure on line 1540 in webapp/src/Service/DOMJudgeService.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected at least 8 spaces, found 4
$backgroundColors = array_merge($backgroundColors, ['#FFFF99']);

Check failure on line 1541 in webapp/src/Service/DOMJudgeService.php

View workflow job for this annotation

GitHub Actions / phpcs

Spaces must be used to indent lines; tabs are not allowed

Check failure on line 1541 in webapp/src/Service/DOMJudgeService.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected at least 8 spaces, found 4
return ['backgroundColors' => $backgroundColors];

Check failure on line 1542 in webapp/src/Service/DOMJudgeService.php

View workflow job for this annotation

GitHub Actions / phpcs

Spaces must be used to indent lines; tabs are not allowed

Check failure on line 1542 in webapp/src/Service/DOMJudgeService.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected at least 8 spaces, found 4
}

private function allowJudge(ContestProblem $problem, Submission $submission, Language $language, bool $manualRequest): bool
{
if (!$problem->getAllowJudge() || !$language->getAllowJudge()) {
Expand Down
1 change: 1 addition & 0 deletions webapp/templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<link rel="stylesheet" href="{{ asset("css/bootstrap.min.css") }}">
<link rel="stylesheet" href="{{ asset("css/fontawesome-all.min.css") }}">
<link rel="stylesheet" href="{{ path('get_dynamic_css') }}">
<script src="{{ asset("js/jquery.min.js") }}"></script>
<script src="{{ asset("js/jquery.debounce.min.js") }}"></script>
<script src="{{ asset("js/bootstrap.bundle.min.js") }}"></script>
Expand Down
18 changes: 0 additions & 18 deletions webapp/templates/partials/scoreboard_table.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -578,24 +578,6 @@
{% endif %}
{% endif %}
<style>
{% for color,i in backgroundColors %}
{% set colorClass = color | replace({"#": "_"}) %}
.cl{{ colorClass }} {
background-color: {{ color }};
}
{% set cMin = color|hexColorToRGBA(0) %}
{% set cMax = color|hexColorToRGBA(1) %}
.cl{{ colorClass }} .forceWidth.toolong:after {
background: linear-gradient(to right,
{{ cMin }} 0%,
{{ cMax }} 96%);
}
{% endfor %}
</style>
<script>
document.querySelectorAll(".forceWidth:not(.toolong)").forEach(el => {
if (el instanceof Element && el.scrollWidth > el.offsetWidth) {
Expand Down
18 changes: 18 additions & 0 deletions webapp/templates/public/dynamic.css.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% autoescape false %}
{% for i,color in backgroundColors %}
{% set colorClass = color | replace({"#": "_"}) %}

.cl{{ colorClass }} {
background-color: {{ color }};
}

{% set cMin = color|hexColorToRGBA(0) %}
{% set cMax = color|hexColorToRGBA(1) %}

.cl{{ colorClass }} .forceWidth.toolong:after {
background: linear-gradient(to right,
{{ cMin }} 0%,
{{ cMax }} 96%);
}
{% endfor %}
{% endautoescape %}

0 comments on commit a0f9cd3

Please sign in to comment.