mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-23 02:09:03 +02:00
Improved documentation and added example CSV file
This commit is contained in:
parent
2c799d894b
commit
b7aae7d87b
4 changed files with 27 additions and 1 deletions
4
docs/assets/usage/import_export/part_import_example.csv
Normal file
4
docs/assets/usage/import_export/part_import_example.csv
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
name;description;category;notes;footprint;tags;quantity;storage_location;mass;ipn;mpn;manufacturing_status;manufacturer;supplier;spn;price;favorite;needs_review;minamount;partUnit;manufacturing_status
|
||||||
|
BC547;NPN transistor;Transistors -> NPN;very important notes;TO -> TO-92;NPN,Transistor;5;Room 1 -> Shelf 1 -> Box 2;10;;;Manufacturer;;You need to fill this line, to use spn and price;BC547C;2,3;0;;;;
|
||||||
|
BC557;PNP transistor;<b>HTML</b>;;TO -> TO-92;PNP,Transistor;10;Room 2-> Box 3;;Internal1234;;;;;;;;1;;;active
|
||||||
|
Copper Wire;;Wire;;;;;;;;;;;;;;;;;Meter;
|
|
|
@ -11,6 +11,11 @@ Part-DB offers the possibility to import existing data (parts, datastructures, e
|
||||||
|
|
||||||
## Import
|
## Import
|
||||||
|
|
||||||
|
{: .note }
|
||||||
|
> As data import is a very powerful feature and can easily fill up your database with lots of data, import is by default only available for
|
||||||
|
> administrators. If you want to allow other users to import data, or can not import data, check the permissions of the user. You can enable import for each data structure
|
||||||
|
> individually in the permissions settings.
|
||||||
|
|
||||||
### Import parts
|
### Import parts
|
||||||
|
|
||||||
Part-DB supports the import of parts from CSV files and other formats. This can be used to import existing parts from other databases or datasources into Part-DB. The import can be done via the "Tools -> Import parts" page, which you can find in the "Tools" sidebar panel.
|
Part-DB supports the import of parts from CSV files and other formats. This can be used to import existing parts from other databases or datasources into Part-DB. The import can be done via the "Tools -> Import parts" page, which you can find in the "Tools" sidebar panel.
|
||||||
|
@ -65,6 +70,8 @@ The following fields can be used to specify the supplier/distributor, supplier p
|
||||||
#### Example data
|
#### Example data
|
||||||
Here you can find some example data for the import of parts, you can use it as a template for your own import (especially the CSV file).
|
Here you can find some example data for the import of parts, you can use it as a template for your own import (especially the CSV file).
|
||||||
|
|
||||||
|
* [Part import CSV example]({% link assets/usage/import_export/part_import_example.csv %}) with all possible fields
|
||||||
|
|
||||||
## Export
|
## Export
|
||||||
|
|
||||||
By default every user, who can read the datastructure, can also export the data of this datastructure, as this does not give the user any additional information.
|
By default every user, who can read the datastructure, can also export the data of this datastructure, as this does not give the user any additional information.
|
||||||
|
|
|
@ -33,6 +33,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
|
||||||
use UnexpectedValueException;
|
use UnexpectedValueException;
|
||||||
|
|
||||||
class PartImportExportController extends AbstractController
|
class PartImportExportController extends AbstractController
|
||||||
|
@ -93,6 +94,9 @@ class PartImportExportController extends AbstractController
|
||||||
$errors = $this->entityImporter->importFileAndPersistToDB($file, $options, $entities);
|
$errors = $this->entityImporter->importFileAndPersistToDB($file, $options, $entities);
|
||||||
} catch (UnexpectedValueException $e) {
|
} catch (UnexpectedValueException $e) {
|
||||||
$this->addFlash('error', 'parts.import.flash.error.invalid_file');
|
$this->addFlash('error', 'parts.import.flash.error.invalid_file');
|
||||||
|
if ($e instanceof NotNormalizableValueException) {
|
||||||
|
$this->addFlash('error', $e->getMessage());
|
||||||
|
}
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,13 +103,24 @@ class PartNormalizer implements NormalizerInterface, DenormalizerInterface, Cach
|
||||||
$data['ipn'] = null;
|
$data['ipn'] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Fill empty needs_review and needs_review_comment fields with false
|
||||||
|
if (empty($data['needs_review'])) {
|
||||||
|
$data['needs_review'] = false;
|
||||||
|
}
|
||||||
|
if (empty($data['favorite'])) {
|
||||||
|
$data['favorite'] = false;
|
||||||
|
}
|
||||||
|
if (empty($data['minamount'])) {
|
||||||
|
$data['minamount'] = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
$object = $this->normalizer->denormalize($data, $type, $format, $context);
|
$object = $this->normalizer->denormalize($data, $type, $format, $context);
|
||||||
|
|
||||||
if (!$object instanceof Part) {
|
if (!$object instanceof Part) {
|
||||||
throw new \InvalidArgumentException('This normalizer only supports Part objects!');
|
throw new \InvalidArgumentException('This normalizer only supports Part objects!');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($data['instock']) || isset($data['storelocation'])) {
|
if ((isset($data['instock']) && trim($data['instock']) !== "") || (isset($data['storelocation']) && trim($data['storelocation']) !== "")) {
|
||||||
$partLot = new PartLot();
|
$partLot = new PartLot();
|
||||||
|
|
||||||
if (isset($data['instock']) && $data['instock'] !== "") {
|
if (isset($data['instock']) && $data['instock'] !== "") {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue