mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Merge branch 'part_associations'
This commit is contained in:
commit
01ed3eeecd
31 changed files with 1124 additions and 7 deletions
|
@ -27,7 +27,7 @@ export default class extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
let tmp = '<div class="row m-0">' +
|
let tmp = '<div class="row m-0">' +
|
||||||
"<div class='col-2 p-0 d-flex align-items-center'>" +
|
"<div class='col-2 p-0 d-flex align-items-center' style='max-width: 80px;'>" +
|
||||||
(data.image ? "<img class='typeahead-image' src='" + data.image + "'/>" : "") +
|
(data.image ? "<img class='typeahead-image' src='" + data.image + "'/>" : "") +
|
||||||
"</div>" +
|
"</div>" +
|
||||||
"<div class='col-10'>" +
|
"<div class='col-10'>" +
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {Controller} from "@hotwired/stimulus";
|
||||||
|
|
||||||
|
export default class extends Controller {
|
||||||
|
|
||||||
|
static targets = [ "display", "select" ]
|
||||||
|
|
||||||
|
connect()
|
||||||
|
{
|
||||||
|
this.update();
|
||||||
|
this.selectTarget.addEventListener('change', this.update.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
update()
|
||||||
|
{
|
||||||
|
//If the select value is 0, then we show the input field
|
||||||
|
if( this.selectTarget.value === '0')
|
||||||
|
{
|
||||||
|
this.displayTarget.classList.remove('d-none');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.displayTarget.classList.add('d-none');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import {Tab, Dropdown} from "bootstrap";
|
import {Tab, Dropdown, Collapse} from "bootstrap";
|
||||||
import tab from "bootstrap/js/src/tab";
|
import tab from "bootstrap/js/src/tab";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,6 +54,7 @@ class TabRememberHelper {
|
||||||
const first_element = merged[0] ?? null;
|
const first_element = merged[0] ?? null;
|
||||||
if(first_element) {
|
if(first_element) {
|
||||||
this.revealElementOnTab(first_element);
|
this.revealElementOnTab(first_element);
|
||||||
|
this.revealElementInCollapse(first_element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,10 +63,20 @@ class TabRememberHelper {
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
onInvalid(event) {
|
onInvalid(event) {
|
||||||
|
this.revealElementInCollapse(event.target);
|
||||||
this.revealElementOnTab(event.target);
|
this.revealElementOnTab(event.target);
|
||||||
this.revealElementInDropdown(event.target);
|
this.revealElementInDropdown(event.target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
revealElementInCollapse(element) {
|
||||||
|
let collapse = element.closest('.collapse');
|
||||||
|
|
||||||
|
if(collapse) {
|
||||||
|
let bs_collapse = Collapse.getOrCreateInstance(collapse);
|
||||||
|
bs_collapse.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
revealElementInDropdown(element) {
|
revealElementInDropdown(element) {
|
||||||
let dropdown = element.closest('.dropdown-menu');
|
let dropdown = element.closest('.dropdown-menu');
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ twig:
|
||||||
avatar_helper: '@App\Services\UserSystem\UserAvatarHelper'
|
avatar_helper: '@App\Services\UserSystem\UserAvatarHelper'
|
||||||
available_themes: '%partdb.available_themes%'
|
available_themes: '%partdb.available_themes%'
|
||||||
saml_enabled: '%partdb.saml.enabled%'
|
saml_enabled: '%partdb.saml.enabled%'
|
||||||
|
part_preview_generator: '@App\Services\Attachments\PartPreviewGenerator'
|
||||||
|
|
||||||
when@test:
|
when@test:
|
||||||
twig:
|
twig:
|
||||||
|
|
71
migrations/Version20231114223101.php
Normal file
71
migrations/Version20231114223101.php
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use App\Migration\AbstractMultiPlatformMigration;
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20231114223101 extends AbstractMultiPlatformMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Add schema for part associations and vendor barcodes';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function mySQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$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, other_type VARCHAR(255) DEFAULT 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 mySQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$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');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sqLiteUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('CREATE TABLE part_association (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, owner_id INTEGER NOT NULL, other_id INTEGER NOT NULL, type SMALLINT NOT NULL, other_type VARCHAR(255) DEFAULT NULL, comment CLOB DEFAULT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, CONSTRAINT FK_61B952E07E3C61F9 FOREIGN KEY (owner_id) REFERENCES "parts" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_61B952E0998D9879 FOREIGN KEY (other_id) REFERENCES "parts" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_61B952E07E3C61F9 ON part_association (owner_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_61B952E0998D9879 ON part_association (other_id)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__part_lots AS SELECT id, id_store_location, id_part, id_owner, description, comment, expiration_date, instock_unknown, amount, needs_refill, last_modified, datetime_added FROM part_lots');
|
||||||
|
$this->addSql('DROP TABLE part_lots');
|
||||||
|
$this->addSql('CREATE TABLE part_lots (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, id_store_location INTEGER DEFAULT NULL, id_part INTEGER NOT NULL, id_owner INTEGER DEFAULT NULL, description CLOB NOT NULL, comment CLOB NOT NULL, expiration_date DATETIME DEFAULT NULL, instock_unknown BOOLEAN NOT NULL, amount DOUBLE PRECISION NOT NULL, needs_refill BOOLEAN NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, vendor_barcode VARCHAR(255) DEFAULT NULL, CONSTRAINT FK_EBC8F9435D8F4B37 FOREIGN KEY (id_store_location) REFERENCES storelocations (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_EBC8F943C22F6CC4 FOREIGN KEY (id_part) REFERENCES parts (id) ON UPDATE NO ACTION ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_EBC8F94321E5A74C FOREIGN KEY (id_owner) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO part_lots (id, id_store_location, id_part, id_owner, description, comment, expiration_date, instock_unknown, amount, needs_refill, last_modified, datetime_added) SELECT id, id_store_location, id_part, id_owner, description, comment, expiration_date, instock_unknown, amount, needs_refill, last_modified, datetime_added FROM __temp__part_lots');
|
||||||
|
$this->addSql('DROP TABLE __temp__part_lots');
|
||||||
|
$this->addSql('CREATE INDEX IDX_EBC8F94321E5A74C ON part_lots (id_owner)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_EBC8F943C22F6CC4 ON part_lots (id_part)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_EBC8F9435D8F4B37 ON part_lots (id_store_location)');
|
||||||
|
$this->addSql('CREATE INDEX part_lots_idx_instock_un_expiration_id_part ON part_lots (instock_unknown, expiration_date, id_part)');
|
||||||
|
$this->addSql('CREATE INDEX part_lots_idx_needs_refill ON part_lots (needs_refill)');
|
||||||
|
$this->addSql('CREATE INDEX part_lots_idx_barcode ON part_lots (vendor_barcode)');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sqLiteDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('DROP TABLE part_association');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__part_lots AS SELECT id, id_store_location, id_part, id_owner, description, comment, expiration_date, instock_unknown, amount, needs_refill, last_modified, datetime_added FROM part_lots');
|
||||||
|
$this->addSql('DROP TABLE part_lots');
|
||||||
|
$this->addSql('CREATE TABLE part_lots (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, id_store_location INTEGER DEFAULT NULL, id_part INTEGER NOT NULL, id_owner INTEGER DEFAULT NULL, description CLOB NOT NULL, comment CLOB NOT NULL, expiration_date DATETIME DEFAULT NULL, instock_unknown BOOLEAN NOT NULL, amount DOUBLE PRECISION NOT NULL, needs_refill BOOLEAN NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, CONSTRAINT FK_EBC8F9435D8F4B37 FOREIGN KEY (id_store_location) REFERENCES "storelocations" (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_EBC8F943C22F6CC4 FOREIGN KEY (id_part) REFERENCES "parts" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_EBC8F94321E5A74C FOREIGN KEY (id_owner) REFERENCES "users" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO part_lots (id, id_store_location, id_part, id_owner, description, comment, expiration_date, instock_unknown, amount, needs_refill, last_modified, datetime_added) SELECT id, id_store_location, id_part, id_owner, description, comment, expiration_date, instock_unknown, amount, needs_refill, last_modified, datetime_added FROM __temp__part_lots');
|
||||||
|
$this->addSql('DROP TABLE __temp__part_lots');
|
||||||
|
$this->addSql('CREATE INDEX IDX_EBC8F9435D8F4B37 ON part_lots (id_store_location)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_EBC8F943C22F6CC4 ON part_lots (id_part)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_EBC8F94321E5A74C ON part_lots (id_owner)');
|
||||||
|
$this->addSql('CREATE INDEX part_lots_idx_instock_un_expiration_id_part ON part_lots (instock_unknown, expiration_date, id_part)');
|
||||||
|
$this->addSql('CREATE INDEX part_lots_idx_needs_refill ON part_lots (needs_refill)');
|
||||||
|
}
|
||||||
|
}
|
|
@ -103,6 +103,7 @@ class PartFixtures extends Fixture implements DependentFixtureInterface
|
||||||
$partLot2->setComment('Test');
|
$partLot2->setComment('Test');
|
||||||
$partLot2->setNeedsRefill(true);
|
$partLot2->setNeedsRefill(true);
|
||||||
$partLot2->setStorageLocation($manager->find(StorageLocation::class, 3));
|
$partLot2->setStorageLocation($manager->find(StorageLocation::class, 3));
|
||||||
|
$partLot2->setVendorBarcode('lot2_vendor_barcode');
|
||||||
$part->addPartLot($partLot2);
|
$part->addPartLot($partLot2);
|
||||||
|
|
||||||
$orderdetail = new Orderdetail();
|
$orderdetail = new Orderdetail();
|
||||||
|
|
|
@ -29,6 +29,7 @@ use App\Entity\Parts\Footprint;
|
||||||
use App\Entity\Parts\Manufacturer;
|
use App\Entity\Parts\Manufacturer;
|
||||||
use App\Entity\Parts\MeasurementUnit;
|
use App\Entity\Parts\MeasurementUnit;
|
||||||
use App\Entity\Parts\Part;
|
use App\Entity\Parts\Part;
|
||||||
|
use App\Entity\Parts\PartAssociation;
|
||||||
use App\Entity\Parts\PartLot;
|
use App\Entity\Parts\PartLot;
|
||||||
use App\Entity\Parts\StorageLocation;
|
use App\Entity\Parts\StorageLocation;
|
||||||
use App\Entity\Parts\Supplier;
|
use App\Entity\Parts\Supplier;
|
||||||
|
@ -63,6 +64,8 @@ enum LogTargetType: int
|
||||||
case PARAMETER = 18;
|
case PARAMETER = 18;
|
||||||
case LABEL_PROFILE = 19;
|
case LABEL_PROFILE = 19;
|
||||||
|
|
||||||
|
case PART_ASSOCIATION = 20;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the class name of the target type or null if the target type is NONE.
|
* Returns the class name of the target type or null if the target type is NONE.
|
||||||
* @return string|null
|
* @return string|null
|
||||||
|
@ -90,6 +93,7 @@ enum LogTargetType: int
|
||||||
self::MEASUREMENT_UNIT => MeasurementUnit::class,
|
self::MEASUREMENT_UNIT => MeasurementUnit::class,
|
||||||
self::PARAMETER => AbstractParameter::class,
|
self::PARAMETER => AbstractParameter::class,
|
||||||
self::LABEL_PROFILE => LabelProfile::class,
|
self::LABEL_PROFILE => LabelProfile::class,
|
||||||
|
self::PART_ASSOCIATION => PartAssociation::class,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
46
src/Entity/Parts/AssociationType.php
Normal file
46
src/Entity/Parts/AssociationType.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?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\Entity\Parts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The values of this enums are used to describe how two parts are associated with each other.
|
||||||
|
*/
|
||||||
|
enum AssociationType: int
|
||||||
|
{
|
||||||
|
/** A user definable association type, which can be described in the comment field */
|
||||||
|
case OTHER = 0;
|
||||||
|
/** The owning part is compatible with the other part */
|
||||||
|
case COMPATIBLE = 1;
|
||||||
|
/** The owning part supersedes the other part (owner is newer version) */
|
||||||
|
case SUPERSEDES = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the translation key for this association type.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTranslationKey(): string
|
||||||
|
{
|
||||||
|
return 'part_association.type.' . strtolower($this->name);
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,6 +41,7 @@ use App\ApiPlatform\Filter\EntityFilter;
|
||||||
use App\ApiPlatform\Filter\LikeFilter;
|
use App\ApiPlatform\Filter\LikeFilter;
|
||||||
use App\ApiPlatform\Filter\PartStoragelocationFilter;
|
use App\ApiPlatform\Filter\PartStoragelocationFilter;
|
||||||
use App\Entity\Attachments\AttachmentTypeAttachment;
|
use App\Entity\Attachments\AttachmentTypeAttachment;
|
||||||
|
use App\Entity\Parts\PartTraits\AssociationTrait;
|
||||||
use App\Repository\PartRepository;
|
use App\Repository\PartRepository;
|
||||||
use Doctrine\DBAL\Types\Types;
|
use Doctrine\DBAL\Types\Types;
|
||||||
use App\Entity\Attachments\Attachment;
|
use App\Entity\Attachments\Attachment;
|
||||||
|
@ -58,6 +59,7 @@ use DateTime;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Jfcherng\Diff\Utility\Arr;
|
||||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||||
use Symfony\Component\Serializer\Annotation\Groups;
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
@ -112,6 +114,7 @@ class Part extends AttachmentContainingDBElement
|
||||||
use OrderTrait;
|
use OrderTrait;
|
||||||
use ParametersTrait;
|
use ParametersTrait;
|
||||||
use ProjectTrait;
|
use ProjectTrait;
|
||||||
|
use AssociationTrait;
|
||||||
|
|
||||||
/** @var Collection<int, PartParameter>
|
/** @var Collection<int, PartParameter>
|
||||||
*/
|
*/
|
||||||
|
@ -165,6 +168,9 @@ class Part extends AttachmentContainingDBElement
|
||||||
$this->parameters = new ArrayCollection();
|
$this->parameters = new ArrayCollection();
|
||||||
$this->project_bom_entries = new ArrayCollection();
|
$this->project_bom_entries = new ArrayCollection();
|
||||||
|
|
||||||
|
$this->associated_parts_as_owner = new ArrayCollection();
|
||||||
|
$this->associated_parts_as_other = new ArrayCollection();
|
||||||
|
|
||||||
//By default, the part has no provider
|
//By default, the part has no provider
|
||||||
$this->providerReference = InfoProviderReference::noProvider();
|
$this->providerReference = InfoProviderReference::noProvider();
|
||||||
}
|
}
|
||||||
|
@ -193,6 +199,13 @@ class Part extends AttachmentContainingDBElement
|
||||||
$this->addParameter(clone $parameter);
|
$this->addParameter(clone $parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Deep clone the owned part associations (the owned ones make not much sense without the owner)
|
||||||
|
$ownedAssociations = $this->associated_parts_as_owner;
|
||||||
|
$this->associated_parts_as_owner = new ArrayCollection();
|
||||||
|
foreach ($ownedAssociations as $association) {
|
||||||
|
$this->addAssociatedPartsAsOwner(clone $association);
|
||||||
|
}
|
||||||
|
|
||||||
//Deep clone info provider
|
//Deep clone info provider
|
||||||
$this->providerReference = clone $this->providerReference;
|
$this->providerReference = clone $this->providerReference;
|
||||||
}
|
}
|
||||||
|
|
233
src/Entity/Parts/PartAssociation.php
Normal file
233
src/Entity/Parts/PartAssociation.php
Normal file
|
@ -0,0 +1,233 @@
|
||||||
|
<?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\Entity\Parts;
|
||||||
|
|
||||||
|
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
|
||||||
|
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
||||||
|
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||||
|
use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
|
||||||
|
use ApiPlatform\Metadata\ApiFilter;
|
||||||
|
use ApiPlatform\Metadata\ApiProperty;
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Delete;
|
||||||
|
use ApiPlatform\Metadata\Get;
|
||||||
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
|
use ApiPlatform\Metadata\Patch;
|
||||||
|
use ApiPlatform\Metadata\Post;
|
||||||
|
use ApiPlatform\Serializer\Filter\PropertyFilter;
|
||||||
|
use App\ApiPlatform\Filter\LikeFilter;
|
||||||
|
use App\Repository\DBElementRepository;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use App\Entity\Base\AbstractDBElement;
|
||||||
|
use App\Entity\Base\TimestampTrait;
|
||||||
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||||
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This entity describes a part association, which is a semantic connection between two parts.
|
||||||
|
* For example, a part association can be used to describe that a part is a replacement for another part.
|
||||||
|
*/
|
||||||
|
#[ORM\Entity(repositoryClass: DBElementRepository::class)]
|
||||||
|
#[ORM\HasLifecycleCallbacks]
|
||||||
|
#[UniqueEntity(fields: ['other', 'owner', 'type'], message: 'validator.part_association.already_exists')]
|
||||||
|
#[ApiResource(
|
||||||
|
operations: [
|
||||||
|
new Get(security: 'is_granted("read", object)'),
|
||||||
|
new GetCollection(security: 'is_granted("@parts.read")'),
|
||||||
|
new Post(securityPostDenormalize: 'is_granted("create", object)'),
|
||||||
|
new Patch(security: 'is_granted("edit", object)'),
|
||||||
|
new Delete(security: 'is_granted("delete", object)'),
|
||||||
|
],
|
||||||
|
normalizationContext: ['groups' => ['part_assoc:read', 'part_assoc:read:standalone', 'api:basic:read'], 'openapi_definition_name' => 'Read'],
|
||||||
|
denormalizationContext: ['groups' => ['part_assoc:write', 'api:basic:write'], 'openapi_definition_name' => 'Write'],
|
||||||
|
)]
|
||||||
|
#[ApiFilter(PropertyFilter::class)]
|
||||||
|
#[ApiFilter(LikeFilter::class, properties: ["other_type", "comment"])]
|
||||||
|
#[ApiFilter(DateFilter::class, strategy: DateFilter::EXCLUDE_NULL)]
|
||||||
|
#[ApiFilter(OrderFilter::class, properties: ['comment', 'addedDate', 'lastModified'])]
|
||||||
|
class PartAssociation extends AbstractDBElement
|
||||||
|
{
|
||||||
|
use TimestampTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var AssociationType The type of this association (how the two parts are related)
|
||||||
|
*/
|
||||||
|
#[ORM\Column(type: Types::SMALLINT, enumType: AssociationType::class)]
|
||||||
|
#[Groups(['part_assoc:read', 'part_assoc:write'])]
|
||||||
|
protected AssociationType $type = AssociationType::OTHER;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string|null A user definable association type, which can be described in the comment field, which
|
||||||
|
* is used if the type is OTHER
|
||||||
|
*/
|
||||||
|
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
|
||||||
|
#[Assert\Expression("this.getType().value !== 0 or this.getOtherType() !== null",
|
||||||
|
message: 'validator.part_association.must_set_an_value_if_type_is_other')]
|
||||||
|
#[Groups(['part_assoc:read', 'part_assoc:write'])]
|
||||||
|
protected ?string $other_type = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string|null A comment describing this association further.
|
||||||
|
*/
|
||||||
|
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
||||||
|
#[Groups(['part_assoc:read', 'part_assoc:write'])]
|
||||||
|
protected ?string $comment = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Part|null The part which "owns" this association, e.g. the part which is a replacement for another part
|
||||||
|
*/
|
||||||
|
#[ORM\ManyToOne(targetEntity: Part::class, inversedBy: 'associated_parts_as_owner')]
|
||||||
|
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
||||||
|
#[Assert\NotNull]
|
||||||
|
#[Groups(['part_assoc:read:standalone', 'part_assoc:write'])]
|
||||||
|
protected ?Part $owner = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Part|null The part which is "owned" by this association, e.g. the part which is replaced by another part
|
||||||
|
*/
|
||||||
|
#[ORM\ManyToOne(targetEntity: Part::class, inversedBy: 'associated_parts_as_other')]
|
||||||
|
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
||||||
|
#[Assert\NotNull]
|
||||||
|
#[Assert\Expression("this.getOwner() !== this.getOther()",
|
||||||
|
message: 'validator.part_association.part_cannot_be_associated_with_itself')]
|
||||||
|
#[Groups(['part_assoc:read', 'part_assoc:write'])]
|
||||||
|
protected ?Part $other = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the (semantic) relation type of this association as an AssociationType enum value.
|
||||||
|
* If the type is set to OTHER, then the other_type field value is used for the user defined type.
|
||||||
|
* @return AssociationType
|
||||||
|
*/
|
||||||
|
public function getType(): AssociationType
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the (semantic) relation type of this association as an AssociationType enum value.
|
||||||
|
* @param AssociationType $type
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setType(AssociationType $type): PartAssociation
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a comment, which describes this association further.
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getComment(): ?string
|
||||||
|
{
|
||||||
|
return $this->comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a comment, which describes this association further.
|
||||||
|
* @param string|null $comment
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setComment(?string $comment): PartAssociation
|
||||||
|
{
|
||||||
|
$this->comment = $comment;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the part which "owns" this association, e.g. the part which is a replacement for another part.
|
||||||
|
* @return Part|null
|
||||||
|
*/
|
||||||
|
public function getOwner(): ?Part
|
||||||
|
{
|
||||||
|
return $this->owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the part which "owns" this association, e.g. the part which is a replacement for another part.
|
||||||
|
* @param Part|null $owner
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setOwner(?Part $owner): PartAssociation
|
||||||
|
{
|
||||||
|
$this->owner = $owner;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the part which is "owned" by this association, e.g. the part which is replaced by another part.
|
||||||
|
* @return Part|null
|
||||||
|
*/
|
||||||
|
public function getOther(): ?Part
|
||||||
|
{
|
||||||
|
return $this->other;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the part which is "owned" by this association, e.g. the part which is replaced by another part.
|
||||||
|
* @param Part|null $other
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setOther(?Part $other): PartAssociation
|
||||||
|
{
|
||||||
|
$this->other = $other;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the user defined association type, which is used if the type is set to OTHER.
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getOtherType(): ?string
|
||||||
|
{
|
||||||
|
return $this->other_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the user defined association type, which is used if the type is set to OTHER.
|
||||||
|
* @param string|null $other_type
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setOtherType(?string $other_type): PartAssociation
|
||||||
|
{
|
||||||
|
$this->other_type = $other_type;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the translation key for the type of this association.
|
||||||
|
* If the type is set to OTHER, then the other_type field value is used.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTypeTranslationKey(): string
|
||||||
|
{
|
||||||
|
if ($this->type === AssociationType::OTHER) {
|
||||||
|
return $this->other_type ?? 'Unknown';
|
||||||
|
}
|
||||||
|
return $this->type->getTranslationKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -47,6 +47,7 @@ use App\Validator\Constraints\ValidPartLot;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||||
use Symfony\Component\Serializer\Annotation\Groups;
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
|
@ -60,9 +61,11 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
#[ORM\Entity]
|
#[ORM\Entity]
|
||||||
#[ORM\HasLifecycleCallbacks]
|
#[ORM\HasLifecycleCallbacks]
|
||||||
#[ORM\Table(name: 'part_lots')]
|
#[ORM\Table(name: 'part_lots')]
|
||||||
#[ORM\Index(name: 'part_lots_idx_instock_un_expiration_id_part', columns: ['instock_unknown', 'expiration_date', 'id_part'])]
|
#[ORM\Index(columns: ['instock_unknown', 'expiration_date', 'id_part'], name: 'part_lots_idx_instock_un_expiration_id_part')]
|
||||||
#[ORM\Index(name: 'part_lots_idx_needs_refill', columns: ['needs_refill'])]
|
#[ORM\Index(columns: ['needs_refill'], name: 'part_lots_idx_needs_refill')]
|
||||||
|
#[ORM\Index(columns: ['vendor_barcode'], name: 'part_lots_idx_barcode')]
|
||||||
#[ValidPartLot]
|
#[ValidPartLot]
|
||||||
|
#[UniqueEntity(['vendor_barcode'], message: 'validator.part_lot.vendor_barcode_must_be_unique')]
|
||||||
#[ApiResource(
|
#[ApiResource(
|
||||||
operations: [
|
operations: [
|
||||||
new Get(security: 'is_granted("read", object)'),
|
new Get(security: 'is_granted("read", object)'),
|
||||||
|
@ -154,6 +157,13 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
|
||||||
#[Groups(['part_lot:read', 'part_lot:write'])]
|
#[Groups(['part_lot:read', 'part_lot:write'])]
|
||||||
protected ?User $owner = null;
|
protected ?User $owner = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string|null The content of the barcode of this part lot (e.g. a barcode on the package put by the vendor)
|
||||||
|
*/
|
||||||
|
#[ORM\Column(type: Types::STRING, nullable: true)]
|
||||||
|
#[Groups(['part_lot:read', 'part_lot:write'])]
|
||||||
|
protected ?string $vendor_barcode = null;
|
||||||
|
|
||||||
public function __clone()
|
public function __clone()
|
||||||
{
|
{
|
||||||
if ($this->id) {
|
if ($this->id) {
|
||||||
|
@ -354,6 +364,29 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
|
||||||
return $this->description;
|
return $this->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The content of the barcode of this part lot (e.g. a barcode on the package put by the vendor), or
|
||||||
|
* null if no barcode is set.
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getVendorBarcode(): ?string
|
||||||
|
{
|
||||||
|
return $this->vendor_barcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the content of the barcode of this part lot (e.g. a barcode on the package put by the vendor).
|
||||||
|
* @param string|null $vendor_barcode
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setVendorBarcode(?string $vendor_barcode): PartLot
|
||||||
|
{
|
||||||
|
$this->vendor_barcode = $vendor_barcode;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[Assert\Callback]
|
#[Assert\Callback]
|
||||||
public function validate(ExecutionContextInterface $context, $payload): void
|
public function validate(ExecutionContextInterface $context, $payload): void
|
||||||
{
|
{
|
||||||
|
|
111
src/Entity/Parts/PartTraits/AssociationTrait.php
Normal file
111
src/Entity/Parts/PartTraits/AssociationTrait.php
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
<?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\Entity\Parts\PartTraits;
|
||||||
|
|
||||||
|
use App\Entity\Parts\Part;
|
||||||
|
use App\Entity\Parts\PartAssociation;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
|
use Symfony\Component\Validator\Constraints\Valid;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
trait AssociationTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Collection<PartAssociation> All associations where this part is the owner
|
||||||
|
*/
|
||||||
|
#[Valid]
|
||||||
|
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: PartAssociation::class,
|
||||||
|
cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||||
|
#[Groups(['part:read', 'part:write'])]
|
||||||
|
protected Collection $associated_parts_as_owner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Collection<PartAssociation> All associations where this part is the owned/other part
|
||||||
|
*/
|
||||||
|
#[Valid]
|
||||||
|
#[ORM\OneToMany(mappedBy: 'other', targetEntity: PartAssociation::class,
|
||||||
|
cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||||
|
#[Groups(['part:read'])]
|
||||||
|
protected Collection $associated_parts_as_other;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all associations where this part is the owner.
|
||||||
|
* @return Collection<PartAssociation>
|
||||||
|
*/
|
||||||
|
public function getAssociatedPartsAsOwner(): Collection
|
||||||
|
{
|
||||||
|
return $this->associated_parts_as_owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new association where this part is the owner.
|
||||||
|
* @param PartAssociation $association
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function addAssociatedPartsAsOwner(PartAssociation $association): self
|
||||||
|
{
|
||||||
|
//Ensure that the association is really owned by this part
|
||||||
|
$association->setOwner($this);
|
||||||
|
|
||||||
|
$this->associated_parts_as_owner->add($association);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove an association where this part is the owner.
|
||||||
|
* @param PartAssociation $association
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function removeAssociatedPartsAsOwner(PartAssociation $association): self
|
||||||
|
{
|
||||||
|
$this->associated_parts_as_owner->removeElement($association);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all associations where this part is the owned/other part.
|
||||||
|
* If you want to modify the association, do it on the owning part
|
||||||
|
* @return Collection<PartAssociation>
|
||||||
|
*/
|
||||||
|
public function getAssociatedPartsAsOther(): Collection
|
||||||
|
{
|
||||||
|
return $this->associated_parts_as_other;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all associations where this part is the owned or other part.
|
||||||
|
* @return Collection<PartAssociation>
|
||||||
|
*/
|
||||||
|
public function getAssociatedPartsAll(): Collection
|
||||||
|
{
|
||||||
|
return new ArrayCollection(
|
||||||
|
array_merge(
|
||||||
|
$this->associated_parts_as_owner->toArray(),
|
||||||
|
$this->associated_parts_as_other->toArray()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -148,6 +148,7 @@ class LogFilterType extends AbstractType
|
||||||
LogTargetType::MEASUREMENT_UNIT => 'measurement_unit.label',
|
LogTargetType::MEASUREMENT_UNIT => 'measurement_unit.label',
|
||||||
LogTargetType::PARAMETER => 'parameter.label',
|
LogTargetType::PARAMETER => 'parameter.label',
|
||||||
LogTargetType::LABEL_PROFILE => 'label_profile.label',
|
LogTargetType::LABEL_PROFILE => 'label_profile.label',
|
||||||
|
LogTargetType::PART_ASSOCIATION => 'part_association.label',
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@ class ScanDialogType extends AbstractType
|
||||||
null => 'scan_dialog.mode.auto',
|
null => 'scan_dialog.mode.auto',
|
||||||
BarcodeSourceType::INTERNAL => 'scan_dialog.mode.internal',
|
BarcodeSourceType::INTERNAL => 'scan_dialog.mode.internal',
|
||||||
BarcodeSourceType::IPN => 'scan_dialog.mode.ipn',
|
BarcodeSourceType::IPN => 'scan_dialog.mode.ipn',
|
||||||
|
BarcodeSourceType::VENDOR => 'scan_dialog.mode.vendor',
|
||||||
},
|
},
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
|
73
src/Form/Part/PartAssociationType.php
Normal file
73
src/Form/Part/PartAssociationType.php
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
<?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('other', PartSelectType::class, [
|
||||||
|
'label' => 'part_association.edit.other_part',
|
||||||
|
])
|
||||||
|
->add('type', EnumType::class, [
|
||||||
|
'class' => AssociationType::class,
|
||||||
|
'label' => 'part_association.edit.type',
|
||||||
|
'choice_label' => fn(AssociationType $type) => $type->getTranslationKey(),
|
||||||
|
'help' => 'part_association.edit.type.help',
|
||||||
|
'attr' => [
|
||||||
|
'data-pages--association-edit-type-select-target' => 'select'
|
||||||
|
]
|
||||||
|
])
|
||||||
|
->add('other_type', TextType::class, [
|
||||||
|
'required' => false,
|
||||||
|
'label' => 'part_association.edit.other_type',
|
||||||
|
'row_attr' => [
|
||||||
|
'data-pages--association-edit-type-select-target' => 'display'
|
||||||
|
]
|
||||||
|
])
|
||||||
|
->add('comment', TextType::class, [
|
||||||
|
'required' => false,
|
||||||
|
'label' => 'part_association.edit.comment'
|
||||||
|
])
|
||||||
|
;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$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, [
|
$builder->add('log_comment', TextType::class, [
|
||||||
'label' => 'edit.log_comment',
|
'label' => 'edit.log_comment',
|
||||||
'mapped' => false,
|
'mapped' => false,
|
||||||
|
|
|
@ -80,7 +80,7 @@ class PartLotType extends AbstractType
|
||||||
'required' => false,
|
'required' => false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$builder->add('expirationDate', DateType::class, [
|
$builder->add('expiration_date', DateType::class, [
|
||||||
'label' => 'part_lot.edit.expiration_date',
|
'label' => 'part_lot.edit.expiration_date',
|
||||||
'attr' => [],
|
'attr' => [],
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
|
@ -102,6 +102,12 @@ class PartLotType extends AbstractType
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'help' => 'part_lot.owner.help',
|
'help' => 'part_lot.owner.help',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$builder->add('vendor_barcode', TextType::class, [
|
||||||
|
'label' => 'part_lot.edit.vendor_barcode',
|
||||||
|
'help' => 'part_lot.edit.vendor_barcode.help',
|
||||||
|
'required' => false,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver): void
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
|
104
src/Security/Voter/PartAssociationVoter.php
Normal file
104
src/Security/Voter/PartAssociationVoter.php
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 - 2022 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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 - 2022 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\Security\Voter;
|
||||||
|
|
||||||
|
use App\Entity\Parts\PartAssociation;
|
||||||
|
use App\Services\UserSystem\VoterHelper;
|
||||||
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
|
use App\Entity\Parts\Part;
|
||||||
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||||
|
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This voter handles permissions for part associations.
|
||||||
|
* The permissions are inherited from the part.
|
||||||
|
*/
|
||||||
|
final class PartAssociationVoter extends Voter
|
||||||
|
{
|
||||||
|
public function __construct(private readonly Security $security, private readonly VoterHelper $helper)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected const ALLOWED_PERMS = ['read', 'edit', 'create', 'delete', 'show_history', 'revert_element'];
|
||||||
|
|
||||||
|
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
|
||||||
|
{
|
||||||
|
if (!is_string($subject) && !$subject instanceof PartAssociation) {
|
||||||
|
throw new \RuntimeException('Invalid subject type!');
|
||||||
|
}
|
||||||
|
|
||||||
|
$operation = match ($attribute) {
|
||||||
|
'read' => 'read',
|
||||||
|
'edit', 'create', 'delete' => 'edit',
|
||||||
|
'show_history' => 'show_history',
|
||||||
|
'revert_element' => 'revert_element',
|
||||||
|
default => throw new \RuntimeException('Encountered unknown operation "'.$attribute.'"!'),
|
||||||
|
};
|
||||||
|
|
||||||
|
//If we have no part associated use the generic part permission
|
||||||
|
if (is_string($subject) || !$subject->getOwner() instanceof Part) {
|
||||||
|
return $this->helper->isGranted($token, 'parts', $operation);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Otherwise vote on the part
|
||||||
|
return $this->security->isGranted($attribute, $subject->getOwner());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function supports($attribute, $subject): bool
|
||||||
|
{
|
||||||
|
if (is_a($subject, PartAssociation::class, true)) {
|
||||||
|
return in_array($attribute, self::ALLOWED_PERMS, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportsType(string $subjectType): bool
|
||||||
|
{
|
||||||
|
return $subjectType === 'string' || is_a($subjectType, PartAssociation::class, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportsAttribute(string $attribute): bool
|
||||||
|
{
|
||||||
|
return in_array($attribute, self::ALLOWED_PERMS, true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ use App\Entity\Attachments\AttachmentType;
|
||||||
use App\Entity\Base\AbstractDBElement;
|
use App\Entity\Base\AbstractDBElement;
|
||||||
use App\Entity\Base\AbstractNamedDBElement;
|
use App\Entity\Base\AbstractNamedDBElement;
|
||||||
use App\Entity\Contracts\NamedElementInterface;
|
use App\Entity\Contracts\NamedElementInterface;
|
||||||
|
use App\Entity\Parts\PartAssociation;
|
||||||
use App\Entity\ProjectSystem\Project;
|
use App\Entity\ProjectSystem\Project;
|
||||||
use App\Entity\LabelSystem\LabelProfile;
|
use App\Entity\LabelSystem\LabelProfile;
|
||||||
use App\Entity\Parameters\AbstractParameter;
|
use App\Entity\Parameters\AbstractParameter;
|
||||||
|
@ -80,6 +81,7 @@ class ElementTypeNameGenerator
|
||||||
User::class => $this->translator->trans('user.label'),
|
User::class => $this->translator->trans('user.label'),
|
||||||
AbstractParameter::class => $this->translator->trans('parameter.label'),
|
AbstractParameter::class => $this->translator->trans('parameter.label'),
|
||||||
LabelProfile::class => $this->translator->trans('label_profile.label'),
|
LabelProfile::class => $this->translator->trans('label_profile.label'),
|
||||||
|
PartAssociation::class => $this->translator->trans('part_association.label'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ namespace App\Services\LabelSystem\Barcodes;
|
||||||
|
|
||||||
use App\Entity\LabelSystem\LabelSupportedElement;
|
use App\Entity\LabelSystem\LabelSupportedElement;
|
||||||
use App\Entity\Parts\Part;
|
use App\Entity\Parts\Part;
|
||||||
|
use App\Entity\Parts\PartLot;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
|
@ -82,6 +83,9 @@ final class BarcodeScanHelper
|
||||||
if ($type === BarcodeSourceType::INTERNAL) {
|
if ($type === BarcodeSourceType::INTERNAL) {
|
||||||
return $this->parseInternalBarcode($input) ?? throw new InvalidArgumentException('Could not parse barcode');
|
return $this->parseInternalBarcode($input) ?? throw new InvalidArgumentException('Could not parse barcode');
|
||||||
}
|
}
|
||||||
|
if ($type === BarcodeSourceType::VENDOR) {
|
||||||
|
return $this->parseVendorBarcode($input) ?? throw new InvalidArgumentException('Could not parse barcode');
|
||||||
|
}
|
||||||
if ($type === BarcodeSourceType::IPN) {
|
if ($type === BarcodeSourceType::IPN) {
|
||||||
return $this->parseIPNBarcode($input) ?? throw new InvalidArgumentException('Could not parse barcode');
|
return $this->parseIPNBarcode($input) ?? throw new InvalidArgumentException('Could not parse barcode');
|
||||||
}
|
}
|
||||||
|
@ -93,13 +97,38 @@ final class BarcodeScanHelper
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Try to parse as vendor barcode
|
||||||
|
$result = $this->parseVendorBarcode($input);
|
||||||
|
if ($result !== null) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
//Try to parse as IPN barcode
|
//Try to parse as IPN barcode
|
||||||
$result = $this->parseIPNBarcode($input);
|
$result = $this->parseIPNBarcode($input);
|
||||||
if ($result !== null) {
|
if ($result !== null) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new InvalidArgumentException('Unknown barcode format');
|
throw new InvalidArgumentException('Unknown barcode');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function parseVendorBarcode(string $input): ?BarcodeScanResult
|
||||||
|
{
|
||||||
|
$lot_repo = $this->entityManager->getRepository(PartLot::class);
|
||||||
|
//Find only the first result
|
||||||
|
$results = $lot_repo->findBy(['vendor_barcode' => $input], limit: 1);
|
||||||
|
|
||||||
|
if (count($results) === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//We found a part, so use it to create the result
|
||||||
|
$lot = $results[0];
|
||||||
|
|
||||||
|
return new BarcodeScanResult(
|
||||||
|
target_type: LabelSupportedElement::PART_LOT,
|
||||||
|
target_id: $lot->getID(),
|
||||||
|
source_type: BarcodeSourceType::VENDOR
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseIPNBarcode(string $input): ?BarcodeScanResult
|
private function parseIPNBarcode(string $input): ?BarcodeScanResult
|
||||||
|
|
|
@ -32,4 +32,9 @@ enum BarcodeSourceType
|
||||||
case INTERNAL;
|
case INTERNAL;
|
||||||
/** This barcode is containing an internal part number (IPN) */
|
/** This barcode is containing an internal part number (IPN) */
|
||||||
case IPN;
|
case IPN;
|
||||||
|
/**
|
||||||
|
* This barcode is a custom barcode from a third party like a vendor, which was set via the vendor_barcode
|
||||||
|
* field of a part lot.
|
||||||
|
*/
|
||||||
|
case VENDOR;
|
||||||
}
|
}
|
|
@ -188,6 +188,15 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% macro part_icon_link(part) %}
|
||||||
|
{% set preview_attach = part_preview_generator.tablePreviewAttachment(part) %}
|
||||||
|
{% if preview_attach %}
|
||||||
|
<img src="{{ attachment_thumbnail(preview_attach, 'thumbnail_xs') }}" class="entity-image-xs" alt="Part image"
|
||||||
|
{{ stimulus_controller('elements/hoverpic') }} data-thumbnail="{{ attachment_thumbnail(preview_attach) }}">
|
||||||
|
{% endif %}
|
||||||
|
<a href="{{ entity_url(part) }}">{{ part.name }}</a>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro entity_preview_sm(entity) %}
|
{% macro entity_preview_sm(entity) %}
|
||||||
{# @var entity \App\Entity\Contracts\HasMasterAttachmentInterface #}
|
{# @var entity \App\Entity\Contracts\HasMasterAttachmentInterface #}
|
||||||
{% if entity.masterPictureAttachment and entity.masterPictureAttachment.picture and attachment_manager.fileExisting(entity.masterPictureAttachment) %}
|
{% if entity.masterPictureAttachment and entity.masterPictureAttachment.picture and attachment_manager.fileExisting(entity.masterPictureAttachment) %}
|
||||||
|
|
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_association.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>
|
|
@ -89,7 +89,23 @@
|
||||||
{% import 'components/collection_type.macro.html.twig' as collection %}
|
{% import 'components/collection_type.macro.html.twig' as collection %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
{{ form_widget(form) }}
|
{{ form_row(form.description) }}
|
||||||
|
{{ form_row(form.storage_location) }}
|
||||||
|
{{ form_row(form.amount) }}
|
||||||
|
{{ form_row(form.instock_unknown) }}
|
||||||
|
{{ form_row(form.needs_refill) }}
|
||||||
|
{{ form_row(form.expiration_date) }}
|
||||||
|
|
||||||
|
{% set id = 'collapse_' ~ random() %}
|
||||||
|
|
||||||
|
<a class="btn btn-link offset-sm-3 btn-sm" data-bs-toggle="collapse" href="#{{ id }}" role="button" aria-expanded="false" aria-controls="{{ id }}">
|
||||||
|
{% trans %}part_lot.edit.advanced{% endtrans %}
|
||||||
|
</a>
|
||||||
|
<div class="collapse" id="{{ id }}">
|
||||||
|
{{ form_row(form.comment) }}
|
||||||
|
{{ form_row(form.owner) }}
|
||||||
|
{{ form_row(form.vendor_barcode) }}
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button type="button" class="btn btn-danger lot_btn_delete" {{ collection.delete_btn() }}>
|
<button type="button" class="btn btn-danger lot_btn_delete" {{ collection.delete_btn() }}>
|
||||||
|
@ -184,3 +200,21 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block part_association_widget %}
|
||||||
|
{% import 'components/collection_type.macro.html.twig' as collection %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div {{ stimulus_controller('pages/association_edit_type_select') }}>
|
||||||
|
{{ form_widget(form) }}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button type="button" class="btn btn-danger lot_btn_delete" {{ collection.delete_btn() }}>
|
||||||
|
<i class="fas fa-trash-alt fa-fw"></i>
|
||||||
|
{% trans %}part_lot.delete{% endtrans %}
|
||||||
|
</button>
|
||||||
|
{{ form_errors(form) }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endblock %}
|
|
@ -58,6 +58,12 @@
|
||||||
{% trans %}part.edit.tab.specifications{% endtrans %}
|
{% trans %}part.edit.tab.specifications{% endtrans %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</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">
|
<li class="nav-item">
|
||||||
<a class="nav-link" data-bs-toggle="tab" role="tab" href="#comment">
|
<a class="nav-link" data-bs-toggle="tab" role="tab" href="#comment">
|
||||||
<i class="fas fa-sticky-note fa-fw"></i>
|
<i class="fas fa-sticky-note fa-fw"></i>
|
||||||
|
@ -90,6 +96,9 @@
|
||||||
<div class="tab-pane fade p-2" id="specifications" role="tabpanel">
|
<div class="tab-pane fade p-2" id="specifications" role="tabpanel">
|
||||||
{% include "parts/edit/_specifications.html.twig" %}
|
{% include "parts/edit/_specifications.html.twig" %}
|
||||||
</div>
|
</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">
|
<div class="tab-pane fade p-2" id="comment" role="tabpanel">
|
||||||
{{ form_widget(form.comment)}}
|
{{ form_widget(form.comment)}}
|
||||||
</div>
|
</div>
|
||||||
|
|
40
templates/parts/info/_associations.html.twig
Normal file
40
templates/parts/info/_associations.html.twig
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
{% import "helper.twig" as helper %}
|
||||||
|
|
||||||
|
{% macro assoc_row(assoc) %}
|
||||||
|
{# @var assoc \App\Entity\Parts\PartAssociation #}
|
||||||
|
<tr>
|
||||||
|
<td>{{ helper.part_icon_link(assoc.owner) }}</td>
|
||||||
|
<td>{{ assoc.typeTranslationKey | trans }}</td>
|
||||||
|
<td>{{ helper.part_icon_link(assoc.other) }}</td>
|
||||||
|
<td>{{ assoc.comment }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% macro assoc_table(assocs, caption) %}
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-hover caption-top">
|
||||||
|
<caption>{{ caption | trans }}:</caption>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans %}part_association.table.from{% endtrans %}</th>
|
||||||
|
<th>{% trans %}part_association.table.type{% endtrans %}</th>
|
||||||
|
<th>{% trans %}part_association.table.to{% endtrans %}</th>
|
||||||
|
<th>{% trans %}part_association.edit.comment{% endtrans %}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for assoc in assocs %}
|
||||||
|
{{ _self.assoc_row(assoc) }}
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% if part.associatedPartsAsOwner is not empty %}
|
||||||
|
{{ _self.assoc_table(part.associatedPartsAsOwner, 'part_association.table.from_this_part') }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if part.associatedPartsAsOther is not empty %}
|
||||||
|
{{ _self.assoc_table(part.associatedPartsAsOther, 'part_association.table.to_this_part') }}
|
||||||
|
{% endif %}
|
|
@ -88,6 +88,17 @@
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if part.associatedPartsAll is not empty %}
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" id="associations-tab" data-bs-toggle="tab" href="#associations" role="tab">
|
||||||
|
<i class="fas fas fa-circle-nodes fa-fw fa-fw"></i>
|
||||||
|
{% trans %}part.edit.tab.associations{% endtrans %}
|
||||||
|
<span class="badge bg-secondary">{{ part.associatedPartsAll | length }}</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<li class="nav-item {% if datatable is null %}not-allowed{% endif %}">
|
<li class="nav-item {% if datatable is null %}not-allowed{% endif %}">
|
||||||
<a class="nav-link {% if datatable is null %}disabled{% endif %}" id="history-tab" data-bs-toggle="tab" href="#history" role="tab">
|
<a class="nav-link {% if datatable is null %}disabled{% endif %}" id="history-tab" data-bs-toggle="tab" href="#history" role="tab">
|
||||||
<i class="fas fa-history"></i>
|
<i class="fas fa-history"></i>
|
||||||
|
@ -142,6 +153,12 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if part.associatedPartsAll is not empty %}
|
||||||
|
<div class="tab-pane fade" id="associations" role="tabpanel" aria-labelledby="associations-tab">
|
||||||
|
{% include "parts/info/_associations.html.twig" %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="tab-pane fade" id="projects" role="tabpanel" aria-labelledby="projects-tab">
|
<div class="tab-pane fade" id="projects" role="tabpanel" aria-labelledby="projects-tab">
|
||||||
{% include "parts/info/_projects.html.twig" %}
|
{% include "parts/info/_projects.html.twig" %}
|
||||||
</div>
|
</div>
|
||||||
|
|
43
tests/Entity/Parts/PartAssociationTest.php
Normal file
43
tests/Entity/Parts/PartAssociationTest.php
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Tests\Entity\Parts;
|
||||||
|
|
||||||
|
use App\Entity\Parts\AssociationType;
|
||||||
|
use App\Entity\Parts\PartAssociation;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class PartAssociationTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function testGetTypeTranslationKey(): void
|
||||||
|
{
|
||||||
|
$assoc = new PartAssociation();
|
||||||
|
$assoc->setType(AssociationType::COMPATIBLE);
|
||||||
|
$assoc->setOtherType('Custom Type');
|
||||||
|
|
||||||
|
//If the type is not OTHER the translation key should be the same as the type
|
||||||
|
$this->assertEquals($assoc->getType()->getTranslationKey(), $assoc->getTypeTranslationKey());
|
||||||
|
|
||||||
|
//If the type is OTHER the translation key should be the other type
|
||||||
|
$assoc->setType(AssociationType::OTHER);
|
||||||
|
$this->assertEquals($assoc->getOtherType(), $assoc->getTypeTranslationKey());
|
||||||
|
}
|
||||||
|
}
|
|
@ -107,6 +107,10 @@ class BarcodeScanHelperTest extends WebTestCase
|
||||||
//Test IPN barcode
|
//Test IPN barcode
|
||||||
yield [new BarcodeScanResult(LabelSupportedElement::PART, 2, BarcodeSourceType::IPN),
|
yield [new BarcodeScanResult(LabelSupportedElement::PART, 2, BarcodeSourceType::IPN),
|
||||||
'IPN123'];
|
'IPN123'];
|
||||||
|
|
||||||
|
//Test vendor barcode
|
||||||
|
yield [new BarcodeScanResult(LabelSupportedElement::PART_LOT, 2,BarcodeSourceType::VENDOR),
|
||||||
|
'lot2_vendor_barcode'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function invalidDataProvider(): array
|
public static function invalidDataProvider(): array
|
||||||
|
|
|
@ -11831,5 +11831,125 @@ Please note, that you can not impersonate a disabled user. If you try you will g
|
||||||
<target>Part-DB barcode</target>
|
<target>Part-DB barcode</target>
|
||||||
</segment>
|
</segment>
|
||||||
</unit>
|
</unit>
|
||||||
|
<unit id="hrPuOzr" name="part_association.label">
|
||||||
|
<segment>
|
||||||
|
<source>part_association.label</source>
|
||||||
|
<target>Part association</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="BntFEyV" name="part.edit.tab.associations">
|
||||||
|
<segment>
|
||||||
|
<source>part.edit.tab.associations</source>
|
||||||
|
<target>Associated parts</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="J8xCiOb" name="part_association.edit.other_part">
|
||||||
|
<segment>
|
||||||
|
<source>part_association.edit.other_part</source>
|
||||||
|
<target>Associated part</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="ov0J5BG" name="part_association.edit.type">
|
||||||
|
<segment>
|
||||||
|
<source>part_association.edit.type</source>
|
||||||
|
<target>Relation Type</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="Rdl3E1f" name="part_association.edit.comment">
|
||||||
|
<segment>
|
||||||
|
<source>part_association.edit.comment</source>
|
||||||
|
<target>Notes</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="rL3sVOB" name="part_association.edit.type.help">
|
||||||
|
<segment>
|
||||||
|
<source>part_association.edit.type.help</source>
|
||||||
|
<target>You can select here, how the chosen part is related to this part.</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="ulXO3uA" name="part_association.table.from_this_part">
|
||||||
|
<segment>
|
||||||
|
<source>part_association.table.from_this_part</source>
|
||||||
|
<target>Associations from this part to others</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="hDksqGC" name="part_association.table.from">
|
||||||
|
<segment>
|
||||||
|
<source>part_association.table.from</source>
|
||||||
|
<target>From</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="QyRxFA7" name="part_association.table.type">
|
||||||
|
<segment>
|
||||||
|
<source>part_association.table.type</source>
|
||||||
|
<target>Relation</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="6ZyXTCs" name="part_association.table.to">
|
||||||
|
<segment>
|
||||||
|
<source>part_association.table.to</source>
|
||||||
|
<target>To</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="Lwwff7k" name="part_association.type.compatible">
|
||||||
|
<segment>
|
||||||
|
<source>part_association.type.compatible</source>
|
||||||
|
<target>Is compatible with</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="tgOSN9E" name="part_association.table.to_this_part">
|
||||||
|
<segment>
|
||||||
|
<source>part_association.table.to_this_part</source>
|
||||||
|
<target>Associations to this part from others</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="J2hj9bY" name="part_association.type.other">
|
||||||
|
<segment>
|
||||||
|
<source>part_association.type.other</source>
|
||||||
|
<target>Other (custom value)</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="Sy57UAe" name="part_association.type.supersedes">
|
||||||
|
<segment>
|
||||||
|
<source>part_association.type.supersedes</source>
|
||||||
|
<target>Supersedes</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="bpmECSR" name="part_association.edit.other_type">
|
||||||
|
<segment>
|
||||||
|
<source>part_association.edit.other_type</source>
|
||||||
|
<target>Custom type</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="JDsNNm8" name="part_association.edit.delete.confirm">
|
||||||
|
<segment>
|
||||||
|
<source>part_association.edit.delete.confirm</source>
|
||||||
|
<target>Do you really want to delete this association? This can not be undone.</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="o3HcwZn" name="part_lot.edit.advanced">
|
||||||
|
<segment>
|
||||||
|
<source>part_lot.edit.advanced</source>
|
||||||
|
<target>Expand advanced options</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="f9LyaPM" name="part_lot.edit.vendor_barcode">
|
||||||
|
<segment>
|
||||||
|
<source>part_lot.edit.vendor_barcode</source>
|
||||||
|
<target>Vendor barcode</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="wSvbQyH" name="part_lot.edit.vendor_barcode.help">
|
||||||
|
<segment>
|
||||||
|
<source>part_lot.edit.vendor_barcode.help</source>
|
||||||
|
<target>If this lot already have a barcode (e.g. put there by the vendor), you can input its content here, to easily scan it.</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="2d3cSdD" name="scan_dialog.mode.vendor">
|
||||||
|
<segment>
|
||||||
|
<source>scan_dialog.mode.vendor</source>
|
||||||
|
<target>Vendor barcode (configured in part lot)</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
|
@ -317,5 +317,29 @@
|
||||||
<target>A lot owner must not be the anonymous user!</target>
|
<target>A lot owner must not be the anonymous user!</target>
|
||||||
</segment>
|
</segment>
|
||||||
</unit>
|
</unit>
|
||||||
|
<unit id="N8aA0Uh" name="validator.part_association.must_set_an_value_if_type_is_other">
|
||||||
|
<segment>
|
||||||
|
<source>validator.part_association.must_set_an_value_if_type_is_other</source>
|
||||||
|
<target>If you set the type to "other", then you have to set a descriptive value for it!</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="9VYNZ4v" name="validator.part_association.part_cannot_be_associated_with_itself">
|
||||||
|
<segment>
|
||||||
|
<source>validator.part_association.part_cannot_be_associated_with_itself</source>
|
||||||
|
<target>A part can not be associated with itself!</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="csc1PNn" name="validator.part_association.already_exists">
|
||||||
|
<segment>
|
||||||
|
<source>validator.part_association.already_exists</source>
|
||||||
|
<target>The association with this part already exists!</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="sfW4NYE" name="validator.part_lot.vendor_barcode_must_be_unique">
|
||||||
|
<segment>
|
||||||
|
<source>validator.part_lot.vendor_barcode_must_be_unique</source>
|
||||||
|
<target>This vendor barcode value was already used in another lot. The barcode must be unique!</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue