commit e0af45a5462ba4743ea5ecb108c5c4ccf6aaaf95
parent a241247e3ee7b27f8dd5cec559ba41c04876d7be
Author: Felicitus <felicitus@felicitus.org>
Date: Wed, 2 Dec 2015 17:17:06 +0100
Added project name display and all other previous fields, fixes #514
Diffstat:
2 files changed, 44 insertions(+), 22 deletions(-)
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartDisplay.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartDisplay.js
@@ -9,7 +9,7 @@ Ext.define('PartKeepr.PartDisplay', {
overflowY: 'auto',
fieldConfigs: {
- categoryName: {
+ "category.name": {
displayName: i18n("Category Name")
},
stockLevel: {
@@ -18,10 +18,10 @@ Ext.define('PartKeepr.PartDisplay', {
minStockLevel: {
displayName: i18n("Minimum Stock Level")
},
- footprintName: {
+ "footprint.name": {
displayName: i18n("Footprint")
},
- storageLocationName: {
+ "storageLocation.name": {
displayName: i18n("Storage Location")
},
comment: {
@@ -30,12 +30,6 @@ Ext.define('PartKeepr.PartDisplay', {
createDate: {
displayName: i18n("Create Date"),
type: 'date',
- renderer: function (v)
- {
- "use strict";
- var format = Ext.getDateFormat();
- return Ext.Date.format(v, format);
- }
},
status: {
displayName: i18n("Status")
@@ -47,11 +41,18 @@ Ext.define('PartKeepr.PartDisplay', {
displayName: i18n("Needs Review"),
type: 'boolean'
},
- projects: {
- displayName: i18n("Projects")
+ projectNames: {
+ displayName: i18n("Used in Projects")
+ },
+ "@id": {
+ displayName: i18n("Internal ID"),
+ renderer: function (value)
+ {
+ var values = value.split("/");
+ return values[values.length - 1];
+ }
}
- }
- ,
+ },
/**
* Initializes the component and adds a template as well as the add/remove stock and edit part buttons.
@@ -167,17 +168,20 @@ Ext.define('PartKeepr.PartDisplay', {
{
this.record = r;
- var values = {};
+ var values = {}, value;
var recordData = this.record.getData();
- for (var i in recordData) {
- if (this.fieldConfigs[i]) {
- if (typeof recordData[i] === "string") {
- values[i] = htmlentities(recordData[i]); // phpjs
+ for (var i in this.fieldConfigs) {
+ value = this.record.get(i);
+ if (value !== undefined) {
+ if (typeof(value === "string")) {
+ values[i] = htmlentities(value); // phpjs
} else {
- values[i] = recordData[i];
+ values[i] = value;
}
+ } else {
+ values[i] = i18n("none");
}
}
diff --git a/src/PartKeepr/PartBundle/Entity/Part.php b/src/PartKeepr/PartBundle/Entity/Part.php
@@ -3,6 +3,7 @@ namespace PartKeepr\PartBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
+use PartKeepr\CoreBundle\Entity\BaseEntity;
use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService;
use PartKeepr\FootprintBundle\Entity\Footprint;
use PartKeepr\PartBundle\Exceptions\CategoryNotAssignedException;
@@ -12,7 +13,6 @@ use PartKeepr\ProjectBundle\Entity\ProjectPart;
use PartKeepr\StockBundle\Entity\StockEntry;
use PartKeepr\StorageLocationBundle\Entity\StorageLocation;
use PartKeepr\UploadedFileBundle\Annotation\UploadedFileCollection;
-use PartKeepr\CoreBundle\Entity\BaseEntity;
use Symfony\Component\Serializer\Annotation\Groups;
/**
@@ -638,6 +638,7 @@ class Part extends BaseEntity
/**
* Sets the average price for this part
+ *
* @param float $price The price to set
*/
public function setAveragePrice($price)
@@ -650,7 +651,8 @@ class Part extends BaseEntity
*
* @return float
*/
- public function getAveragePrice () {
+ public function getAveragePrice()
+ {
return $this->averagePrice;
}
@@ -789,6 +791,22 @@ class Part extends BaseEntity
return $this->projectParts;
}
+ /**
+ * Returns the project names this part is used in
+ * @Groups({"default"})
+ *
+ * @return array
+ */
+ public function getProjectNames()
+ {
+ $projectNames = [];
+ foreach ($this->projectParts as $projectPart) {
+ $projectNames[] = $projectPart->getProject()->getName();
+ }
+
+ return array_unique($projectNames);
+ }
+
public function recomputeStockLevels()
{
$sum = 0;
@@ -809,7 +827,7 @@ class Part extends BaseEntity
} else {
$this->setAveragePrice(0);
}
-
+
$this->setStockLevel($sum);
if ($sum < $this->getMinStockLevel()) {