Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
21 changes: 18 additions & 3 deletions webapp/src/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
use Symfony\Component\Intl\Countries;
use Symfony\Component\Intl\Exception\MissingResourceException;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
Expand Down Expand Up @@ -126,6 +128,7 @@ public function getFilters(): array
new TwigFilter('medalType', $this->awards->medalType(...)),
new TwigFilter('numTableActions', $this->numTableActions(...)),
new TwigFilter('extensionToMime', $this->extensionToMime(...)),
new TwigFilter('relativePath', $this->relativePath(...), ['is_safe' => ['html']]),
];
}

Expand Down Expand Up @@ -363,7 +366,7 @@ public static function statusIcon(string $status): string
$status);
}

public function countryFlag(?string $alpha3CountryCode, bool $showFullname = false): string
public function countryFlag(?string $alpha3CountryCode, bool $showFullname = false, bool $relative = false): string
{
if (empty($alpha3CountryCode)) {
return '';
Expand All @@ -376,6 +379,7 @@ public function countryFlag(?string $alpha3CountryCode, bool $showFullname = fal
}
$assetFunction = $this->twig->getFunction('asset')->getCallable();
$countryFlagUrl = call_user_func($assetFunction, sprintf('flags/4x3/%s.svg', $countryAlpha2));
$countryFlagUrl = $this->relativePath($countryFlagUrl, $relative);

$countryName = Countries::getAlpha3Name($alpha3CountryCode);

Expand All @@ -387,11 +391,12 @@ public function countryFlag(?string $alpha3CountryCode, bool $showFullname = fal
$countryFlagUrl, $alpha3CountryCode, $countryName);
}

public function affiliationLogo(string $affiliationId, string $shortName): string
public function affiliationLogo(string $affiliationId, string $shortName, bool $relative = false): string
{
if ($asset = $this->dj->assetPath($affiliationId, 'affiliation')) {
$assetFunction = $this->twig->getFunction('asset')->getCallable();
$assetUrl = call_user_func($assetFunction, $asset);
$assetUrl = $this->relativePath($assetUrl, $relative);
return sprintf('<img src="%s" alt="%s" class="affiliation-logo">',
htmlspecialchars($assetUrl), htmlspecialchars($shortName));
}
Expand Down Expand Up @@ -1195,7 +1200,7 @@ public function problemBadgeMaybe(
}

$submissionsUrl = $static
? $this->router->generate('public_submissions_data')
? $this->router->generate('public_submissions_data', referenceType: UrlGeneratorInterface::RELATIVE_PATH)
: $this->router->generate('public_submissions_data_cell', [
'teamId' => $score->team->getExternalid(),
'problemId' => $problem->getExternalId(),
Expand Down Expand Up @@ -1381,4 +1386,14 @@ public function extensionToMime(string $extension): string
{
return DOMJudgeService::EXTENSION_TO_MIMETYPE[$extension];
}

public function relativePath(string $path, bool $relative = true) : string
{
if (!$relative) {
return $path;
}
return UrlGenerator::getRelativePath(
$this->router->getContext()->getBaseUrl()
. $this->router->getContext()->getPathInfo(), $path);
}
}
30 changes: 16 additions & 14 deletions webapp/templates/base.html.twig
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
{% if static is not defined %}
{% set static = false %}
{% endif %}
<!DOCTYPE html>
<html lang="en">
<head>
<!-- DOMjudge version {{ DOMJUDGE_VERSION }} -->
<meta charset="{{ DJ_CHARACTER_SET }}">
<title>{% block title %}DOMjudge{% endblock %}</title>
<link rel="icon" href="{{ asset('favicon.ico') }}">
<title>{% block title %}DOMjudge {% endblock %}</title>
<link rel="icon" href="{{ asset('favicon.ico') | relativePath(static) }}">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="{{ asset("css/bootstrap.min.css") | relativePath(static) }}">
<link rel="stylesheet" href="{{ asset("css/fontawesome-all.min.css") | relativePath(static) }}">
<link rel="stylesheet" href="{{ path('scoreboard_category_color_css', relative=static) }}">
<script src="{{ asset("js/jquery.min.js") | relativePath(static) }}"></script>
<script src="{{ asset("js/jquery.debounce.min.js") | relativePath(static) }}"></script>
<script src="{{ asset("js/bootstrap.bundle.min.js") | relativePath(static) }}"></script>

<link rel="stylesheet" href="{{ asset("css/bootstrap.min.css") }}">
<link rel="stylesheet" href="{{ asset("css/fontawesome-all.min.css") }}">
<link rel="stylesheet" href="{{ path('scoreboard_category_color_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>

<script src="{{ asset("js/domjudge.js") }}"></script>
<script src="{{ asset("js/domjudge.js") | relativePath(static) }}"></script>
{% for file in customAssetFiles('js') %}
<script src="{{ asset('js/custom/' ~ file) }}"></script>
<script src="{{ asset('js/custom/' ~ file) | relativePath(static) }}"></script>
{% endfor %}
{% block extrahead %}
<link rel="stylesheet" href="{{ asset('style_domjudge.css') }}">
<link rel="stylesheet" href="{{ asset('style_domjudge.css') | relativePath(static) }}">

{{ extrahead | default('') }}
{% endblock %}
{% for file in customAssetFiles('css') %}
<link rel="stylesheet" href="{{ asset('css/custom/' ~ file) }}">
<link rel="stylesheet" href="{{ asset('css/custom/' ~ file) | relativePath(static) }}">
{% endfor %}
</head>
<body{% if static is defined and static %} class="static"{% endif %}>
<body{% if static %} class="static"{% endif %}>
{% block menu %}{% endblock %}
{% block body %}
<div class="container-fluid">
Expand Down
4 changes: 2 additions & 2 deletions webapp/templates/partials/scoreboard.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@
{% endif %}
<li class="list-group-item cl{{ colorClass }}">
{% if showFlags and affiliation.country is defined %}
{{ affiliation.country|countryFlag }}
{{ affiliation.country|countryFlag(false, static) }}
{% endif %}
{% set affiliationLogo = affiliation.id | assetPath('affiliation') %}
{% if affiliationLogo %}
<img loading="lazy" class="affiliation-logo"
src="{{ asset(affiliationLogo) }}" alt="{{ affiliation.name }}"
src="{{ asset(affiliationLogo) | relativePath(static) }}" alt="{{ affiliation.name }}"
title="{{ affiliation.name }}">
{% endif %}
{{ affiliation.name }}
Expand Down
14 changes: 7 additions & 7 deletions webapp/templates/partials/scoreboard_table.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@
{% if score.team.affiliation %}
{% set link = null %}
{% if jury %}
{% set link = path('jury_team_affiliation', {'affilId': score.team.affiliation.affilid}) %}
{% set link = path('jury_team_affiliation', {'affilId': score.team.affiliation.affilid}, relative = static) %}
{% endif %}
<a {% if link %}href="{{ link }}"{% endif %}>
{{ score.team.affiliation.country|countryFlag }}
{{ score.team.affiliation.country|countryFlag(false, static) }}
</a>
{% endif %}
{% endif %}
Expand All @@ -201,14 +201,14 @@
{% if score.team.affiliation %}
{% set link = null %}
{% if jury %}
{% set link = path('jury_team_affiliation', {'affilId': score.team.affiliation.affilid}) %}
{% set link = path('jury_team_affiliation', {'affilId': score.team.affiliation.affilid}, relative = static) %}
{% endif %}
<a {% if link %}href="{{ link }}"{% endif %}>
{% set affiliationId = score.team.affiliation.externalid %}
{% set affiliationImage = affiliationId | assetPath('affiliation') %}
{% if affiliationImage %}
<img loading="lazy" class="affiliation-logo"
src="{{ asset(affiliationImage) }}" alt="{{ score.team.affiliation.name }}"
src="{{ asset(affiliationImage) | relativePath(static) }}" alt="{{ score.team.affiliation.name }}"
title="{{ score.team.affiliation.name }}">
{% else %}
{{ affiliationId }}
Expand Down Expand Up @@ -325,7 +325,7 @@
{% set link = path('jury_team', {teamId: score.team.teamid, restrict: restrict}) %}
{% elseif static %}
{% set link = '#' %}
{% set extra = 'data-submissions-url="' ~ path('public_submissions_data') ~ '"' %}
{% set extra = 'data-submissions-url="' ~ path('public_submissions_data', relative = true) ~ '"' %}
{% set extra = extra ~ ' data-team-id="' ~ score.team.externalid ~ '"' %}
{% set extra = extra ~ ' data-problem-id="' ~ problem.externalid ~ '"' %}
{% elseif public %}
Expand Down Expand Up @@ -466,7 +466,7 @@
{% set link = path('jury_team_affiliation', {'affilId': score.team.affiliation.affilid}) %}
{% endif %}
<a {% if link %}href="{{ link }}"{% endif %}>
{{ score.team.affiliation.country|countryFlag }}
{{ score.team.affiliation.country|countryFlag(false, static) }}
</a>
{% endif %}
{% endif %}
Expand All @@ -483,7 +483,7 @@
{% set affiliationImage = affiliationId | assetPath('affiliation') %}
{% if affiliationImage %}
<img loading="lazy" width="16px" height="16px"
src="{{ asset(affiliationImage) }}" alt="{{ score.team.affiliation.name }}"
src="{{ asset(affiliationImage) | relativePath(static) }}" alt="{{ score.team.affiliation.name }}"
title="{{ score.team.affiliation.name }}">
{% else %}
{{ affiliationId }}
Expand Down
7 changes: 5 additions & 2 deletions webapp/templates/partials/team.html.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% if static is not defined %}
{% set static = false %}
{% endif %}
{% if team is empty %}
<div class="alert alert-danger mt-4">
No team found by this id.
Expand Down Expand Up @@ -28,7 +31,7 @@
{% set affiliationId = team.affiliation.externalid %}
{% set affiliationLogo = affiliationId | assetPath('affiliation') %}
{% if affiliationLogo %}
<img src="{{ asset(affiliationLogo) }}" alt="{{ team.affiliation.shortname }}"
<img src="{{ asset(affiliationLogo) | relativePath(static) }}" alt="{{ team.affiliation.shortname }}"
title="{{ team.affiliation.shortname }}" class="affiliation-logo">
{% endif %}
{{ team.affiliation.name }}</td>
Expand All @@ -37,7 +40,7 @@
<tr>
<th>Country</th>
<td>
{{ team.affiliation.country | countryFlag(true) }}
{{ team.affiliation.country | countryFlag(true, static) }}
</td>
</tr>
{% endif %}
Expand Down
Loading