Skip to content

Commit

Permalink
Added project name display and all other previous fields, fixes #514
Browse files Browse the repository at this point in the history
  • Loading branch information
Felicitus committed Dec 2, 2015
1 parent a241247 commit e0af45a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Ext.define('PartKeepr.PartDisplay', {
overflowY: 'auto',

fieldConfigs: {
categoryName: {
"category.name": {
displayName: i18n("Category Name")
},
stockLevel: {
Expand All @@ -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: {
Expand All @@ -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")
Expand All @@ -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.
Expand Down Expand Up @@ -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");
}
}

Expand Down
24 changes: 21 additions & 3 deletions src/PartKeepr/PartBundle/Entity/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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;
Expand All @@ -12,7 +13,6 @@
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;

/**
Expand Down Expand Up @@ -638,6 +638,7 @@ public function setMinStockLevel($minStockLevel)

/**
* Sets the average price for this part
*
* @param float $price The price to set
*/
public function setAveragePrice($price)
Expand All @@ -650,7 +651,8 @@ public function setAveragePrice($price)
*
* @return float
*/
public function getAveragePrice () {
public function getAveragePrice()
{
return $this->averagePrice;
}

Expand Down Expand Up @@ -789,6 +791,22 @@ public function getProjectParts()
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;
Expand All @@ -809,7 +827,7 @@ public function recomputeStockLevels()
} else {
$this->setAveragePrice(0);
}

$this->setStockLevel($sum);

if ($sum < $this->getMinStockLevel()) {
Expand Down

0 comments on commit e0af45a

Please sign in to comment.