Started to implement a very basic builtin footprints gallery tool

This commit is contained in:
Jan Böhmer 2023-01-09 22:51:12 +01:00
parent 39d4f06c12
commit ddd8a66024
3 changed files with 96 additions and 0 deletions

View file

@ -20,12 +20,16 @@
namespace App\Controller;
use App\Services\Attachments\AttachmentPathResolver;
use App\Services\Attachments\AttachmentURLGenerator;
use App\Services\Attachments\BuiltinAttachmentsFinder;
use App\Services\Misc\GitVersionInfo;
use App\Services\Misc\DBInfoHelper;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGenerator;
/**
* @Route("/tools")
@ -84,4 +88,26 @@ class ToolsController extends AbstractController
'db_version' => $DBInfoHelper->getDatabaseVersion() ?? 'Unknown',
]);
}
/**
* @Route("/builtin_footprints")
* @param AttachmentPathResolver $pathResolver
* @return Response
*/
public function builtInFootprintsViewer(BuiltinAttachmentsFinder $builtinAttachmentsFinder, AttachmentURLGenerator $urlGenerator, ): Response
{
$grouped_footprints = $builtinAttachmentsFinder->getListOfFootprintsGroupedByFolder();
$grouped_footprints = array_map(function($group) use ($urlGenerator) {
return array_map(function($placeholder_filepath) use ($urlGenerator) {
return [
'filename' => basename($placeholder_filepath),
'assets_path' => $urlGenerator->placeholderPathToAssetPath($placeholder_filepath),
];
}, $group);
}, $grouped_footprints);
return $this->render('Tools/BuiltInFootprintsViewer/main.html.twig', [
'grouped_footprints' => $grouped_footprints,
]);
}
}

View file

@ -42,6 +42,39 @@ class BuiltinAttachmentsFinder
$this->cache = $cache;
}
/**
* Returns an array with all builtin footprints, grouped by their folders
* The array have the form of: [
* '/path/to/folder' => [
* '%FOOTPRINTS%/path/to/folder/file1.png',
* '%FOOTPRINTS%/path/to/folder/file2.png',
* ]
* @return array
*/
public function getListOfFootprintsGroupedByFolder(): array
{
$finder = new Finder();
//We search only files
$finder->files();
$finder->in($this->pathResolver->getFootprintsPath());
$output = [];
foreach($finder as $file) {
$folder = $file->getRelativePath();
//Normalize path (replace \ with /)
$folder = str_replace('\\', '/', $folder);
if(!isset($output[$folder])) {
$output[$folder] = [];
}
//Add file to group
$output[$folder][] = $this->pathResolver->realPathToPlaceholder($file->getPathname());
}
return $output;
}
/**
* Returns a list of all builtin ressources.
* The array is a list of the relative filenames using the %PLACEHOLDERS%.

View file

@ -0,0 +1,37 @@
{% extends "main_card.html.twig" %}
{% macro path_to_breadcrumb(path) %}
<nav aria-label="breadcrumb" >
<ol class="breadcrumb p-2 bg-light rounded mt-2" id="path-{{ path|replace({'/': '-'}) }}">
{% set path_array = path|split("/") %}
{% for part in path_array %}
<li class="breadcrumb-item {% if loop.last %}active{% endif %}" aria-current="page">
{{ part }}
</li>
{% endfor %}
</ol>
</nav>
{% endmacro %}
{% block card_title %}
Built in Footprints
{% endblock %}
{% block card_content %}
{% for folder, file_array in grouped_footprints %}
{{ _self.path_to_breadcrumb(folder) }}
<div class="row row-cols-2 row-cols-md-6 g-4">
{% for file_info in file_array %}
<div class="col">
<div class="card text-center">
<img src="{{ asset(file_info.assets_path) }}" class="card-img-top" alt="{{ file_info.filename }}">
<div class="card-body">
<p class="card-text"><b>{{ file_info.filename }}</b></p>
</div>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
{% endblock %}