partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit b062928a078443667d0c6ce7ed02f6e5d203a572
parent 44eaae0784c2a4f1ea73075072fa834f8c168bf7
Author: Felicitus <felicitus@felicitus.org>
Date:   Sat, 18 Jul 2015 00:51:17 +0200

Fixed footprint attachment uploading

Diffstat:
Mapp/config/config.yml | 35+++++++++++++++++++++++++++++------
Mapp/config/partkeepr.yml | 1+
Msrc/PartKeepr/FootprintBundle/Entity/Footprint.php | 6++++--
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/AttachmentGrid.js | 7+------
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Dialogs/FileUploadDialog.js | 4++--
Msrc/PartKeepr/UploadedFileBundle/Controller/FileController.php | 31+++++++++++++++++++++++++++++--
Msrc/PartKeepr/UploadedFileBundle/Controller/TemporaryFileController.php | 2+-
Msrc/PartKeepr/UploadedFileBundle/EventListener/TemporaryFileEventListener.php | 27+++++++++++++--------------
8 files changed, 80 insertions(+), 33 deletions(-)

diff --git a/app/config/config.yml b/app/config/config.yml @@ -386,7 +386,7 @@ services: arguments: - "@resource.tempimage" # Resource - [ "POST" ] # Methods - - "/temporaryImage/upload" # Path + - "/temp_images/upload" # Path - "PartKeeprImageBundle:TemporaryImage:upload" # Controller - "TemporaryImageUpload" # Route name - # Context (will be present in Hydra documentation) @@ -401,7 +401,7 @@ services: arguments: - "@resource.tempimage" # Resource - [ "GET" ] # Methods - - "/temporaryImage/{id}/getImage" # Path + - "/temp_images/{id}/getImage" # Path - "PartKeeprImageBundle:TemporaryImage:getImage" # Controller - "TemporaryImageGet" # Route name - # Context (will be present in Hydra documentation) @@ -426,7 +426,7 @@ services: arguments: - "@resource.tempfile" # Resource - [ "POST" ] # Methods - - "/temporaryFile/upload" # Path + - "/temp_uploaded_files/upload" # Path - "PartKeeprUploadedFileBundle:TemporaryFile:upload" # Controller - "TemporaryFileUpload" # Route name - # Context (will be present in Hydra documentation) @@ -434,6 +434,12 @@ services: "hydra:title": "A custom operation" "returns": "xmls:string" + resource.tempfile.item_operation.get: + class: "Dunglas\ApiBundle\Api\Operation\Operation" + public: false + factory: [ "@api.operation_factory", "createItemOperation" ] + arguments: [ "@resource.tempfile", "GET" ] + resource.tempfile.item_operation.custom_get: class: "Dunglas\ApiBundle\Api\Operation\Operation" public: false @@ -441,7 +447,7 @@ services: arguments: - "@resource.tempfile" # Resource - [ "GET" ] # Methods - - "/temporaryFile/{id}/getFile" # Path + - "/temp_uploaded_files/{id}/getFile" # Path - "PartKeeprUploadedFileBundle:TemporaryFile:getFile" # Controller - "TemporaryFileGet" # Route name - # Context (will be present in Hydra documentation) @@ -449,6 +455,23 @@ services: "hydra:title": "A custom operation" "returns": "xmls:string" + resource.tempfile.item_operation.custom_get_mimetype: + class: "Dunglas\ApiBundle\Api\Operation\Operation" + public: false + factory: [ "@api.operation_factory", "createItemOperation" ] + arguments: + - "@resource.tempfile" # Resource + - [ "GET" ] # Methods + - "/temp_uploaded_files/{id}/getMimeTypeIcon" # Path + - "PartKeeprUploadedFileBundle:TemporaryFile:getMimeTypeIcon" # Controller + - "TemporaryFileGetMimeTypeIcon" # Route name + - # Context (will be present in Hydra documentation) + "@type": "hydra:Operation" + "hydra:title": "A custom operation" + "returns": "xmls:string" + + + resource.tempfile: parent: "api.resource" arguments: [ "PartKeepr\\UploadedFileBundle\\Entity\\TempUploadedFile" ] @@ -457,4 +480,4 @@ services: - method: "initCollectionOperations" arguments: [ [ "@resource.tempfile.collection_operation.custom_post" ] ] - method: "initItemOperations" - arguments: [ [ "@resource.tempfile.item_operation.custom_get" ] ]- \ No newline at end of file + arguments: [ [ "@resource.tempfile.item_operation.get", "@resource.tempfile.item_operation.custom_get", "@resource.tempfile.item_operation.custom_get_mimetype" ] ]+ \ No newline at end of file diff --git a/app/config/partkeepr.yml b/app/config/partkeepr.yml @@ -4,4 +4,5 @@ partkeepr: iclogo: %kernel.root_dir%/../data/images/iclogo/ temp: %kernel.root_dir%/../data/temp/ tempfile: %kernel.root_dir%/../data/files/Temporary/ + footprintattachment: %kernel.root_dir%/../data/files/FootprintAttachment/ mimetype_icons: %kernel.root_dir%/../src/PartKeepr/MimetypeIconsBundle/Resources/public/images/mimes/ \ No newline at end of file diff --git a/src/PartKeepr/FootprintBundle/Entity/Footprint.php b/src/PartKeepr/FootprintBundle/Entity/Footprint.php @@ -5,6 +5,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService; use PartKeepr\Util\BaseEntity; +use PartKeepr\UploadedFileBundle\Annotation\UploadedFileCollection; use Symfony\Component\Serializer\Annotation\Groups; /** @@ -57,8 +58,9 @@ class Footprint extends BaseEntity /** * Holds the footprint attachments * - * @ORM\OneToMany(targetEntity="FootprintAttachment", mappedBy="footprint", cascade={"persist", "remove"}) - * + * @ORM\OneToMany(targetEntity="PartKeepr\FootprintBundle\Entity\FootprintAttachment", + * mappedBy="footprint", cascade={"persist", "remove"}) + * @UploadedFileCollection() * @Groups({"default"}) * * @var FootprintAttachment diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/AttachmentGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/AttachmentGrid.js @@ -122,12 +122,7 @@ Ext.define('PartKeepr.AttachmentGrid', { onFileUploaded: function (response) { this.editing.cancelEdit(); - this.store.insert(this.store.getCount(), Ext.create(this.model, { - id: "TMP:"+response.id, - extension: response.extension, - size: response.size, - originalFilename: response.originalFilename - })); + this.store.add(response); }, onDeleteClick: function () { diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Dialogs/FileUploadDialog.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Dialogs/FileUploadDialog.js @@ -4,7 +4,7 @@ Ext.define('PartKeepr.FileUploadDialog', { title: i18n("File Upload"), fileFieldLabel: i18n("File"), uploadButtonText: i18n('Select File...'), - uploadURL: PartKeepr.getBasePath() + "/api/temporaryFile/upload", + uploadURL: PartKeepr.getBasePath() + "/api/temp_uploaded_files/upload", layout: 'fit', resizable: false, modal: true, @@ -13,7 +13,7 @@ Ext.define('PartKeepr.FileUploadDialog', { { if (this.imageUpload) { - this.uploadURL = PartKeepr.getBasePath() + "/api/temporaryImage/upload"; + this.uploadURL = PartKeepr.getBasePath() + "/api/temp_images/upload"; } this.uploadButton = Ext.create("Ext.button.Button", diff --git a/src/PartKeepr/UploadedFileBundle/Controller/FileController.php b/src/PartKeepr/UploadedFileBundle/Controller/FileController.php @@ -25,12 +25,13 @@ abstract class FileController extends ResourceController /** * Returns the mimetype icon for an uploaded file * - * @param integer $id The ID of the entity + * @param integer $id The ID of the entity + * * @return Response */ public function getMimeTypeIconAction($id) { - /** + /** * @var $em EntityManager */ $em = $this->getDoctrine()->getManager(); @@ -46,6 +47,32 @@ abstract class FileController extends ResourceController } /** + * Returns the file. Directly sends the response to the browser + * + * @param integer $id The ID of the file + * + * @return Response + */ + public function getFileAction($id) + { + /** + * @var $em EntityManager + */ + $em = $this->getDoctrine()->getManager(); + + /** + * @var $file UploadedFile + */ + $file = $em->find($this->getEntityClass(), $id); + + return new Response( + file_get_contents($this->getFilename($file)), + 200, + array("Content-Type" => $file->getMimeType()) + ); + } + + /** * Returns the entity class (FQDN) for operation * * @return string diff --git a/src/PartKeepr/UploadedFileBundle/Controller/TemporaryFileController.php b/src/PartKeepr/UploadedFileBundle/Controller/TemporaryFileController.php @@ -62,6 +62,6 @@ class TemporaryFileController extends FileController */ public function getEntityClass() { - return "PartKeepr\\UploadedFileBunde\\Entity\\TempUploadedFile"; + return "PartKeepr\\UploadedFileBundle\\Entity\\TempUploadedFile"; } } diff --git a/src/PartKeepr/UploadedFileBundle/EventListener/TemporaryFileEventListener.php b/src/PartKeepr/UploadedFileBundle/EventListener/TemporaryFileEventListener.php @@ -4,6 +4,7 @@ namespace PartKeepr\UploadedFileBundle\EventListener; use Doctrine\Common\Annotations\Reader; use Dunglas\ApiBundle\Event\DataEvent; use PartKeepr\ImageBundle\Entity\TempImage; +use PartKeepr\UploadedFileBundle\Entity\TempUploadedFile; use PartKeepr\UploadedFileBundle\Entity\UploadedFile; use PartKeepr\UploadedFileBundle\Services\UploadedFileService; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; @@ -43,14 +44,13 @@ class TemporaryFileEventListener * * @param DataEvent $event The event */ - public function replaceTemporaryImage (DataEvent $event) + public function replaceTemporaryImage(DataEvent $event) { $data = $event->getData(); $classReflection = new \ReflectionClass($data); foreach ($classReflection->getProperties() as $property) { - $propertyAnnotation = $this->reader->getPropertyAnnotation( $property, 'PartKeepr\UploadedFileBundle\Annotation\UploadedFileCollection' @@ -65,33 +65,33 @@ class TemporaryFileEventListener $collection = $this->propertyAccessor->getValue($data, $property->getName()); foreach ($collection as $key => $item) { - if ($item instanceof TempImage) { + if ($item instanceof TempImage || $item instanceof TempUploadedFile) { $targetEntity = $manyToOneAnnotation->targetEntity; /** - * @var $newImage UploadedFile + * @var $newFile UploadedFile */ - $newImage = new $targetEntity(); + $newFile = new $targetEntity(); - $this->uploadedFileService->replaceFromUploadedFile($newImage, $item); - $newImage->setOriginalFilename($item->getOriginalFilename()); + $this->uploadedFileService->replaceFromUploadedFile($newFile, $item); + $newFile->setOriginalFilename($item->getOriginalFilename()); // Find the setter for the association - $inverseSideReflection = new \ReflectionClass($newImage); + $inverseSideReflection = new \ReflectionClass($newFile); foreach ($inverseSideReflection->getProperties() as $inverseSideProperty) { - $oneToManyAssociation = $this->reader->getPropertyAnnotation( $inverseSideProperty, 'Doctrine\ORM\Mapping\ManyToOne' ); - if ($oneToManyAssociation !== null && $oneToManyAssociation->targetEntity == $classReflection->getName()) { - $this->propertyAccessor->setValue($newImage, $inverseSideProperty->getName(), $data); + if ($oneToManyAssociation !== null && + $oneToManyAssociation->targetEntity == $classReflection->getName()) { + $this->propertyAccessor->setValue($newFile, $inverseSideProperty->getName(), $data); } } - $collection[$key] = $newImage; + $collection[$key] = $newFile; } } @@ -99,4 +99,4 @@ class TemporaryFileEventListener } } } -}- \ No newline at end of file +}