partkeepr

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

commit d551e66219771230860b2e5b4177c652813b9d54
parent dbc31a734259153a0433b44e04da354da822cd33
Author: Timo A. Hummel <timo@netraver.de>
Date:   Mon,  6 Jun 2011 23:28:22 +0200

Added part units

Diffstat:
Mfrontend/index.html | 6++++++
Mfrontend/js/Components/MenuBar.js | 13+++++++++++++
Mfrontend/js/Components/Part/PartEditor.js | 4++++
Mfrontend/js/Components/Part/PartsGrid.js | 2+-
Afrontend/js/Components/PartUnit/PartUnitEditor.js | 15+++++++++++++++
Afrontend/js/Components/PartUnit/PartUnitEditorComponent.js | 21+++++++++++++++++++++
Afrontend/js/Components/PartUnit/PartUnitGrid.js | 10++++++++++
Afrontend/js/Components/Widgets/PartUnitComboBox.js | 27+++++++++++++++++++++++++++
Mfrontend/js/Models/Part.js | 1+
Afrontend/js/Models/PartUnit.js | 13+++++++++++++
Mfrontend/js/PartDB2.js | 11+++++++++++
Msrc/de/RaumZeitLabor/PartDB2/Part/Part.php | 28++++++++++++++++++++++++++++
Msrc/de/RaumZeitLabor/PartDB2/Part/PartManager.php | 15+++++++++++++--
Msrc/de/RaumZeitLabor/PartDB2/Part/PartService.php | 4++++
Asrc/de/RaumZeitLabor/PartDB2/Part/PartUnit.php | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/de/RaumZeitLabor/PartDB2/PartDB2.php | 1+
Asrc/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitManager.php | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitService.php | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18 files changed, 401 insertions(+), 3 deletions(-)

diff --git a/frontend/index.html b/frontend/index.html @@ -37,6 +37,7 @@ <script type="text/javascript" src="js/Components/Widgets/FootprintComboBox.js"></script> <script type="text/javascript" src="js/Components/Widgets/ManufacturerComboBox.js"></script> <script type="text/javascript" src="js/Components/Widgets/DistributorComboBox.js"></script> + <script type="text/javascript" src="js/Components/Widgets/PartUnitComboBox.js"></script> <script type="text/javascript" src="js/Util/ServiceCall.js"></script> @@ -54,6 +55,7 @@ <script type="text/javascript" src="js/Models/User.js"></script> <script type="text/javascript" src="js/Models/Category.js"></script> <script type="text/javascript" src="js/Models/Part.js"></script> + <script type="text/javascript" src="js/Models/PartUnit.js"></script> <script type="text/javascript" src="js/Models/PartDistributor.js"></script> <script type="text/javascript" src="js/Models/PartManufacturer.js"></script> @@ -98,6 +100,10 @@ <script type="text/javascript" src="js/Components/User/UserEditorComponent.js"></script> <script type="text/javascript" src="js/Components/User/UserGrid.js"></script> + <script type="text/javascript" src="js/Components/PartUnit/PartUnitEditor.js"></script> + <script type="text/javascript" src="js/Components/PartUnit/PartUnitEditorComponent.js"></script> + <script type="text/javascript" src="js/Components/PartUnit/PartUnitGrid.js"></script> + <script type="text/javascript" src="js/Components/Part/PartsManager.js"></script> <script type="text/javascript" src="js/Components/Part/PartsGrid.js"></script> <script type="text/javascript" src="js/Components/Part/PartDistributorGrid.js"></script> diff --git a/frontend/js/Components/MenuBar.js b/frontend/js/Components/MenuBar.js @@ -20,6 +20,10 @@ Ext.define('PartDB2.MenuBar', { text: i18n('Edit Users'), handler: this.editUsers, icon: "resources/silkicons/user.png" + },{ + text: i18n('Edit Part Units'), + handler: this.editPartUnits, + icon: "resources/silkicons/table.png" }] }); @@ -76,6 +80,15 @@ Ext.define('PartDB2.MenuBar', { PartDB2.getApplication().addItem(j); j.show(); + }, + editPartUnits: function () { + var j = Ext.create("PartDB2.PartUnitEditorComponent", { + title: i18n("Part Units"), + closable: true + }); + + PartDB2.getApplication().addItem(j); + j.show(); } }); \ No newline at end of file diff --git a/frontend/js/Components/Part/PartEditor.js b/frontend/js/Components/Part/PartEditor.js @@ -21,6 +21,10 @@ Ext.define('PartDB2.PartEditor', { value: 0, minValue: 0 },{ + xtype: 'PartUnitComboBox', + fieldLabel: i18n("Part Unit"), + name: 'partUnit_id' + },{ xtype: 'CategoryComboBox', fieldLabel: i18n("Category"), name: 'category_id' diff --git a/frontend/js/Components/Part/PartsGrid.js b/frontend/js/Components/Part/PartsGrid.js @@ -4,7 +4,7 @@ Ext.define('PartDB2.PartsGrid', { columns: [ {header: i18n("Name"), dataIndex: 'name', flex: 1}, {header: i18n("Storage Location"), dataIndex: 'storageLocationName'}, - {header: i18n("Stock"), dataIndex: 'stockLevel'}, + {header: i18n("Stock"), dataIndex: 'stockLevel', xtype:'templatecolumn', tpl:'{stockLevel} {partUnit}'}, {header: i18n("Min. Stock"), dataIndex: 'minStockLevel'}, {header: i18n("Footprint"), dataIndex: 'footprintName'} ], diff --git a/frontend/js/Components/PartUnit/PartUnitEditor.js b/frontend/js/Components/PartUnit/PartUnitEditor.js @@ -0,0 +1,15 @@ +Ext.define('PartDB2.PartUnitEditor', { + extend: 'PartDB2.Editor', + alias: 'widget.PartUnitEditor', + items: [{ + xtype: 'textfield', + name: 'name', + fieldLabel: i18n("Unit Name") + },{ + xtype: 'textfield', + name: 'shortName', + fieldLabel: i18n("Short Name") + }], + saveText: i18n("Save Part Unit"), + model: 'PartDB2.PartUnit' +}); diff --git a/frontend/js/Components/PartUnit/PartUnitEditorComponent.js b/frontend/js/Components/PartUnit/PartUnitEditorComponent.js @@ -0,0 +1,20 @@ +Ext.define('PartDB2.PartUnitEditorComponent', { + extend: 'PartDB2.EditorComponent', + alias: 'widget.PartUnitEditorComponent', + gridClass: 'PartDB2.PartUnitGrid', + editorClass: 'PartDB2.PartUnitEditor', + newItemText: i18n("New Part Unit"), + deleteMessage: i18n("Do you really wish to delete the part unit'%s'?"), + deleteTitle: i18n("Delete Part Unit"), + initComponent: function () { + this.createStore({ + model: "PartUnit", + sorters: [{ + property: 'name', + direction:'ASC' + }] + }); + + this.callParent(); + } +});+ \ No newline at end of file diff --git a/frontend/js/Components/PartUnit/PartUnitGrid.js b/frontend/js/Components/PartUnit/PartUnitGrid.js @@ -0,0 +1,9 @@ +Ext.define('PartDB2.PartUnitGrid', { + extend: 'PartDB2.EditorGrid', + alias: 'widget.PartUnitGrid', + columns: [ + {header: i18n("Part Unit"), dataIndex: 'name', flex: 1} + ], + addButtonText: i18n("Add Part Unit"), + deleteButtonText: i18n("Delete Part Unit") +});+ \ No newline at end of file diff --git a/frontend/js/Components/Widgets/PartUnitComboBox.js b/frontend/js/Components/Widgets/PartUnitComboBox.js @@ -0,0 +1,27 @@ +Ext.define("PartDB2.PartUnitComboBox",{ + extend:"Ext.form.field.ComboBox", + alias: 'widget.PartUnitComboBox', + displayField: 'name', + valueField: 'id', + autoSelect: true, + queryMode: 'local', + triggerAction: 'all', + forceSelection: true, + editable: false, + initComponent: function () { + this.store = PartDB2.getApplication().getPartUnitStore(); + + /* Workaround to remember the value when loading */ + this.store.on("beforeload", function () { + this._oldValue = this.getValue(); + }, this); + + /* Set the old value when load is complete */ + this.store.on("load", function () { + this.setValue(this._oldValue); + }, this); + + this.callParent(); + } +}); + diff --git a/frontend/js/Models/Part.js b/frontend/js/Models/Part.js @@ -9,6 +9,7 @@ PartDB2.Part = Ext.define("Part", { { name: 'manufacturer_id',type: 'int'}, { name: 'storageLocation_id',type: 'int'}, { name: 'storageLocationName',type: 'string'}, + { name: 'partUnit',type: 'string'}, { name: 'name',type: 'string'}, { name: 'comment',type: 'string'}, { name: 'stockLevel',type: 'int'}, diff --git a/frontend/js/Models/PartUnit.js b/frontend/js/Models/PartUnit.js @@ -0,0 +1,12 @@ +PartDB2.PartUnit = Ext.define("PartUnit", { + extend: "Ext.data.Model", + fields: [ + { id: 'id', name: 'id', type: 'int' }, + { name: 'name', type: 'string'}, + { name: 'shortName', type: 'string'} + ], + proxy: PartDB2.getRESTProxy("PartUnit"), + getName: function () { + return this.get("name"); + } +});+ \ No newline at end of file diff --git a/frontend/js/PartDB2.js b/frontend/js/PartDB2.js @@ -49,6 +49,16 @@ Ext.application({ pageSize: -1, autoLoad: false }); + + this.partUnitStore = Ext.create("Ext.data.Store", + { + model: 'PartUnit', + pageSize: -1, + autoLoad: false + }); + }, + getPartUnitStore: function () { + return this.partUnitStore; }, getStorageLocationStore: function () { return this.storageLocationStore; @@ -77,6 +87,7 @@ Ext.application({ this.footprintStore.load(); this.manufacturerStore.load(); this.distributorStore.load(); + this.partUnitStore.load(); Ext.defer(PartDB2.getApplication().reloadStores, 100000, this); }, createLayout: function () { diff --git a/src/de/RaumZeitLabor/PartDB2/Part/Part.php b/src/de/RaumZeitLabor/PartDB2/Part/Part.php @@ -32,6 +32,11 @@ class Part { private $footprint; /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Part\PartUnit") + */ + private $partUnit; + + /** * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation") */ private $storageLocation; @@ -77,6 +82,26 @@ class Part { return $this->name; } + /** + * Sets the part unit + * + * @param PartUnit $partUnit The part unit object to set + * @return nothing + */ + public function setPartUnit (PartUnit $partUnit = null) { + $this->partUnit = $partUnit; + } + + /** + * Returns the part unit + * + * @param none + * @return PartUnit The part unit object + */ + public function getPartUnit () { + return $this->partUnit; + } + public function updateStockLevel () { $this->stockLevel = $this->getStockLevel(); } @@ -155,6 +180,9 @@ class Part { "storageLocation_id" => is_object($this->storageLocation) ? $this->storageLocation->getId() : null, "storageLocationName" => is_object($this->storageLocation) ? $this->storageLocation->getName() : null, "category_id" => is_object($this->category) ? $this->category->getId() : null, + "partUnit_id" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : null, + "partUnit_name" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : PartDB2::i18n("Pieces"), + "partUnit_shortName" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : "", "manufacturers" => $aManufacturers, "distributors" => $aDistributors, diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartManager.php b/src/de/RaumZeitLabor/PartDB2/Part/PartManager.php @@ -8,6 +8,7 @@ use de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation; use de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocationManager; use de\RaumZeitLabor\PartDB2\Part\Part; +use de\RaumZeitLabor\PartDB2\PartUnit\PartUnitManager; use de\RaumZeitLabor\PartDB2\Distributor\Distributor; use de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer; use de\RaumZeitLabor\PartDB2\Footprint\FootprintManager; @@ -30,7 +31,8 @@ class PartManager extends Singleton { $qb->select("COUNT(p.id)")->from("de\RaumZeitLabor\PartDB2\Part\Part","p") ->join("p.storageLocation", "st") ->leftJoin("p.footprint", "f") - ->join("p.category", "c"); + ->join("p.category", "c") + ->leftJoin("p.partUnit", "pu"); $qb->where("1=1"); if ($filter != "") { @@ -87,7 +89,7 @@ class PartManager extends Singleton { - $qb->select("p.name, p.id, p.stockLevel, p.minStockLevel, p.comment, st.id AS storageLocation_id, st.name as storageLocationName, f.id AS footprint_id, f.footprint AS footprintName, c.id AS category_id, c.name AS categoryName"); + $qb->select("p.name, p.id, p.stockLevel, p.minStockLevel, p.comment, st.id AS storageLocation_id, st.name as storageLocationName, f.id AS footprint_id, f.footprint AS footprintName, c.id AS category_id, c.name AS categoryName, pu.name AS partUnit"); if ($limit > -1) { $qb->setMaxResults($limit); @@ -173,6 +175,15 @@ class PartManager extends Singleton { } } + if (array_key_exists("partUnit", $aParameters)) { + if ($aParameters["partUnit"] === null) { + $part->setPartUnit(null); + } else { + $part->setPartUnit(PartUnitManager::getInstance()->getPartUnit($aParameters["partUnit"])); + } + } + + PartDB2::getEM()->persist($part); PartDB2::getEM()->flush(); diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartService.php b/src/de/RaumZeitLabor/PartDB2/Part/PartService.php @@ -122,6 +122,10 @@ class PartService extends Service implements RestfulService { $aParameters["manufacturerChanges"] = $this->getParameter("manufacturerChanges"); } + if ($this->hasParameter("partUnit_id")) { + $aParameters["partUnit"] = $this->getParameter("partUnit_id"); + } + PartManager::getInstance()->addOrUpdatePart($aParameters); return true; diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartUnit.php b/src/de/RaumZeitLabor/PartDB2/Part/PartUnit.php @@ -0,0 +1,93 @@ +<?php +namespace de\RaumZeitLabor\PartDB2\Part; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartDB2\PartDB2, + de\RaumZeitLabor\PartDB2\Util\Exceptions\OutOfRangeException; + + +/** @Entity **/ +class PartUnit { + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var int + */ + private $id; + + /** + * Defines the name of the unit + * @Column + * @var string + */ + private $name; + + /** + * Defines the short name of the unit + * @Column + * @var string + */ + private $shortName; + + /** + * Sets the name for this unit + * @param string $name The name for this unit + * @return nothing + */ + public function setName ($name) { + $this->name = $name; + } + + /** + * Returns the name for this unit + * @param none + * @return string The name for this unit + */ + public function getName () { + return $this->name; + } + + /** + * Sets the short name for this unit. + * + * Short names are used for list views (e.g. if your unit name is "metres", your short name could be "m") + * @param string $shortName The short name + * @return nothing + */ + public function setShortName ($shortName) { + $this->shortName = $shortName; + } + + /** + * Returns the short name for this unit + * @param none + * @return string The short name for this unit + */ + public function getShortName () { + return $this->shortName; + } + + /** + * Returns the ID for this object. + * @param none + * @return int The ID for this object + */ + public function getId () { + return $this->id; + } + + /** + * Serializes the object and returns it as array, suitable + * to process via json_encode. + * @param none + * @return array An array containing the object information + */ + public function serialize () { + return array( + "id" => $this->getId(), + "name" => $this->getName(), + "shortName" => $this->getShortName() + ); + } +} + + \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/PartDB2.php b/src/de/RaumZeitLabor/PartDB2/PartDB2.php @@ -171,6 +171,7 @@ class PartDB2 { 'de\RaumZeitLabor\PartDB2\Footprint\Footprint', 'de\RaumZeitLabor\PartDB2\Category\Category', 'de\RaumZeitLabor\PartDB2\Part\Part', + 'de\RaumZeitLabor\PartDB2\Part\PartUnit', 'de\RaumZeitLabor\PartDB2\Part\PartManufacturer', 'de\RaumZeitLabor\PartDB2\Part\PartDistributor', 'de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation', diff --git a/src/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitManager.php b/src/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitManager.php @@ -0,0 +1,64 @@ +<?php +namespace de\RaumZeitLabor\PartDB2\PartUnit; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartDB2\Util\Singleton, + de\RaumZeitLabor\PartDB2\Part\PartUnit, + de\RaumZeitLabor\PartDB2\PartDB2, + de\RaumZeitLabor\PartDB2\Category\CategoryManager, + de\RaumZeitLabor\PartDB2\PartUnit\Exceptions\PartUnitNotFoundException; + +class PartUnitManager extends Singleton { + public function getPartUnits ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { + + $qb = PartDB2::getEM()->createQueryBuilder(); + $qb->select("st.id, st.name, st.shortName")->from("de\RaumZeitLabor\PartDB2\Part\PartUnit","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\Part\PartUnit","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 getPartUnit ($id) { + $partUnit = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Part\PartUnit", $id); + + if ($partUnit) { + return $partUnit; + } else { + throw new PartUnitNotFoundException(); + } + } + + public function deletePartUnit ($id) { + $partUnit = $this->getPartUnit($id); + + PartDB2::getEM()->remove($partUnit); + PartDB2::getEM()->flush(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitService.php b/src/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitService.php @@ -0,0 +1,73 @@ +<?php +namespace de\RaumZeitLabor\PartDB2\PartUnit; +use de\RaumZeitLabor\PartDB2\Service\RestfulService; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartDB2\Service\Service; +use de\RaumZeitLabor\PartDB2\PartDB2, + de\RaumZeitLabor\PartDB2\Part\PartUnit, + de\RaumZeitLabor\PartDB2\Session\SessionManager; + +class PartUnitService extends Service implements RestfulService { + public function get () { + if ($this->hasParameter("id")) { + return PartUnitManager::getInstance()->getPartUnit($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 PartUnitManager::getInstance()->getPartUnits( + $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"); + + $partUnit = new PartUnit; + + $this->setPartUnitData($partUnit); + + PartDB2::getEM()->persist($partUnit); + PartDB2::getEM()->flush(); + + return array("data" => $partUnit->serialize()); + } + + private function setPartUnitData (PartUnit $partUnit) { + $partUnit->setName($this->getParameter("name")); + $partUnit->setShortName($this->getParameter("shortName","")); + } + + public function update () { + $this->requireParameter("id"); + $this->requireParameter("name"); + + $partUnit = PartUnitManager::getInstance()->getPartUnit($this->getParameter("id")); + + $this->setPartUnitData($partUnit); + PartDB2::getEM()->flush(); + + return array("data" => $partUnit->serialize()); + + } + + public function destroy () { + $this->requireParameter("id"); + + PartUnitManager::getInstance()->deletePartUnit($this->getParameter("id")); + + return array("data" => null); + } +}+ \ No newline at end of file