From 193650efd4c172f98cb08ca9211c76b5bf5bb17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Wed, 15 Mar 2023 21:46:14 +0100 Subject: [PATCH] Added option to mark all imported parts as "needs review" --- docs/usage/import_export.md | 1 + src/Controller/AdminPages/BaseAdminController.php | 1 + src/Controller/PartImportExportController.php | 2 ++ src/Form/AdminPages/ImportType.php | 7 +++++++ src/Services/ImportExportSystem/EntityImporter.php | 11 +++++++++-- translations/messages.en.xlf | 12 ++++++++++++ 6 files changed, 32 insertions(+), 2 deletions(-) diff --git a/docs/usage/import_export.md b/docs/usage/import_export.md index 38b79774..c16f5767 100644 --- a/docs/usage/import_export.md +++ b/docs/usage/import_export.md @@ -28,6 +28,7 @@ You can upload the file which should be imported here and choose various options * **Format**: By default "auto" is selected here and Part-DB will try to detect the format of the file automatically based on its file extension. If you want to force a specific format or Part-DB can not auto-detect the format, you can select it here. * **CSV delimiter**: If you upload an CSV file, you can select the delimiter character which is used to separate the columns in the CSV file. Depending on the CSV file, this might be a comma (`,`), semicolon (`;`). * **Category override**: You can select (or create) a category here, to which all imported parts should be assigned, no matter what was specified in the import file. This can be useful if you want to assign all imports to a certain category or if no category is specified in the data. If you leave this field empty, the category will be determined by the import file (or the export will error, if no category is specified). +* **Mark all imported parts as "Needs review"**: If this is selected, all imported parts will be marked as "Needs review" after the import. This can be useful if you want to review all imported parts before using them. * **Create unknown datastructures**: If this is selected Part-DB will create new datastructures (like categories, manufacturers, etc.) if no datastructure(s) with the same name and path already exists. If this is not selected, only existing datastructures will be used and if no matching datastrucure is found, the imported parts field will be empty. * **Path delimiter**: Part-DB allows you to create/select nested datastructures (like categories, manufacturers, etc.) by using a path (e.g. `Category 1->Category 1.1`, which will select/create the `Category 1.1` whose parent is `Category 1`). This path is separated by the path delimiter. If you want to use a different path delimiter than the default one (which is `>`), you can select it here. * **Abort on validation error**: If this is selected, the import will be aborted if a validation error occurs (e.g. if a required field is empty) for any of the imported parts and validation errors will be shown on top of the page. If this is not selected, the import will continue for the other parts and only the invalid parts will be skipped. diff --git a/src/Controller/AdminPages/BaseAdminController.php b/src/Controller/AdminPages/BaseAdminController.php index c657070a..28c9df60 100644 --- a/src/Controller/AdminPages/BaseAdminController.php +++ b/src/Controller/AdminPages/BaseAdminController.php @@ -355,6 +355,7 @@ abstract class BaseAdminController extends AbstractController 'format' => $format, 'class' => $this->entity_class, 'csv_delimiter' => $data['csv_delimiter'], + 'abort_on_validation_error' => $data['abort_on_validation_error'], ]; $this->commentHelper->setMessage('Import '.$file->getClientOriginalName()); diff --git a/src/Controller/PartImportExportController.php b/src/Controller/PartImportExportController.php index 7b8038c0..22b5b528 100644 --- a/src/Controller/PartImportExportController.php +++ b/src/Controller/PartImportExportController.php @@ -84,6 +84,8 @@ class PartImportExportController extends AbstractController 'part_category' => $data['part_category'], 'class' => Part::class, 'csv_delimiter' => $data['csv_delimiter'], + 'part_needs_review' => $data['part_needs_review'], + 'abort_on_validation_error' => $data['abort_on_validation_error'], ]; $this->commentHelper->setMessage('Import '.$file->getClientOriginalName()); diff --git a/src/Form/AdminPages/ImportType.php b/src/Form/AdminPages/ImportType.php index e33bf450..ded1da2f 100644 --- a/src/Form/AdminPages/ImportType.php +++ b/src/Form/AdminPages/ImportType.php @@ -91,6 +91,13 @@ class ImportType extends AbstractType 'disable_not_selectable' => true, 'allow_add' => true ]); + $builder->add('part_needs_review', CheckboxType::class, [ + 'data' => false, + 'required' => false, + 'label' => 'parts.import.part_needs_review.label', + 'help' => 'parts.import.part_needs_review.help', + 'disabled' => $disabled, + ]); } if ($entity instanceof AbstractStructuralDBElement) { diff --git a/src/Services/ImportExportSystem/EntityImporter.php b/src/Services/ImportExportSystem/EntityImporter.php index 25e4338b..c798f9f5 100644 --- a/src/Services/ImportExportSystem/EntityImporter.php +++ b/src/Services/ImportExportSystem/EntityImporter.php @@ -179,8 +179,13 @@ class EntityImporter if ($entity instanceof AbstractStructuralDBElement) { $entity->setParent($options['parent']); } - if ($entity instanceof Part && $options['part_category']) { - $entity->setCategory($options['part_category']); + if ($entity instanceof Part) { + if ($options['part_category']) { + $entity->setCategory($options['part_category']); + } + if ($options['part_needs_review']) { + $entity->setNeedsReview(true); + } } } @@ -218,6 +223,7 @@ class EntityImporter 'parent' => null, //The parent element to which the imported elements should be added 'abort_on_validation_error' => true, 'part_category' => null, + 'part_needs_review' => false, //If true, the imported parts will be marked as "needs review", otherwise the value from the file will be used 'create_unknown_datastructures' => true, //If true, unknown datastructures (categories, footprints, etc.) will be created on the fly 'path_delimiter' => '->', //The delimiter used to separate the path elements in the name of a structural element ]); @@ -227,6 +233,7 @@ class EntityImporter $resolver->setAllowedTypes('preserve_children', 'bool'); $resolver->setAllowedTypes('class', 'string'); $resolver->setAllowedTypes('part_category', [Category::class, 'null']); + $resolver->setAllowedTypes('part_needs_review', 'bool'); return $resolver; } diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index e2ac1271..ae635b5d 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -11121,5 +11121,17 @@ Element 3 Import data + + + parts.import.part_needs_review.label + Mark all imported parts as "Needs review" + + + + + parts.import.part_needs_review.help + If this option is selected, then all parts will be marked as "Needs review", no matter what was set in the data. + +