commit 0830f17ed95bf3d18bcd857d5dcb89baaffef991
parent 8e0628ecc8e2014e7d2ad12e041f68375ff93d67
Author: Felicitus <felicitus@felicitus.org>
Date: Wed, 7 Sep 2011 05:23:48 +0200
Added storage location image, fixes #18
Diffstat:
9 files changed, 197 insertions(+), 10 deletions(-)
diff --git a/frontend/image.php b/frontend/image.php
@@ -1,6 +1,7 @@
<?php
namespace de\RaumZeitLabor\PartKeepr\Frontend;
use de\RaumZeitLabor\PartKeepr\Part\PartImage;
+use de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocationImage;
use de\RaumZeitLabor\PartKeepr\Footprint\FootprintImage;
@@ -32,6 +33,9 @@ if (substr($id, 0, 4) === "TMP:") {
case Image::IMAGE_FOOTPRINT:
$image = FootprintImage::loadById($id);
break;
+ case Image::IMAGE_STORAGELOCATION:
+ $image = StorageLocationImage::loadById($id);
+ break;
case Image::IMAGE_PART:
$image = PartImage::loadById($id);
break;
diff --git a/frontend/js/Components/StorageLocation/StorageLocationEditor.js b/frontend/js/Components/StorageLocation/StorageLocationEditor.js
@@ -3,6 +3,8 @@ Ext.define('PartKeepr.StorageLocationEditor', {
alias: 'widget.StorageLocationEditor',
saveText: i18n("Save Storage Location"),
+ layout: 'column',
+
initComponent: function () {
var config = {};
@@ -32,17 +34,39 @@ Ext.define('PartKeepr.StorageLocationEditor', {
var container = Ext.create("Ext.form.FieldContainer", {
fieldLabel: i18n("Contained Parts"),
- labelWidth: 150,
+ labelWidth: 110,
layout: 'fit',
height: 200,
items: this.gridPanel
});
+
+
this.items = [{
- xtype: 'textfield',
- name: 'name',
- fieldLabel: i18n("Storage Location")
- }, container ];
+ columnWidth: 1,
+ minWidth: 500,
+ layout: 'anchor',
+ xtype: 'container',
+ margin: '0 5 0 0',
+ items: [{
+ xtype: 'textfield',
+ name: 'name',
+ labelWidth: 110,
+ fieldLabel: i18n("Storage Location")
+ },
+ container
+ ]},
+ {
+ width: 370,
+ height: 250,
+ xtype: 'remoteimagefield',
+ name: 'image_id',
+ imageType: 'storagelocation',
+ imageWidth: 256,
+ imageHeight: 256,
+ labelWidth: 110,
+ fieldLabel: i18n("Image")
+ }];
this.on("startEdit", this.onStartEdit, this);
this.callParent();
diff --git a/frontend/js/Models/StorageLocation.js b/frontend/js/Models/StorageLocation.js
@@ -2,8 +2,10 @@ Ext.define("PartKeepr.StorageLocation", {
extend: "Ext.data.Model",
fields: [
{ id: 'id', name: 'id', type: 'int' },
- { name: 'name', type: 'string'}
- ],
+ { name: 'name', type: 'string'},
+ // image_id needs to be a string because we need to be able to push TMP:<id> back
+ { name: 'image_id', type: 'string' }
+ ],
proxy: PartKeepr.getRESTProxy("StorageLocation"),
getRecordName: function () {
return this.get("name");
diff --git a/src/de/RaumZeitLabor/PartKeepr/Image/Image.php b/src/de/RaumZeitLabor/PartKeepr/Image/Image.php
@@ -15,6 +15,7 @@ abstract class Image extends UploadedFile {
const IMAGE_ICLOGO = "iclogo";
const IMAGE_TEMP = "temp";
const IMAGE_PART = "part";
+ const IMAGE_STORAGELOCATION = "storagelocation";
const IMAGE_FOOTPRINT = "footprint";
/**
@@ -40,6 +41,7 @@ abstract class Image extends UploadedFile {
case Image::IMAGE_TEMP:
case Image::IMAGE_PART:
case Image::IMAGE_FOOTPRINT:
+ case Image::IMAGE_STORAGELOCATION:
parent::setType($type);
break;
default:
diff --git a/src/de/RaumZeitLabor/PartKeepr/PartKeepr.php b/src/de/RaumZeitLabor/PartKeepr/PartKeepr.php
@@ -192,6 +192,7 @@ class PartKeepr {
'de\RaumZeitLabor\PartKeepr\PartCategory\PartCategory',
'de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocation',
+ 'de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocationImage',
'de\RaumZeitLabor\PartKeepr\Stock\StockEntry',
@@ -214,7 +215,7 @@ class PartKeepr {
'de\RaumZeitLabor\PartKeepr\TipOfTheDay\TipOfTheDay',
'de\RaumZeitLabor\PartKeepr\TipOfTheDay\TipOfTheDayHistory',
- 'de\RaumZeitLabor\PartKeepr\UserPreference\UserPreference',
+ 'de\RaumZeitLabor\PartKeepr\UserPreference\UserPreference'
);
}
diff --git a/src/de/RaumZeitLabor/PartKeepr/Service/ServiceManager.php b/src/de/RaumZeitLabor/PartKeepr/Service/ServiceManager.php
@@ -90,7 +90,7 @@ class ServiceManager {
return $service->getHeader("session");
}
- if (array_key_exists("session", $_REQUEST) && $session === null) {
+ if (array_key_exists("session", $_REQUEST)) {
return $_REQUEST["session"];
}
}
diff --git a/src/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocation.php b/src/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocation.php
@@ -17,6 +17,13 @@ class StorageLocation extends BaseEntity implements Serializable, Deserializable
private $name;
/**
+ * Holds the storage location image
+ * @OneToOne(targetEntity="de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocationImage",mappedBy="storageLocation",cascade={"persist", "remove"})
+ * @var StorageLocationImage
+ */
+ private $image;
+
+ /**
* Sets the name for the storage location
* @param string $name the name to set
*/
@@ -33,11 +40,31 @@ class StorageLocation extends BaseEntity implements Serializable, Deserializable
}
/**
+ * Sets the storage location image
+ * @param StorageLocationImage $image The storage location image
+ */
+ public function setImage (StorageLocationImage $image) {
+ $this->image = $image;
+ $image->setStorageLocation($this);
+ }
+
+ /**
+ * Returns the storage location image
+ * @return StorageLocationImage The storage location image
+ */
+ public function getImage () {
+ return $this->image;
+ }
+
+ /**
* Returns this storage location in serialized form
* @return array The serialized storage location
*/
public function serialize () {
- return array("id" => $this->getId(), "name" => $this->getName());
+ return array(
+ "id" => $this->getId(),
+ "name" => $this->getName(),
+ "image_id" => is_object($this->getImage()) ? $this->getImage()->getId() : null);
}
/**
@@ -50,6 +77,30 @@ class StorageLocation extends BaseEntity implements Serializable, Deserializable
case "name":
$this->setName($value);
break;
+ case "image_id":
+ if ($value == "") {
+ echo "/** Breaking because of empty value */";
+ break;
+ }
+
+ try {
+ $image = StorageLocationImage::loadById($value);
+ $this->setImage($image);
+ } catch (\Exception $e) {
+ if ($this->getImage()) {
+ // Image was not found, maybe a temporary image?
+ $this->getImage()->replaceFromTemporaryFile($value);
+ } else {
+ $image = StorageLocationImage::createFromTemporaryFile($value);
+ $this->setImage($image);
+ echo "/**";
+ echo $image->getId();
+ echo "*/";
+ echo "/** FOO */";
+ }
+ }
+
+ break;
}
}
}
diff --git a/src/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocationImage.php b/src/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocationImage.php
@@ -0,0 +1,52 @@
+<?php
+namespace de\RaumZeitLabor\PartKeepr\StorageLocation;
+use de\RaumZeitLabor\PartKeepr\Util\Serializable;
+
+declare(encoding = 'UTF-8');
+
+use de\RaumZeitLabor\PartKeepr\Image\Image;
+
+/**
+ * Holds a storage location image
+ * @Entity
+ **/
+class StorageLocationImage extends Image implements Serializable {
+ /**
+ * The storage location object
+ * @OneToOne(targetEntity="de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocation",inversedBy="image")
+ * @var StorageLocation
+ */
+ private $storageLocation = null;
+
+ /**
+ * Creates a new storage location image instance
+ */
+ public function __construct () {
+ parent::__construct(Image::IMAGE_STORAGELOCATION);
+ }
+
+ /**
+ * Sets the storage location
+ * @param StorageLocation $storageLocation The storage location to set
+ */
+ public function setStorageLocation (StorageLocation $storageLocation) {
+ $this->storageLocation = $storageLocation;
+ }
+
+ /**
+ * Returns the storage location
+ * @return StorageLocation the storage location
+ */
+ public function getStorageLocation () {
+ return $this->storageLocation;
+ }
+
+ /**
+ *
+ * Serializes this storage location image
+ * @return array The serialized storage location image
+ */
+ public function serialize () {
+ return array("id" => $this->getId(), "storageLocation_id" => $this->getStorageLocation()->getId());
+ }
+}+
\ No newline at end of file
diff --git a/src/de/RaumZeitLabor/PartKeepr/Versions/Version20110907043603.php b/src/de/RaumZeitLabor/PartKeepr/Versions/Version20110907043603.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace DoctrineMigrations;
+
+use de\RaumZeitLabor\PartKeepr\PartKeepr;
+
+use Doctrine\DBAL\Migrations\AbstractMigration,
+ Doctrine\DBAL\Schema\Schema;
+
+/**
+ * Auto-generated Migration: Please modify to your need!
+ */
+class Version20110907043603 extends AbstractMigration
+{
+ public function up(Schema $schema)
+ {
+ $tool = new \Doctrine\ORM\Tools\SchemaTool(PartKeepr::getEM());
+
+ $classes = array(
+ 'de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocationImage'
+ );
+
+ $aClasses = array();
+
+ foreach ($classes as $class) {
+ $aClasses[] = PartKeepr::getEM()->getClassMetadata($class);
+ }
+
+ $tool->updateSchema($aClasses, true);
+
+ }
+
+ public function down(Schema $schema)
+ {
+ $tool = new \Doctrine\ORM\Tools\SchemaTool(PartKeepr::getEM());
+
+ $classes = array(
+ 'de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocationImage'
+ );
+
+ $aClasses = array();
+
+ foreach ($classes as $class) {
+ $aClasses[] = PartKeepr::getEM()->getClassMetadata($class);
+ }
+
+ $tool->dropSchema($aClasses);
+
+ }
+}