Added a basic possibility to create/edit/delete specifications for parts.

This commit is contained in:
Jan Böhmer 2020-03-08 22:46:29 +01:00
parent 502febb008
commit a6e0f1738b
15 changed files with 1359 additions and 765 deletions

View file

@ -50,6 +50,8 @@ use Symfony\Component\Serializer\Annotation\Groups;
*/
abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement
{
use SpecificationsTrait;
public const ID_ROOT_ELEMENT = 0;
/**

View file

@ -0,0 +1,54 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2020 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/>.
*/
namespace App\Entity\Base;
use App\Entity\Specifications\Specification;
use Symfony\Component\Validator\Constraints as Assert;
trait SpecificationsTrait
{
/**
* @var Specification[]
* @ORM\Column(type="json_document")
* @Assert\Valid()
*/
protected $specifications = [];
/**
* Return all associated specifications
* @return Specification[]
*/
public function getSpecifications(): array
{
return $this->specifications ?? [];
}
/**
* @param array $specifications
* @return $this
*/
public function setSpecifications(array $specifications): self
{
$this->specifications = $specifications;
return $this;
}
}

View file

@ -52,6 +52,7 @@ namespace App\Entity\Parts;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Base\SpecificationsTrait;
use App\Entity\Devices\Device;
use App\Entity\Parts\PartTraits\AdvancedPropertyTrait;
use App\Entity\Parts\PartTraits\BasicPropertyTrait;
@ -81,6 +82,7 @@ class Part extends AttachmentContainingDBElement
use InstockTrait;
use ManufacturerTrait;
use OrderTrait;
use SpecificationsTrait;
/**
* TODO.

View file

@ -0,0 +1,214 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2020 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/>.
*/
namespace App\Entity\Specifications;
use Symfony\Component\Validator\Constraints as Assert;
class Specification
{
/**
* @var string The name of the specification (e.g. "Collector-Base Voltage"). Required!
* @Assert\NotBlank()
*/
protected $name = "";
/**
* @var string The mathematical symbol for this specification. Can be rendered pretty later. Should be short
* @Assert\Length(max=10)
*/
protected $symbol = "";
/**
* @var float|null The guaranteed minimum value of this property.
* @Assert\Type({"float","null"})
* @Assert\LessThanOrEqual(propertyPath="value_typical")
* @Assert\LessThan(propertyPath="value_max")
*/
protected $value_min;
/**
* @var float|null The typical value of this property.
* @Assert\Type({"null", "float"})
*/
protected $value_typical;
/**
* @var float|null The maximum value of this property.
* @Assert\Type({"float", "null"})
* @Assert\GreaterThanOrEqual(propertyPath="value_typical")
*/
protected $value_max;
/**
* @var string The unit in which the value values are given (e.g. V)
* @Assert\Length(max=5)
*/
protected $unit = "";
/**
* @var string A text value for the given property.
*
*/
protected $value_text = "";
/**
* Returns the name of the specification (e.g. "Collector-Base Voltage").
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* Sets the name of the specification. This value is required.
* @param string $name
* @return $this
*/
public function setName(string $name): Specification
{
$this->name = $name;
return $this;
}
/**
* Returns the mathematical symbol for this specification (e.g. "V_CB")
* @return string
*/
public function getSymbol(): string
{
return $this->symbol;
}
/**
* Sets the mathematical symbol for this specification (e.g. "V_CB")
* @param string $symbol
* @return $this
*/
public function setSymbol(string $symbol): Specification
{
$this->symbol = $symbol;
return $this;
}
/**
* Returns The guaranteed minimum value of this property.
* @return float|null
*/
public function getValueMin(): ?float
{
return $this->value_min;
}
/**
* Sets the minimum value of this property.
* @param float|null $value_min
* @return $this
*/
public function setValueMin(?float $value_min): Specification
{
$this->value_min = $value_min;
return $this;
}
/**
* Returns the typical value of this property.
* @return float|null
*/
public function getValueTypical(): ?float
{
return $this->value_typical;
}
/**
* Sets the typical value of this property
* @param float $value_typical
* @return $this
*/
public function setValueTypical(?float $value_typical): Specification
{
$this->value_typical = $value_typical;
return $this;
}
/**
* Returns the guaranteed maximum value
* @return float|null
*/
public function getValueMax(): ?float
{
return $this->value_max;
}
/**
* Sets the guaranteed maximum value
* @param float|null $value_max
* @return $this
*/
public function setValueMax(?float $value_max): Specification
{
$this->value_max = $value_max;
return $this;
}
/**
* Returns the unit used by the value (e.g. "V")
* @return string
*/
public function getUnit(): string
{
return $this->unit;
}
/**
* Sets the unit used by the value.
* @param string $unit
* @return $this
*/
public function setUnit(string $unit): Specification
{
$this->unit = $unit;
return $this;
}
/**
* Returns the text value.
* @return string
*/
public function getValueText(): string
{
return $this->value_text;
}
/**
* Sets the text value.
* @param string $value_text
* @return $this
*/
public function setValueText(string $value_text): Specification
{
$this->value_text = $value_text;
return $this;
}
}

View file

@ -50,7 +50,9 @@ use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\PriceInformations\Orderdetail;
use App\Entity\Specifications\Specification;
use App\Form\AttachmentFormType;
use App\Form\SpecificationType;
use App\Form\Type\MasterPictureAttachmentType;
use App\Form\Type\SIUnitType;
use App\Form\Type\StructuralEntityType;
@ -264,6 +266,15 @@ class PartBaseType extends AbstractType
],
]);
$builder->add('specifications', CollectionType::class, [
'entry_type' => SpecificationType::class,
'allow_add' => true,
'allow_delete' => true,
'label' => false,
'by_reference' => false,
'prototype_data' => new Specification(),
]);
$builder->add('log_comment', TextType::class, [
'label' => 'edit.log_comment',
'mapped' => false,
@ -280,7 +291,7 @@ class PartBaseType extends AbstractType
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Part::class,
]);
'data_class' => Part::class,
]);
}
}

