mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-14 14:19:33 +00:00
Merge remote-tracking branch 'upstream/master' into Buerklin-provider
This commit is contained in:
commit
b8638b6390
185 changed files with 23450 additions and 15606 deletions
|
|
@ -47,6 +47,12 @@ class AppSettings
|
|||
#[EmbeddedSettings()]
|
||||
public ?InfoProviderSettings $infoProviders = null;
|
||||
|
||||
#[EmbeddedSettings]
|
||||
public ?SynonymSettings $synonyms = null;
|
||||
|
||||
#[EmbeddedSettings()]
|
||||
public ?MiscSettings $miscSettings = null;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ enum PartTableColumns : string implements TranslatableInterface
|
|||
case FAVORITE = "favorite";
|
||||
case MANUFACTURING_STATUS = "manufacturing_status";
|
||||
case MPN = "manufacturer_product_number";
|
||||
case CUSTOM_PART_STATE = 'partCustomState';
|
||||
case MASS = "mass";
|
||||
case TAGS = "tags";
|
||||
case ATTACHMENTS = "attachments";
|
||||
|
|
@ -63,4 +64,4 @@ enum PartTableColumns : string implements TranslatableInterface
|
|||
|
||||
return $translator->trans($key, locale: $locale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class TableSettings
|
|||
#[Assert\All([new Assert\Type(PartTableColumns::class)])]
|
||||
public array $partsDefaultColumns = [PartTableColumns::NAME, PartTableColumns::DESCRIPTION,
|
||||
PartTableColumns::CATEGORY, PartTableColumns::FOOTPRINT, PartTableColumns::MANUFACTURER,
|
||||
PartTableColumns::LOCATION, PartTableColumns::AMOUNT];
|
||||
PartTableColumns::LOCATION, PartTableColumns::AMOUNT, PartTableColumns::CUSTOM_PART_STATE];
|
||||
|
||||
#[SettingsParameter(label: new TM("settings.behavior.table.preview_image_min_width"),
|
||||
formOptions: ['attr' => ['min' => 1, 'max' => 100]],
|
||||
|
|
|
|||
109
src/Settings/MiscSettings/IpnSuggestSettings.php
Normal file
109
src/Settings/MiscSettings/IpnSuggestSettings.php
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Settings\MiscSettings;
|
||||
|
||||
use App\Settings\SettingsIcon;
|
||||
use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
|
||||
use Jbtronics\SettingsBundle\ParameterTypes\StringType;
|
||||
use Jbtronics\SettingsBundle\Settings\Settings;
|
||||
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
|
||||
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
|
||||
use Symfony\Component\Translation\StaticMessage;
|
||||
use Symfony\Component\Translation\TranslatableMessage as TM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[Settings(label: new TM("settings.misc.ipn_suggest"))]
|
||||
#[SettingsIcon("fa-arrow-up-1-9")]
|
||||
class IpnSuggestSettings
|
||||
{
|
||||
use SettingsTrait;
|
||||
|
||||
#[SettingsParameter(
|
||||
label: new TM("settings.misc.ipn_suggest.regex"),
|
||||
description: new TM("settings.misc.ipn_suggest.regex.help"),
|
||||
options: ['type' => StringType::class],
|
||||
formOptions: ['attr' => ['placeholder' => new StaticMessage( '^[A-Za-z0-9]{3,4}(?:-[A-Za-z0-9]{3,4})*-\d{4}$')]],
|
||||
envVar: "IPN_SUGGEST_REGEX", envVarMode: EnvVarMode::OVERWRITE,
|
||||
)]
|
||||
public ?string $regex = null;
|
||||
|
||||
#[SettingsParameter(
|
||||
label: new TM("settings.misc.ipn_suggest.regex_help"),
|
||||
description: new TM("settings.misc.ipn_suggest.regex_help_description"),
|
||||
options: ['type' => StringType::class],
|
||||
formOptions: ['attr' => ['placeholder' => new TM('settings.misc.ipn_suggest.regex.help.placeholder')]],
|
||||
envVar: "IPN_SUGGEST_REGEX_HELP", envVarMode: EnvVarMode::OVERWRITE,
|
||||
)]
|
||||
public ?string $regexHelp = null;
|
||||
|
||||
#[SettingsParameter(
|
||||
label: new TM("settings.misc.ipn_suggest.autoAppendSuffix"),
|
||||
envVar: "bool:IPN_AUTO_APPEND_SUFFIX", envVarMode: EnvVarMode::OVERWRITE,
|
||||
)]
|
||||
public bool $autoAppendSuffix = false;
|
||||
|
||||
#[SettingsParameter(label: new TM("settings.misc.ipn_suggest.suggestPartDigits"),
|
||||
description: new TM("settings.misc.ipn_suggest.suggestPartDigits.help"),
|
||||
formOptions: ['attr' => ['min' => 1, 'max' => 8]],
|
||||
envVar: "int:IPN_SUGGEST_PART_DIGITS", envVarMode: EnvVarMode::OVERWRITE
|
||||
)]
|
||||
#[Assert\Range(min: 1, max: 8)]
|
||||
public int $suggestPartDigits = 4;
|
||||
|
||||
#[SettingsParameter(
|
||||
label: new TM("settings.misc.ipn_suggest.useDuplicateDescription"),
|
||||
description: new TM("settings.misc.ipn_suggest.useDuplicateDescription.help"),
|
||||
envVar: "bool:IPN_USE_DUPLICATE_DESCRIPTION", envVarMode: EnvVarMode::OVERWRITE,
|
||||
)]
|
||||
public bool $useDuplicateDescription = false;
|
||||
|
||||
#[SettingsParameter(
|
||||
label: new TM("settings.misc.ipn_suggest.fallbackPrefix"),
|
||||
description: new TM("settings.misc.ipn_suggest.fallbackPrefix.help"),
|
||||
options: ['type' => StringType::class],
|
||||
)]
|
||||
public string $fallbackPrefix = 'N.A.';
|
||||
|
||||
#[SettingsParameter(
|
||||
label: new TM("settings.misc.ipn_suggest.numberSeparator"),
|
||||
description: new TM("settings.misc.ipn_suggest.numberSeparator.help"),
|
||||
options: ['type' => StringType::class],
|
||||
)]
|
||||
public string $numberSeparator = '-';
|
||||
|
||||
#[SettingsParameter(
|
||||
label: new TM("settings.misc.ipn_suggest.categorySeparator"),
|
||||
description: new TM("settings.misc.ipn_suggest.categorySeparator.help"),
|
||||
options: ['type' => StringType::class],
|
||||
)]
|
||||
public string $categorySeparator = '-';
|
||||
|
||||
#[SettingsParameter(
|
||||
label: new TM("settings.misc.ipn_suggest.globalPrefix"),
|
||||
description: new TM("settings.misc.ipn_suggest.globalPrefix.help"),
|
||||
options: ['type' => StringType::class],
|
||||
)]
|
||||
public ?string $globalPrefix = null;
|
||||
}
|
||||
|
|
@ -35,4 +35,7 @@ class MiscSettings
|
|||
|
||||
#[EmbeddedSettings]
|
||||
public ?ExchangeRateSettings $exchangeRate = null;
|
||||
|
||||
#[EmbeddedSettings]
|
||||
public ?IpnSuggestSettings $ipnSuggestSettings = null;
|
||||
}
|
||||
|
|
|
|||
116
src/Settings/SynonymSettings.php
Normal file
116
src/Settings/SynonymSettings.php
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Settings;
|
||||
|
||||
use App\Form\Settings\TypeSynonymsCollectionType;
|
||||
use App\Services\ElementTypes;
|
||||
use Jbtronics\SettingsBundle\ParameterTypes\ArrayType;
|
||||
use Jbtronics\SettingsBundle\ParameterTypes\SerializeType;
|
||||
use Jbtronics\SettingsBundle\Settings\Settings;
|
||||
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
|
||||
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
|
||||
use Symfony\Component\Translation\TranslatableMessage as TM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[Settings(label: new TM("settings.synonyms"), description: "settings.synonyms.help")]
|
||||
#[SettingsIcon("fa-language")]
|
||||
class SynonymSettings
|
||||
{
|
||||
use SettingsTrait;
|
||||
|
||||
#[SettingsParameter(
|
||||
ArrayType::class,
|
||||
label: new TM("settings.synonyms.type_synonyms"),
|
||||
description: new TM("settings.synonyms.type_synonyms.help"),
|
||||
options: ['type' => SerializeType::class],
|
||||
formType: TypeSynonymsCollectionType::class,
|
||||
formOptions: [
|
||||
'required' => false,
|
||||
],
|
||||
)]
|
||||
#[Assert\Type('array')]
|
||||
#[Assert\All([new Assert\Type('array')])]
|
||||
/**
|
||||
* @var array<string, array<string, array{singular: string, plural: string}>> $typeSynonyms
|
||||
* An array of the form: [
|
||||
* 'category' => [
|
||||
* 'en' => ['singular' => 'Category', 'plural' => 'Categories'],
|
||||
* 'de' => ['singular' => 'Kategorie', 'plural' => 'Kategorien'],
|
||||
* ],
|
||||
* 'manufacturer' => [
|
||||
* 'en' => ['singular' => 'Manufacturer', 'plural' =>'Manufacturers'],
|
||||
* ],
|
||||
* ]
|
||||
*/
|
||||
public array $typeSynonyms = [];
|
||||
|
||||
/**
|
||||
* Checks if there is any synonym defined for the given type (no matter which language).
|
||||
* @param ElementTypes $type
|
||||
* @return bool
|
||||
*/
|
||||
public function isSynonymDefinedForType(ElementTypes $type): bool
|
||||
{
|
||||
return isset($this->typeSynonyms[$type->value]) && count($this->typeSynonyms[$type->value]) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the singular synonym for the given type and locale, or null if none is defined.
|
||||
* @param ElementTypes $type
|
||||
* @param string $locale
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSingularSynonymForType(ElementTypes $type, string $locale): ?string
|
||||
{
|
||||
return $this->typeSynonyms[$type->value][$locale]['singular'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plural synonym for the given type and locale, or null if none is defined.
|
||||
* @param ElementTypes $type
|
||||
* @param string|null $locale
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPluralSynonymForType(ElementTypes $type, ?string $locale): ?string
|
||||
{
|
||||
return $this->typeSynonyms[$type->value][$locale]['plural']
|
||||
?? $this->typeSynonyms[$type->value][$locale]['singular']
|
||||
?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a synonym for the given type and locale.
|
||||
* @param ElementTypes $type
|
||||
* @param string $locale
|
||||
* @param string $singular
|
||||
* @param string $plural
|
||||
* @return void
|
||||
*/
|
||||
public function setSynonymForType(ElementTypes $type, string $locale, string $singular, string $plural): void
|
||||
{
|
||||
$this->typeSynonyms[$type->value][$locale] = [
|
||||
'singular' => $singular,
|
||||
'plural' => $plural,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Settings\SystemSettings;
|
||||
|
||||
use App\Form\Type\LanguageMenuEntriesType;
|
||||
use App\Form\Settings\LanguageMenuEntriesType;
|
||||
use App\Form\Type\LocaleSelectType;
|
||||
use App\Settings\SettingsIcon;
|
||||
use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ class SystemSettings
|
|||
#[EmbeddedSettings()]
|
||||
public ?LocalizationSettings $localization = null;
|
||||
|
||||
|
||||
|
||||
#[EmbeddedSettings()]
|
||||
public ?CustomizationSettings $customization = null;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue