mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-26 11:48:49 +02:00
Started to implement a very basic builtin footprints gallery tool
This commit is contained in:
parent
39d4f06c12
commit
ddd8a66024
3 changed files with 96 additions and 0 deletions
|
@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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%.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue