diff --git a/assets/controllers/pages/latex_preview_controller.js b/assets/controllers/pages/latex_preview_controller.js index 6113393a..c836faa6 100644 --- a/assets/controllers/pages/latex_preview_controller.js +++ b/assets/controllers/pages/latex_preview_controller.js @@ -25,20 +25,9 @@ import "katex/dist/katex.css"; export default class extends Controller { static targets = ["input", "preview"]; - static values = { - unit: {type: Boolean, default: false} //Render as upstanding (non-italic) text, useful for units - } - updatePreview() { - let value = ""; - if (this.unitValue) { - value = "\\mathrm{" + this.inputTarget.value + "}"; - } else { - value = this.inputTarget.value; - } - - katex.render(value, this.previewTarget, { + katex.render(this.inputTarget.value, this.previewTarget, { throwOnError: false, }); } diff --git a/assets/css/app/helpers.css b/assets/css/app/helpers.css index 8e7b6fa3..2741d667 100644 --- a/assets/css/app/helpers.css +++ b/assets/css/app/helpers.css @@ -111,11 +111,4 @@ ul.structural_link li a:hover { .permission-checkbox:checked { background-color: var(--bs-success); border-color: var(--bs-success); -} - -/*********************************************** - * Katex rendering with same height as text - ***********************************************/ -.katex-same-height-as-text .katex { - font-size: 1.0em; } \ No newline at end of file diff --git a/docs/usage/console_commands.md b/docs/usage/console_commands.md index e5197251..d23f10c4 100644 --- a/docs/usage/console_commands.md +++ b/docs/usage/console_commands.md @@ -71,9 +71,3 @@ docker exec --user=www-data partdb php bin/console cache:clear * `php bin/console doctrine:migrations:migrate`: Migrate the database to the latest version * `php bin/console doctrine:migrations:up-to-date`: Check if the database is up-to-date - -## Attachment commands - -* `php bin/console partdb:attachments:download`: Download all attachments, which are not already downloaded, to the - local filesystem. This is useful to create local backups of the attachments, no matter what happens on the remote and - also makes pictures thumbnails available for the frontend for them \ No newline at end of file diff --git a/src/Command/Attachments/DownloadAttachmentsCommand.php b/src/Command/Attachments/DownloadAttachmentsCommand.php deleted file mode 100644 index 34deef0e..00000000 --- a/src/Command/Attachments/DownloadAttachmentsCommand.php +++ /dev/null @@ -1,136 +0,0 @@ -. - */ - -declare(strict_types=1); - - -namespace App\Command\Attachments; - -use App\Entity\Attachments\Attachment; -use App\Entity\Attachments\AttachmentUpload; -use App\Exceptions\AttachmentDownloadException; -use App\Services\Attachments\AttachmentManager; -use App\Services\Attachments\AttachmentSubmitHandler; -use Doctrine\ORM\EntityManagerInterface; -use Symfony\Component\Console\Attribute\AsCommand; -use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; - -#[AsCommand('partdb:attachments:download', "Downloads all attachments which have only an external URL to the local filesystem.")] -class DownloadAttachmentsCommand extends Command -{ - public function __construct(private readonly AttachmentSubmitHandler $attachmentSubmitHandler, - private EntityManagerInterface $entityManager) - { - parent::__construct(); - } - - public function configure(): void - { - $this->setHelp('This command downloads all attachments, which only have an external URL, to the local filesystem, so that you have an offline copy of the attachments.'); - $this->addOption('--private', null, null, 'If set, the attachments will be downloaded to the private storage.'); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $io = new SymfonyStyle($input, $output); - - $qb = $this->entityManager->createQueryBuilder(); - $qb->select('attachment') - ->from(Attachment::class, 'attachment') - ->where('attachment.external_path IS NOT NULL') - ->andWhere('attachment.external_path != \'\'') - ->andWhere('attachment.internal_path IS NULL'); - - $query = $qb->getQuery(); - $attachments = $query->getResult(); - - if (count($attachments) === 0) { - $io->success('No attachments with external URL found.'); - return Command::SUCCESS; - } - - $io->note('Found ' . count($attachments) . ' attachments with external URL, that will be downloaded.'); - - //If the option --private is set, the attachments will be downloaded to the private storage. - $private = $input->getOption('private'); - if ($private) { - if (!$io->confirm('Attachments will be downloaded to the private storage. Continue?')) { - return Command::SUCCESS; - } - } else { - if (!$io->confirm('Attachments will be downloaded to the public storage, where everybody knowing the correct URL can access it. Continue?')){ - return Command::SUCCESS; - } - } - - $progressBar = $io->createProgressBar(count($attachments)); - $progressBar->setFormat("%current%/%max% [%bar%] %percent:3s%% %elapsed:16s%/%estimated:-16s% \n%message%"); - - $progressBar->setMessage('Starting download...'); - $progressBar->start(); - - - $errors = []; - - foreach ($attachments as $attachment) { - /** @var Attachment $attachment */ - $progressBar->setMessage(sprintf('%s (ID: %s) from %s', $attachment->getName(), $attachment->getID(), $attachment->getHost())); - $progressBar->advance(); - - try { - $attachmentUpload = new AttachmentUpload(file: null, downloadUrl: true, private: $private); - $this->attachmentSubmitHandler->handleUpload($attachment, $attachmentUpload); - - //Write changes to the database - $this->entityManager->flush(); - } catch (AttachmentDownloadException $e) { - $errors[] = [ - 'attachment' => $attachment, - 'error' => $e->getMessage() - ]; - } - } - - $progressBar->finish(); - - //Fix the line break after the progress bar - $io->newLine(); - $io->newLine(); - - if (count($errors) > 0) { - $io->warning('Some attachments could not be downloaded:'); - foreach ($errors as $error) { - $io->warning(sprintf("Attachment %s (ID %s) could not be downloaded from %s:\n%s", - $error['attachment']->getName(), - $error['attachment']->getID(), - $error['attachment']->getExternalPath(), - $error['error']) - ); - } - } else { - $io->success('All attachments downloaded successfully.'); - } - - return Command::SUCCESS; - } -} \ No newline at end of file diff --git a/src/Entity/Parameters/AbstractParameter.php b/src/Entity/Parameters/AbstractParameter.php index edcedc3e..c42682f9 100644 --- a/src/Entity/Parameters/AbstractParameter.php +++ b/src/Entity/Parameters/AbstractParameter.php @@ -208,7 +208,7 @@ abstract class AbstractParameter extends AbstractNamedDBElement implements Uniqu */ #[Groups(['parameter:read', 'full'])] #[SerializedName('formatted')] - public function getFormattedValue(bool $latex_formatted = false): string + public function getFormattedValue(): string { //If we just only have text value, return early if (null === $this->value_typical && null === $this->value_min && null === $this->value_max) { @@ -218,7 +218,7 @@ abstract class AbstractParameter extends AbstractNamedDBElement implements Uniqu $str = ''; $bracket_opened = false; if ($this->value_typical) { - $str .= $this->getValueTypicalWithUnit($latex_formatted); + $str .= $this->getValueTypicalWithUnit(); if ($this->value_min || $this->value_max) { $bracket_opened = true; $str .= ' ('; @@ -226,11 +226,11 @@ abstract class AbstractParameter extends AbstractNamedDBElement implements Uniqu } if ($this->value_max && $this->value_min) { - $str .= $this->getValueMinWithUnit($latex_formatted).' ... '.$this->getValueMaxWithUnit($latex_formatted); + $str .= $this->getValueMinWithUnit().' ... '.$this->getValueMaxWithUnit(); } elseif ($this->value_max) { - $str .= 'max. '.$this->getValueMaxWithUnit($latex_formatted); + $str .= 'max. '.$this->getValueMaxWithUnit(); } elseif ($this->value_min) { - $str .= 'min. '.$this->getValueMinWithUnit($latex_formatted); + $str .= 'min. '.$this->getValueMinWithUnit(); } //Add closing bracket @@ -344,25 +344,25 @@ abstract class AbstractParameter extends AbstractNamedDBElement implements Uniqu /** * Return a formatted version with the minimum value with the unit of this parameter. */ - public function getValueTypicalWithUnit(bool $with_latex = false): string + public function getValueTypicalWithUnit(): string { - return $this->formatWithUnit($this->value_typical, with_latex: $with_latex); + return $this->formatWithUnit($this->value_typical); } /** * Return a formatted version with the maximum value with the unit of this parameter. */ - public function getValueMaxWithUnit(bool $with_latex = false): string + public function getValueMaxWithUnit(): string { - return $this->formatWithUnit($this->value_max, with_latex: $with_latex); + return $this->formatWithUnit($this->value_max); } /** * Return a formatted version with the typical value with the unit of this parameter. */ - public function getValueMinWithUnit(bool $with_latex = false): string + public function getValueMinWithUnit(): string { - return $this->formatWithUnit($this->value_min, with_latex: $with_latex); + return $this->formatWithUnit($this->value_min); } /** @@ -441,18 +441,11 @@ abstract class AbstractParameter extends AbstractNamedDBElement implements Uniqu /** * Return a string representation and (if possible) with its unit. */ - protected function formatWithUnit(float $value, string $format = '%g', bool $with_latex = false): string + protected function formatWithUnit(float $value, string $format = '%g'): string { $str = sprintf($format, $value); if ($this->unit !== '') { - - if (!$with_latex) { - $unit = $this->unit; - } else { - $unit = '$\mathrm{'.$this->unit.'}$'; - } - - return $str.' '.$unit; + return $str.' '.$this->unit; } return $str; diff --git a/src/Repository/AttachmentRepository.php b/src/Repository/AttachmentRepository.php index 4fc0abc9..0a6b1db2 100644 --- a/src/Repository/AttachmentRepository.php +++ b/src/Repository/AttachmentRepository.php @@ -66,7 +66,7 @@ class AttachmentRepository extends DBElementRepository } /** - * Gets the count of all external attachments (attachments containing only an external path). + * Gets the count of all external attachments (attachments containing an external path). * * @throws NoResultException * @throws NonUniqueResultException @@ -75,9 +75,8 @@ class AttachmentRepository extends DBElementRepository { $qb = $this->createQueryBuilder('attachment'); $qb->select('COUNT(attachment)') - ->where('attachment.external_path IS NOT NULL') - ->andWhere('attachment.internal_path IS NULL'); - + ->andWhere('attaachment.internal_path IS NULL') + ->where('attachment.external_path IS NOT NULL'); $query = $qb->getQuery(); return (int) $query->getSingleScalarResult(); diff --git a/src/Services/EDA/KiCadHelper.php b/src/Services/EDA/KiCadHelper.php index d4cbab34..c0144585 100644 --- a/src/Services/EDA/KiCadHelper.php +++ b/src/Services/EDA/KiCadHelper.php @@ -66,10 +66,6 @@ class KiCadHelper $secure_class_name = $this->tagGenerator->getElementTypeCacheTag(Category::class); $item->tag($secure_class_name); - //Invalidate the cache on part changes (as the visibility depends on parts, and the parts can change) - $secure_class_name = $this->tagGenerator->getElementTypeCacheTag(Part::class); - $item->tag($secure_class_name); - //If the category depth is smaller than 0, create only one dummy category if ($this->category_depth < 0) { return [ diff --git a/templates/form/filter_types_layout.html.twig b/templates/form/filter_types_layout.html.twig index cae9e3ea..e99e6b62 100644 --- a/templates/form/filter_types_layout.html.twig +++ b/templates/form/filter_types_layout.html.twig @@ -54,7 +54,7 @@