View file

@ -0,0 +1,67 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2020 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/>.
*/
namespace App\Form;
use App\Entity\Specifications\Specification;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class SpecificationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', TextType::class,[
'empty_data' => '',
]);
$builder->add('symbol', TextType::class, [
'required' => false,
'empty_data' => '',
]);
$builder->add('value_text', TextType::class, [
'required' => false,
'empty_data' => '',
]);
$builder->add('value_max', NumberType::class, [
'required' => false,
]);
$builder->add('value_min', NumberType::class, [
'required' => false,
]);
$builder->add('value_typical', NumberType::class, [
'required' => false
]);
$builder->add('unit', TextType::class, [
'required' => false,
'empty_data' => '',
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Specification::class
]);
}
}

View file

@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200308204758 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE attachment_types ADD specifications JSON NOT NULL COMMENT \'(DC2Type:json_document)\'');
$this->addSql('ALTER TABLE categories ADD specifications JSON NOT NULL COMMENT \'(DC2Type:json_document)\'');
$this->addSql('ALTER TABLE currencies ADD specifications JSON NOT NULL COMMENT \'(DC2Type:json_document)\'');
$this->addSql('ALTER TABLE devices ADD specifications JSON NOT NULL COMMENT \'(DC2Type:json_document)\'');
$this->addSql('ALTER TABLE footprints ADD specifications JSON NOT NULL COMMENT \'(DC2Type:json_document)\'');
$this->addSql('ALTER TABLE manufacturers ADD specifications JSON NOT NULL COMMENT \'(DC2Type:json_document)\'');
$this->addSql('ALTER TABLE measurement_units ADD specifications JSON NOT NULL COMMENT \'(DC2Type:json_document)\'');
$this->addSql('ALTER TABLE storelocations ADD specifications JSON NOT NULL COMMENT \'(DC2Type:json_document)\'');
$this->addSql('ALTER TABLE suppliers ADD specifications JSON NOT NULL COMMENT \'(DC2Type:json_document)\'');
$this->addSql('ALTER TABLE groups ADD specifications JSON NOT NULL COMMENT \'(DC2Type:json_document)\'');
$this->addSql('ALTER TABLE parts ADD specifications JSON NOT NULL COMMENT \'(DC2Type:json_document)\'');
$this->addSql('ALTER TABLE log CHANGE level level TINYINT');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE `attachment_types` DROP specifications');
$this->addSql('ALTER TABLE `categories` DROP specifications');
$this->addSql('ALTER TABLE currencies DROP specifications');
$this->addSql('ALTER TABLE `devices` DROP specifications');
$this->addSql('ALTER TABLE `footprints` DROP specifications');
$this->addSql('ALTER TABLE `groups` DROP specifications');
$this->addSql('ALTER TABLE log CHANGE level level TINYINT(1) DEFAULT NULL');
$this->addSql('ALTER TABLE `manufacturers` DROP specifications');
$this->addSql('ALTER TABLE `measurement_units` DROP specifications');
$this->addSql('ALTER TABLE `parts` DROP specifications');
$this->addSql('ALTER TABLE `storelocations` DROP specifications');
$this->addSql('ALTER TABLE `suppliers` DROP specifications');
}
}