mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-21 02:41:35 +00:00
Unterstützung für Projekt- und Baugruppensuche zum QuickSearch-Suggest hinzufügen
This commit is contained in:
parent
4911b5bf24
commit
74513b748d
23 changed files with 519 additions and 50 deletions
|
|
@ -24,6 +24,8 @@ namespace App\Controller;
|
|||
|
||||
use App\Entity\AssemblySystem\Assembly;
|
||||
use App\Entity\Parameters\AbstractParameter;
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
use App\Services\Attachments\ProjectPreviewGenerator;
|
||||
use App\Settings\MiscSettings\IpnSuggestSettings;
|
||||
use App\Services\Attachments\AssemblyPreviewGenerator;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
|
@ -124,7 +126,10 @@ class TypeaheadController extends AbstractController
|
|||
public function parts(
|
||||
EntityManagerInterface $entityManager,
|
||||
PartPreviewGenerator $previewGenerator,
|
||||
ProjectPreviewGenerator $projectPreviewGenerator,
|
||||
AssemblyPreviewGenerator $assemblyPreviewGenerator,
|
||||
AttachmentURLGenerator $attachmentURLGenerator,
|
||||
Request $request,
|
||||
string $query = ""
|
||||
): JsonResponse {
|
||||
$this->denyAccessUnlessGranted('@parts.read');
|
||||
|
|
@ -133,18 +138,20 @@ class TypeaheadController extends AbstractController
|
|||
|
||||
$parts = $partRepository->autocompleteSearch($query, 100);
|
||||
|
||||
/** @var Part[]|Assembly[] $data */
|
||||
$data = [];
|
||||
foreach ($parts as $part) {
|
||||
//Determine the picture to show:
|
||||
$preview_attachment = $previewGenerator->getTablePreviewAttachment($part);
|
||||
if($preview_attachment instanceof Attachment) {
|
||||
$preview_url = $attachmentURLGenerator->getThumbnailURL($preview_attachment, 'thumbnail_sm');
|
||||
$preview_url = $attachmentURLGenerator->getThumbnailURL($preview_attachment);
|
||||
} else {
|
||||
$preview_url = '';
|
||||
}
|
||||
|
||||
/** @var Part $part */
|
||||
$data[] = [
|
||||
'type' => 'part',
|
||||
'id' => $part->getID(),
|
||||
'name' => $part->getName(),
|
||||
'category' => $part->getCategory() instanceof Category ? $part->getCategory()->getName() : 'Unknown',
|
||||
|
|
@ -154,6 +161,64 @@ class TypeaheadController extends AbstractController
|
|||
];
|
||||
}
|
||||
|
||||
$multiDataSources = $request->query->getBoolean('multidatasources');
|
||||
|
||||
if ($multiDataSources) {
|
||||
if ($this->isGranted('@projects.read')) {
|
||||
$projectRepository = $entityManager->getRepository(Project::class);
|
||||
|
||||
$projects = $projectRepository->autocompleteSearch($query, 100);
|
||||
|
||||
foreach ($projects as $project) {
|
||||
$preview_attachment = $projectPreviewGenerator->getTablePreviewAttachment($project);
|
||||
|
||||
if ($preview_attachment instanceof Attachment) {
|
||||
$preview_url = $attachmentURLGenerator->getThumbnailURL($preview_attachment);
|
||||
} else {
|
||||
$preview_url = '';
|
||||
}
|
||||
|
||||
/** @var Project $project */
|
||||
$data[] = [
|
||||
'type' => 'project',
|
||||
'id' => $project->getID(),
|
||||
'name' => $project->getName(),
|
||||
'category' => '',
|
||||
'footprint' => '',
|
||||
'description' => mb_strimwidth($project->getDescription(), 0, 127, '...'),
|
||||
'image' => $preview_url,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->isGranted('@assemblies.read')) {
|
||||
$assemblyRepository = $entityManager->getRepository(Assembly::class);
|
||||
|
||||
$assemblies = $assemblyRepository->autocompleteSearch($query, 100);
|
||||
|
||||
foreach ($assemblies as $assembly) {
|
||||
$preview_attachment = $assemblyPreviewGenerator->getTablePreviewAttachment($assembly);
|
||||
|
||||
if ($preview_attachment instanceof Attachment) {
|
||||
$preview_url = $attachmentURLGenerator->getThumbnailURL($preview_attachment);
|
||||
} else {
|
||||
$preview_url = '';
|
||||
}
|
||||
|
||||
/** @var Assembly $assembly */
|
||||
$data[] = [
|
||||
'type' => 'assembly',
|
||||
'id' => $assembly->getID(),
|
||||
'name' => $assembly->getName(),
|
||||
'category' => '',
|
||||
'footprint' => '',
|
||||
'description' => mb_strimwidth($assembly->getDescription(), 0, 127, '...'),
|
||||
'image' => $preview_url,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new JsonResponse($data);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue