commit e6e19264c405d8421c688dd6e8946dec76ea83a4
parent 79eaba2d450d0e9139ac4c358ece5d866ccd8736
Author: Felicitus <felicitus@felicitus.org>
Date: Sat, 1 Aug 2015 19:52:26 +0200
Implemented part category tree
Diffstat:
3 files changed, 203 insertions(+), 54 deletions(-)
diff --git a/app/config/config.yml b/app/config/config.yml
@@ -343,6 +343,76 @@ services:
arguments:
- { groups: [ "default" ] }
+ resource.part_category.item_operation.move:
+ class: "Dunglas\ApiBundle\Api\Operation\Operation"
+ public: false
+ factory: [ "@api.operation_factory", "createItemOperation" ]
+ arguments:
+ - "@resource.part_category" # Resource
+ - [ "PUT" ] # Methods
+ - "/part_categories/{id}/move" # Path
+ - "PartKeeprCategoryBundle:Category:move" # Controller
+ - "PartCategoryMove" # Route name
+ - # Context (will be present in Hydra documentation)
+ "@type": "hydra:Operation"
+ "hydra:title": "A custom operation"
+ "returns": "xmls:string"
+
+ resource.part_category.collection_operation.post:
+ class: "Dunglas\ApiBundle\Api\Operation\Operation"
+ public: false
+ factory: [ "@api.operation_factory", "createCollectionOperation" ]
+ arguments: [ "@resource.part_category", "POST" ]
+
+ resource.part_category.collection_operation.get_root:
+ class: "Dunglas\ApiBundle\Api\Operation\Operation"
+ public: false
+ factory: [ "@api.operation_factory", "createCollectionOperation" ]
+ arguments:
+ - "@resource.part_category" # Resource
+ - [ "GET" ] # Methods
+ - "/part_categories/getExtJSRootNode" # Path
+ - "PartKeeprCategoryBundle:Category:getExtJSRootNode" # Controller
+ - "PartCategoryGetRoot" # Route name
+ - # Context (will be present in Hydra documentation)
+ "@type": "hydra:Operation"
+ "hydra:title": "A custom operation"
+ "returns": "xmls:string"
+
+ resource.part_category.item_operation.get:
+ class: "Dunglas\ApiBundle\Api\Operation\Operation"
+ public: false
+ factory: [ "@api.operation_factory", "createItemOperation" ]
+ arguments: [ "@resource.part_category", "GET" ]
+
+ resource.part_category.item_operation.put:
+ class: "Dunglas\ApiBundle\Api\Operation\Operation"
+ public: false
+ factory: [ "@api.operation_factory", "createItemOperation" ]
+ arguments: [ "@resource.part_category", "PUT" ]
+
+ resource.part_category.item_operation.delete:
+ class: "Dunglas\ApiBundle\Api\Operation\Operation"
+ public: false
+ factory: [ "@api.operation_factory", "createItemOperation" ]
+ arguments: [ "@resource.part_category", "DELETE" ]
+
+ resource.part_category:
+ parent: "api.resource"
+ arguments: [ "PartKeepr\\PartBundle\Entity\\PartCategory" ]
+ tags: [ { name: "api.resource" } ]
+ calls:
+ - method: "initCollectionOperations"
+ arguments: [ [ "@resource.part_category.collection_operation.get_root", "@resource.part_category.collection_operation.post" ] ]
+ - method: "initItemOperations"
+ arguments: [ [ "@resource.part_category.item_operation.get", "@resource.part_category.item_operation.put", "@resource.part_category.item_operation.delete", "@resource.part_category.item_operation.move" ] ]
+ - method: "initNormalizationContext"
+ arguments: [ { groups: [ "default" ] } ]
+ - method: "initDenormalizationContext"
+ arguments:
+ - { groups: [ "default" ] }
+
+
resource.manufacturer:
parent: "api.resource"
arguments: [ "PartKeepr\\ManufacturerBundle\Entity\Manufacturer" ]
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartCategoryTree.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartCategoryTree.js
@@ -1,52 +1,52 @@
Ext.define("PartKeepr.PartCategoryTree", {
- extend: 'PartKeepr.CategoryEditorTree',
- alias: 'widget.PartCategoryTree',
-
- ddGroup: 'PartTree',
- categoryModel: 'PartKeepr.PartBundle.Entity.PartCategory',
- categoryService: 'PartCategory',
- initComponent: function () {
- this.callParent();
-
- this.syncButton = Ext.create("Ext.button.Button", {
- tooltip: i18n("Reveal Category for selected part"),
- icon: 'bundles/brainbitsfugueicons/icons/fugue/16/arrow-split-180.png',
- handler: Ext.bind(function () {
- this.fireEvent("syncCategory");
- }, this),
- disabled: true
- });
- this.toolbar.add(['->', this.syncButton]);
- },
-
- onBeforeDrop: function (node, data, overModel, dropPosition, dropFunction, options) {
- var draggedRecord = data.records[0];
- var droppedOn = this.getView().getRecord(node);
+ extend: 'PartKeepr.CategoryEditorTree',
+ alias: 'widget.PartCategoryTree',
- if (draggedRecord.modelName == "PartKeepr.PartBundle.Entity.Part") {
- /* Move Part */
- var call = new PartKeepr.ServiceCall("Part", "movePart");
-
- if (data.records.length > 1) {
- var sources = [];
-
- for (var i=0;i<data.records.length;i++) {
- sources.push(data.records[i].get("id"));
- }
-
- call.setParameter("parts", sources);
- } else {
- call.setParameter("part", draggedRecord.get("id"));
- }
+ ddGroup: 'PartTree',
+ categoryModel: 'PartKeepr.PartBundle.Entity.PartCategory',
+ rootVisible: false,
- call.setParameter("targetCategory", droppedOn.get("id"));
- call.setHandler(function () {
- data.view.store.load();
- });
- call.doCall();
-
- return false;
- }
-
- }
+ initComponent: function ()
+ {
+ this.store = Ext.create("Ext.data.TreeStore",
+ {
+ remoteSort: false,
+ folderSort: true,
+ rootVisible: true,
+ autoLoad: true,
+ sorters: [
+ {
+ property: 'name',
+ direction: 'ASC'
+ }
+ ],
+ root: {
+ "@id": "@local-tree-root"
+ },
+ model: "PartKeepr.PartBundle.Entity.PartCategory",
+ proxy: {
+ ignoreLoadId: '@local-tree-root',
+ url: "/api/part_categories/getExtJSRootNode",
+ type: "Hydra",
+ appendId: false,
+ reader: {
+ type: 'json'
+ }
+
+ }
+ });
+
+ this.callParent();
+
+ this.syncButton = Ext.create("Ext.button.Button", {
+ tooltip: i18n("Reveal Category for selected part"),
+ icon: 'bundles/brainbitsfugueicons/icons/fugue/16/arrow-split-180.png',
+ handler: Ext.bind(function ()
+ {
+ this.fireEvent("syncCategory");
+ }, this),
+ disabled: true
+ });
+ this.toolbar.add(['->', this.syncButton]);
+ }
});
\ No newline at end of file
diff --git a/src/PartKeepr/PartBundle/Entity/PartCategory.php b/src/PartKeepr/PartBundle/Entity/PartCategory.php
@@ -1,27 +1,107 @@
-<?php
+<?php
namespace PartKeepr\PartBundle\Entity;
-use PartKeepr\CategoryBundle\Entity\AbstractCategory,
- Doctrine\ORM\Mapping as ORM;
+use Doctrine\Common\Collections\ArrayCollection;
+use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
+use PartKeepr\CategoryBundle\Entity\AbstractCategory;
+use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService;
+use Symfony\Component\Serializer\Annotation\Groups;
+
/**
* @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
* @ORM\Table(indexes={@ORM\Index(columns={"lft"}),@ORM\Index(columns={"rgt"})})
* @Gedmo\Tree(type="nested")
* The entity for our part categories
*
+ * @TargetService(uri="/api/part_categories")
+ *
*/
-class PartCategory extends AbstractCategory {
+class PartCategory extends AbstractCategory
+{
/**
* @Gedmo\TreeParent
* @ORM\ManyToOne(targetEntity="PartCategory", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
+ * @Groups({"default"})
*/
protected $parent;
/**
* @ORM\OneToMany(targetEntity="PartCategory", mappedBy="parent")
* @ORM\OrderBy({"lft" = "ASC"})
+ * @Groups({"default"})
*/
protected $children;
-}-
\ No newline at end of file
+
+ /**
+ * @ORM\Column(type="text",nullable=true)
+ * @Groups({"default"})
+ * @var string
+ */
+ protected $categoryPath;
+
+ /**
+ * Sets the parent category
+ *
+ * @param AbstractCategory|null $parent
+ */
+ public function setParent(AbstractCategory $parent = null)
+ {
+ $this->parent = $parent;
+ }
+
+ /**
+ * Returns the parent category
+ *
+ * @return mixed
+ */
+ public function getParent()
+ {
+ return $this->parent;
+ }
+
+ /**
+ * Returns the children
+ *
+ * @return ArrayCollection
+ */
+ public function getChildren()
+ {
+ return $this->children;
+ }
+
+ /**
+ * Returns the category path
+ *
+ * @return string
+ */
+ public function getCategoryPath()
+ {
+ return $this->categoryPath;
+ }
+
+ /**
+ * Sets the category path
+ *
+ * @param string $categoryPath The category path
+ */
+ public function setCategoryPath($categoryPath)
+ {
+ $this->categoryPath = $categoryPath;
+ }
+
+ /**
+ * Generates the category path
+ *
+ * @return string The category path
+ */
+ public function generateCategoryPath()
+ {
+ if ($this->getParent() !== null) {
+ return $this->getParent()->generateCategoryPath()." / ".$this->getName();
+ } else {
+ return $this->getName();
+ }
+ }
+}