mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-01 12:59:36 +00:00
Add configurable datasheet URL mode for KiCad API
New setting "Datasheet field links to PDF" in KiCad EDA settings. When enabled (default), the datasheet field resolves to the actual PDF attachment URL. When disabled, it links to the Part-DB page (old behavior). Configurable via settings UI or EDA_KICAD_DATASHEET_AS_PDF env var.
This commit is contained in:
parent
6a0db3b1b7
commit
67c0b02248
3 changed files with 28 additions and 3 deletions
|
|
@ -44,6 +44,9 @@ class KiCadHelper
|
|||
/** @var int The maximum level of the shown categories. 0 Means only the top level categories are shown. -1 means only a single one containing */
|
||||
private readonly int $category_depth;
|
||||
|
||||
/** @var bool Whether to resolve actual datasheet PDF URLs (true) or use Part-DB page links (false) */
|
||||
private readonly bool $datasheetAsPdf;
|
||||
|
||||
public function __construct(
|
||||
private readonly NodesListBuilder $nodesListBuilder,
|
||||
private readonly TagAwareCacheInterface $kicadCache,
|
||||
|
|
@ -55,6 +58,7 @@ class KiCadHelper
|
|||
KiCadEDASettings $kiCadEDASettings,
|
||||
) {
|
||||
$this->category_depth = $kiCadEDASettings->categoryDepth;
|
||||
$this->datasheetAsPdf = $kiCadEDASettings->datasheetAsPdf;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -216,9 +220,13 @@ class KiCadHelper
|
|||
UrlGeneratorInterface::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
//Try to find an actual datasheet attachment (by type name, attachment name, or PDF extension)
|
||||
$datasheetUrl = $this->findDatasheetUrl($part);
|
||||
$result["fields"]["datasheet"] = $this->createField($datasheetUrl ?? $partUrl);
|
||||
//Try to find an actual datasheet attachment (configurable: PDF URL vs Part-DB page link)
|
||||
if ($this->datasheetAsPdf) {
|
||||
$datasheetUrl = $this->findDatasheetUrl($part);
|
||||
$result["fields"]["datasheet"] = $this->createField($datasheetUrl ?? $partUrl);
|
||||
} else {
|
||||
$result["fields"]["datasheet"] = $this->createField($partUrl);
|
||||
}
|
||||
$result["fields"]["Part-DB URL"] = $this->createField($partUrl);
|
||||
|
||||
//Add basic fields
|
||||
|
|
|
|||
|
|
@ -43,4 +43,9 @@ class KiCadEDASettings
|
|||
envVar: "int:EDA_KICAD_CATEGORY_DEPTH", envVarMode: EnvVarMode::OVERWRITE)]
|
||||
#[Assert\Range(min: -1)]
|
||||
public int $categoryDepth = 0;
|
||||
|
||||
#[SettingsParameter(label: new TM("settings.misc.kicad_eda.datasheet_link"),
|
||||
description: new TM("settings.misc.kicad_eda.datasheet_link.help"),
|
||||
envVar: "bool:EDA_KICAD_DATASHEET_AS_PDF", envVarMode: EnvVarMode::OVERWRITE)]
|
||||
public bool $datasheetAsPdf = true;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue