commit 9c4435793a2f7b433973b45b856c7330f3fb20ac
parent 9a4eea6c133543f977fde29c6a914da95f2d30d8
Author: Timo A. Hummel <felicitus@felicitus.org>
Date: Mon, 27 Jul 2015 21:22:49 +0200
Added category path listener for the storage location categories, fixed storage location category grouping
Diffstat:
3 files changed, 65 insertions(+), 3 deletions(-)
diff --git a/app/config/config.yml b/app/config/config.yml
@@ -125,13 +125,20 @@ nelmio_api_doc:
json: "application/json"
services:
- my.listener:
+ footprint.category_path_listener:
class: PartKeepr\FootprintBundle\Listeners\CategoryPathListener
arguments:
- "@service_container"
tags:
- { name: doctrine.event_listener, event: onFlush }
+ storage_location.category_path_listener:
+ class: PartKeepr\StorageLocationBundle\Listeners\CategoryPathListener
+ arguments:
+ - "@service_container"
+ tags:
+ - { name: doctrine.event_listener, event: onFlush }
+
my_event_listener:
class: PartKeepr\UploadedFileBundle\EventListener\TemporaryFileEventListener
arguments:
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StorageLocation/StorageLocationGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/StorageLocation/StorageLocationGrid.js
@@ -2,8 +2,14 @@ Ext.define('PartKeepr.StorageLocationGrid', {
extend: 'PartKeepr.EditorGrid',
xtype: 'partkeepr.StorageLocationGrid',
- automaticPageSize: true,
-
+ features: [
+ {
+ ftype: 'grouping',
+ groupHeaderTpl: '{name} ({children.length})',
+ enableNoGroups: true
+ }
+ ],
+
columns: [
{header: i18n("Storage Location"), dataIndex: 'name', flex: 1}
],
diff --git a/src/PartKeepr/StorageLocationBundle/Listeners/CategoryPathListener.php b/src/PartKeepr/StorageLocationBundle/Listeners/CategoryPathListener.php
@@ -0,0 +1,49 @@
+<?php
+namespace PartKeepr\StorageLocationBundle\Listeners;
+
+use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\Event\OnFlushEventArgs;
+use PartKeepr\StorageLocationBundle\Entity\StorageLocationCategory;
+use Symfony\Component\DependencyInjection\ContainerAware;
+
+class CategoryPathListener extends ContainerAware
+{
+ /**
+ * Updates the child category paths when their parent name has changed.
+ *
+ * @param OnFlushEventArgs $eventArgs The event arguments as given by Doctrine
+ */
+ public function onFlush(OnFlushEventArgs $eventArgs)
+ {
+ $entityManager = $eventArgs->getEntityManager();
+ $uow = $entityManager->getUnitOfWork();
+
+ foreach ($uow->getScheduledEntityUpdates() as $updated) {
+ if ($updated instanceof StorageLocationCategory) {
+ $this->updateCategoryPaths($updated, $eventArgs);
+ }
+ }
+ }
+
+ /**
+ * Recursively updates the category paths.
+ *
+ * @param StorageLocationCategory $storageLocationCategory The storage location category to update
+ * @param EntityManager $entityManager The entity manager
+ */
+ public function updateCategoryPaths(StorageLocationCategory $storageLocationCategory, OnFlushEventArgs $eventArgs)
+ {
+ $entityManager = $eventArgs->getEntityManager();
+
+ $storageLocationCategory->setCategoryPath($storageLocationCategory->generateCategoryPath());
+
+ $entityManager->getUnitOfWork()->recomputeSingleEntityChangeSet(
+ $entityManager->getClassMetadata(get_class($storageLocationCategory)),
+ $storageLocationCategory
+ );
+
+ foreach ($storageLocationCategory->getChildren() as $child) {
+ $this->updateCategoryPaths($child, $eventArgs);
+ }
+ }
+}