partkeepr

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

commit 73be3cb8c1c10b6da3eee58d3f6e609452aab1ae
parent e9c5cfe2143404089f63914091de10342e796043
Author: Felicitus <privat@timohummel.com>
Date:   Sun,  5 Jun 2011 20:33:13 +0200

Added distributor model + editor

Diffstat:
Mfrontend/index.html | 5+++++
Afrontend/js/Components/Distributor/DistributorEditor.js | 27+++++++++++++++++++++++++++
Afrontend/js/Components/Distributor/DistributorEditorComponent.js | 19+++++++++++++++++++
Afrontend/js/Components/Distributor/DistributorGrid.js | 10++++++++++
Mfrontend/js/Components/MenuBar.js | 12++++++++++++
Afrontend/js/Models/Distributor.js | 16++++++++++++++++
Asrc/de/RaumZeitLabor/PartDB2/Distributor/Distributor.php | 107+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartDB2/Distributor/DistributorManager.php | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartDB2/Distributor/DistributorService.php | 142+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/de/RaumZeitLabor/PartDB2/PartDB2.php | 1+
10 files changed, 413 insertions(+), 0 deletions(-)

diff --git a/frontend/index.html b/frontend/index.html @@ -46,6 +46,7 @@ <script type="text/javascript" src="js/Models/Footprint.js"></script> <script type="text/javascript" src="js/Models/StorageLocation.js"></script> + <script type="text/javascript" src="js/Models/Distributor.js"></script> <script type="text/javascript" src="js/Models/Manufacturer.js"></script> <script type="text/javascript" src="js/Models/ManufacturerICLogo.js"></script> <script type="text/javascript" src="js/Models/Category.js"></script> @@ -80,6 +81,10 @@ <script type="text/javascript" src="js/Components/Manufacturer/ManufacturerEditor.js"></script> <script type="text/javascript" src="js/Components/Manufacturer/ManufacturerEditorComponent.js"></script> + <script type="text/javascript" src="js/Components/Distributor/DistributorGrid.js"></script> + <script type="text/javascript" src="js/Components/Distributor/DistributorEditor.js"></script> + <script type="text/javascript" src="js/Components/Distributor/DistributorEditorComponent.js"></script> + <script type="text/javascript" src="js/Components/CategoryEditor/CategoryEditorForm.js"></script> <script type="text/javascript" src="js/Components/CategoryEditor/CategoryEditorWindow.js"></script> <script type="text/javascript" src="js/Components/CategoryEditor/CategoryEditorTree.js"></script> diff --git a/frontend/js/Components/Distributor/DistributorEditor.js b/frontend/js/Components/Distributor/DistributorEditor.js @@ -0,0 +1,27 @@ +Ext.define('PartDB2.DistributorEditor', { + extend: 'PartDB2.Editor', + alias: 'widget.DistributorEditor', + items: [{ + xtype: 'textfield', + name: 'name', + fieldLabel: i18n("Distributor") + },{ + xtype: 'textarea', + name: 'address', + fieldLabel: i18n("Address") + },{ + xtype: 'textfield', + name: 'url', + fieldLabel: i18n("Website") + },{ + xtype: 'textfield', + name: 'email', + fieldLabel: i18n("Email") + },{ + xtype: 'textarea', + name: 'comment', + fieldLabel: i18n("Comment") + }], + saveText: i18n("Save Distributor"), + model: 'PartDB2.Distributor' +}); diff --git a/frontend/js/Components/Distributor/DistributorEditorComponent.js b/frontend/js/Components/Distributor/DistributorEditorComponent.js @@ -0,0 +1,18 @@ +Ext.define('PartDB2.DistributorEditorComponent', { + extend: 'PartDB2.EditorComponent', + alias: 'widget.DistributorEditorComponent', + gridClass: 'PartDB2.DistributorGrid', + editorClass: 'PartDB2.DistributorEditor', + newItemText: i18n("New Distributor"), + initComponent: function () { + this.createStore({ + model: "Distributor", + sorters: [{ + property: 'name', + direction:'ASC' + }] + }); + + this.callParent(); + } +});+ \ No newline at end of file diff --git a/frontend/js/Components/Distributor/DistributorGrid.js b/frontend/js/Components/Distributor/DistributorGrid.js @@ -0,0 +1,9 @@ +Ext.define('PartDB2.DistributorGrid', { + extend: 'PartDB2.EditorGrid', + alias: 'widget.DistributorGrid', + columns: [ + {header: i18n("Distributor"), dataIndex: 'name', flex: 1} + ], + addButtonText: i18n("Add Distributor"), + deleteButtonText: i18n("Delete Distributor") +});+ \ No newline at end of file diff --git a/frontend/js/Components/MenuBar.js b/frontend/js/Components/MenuBar.js @@ -13,6 +13,9 @@ Ext.define('PartDB2.MenuBar', { },{ text: i18n('Edit Storage Locations'), handler: this.editStorageLocations + },{ + text: i18n('Edit Distributors'), + handler: this.editDistributors }] }); @@ -51,6 +54,15 @@ Ext.define('PartDB2.MenuBar', { PartDB2.getApplication().addItem(j); j.show(); + }, + editDistributors: function () { + var j = Ext.create("PartDB2.DistributorEditorComponent", { + title: i18n("Distributors"), + closable: true + }); + + PartDB2.getApplication().addItem(j); + j.show(); } }); \ No newline at end of file diff --git a/frontend/js/Models/Distributor.js b/frontend/js/Models/Distributor.js @@ -0,0 +1,15 @@ +PartDB2.Distributor = Ext.define("Distributor", { + extend: "Ext.data.Model", + fields: [ + { id: 'id', name: 'id', type: 'int' }, + { name: 'name', type: 'string'}, + { name: 'url', type: 'string'}, + { name: 'comment', type: 'string'}, + { name: 'address', type: 'string'}, + { name: 'email', type: 'string'}, + ], + proxy: PartDB2.getRESTProxy("Distributor"), + getName: function () { + return this.get("name"); + } +});+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Distributor/Distributor.php b/src/de/RaumZeitLabor/PartDB2/Distributor/Distributor.php @@ -0,0 +1,106 @@ +<?php +namespace de\RaumZeitLabor\PartDB2\Distributor; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartDB2\PartDB2; + +/** @Entity **/ +class Distributor { + + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var unknown_type + */ + private $id; + + /** + * @Column(type="string",unique=true) + */ + private $name; + + /** + * @Column(type="string",nullable=true) + */ + private $address; + + /** + * @Column(type="string",nullable=true) + */ + private $url; + + /** + * @Column(type="string",nullable=true) + */ + private $email; + + /** + * @Column(type="string",nullable=true) + */ + private $comment; + + public function __construct () { + } + public function setName ($name) { + $this->name = $name; + } + + public function getName () { + return $this->name; + } + + public function setAddress ($address) { + $this->address = $address; + } + + public function getAddress () { + return $this->address; + } + + public function setComment ($comment) { + $this->comment = $comment; + } + + public function getComment () { + return $this->comment; + } + + public function setEmail ($email) { + $this->email = $email; + } + + public function getEmail () { + return $this->email; + } + + public function setURL ($url) { + $this->url = $url; + } + + public function getURL () { + return $this->url; + } + + public function getICLogos () { + return $this->icLogos; + } + + public function getId () { + return $this->id; + } + + public function serialize () { + return array( + "id" => $this->getId(), + "name" => $this->getName(), + "url" => $this->getURL(), + "address" => $this->getAddress(), + "email" => $this->getEmail(), + "comment" => $this->getComment() + ); + } + + public static function loadById ($id) { + return PartDB2::getEM()->find(get_called_class(), $id); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Distributor/DistributorManager.php b/src/de/RaumZeitLabor/PartDB2/Distributor/DistributorManager.php @@ -0,0 +1,73 @@ +<?php +namespace de\RaumZeitLabor\PartDB2\Distributor; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartDB2\Util\Singleton, + de\RaumZeitLabor\PartDB2\Distributor\Distributor, + de\RaumZeitLabor\PartDB2\PartDB2, + de\RaumZeitLabor\PartDB2\Category\CategoryManager, + de\RaumZeitLabor\PartDB2\Distributor\Exceptions\DistributorNotFoundException; + +class DistributorManager extends Singleton { + public function getDistributors ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { + + $qb = PartDB2::getEM()->createQueryBuilder(); + $qb->select("st.id, st.name, st.url, st.email, st.comment, st.address")->from("de\RaumZeitLabor\PartDB2\Distributor\Distributor","st"); + + if ($filter != "") { + $qb = $qb->where("st.name LIKE :filter"); + $qb->setParameter("filter", "%".$filter."%"); + } + + if ($limit > -1) { + $qb->setMaxResults($limit); + $qb->setFirstResult($start); + } + + $qb->orderBy("st.".$sort, $dir); + + $query = $qb->getQuery(); + + $result = $query->getResult(); + + $totalQueryBuilder = PartDB2::getEM()->createQueryBuilder(); + $totalQueryBuilder->select("COUNT(st.id)")->from("de\RaumZeitLabor\PartDB2\Distributor\Distributor","st"); + + + + if ($filter != "") { + $totalQueryBuilder = $totalQueryBuilder->where("st.name LIKE :filter"); + $totalQueryBuilder->setParameter("filter", "%".$filter."%"); + } + + $totalQuery = $totalQueryBuilder->getQuery(); + + return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); + } + + public function getDistributor ($id) { + $distributor = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Distributor\Distributor", $id); + + if ($distributor) { + return $distributor; + } else { + throw new DistributorNotFoundException(); + } + } + + public function addDistributor ($name) { + $distributor = new Distributor(); + $distributor->setName($name); + + PartDB2::getEM()->persist($distributor); + PartDB2::getEM()->flush(); + + return $distributor; + } + public function deleteDistributor ($id) { + $distributor = $this->getDistributor($id); + + PartDB2::getEM()->remove($distributor); + PartDB2::getEM()->flush(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Distributor/DistributorService.php b/src/de/RaumZeitLabor/PartDB2/Distributor/DistributorService.php @@ -0,0 +1,141 @@ +<?php +namespace de\RaumZeitLabor\PartDB2\Distributor; +use de\RaumZeitLabor\PartDB2\Service\RestfulService; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartDB2\Service\Service; +use de\RaumZeitLabor\PartDB2\Part\PartManager, + de\RaumZeitLabor\PartDB2\Stock\StockEntry, + de\RaumZeitLabor\PartDB2\PartDB2, + de\RaumZeitLabor\PartDB2\Session\SessionManager; + +class DistributorService extends Service implements RestfulService { + public function get () { + if ($this->hasParameter("id")) { + return DistributorManager::getInstance()->getDistributor($this->getParameter("id"))->serialize(); + } else { + if ($this->hasParameter("sort")) { + $tmp = json_decode($this->getParameter("sort"), true); + + $aSortParams = $tmp[0]; + } else { + $aSortParams = array( + "property" => "name", + "direction" => "ASC"); + } + return DistributorManager::getInstance()->getDistributors( + $this->getParameter("start", $this->getParameter("start", 0)), + $this->getParameter("limit", $this->getParameter("limit", 25)), + $this->getParameter("sortby", $aSortParams["property"]), + $this->getParameter("dir", $aSortParams["direction"]), + $this->getParameter("query", "")); + } + } + + public function create () { + $this->requireParameter("name"); + + $distributor = new Distributor; + + $this->setDistributorData($distributor); + + PartDB2::getEM()->persist($distributor); + PartDB2::getEM()->flush(); + + return array("data" => $distributor->serialize()); + } + + private function setDistributorData (Distributor $distributor) { + $distributor->setName($this->getParameter("name")); + $distributor->setComment($this->getParameter("comment", "")); + $distributor->setAddress($this->getParameter("address", "")); + $distributor->setURL($this->getParameter("url", "")); + $distributor->setEmail($this->getParameter("email", "")); + } + + public function update () { + $this->requireParameter("id"); + $this->requireParameter("name"); + $distributor = DistributorManager::getInstance()->getDistributor($this->getParameter("id")); + + $this->setDistributorData($distributor); + PartDB2::getEM()->flush(); + + return array("data" => $distributor->serialize()); + + } + + public function destroy () { + $this->requireParameter("id"); + + DistributorManager::getInstance()->deleteDistributor($this->getParameter("id")); + + return array("data" => null); + } + + + // Old stuff below + public function getDistributors() { + return DistributorManager::getInstance()->getDistributors( + $this->getParameter("start", 0), + $this->getParameter("limit", 10), + $this->getParameter("sortby", "name"), + $this->getParameter("dir", "asc"), + $this->getParameter("filter", "")); + } + + public function addDistributor () { + $this->requireParameter("name"); + + DistributorManager::getInstance()->addDistributor($this->getParameter("name")); + } + + public function deleteDistributor () { + $this->requireParameter("id"); + + DistributorManager::getInstance()->deleteDistributor($this->getParameter("id")); + } + + public function deleteDistributorLogo () { + $this->requireParameter("id"); + + $logo = DistributorICLogo::loadById($this->getParameter("id")); + + PartDB2::getEM()->remove($logo); + PartDB2::getEM()->flush(); + } + + public function getDistributorLogos () { + $this->requireParameter("id"); + $distributor = DistributorManager::getInstance()->getDistributor($this->getParameter("id")); + + $aData = array(); + + foreach ($distributor->getICLogos() as $logo) { + $aData[] = array("id" => $logo->getId()); + } + + return array("logos" => $aData); + + } + + public function getDistributor () { + $this->requireParameter("id"); + + return DistributorManager::getInstance()->getDistributor($this->getParameter("id"))->serialize(); + } + + public function saveDistributor () { + $this->requireParameter("id"); + $this->requireParameter("name"); + + $Distributor = DistributorManager::getInstance()->getDistributor($this->getParameter("id")); + + $Distributor->setName($this->getParameter("name")); + + PartDB2::getEM()->flush(); + + return $Distributor->serialize(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/PartDB2.php b/src/de/RaumZeitLabor/PartDB2/PartDB2.php @@ -174,6 +174,7 @@ class PartDB2 { 'de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation', 'de\RaumZeitLabor\PartDB2\Stock\StockEntry', 'de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer', + 'de\RaumZeitLabor\PartDB2\Distributor\Distributor', 'de\RaumZeitLabor\PartDB2\Image\Image', 'de\RaumZeitLabor\PartDB2\Image\CachedImage', 'de\RaumZeitLabor\PartDB2\Image\TempImage',