diff --git a/src/Controller/ToolsController.php b/src/Controller/ToolsController.php index eba30e02..e9c68c3e 100644 --- a/src/Controller/ToolsController.php +++ b/src/Controller/ToolsController.php @@ -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, + ]); + } } diff --git a/src/Services/Attachments/BuiltinAttachmentsFinder.php b/src/Services/Attachments/BuiltinAttachmentsFinder.php index 4ed33968..7c3c8f4b 100644 --- a/src/Services/Attachments/BuiltinAttachmentsFinder.php +++ b/src/Services/Attachments/BuiltinAttachmentsFinder.php @@ -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%. diff --git a/templates/Tools/BuiltInFootprintsViewer/main.html.twig b/templates/Tools/BuiltInFootprintsViewer/main.html.twig new file mode 100644 index 00000000..e57c3c90 --- /dev/null +++ b/templates/Tools/BuiltInFootprintsViewer/main.html.twig @@ -0,0 +1,37 @@ +{% extends "main_card.html.twig" %} + +{% macro path_to_breadcrumb(path) %} + +{% endmacro %} + +{% block card_title %} + Built in Footprints +{% endblock %} + +{% block card_content %} + {% for folder, file_array in grouped_footprints %} + {{ _self.path_to_breadcrumb(folder) }} + +
{{ file_info.filename }}
+