mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Added very basic possibility to add an association
This commit is contained in:
parent
b7cfdebad5
commit
8ab9cf1417
8 changed files with 143 additions and 6 deletions
39
migrations/Version20231112211329.php
Normal file
39
migrations/Version20231112211329.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?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 Version20231112211329 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->addSql('CREATE TABLE part_association (id INT AUTO_INCREMENT NOT NULL, owner_id INT NOT NULL, other_id INT NOT NULL, type SMALLINT NOT NULL, comment LONGTEXT DEFAULT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_61B952E07E3C61F9 (owner_id), INDEX IDX_61B952E0998D9879 (other_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||
$this->addSql('ALTER TABLE part_association ADD CONSTRAINT FK_61B952E07E3C61F9 FOREIGN KEY (owner_id) REFERENCES `parts` (id) ON DELETE CASCADE');
|
||||
$this->addSql('ALTER TABLE part_association ADD CONSTRAINT FK_61B952E0998D9879 FOREIGN KEY (other_id) REFERENCES `parts` (id) ON DELETE CASCADE');
|
||||
$this->addSql('ALTER TABLE part_lots ADD vendor_barcode VARCHAR(255) DEFAULT NULL');
|
||||
$this->addSql('CREATE INDEX part_lots_idx_barcode ON part_lots (vendor_barcode)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE part_association DROP FOREIGN KEY FK_61B952E07E3C61F9');
|
||||
$this->addSql('ALTER TABLE part_association DROP FOREIGN KEY FK_61B952E0998D9879');
|
||||
$this->addSql('DROP TABLE part_association');
|
||||
$this->addSql('DROP INDEX part_lots_idx_barcode ON part_lots');
|
||||
$this->addSql('ALTER TABLE part_lots DROP vendor_barcode');
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@ use App\Entity\Parts\Footprint;
|
|||
use App\Entity\Parts\Manufacturer;
|
||||
use App\Entity\Parts\MeasurementUnit;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\Parts\PartAssociation;
|
||||
use App\Entity\Parts\PartLot;
|
||||
use App\Entity\Parts\StorageLocation;
|
||||
use App\Entity\Parts\Supplier;
|
||||
|
@ -63,6 +64,8 @@ enum LogTargetType: int
|
|||
case PARAMETER = 18;
|
||||
case LABEL_PROFILE = 19;
|
||||
|
||||
case PART_ASSOCIATION = 20;
|
||||
|
||||
/**
|
||||
* Returns the class name of the target type or null if the target type is NONE.
|
||||
* @return string|null
|
||||
|
@ -90,6 +93,7 @@ enum LogTargetType: int
|
|||
self::MEASUREMENT_UNIT => MeasurementUnit::class,
|
||||
self::PARAMETER => AbstractParameter::class,
|
||||
self::LABEL_PROFILE => LabelProfile::class,
|
||||
self::PART_ASSOCIATION => PartAssociation::class,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace App\Entity\Parts;
|
|||
/**
|
||||
* The values of this enums are used to describe how two parts are associated with each other.
|
||||
*/
|
||||
enum PartAssociationType: int
|
||||
enum AssociationType: int
|
||||
{
|
||||
/** A user definable association type, which can be described in the comment field */
|
||||
case OTHER = 0;
|
|
@ -41,10 +41,10 @@ class PartAssociation extends AbstractDBElement
|
|||
use TimestampTrait;
|
||||
|
||||
/**
|
||||
* @var PartAssociationType The type of this association (how the two parts are related)
|
||||
* @var AssociationType The type of this association (how the two parts are related)
|
||||
*/
|
||||
#[ORM\Column(type: Types::SMALLINT, enumType: PartAssociationType::class)]
|
||||
protected PartAssociationType $type = PartAssociationType::OTHER;
|
||||
#[ORM\Column(type: Types::SMALLINT, enumType: AssociationType::class)]
|
||||
protected AssociationType $type = AssociationType::OTHER;
|
||||
|
||||
/**
|
||||
* @var string|null A comment describing this association further. Can also be used to specify the OTHER type
|
||||
|
@ -69,12 +69,12 @@ class PartAssociation extends AbstractDBElement
|
|||
#[Assert\NotNull]
|
||||
protected ?Part $other = null;
|
||||
|
||||
public function getType(): PartAssociationType
|
||||
public function getType(): AssociationType
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function setType(PartAssociationType $type): PartAssociation
|
||||
public function setType(AssociationType $type): PartAssociation
|
||||
{
|
||||
$this->type = $type;
|
||||
return $this;
|
||||
|
|
57
src/Form/Part/PartAssociationType.php
Normal file
57
src/Form/Part/PartAssociationType.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2023 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\Form\Part;
|
||||
|
||||
use App\Entity\Parts\AssociationType;
|
||||
use App\Entity\Parts\PartAssociation;
|
||||
use App\Form\Type\PartSelectType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EnumType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class PartAssociationType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('type', EnumType::class, [
|
||||
'class' => AssociationType::class,
|
||||
])
|
||||
->add('other', PartSelectType::class)
|
||||
->add('comment', TextType::class, [
|
||||
'required' => false,
|
||||
])
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => PartAssociation::class,
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -245,6 +245,16 @@ class PartBaseType extends AbstractType
|
|||
],
|
||||
]);
|
||||
|
||||
//Part associations
|
||||
$builder->add('associated_parts_as_owner', CollectionType::class, [
|
||||
'entry_type' => PartAssociationType::class,
|
||||
'allow_add' => true,
|
||||
'allow_delete' => true,
|
||||
'reindex_enable' => true,
|
||||
'label' => false,
|
||||
'by_reference' => false,
|
||||
]);
|
||||
|
||||
$builder->add('log_comment', TextType::class, [
|
||||
'label' => 'edit.log_comment',
|
||||
'mapped' => false,
|
||||
|
|
18
templates/parts/edit/_associated_parts.html.twig
Normal file
18
templates/parts/edit/_associated_parts.html.twig
Normal file
|
@ -0,0 +1,18 @@
|
|||
{% form_theme form with ['parts/edit/edit_form_styles.html.twig'] %}
|
||||
{% import 'components/collection_type.macro.html.twig' as collection %}
|
||||
|
||||
<div {{ collection.controller(form.associated_parts_as_owner, 'part_lot.edit.delete.confirm') }}>
|
||||
<table class="table table-striped table-sm" id="association_table" {{ collection.target() }}>
|
||||
<tbody>
|
||||
{% for assoc in form.associated_parts_as_owner %}
|
||||
{{ form_widget(assoc) }}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<button type="button" class="btn btn-success" {{ collection.create_btn() }}
|
||||
{% if not is_granted('edit', part) %}disabled{% endif %}>
|
||||
<i class="fas fa-plus-square fa-fw"></i>
|
||||
{% trans %}part_lot.create{% endtrans %}
|
||||
</button>
|
||||
</div>
|
|
@ -58,6 +58,12 @@
|
|||
{% trans %}part.edit.tab.specifications{% endtrans %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-bs-toggle="tab" role="tab" href="#associations">
|
||||
<i class="fas fa-circle-nodes fa-fw"></i>
|
||||
{% trans %}part.edit.tab.associations{% endtrans %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-bs-toggle="tab" role="tab" href="#comment">
|
||||
<i class="fas fa-sticky-note fa-fw"></i>
|
||||
|
@ -90,6 +96,9 @@
|
|||
<div class="tab-pane fade p-2" id="specifications" role="tabpanel">
|
||||
{% include "parts/edit/_specifications.html.twig" %}
|
||||
</div>
|
||||
<div class="tab-pane fade p-2" id="associations" role="tabpanel">
|
||||
{% include "parts/edit/_associated_parts.html.twig" %}
|
||||
</div>
|
||||
<div class="tab-pane fade p-2" id="comment" role="tabpanel">
|
||||
{{ form_widget(form.comment)}}
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue