Skip to content

Commit

Permalink
Add progression on main page (#284)
Browse files Browse the repository at this point in the history
* Don't display last update if it's null

* Add region progress bar (welcome or note)

Close #194

* Apply fixes from StyleCI
  • Loading branch information
jbelien authored Dec 30, 2021
1 parent 3cf2fec commit 6100596
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Controller/App/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function index(): Response
$keys = array_keys($regions);
foreach ($keys as $key) {
$regions[$key]['lastUpdate'] = $this->provider->getLastUpdate($key);
$regions[$key]['percent'] = $this->provider->getPercentage($key);
}

return $this->render('app/home/index.html.twig', [
Expand Down
17 changes: 17 additions & 0 deletions src/Service/RegionsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Service;

use App\Entity\Mapper;
use App\Repository\MapperRepository;
use App\Repository\WelcomeRepository;
use DateTime;
use Exception;
use Symfony\Component\Cache\Adapter\AdapterInterface;
Expand All @@ -13,6 +16,8 @@ class RegionsProvider

public function __construct(
private AdapterInterface $cache,
private MapperRepository $mapperRepository,
private WelcomeRepository $welcomeRepository,
private string $projectDirectory
) {
$yaml = Yaml::parseFile(sprintf('%s/config/regions.yaml', $this->projectDirectory));
Expand Down Expand Up @@ -66,4 +71,16 @@ public function getLastUpdate(string $key): ?DateTime

return new DateTime($this->cache->getItem($cacheKey)->get());
}

public function getPercentage(string $key): int
{
/** @var Mapper[] */
$mappers = $this->mapperRepository->findBy(['region' => $key]);

$checked = array_filter($mappers, function (Mapper $mapper): bool {
return null !== $mapper->getWelcome() || false === $mapper->getNotes()->isEmpty();
});

return \count($mappers) > 0 ? round(\count($checked) / \count($mappers) * 100) : 0;
}
}
11 changes: 8 additions & 3 deletions templates/app/home/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@
<div class="flex-shrink-0">
{{ region.flag }}
</div>
<div class="flex-1 min-w-0">
<a href="{{ path('app_list', {regionKey: key}) }}" class="focus:outline-none">
<div class="flex-1 min-w-0 h-full">
<a href="{{ path('app_list', {regionKey: key}) }}" class="flex flex-col h-full focus:outline-none">
<span class="absolute inset-0" aria-hidden="true"></span>
<p class="font-medium text-gray-900">
<p class="flex-grow font-medium text-gray-900">
{{ region.name|trans }}
</p>
{% if region.lastUpdate is not null %}
<p class="text-xs text-gray-500 truncate">
{{ 'Last update'|trans }}:
<time datetime="{{ region.lastUpdate|date('c') }}">{{ region.lastUpdate|format_datetime('medium') }}</time>
</p>
{% endif %}
<div class="w-full bg-gray-200 rounded-full h-0.5 dark:bg-gray-700 mt-1">
<div class="bg-gray-600 h-0.5 rounded-full dark:bg-gray-300" style="width: {{ region.percent }}%"></div>
</div>
</a>
</div>
</div>
Expand Down

0 comments on commit 6100596

Please sign in to comment.