commit 8d623fdc8a794cf78890d5fe808506a750f9c9a3
parent c6130d83762df8ee9ab1ad5c73fc5d69441fdeaa
Author: Felicitus <felicitus@felicitus.org>
Date: Thu, 24 Sep 2015 23:00:25 +0200
Added regular GET operation on the temp image entity
Diffstat:
3 files changed, 148 insertions(+), 124 deletions(-)
diff --git a/app/config/config.yml b/app/config/config.yml
@@ -576,7 +576,7 @@ services:
arguments:
- "@resource.manufacturer_ic_logo" # Resource
- [ "GET" ] # Methods
- - "/manufacturer_i_c_logo/{id}/getImage" # Path
+ - "/manufacturer_i_c_logos/{id}/getImage" # Path
- "PartKeeprManufacturerBundle:ManufacturerIcLogo:getImage" # Controller
- "ManufacturerIcLogoGetImage" # Route name
- # Context (will be present in Hydra documentation)
@@ -800,6 +800,12 @@ services:
- { groups: [ "default" ] }
# ######################## Temporary Images ######################################
+ resource.tempimage.item_operation.get:
+ class: "Dunglas\ApiBundle\Api\Operation\Operation"
+ public: false
+ factory: [ "@api.operation_factory", "createItemOperation" ]
+ arguments: [ "@resource.tempimage", "GET" ]
+
resource.tempimage.collection_operation.custom_post:
class: "Dunglas\ApiBundle\Api\Operation\Operation"
public: false
@@ -853,7 +859,7 @@ services:
- method: "initCollectionOperations"
arguments: [ [ "@resource.tempimage.collection_operation.custom_post", "@resource.tempimage.collection_operation.custom_post_webcam" ] ]
- method: "initItemOperations"
- arguments: [ [ "@resource.tempimage.item_operation.custom_get" ] ]
+ arguments: [ [ "@resource.tempimage.item_operation.get", "@resource.tempimage.item_operation.custom_get" ] ]
resource.tempfile.collection_operation.custom_post:
class: "Dunglas\ApiBundle\Api\Operation\Operation"
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Manufacturer/ManufacturerEditor.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Manufacturer/ManufacturerEditor.js
@@ -1,117 +1,130 @@
Ext.define('PartKeepr.ManufacturerEditor', {
- extend: 'PartKeepr.Editor',
- alias: 'widget.ManufacturerEditor',
- saveText: i18n("Save Manufacturer"),
- labelWidth: 150,
- initComponent: function () {
- this.on("startEdit", Ext.bind(this.onEditStart, this));
-
- this.tpl = new Ext.XTemplate(
- '<tpl for=".">',
- '<div class="dataview-multisort-item iclogo"><img src="{[values["@id"]]}?maxWidth=100&maxHeight=100"/></div>',
- '</tpl>');
+ extend: 'PartKeepr.Editor',
+ alias: 'widget.ManufacturerEditor',
+ saveText: i18n("Save Manufacturer"),
+ labelWidth: 150,
+ initComponent: function ()
+ {
+ this.on("startEdit", Ext.bind(this.onEditStart, this));
- this.addLogoButton = Ext.create("Ext.button.Button", {
- icon: "resources/silkicons/add.png",
- text: i18n("Add Logo"),
- handler: Ext.bind(this.uploadImage, this)
- });
-
- this.deleteLogoButton = Ext.create("Ext.button.Button", {
- icon: "resources/silkicons/delete.png",
- text: i18n("Delete Logo"),
- disabled: true,
- handler: Ext.bind(this.deleteImage, this)
- });
-
- this.iclogoGrid = Ext.create("Ext.view.View", {
- store: null,
- border: true,
- frame: true,
- style: 'background-color: white',
- emptyText: 'No images to display',
- height: 200,
- fieldLabel: i18n("Logos"),
- componentCls: 'manufacturer-ic-logos',
- itemSelector: 'div.dataview-multisort-item',
- singleSelect: true,
- anchor: '100%',
- tpl: this.tpl,
- listeners: {
- selectionchange: Ext.bind(function (view, selections) {
- if (selections.length > 0) {
- this.deleteLogoButton.enable();
- } else {
- this.deleteLogoButton.disable();
- }
- }, this)
- }
- });
-
- this.items = [{
- xtype: 'textfield',
- name: 'name',
- fieldLabel: i18n("Manufacturer Name")
- },{
- xtype: 'textarea',
- name: 'address',
- fieldLabel: i18n("Address")
- },{
- xtype: 'urltextfield',
- name: 'url',
- fieldLabel: i18n("Website")
- },{
- xtype: 'textfield',
- name: 'email',
- fieldLabel: i18n("Email")
- },{
- xtype: 'textfield',
- name: 'phone',
- fieldLabel: i18n("Phone")
- },{
- xtype: 'textfield',
- name: 'fax',
- fieldLabel: i18n("Fax")
- },{
- xtype: 'textarea',
- name: 'comment',
- fieldLabel: i18n("Comment")
- },{
- xtype: 'fieldcontainer',
- fieldLabel: i18n("Manufacturer Logos"),
- items: [{
- xtype: 'panel',
- dockedItems: [{
- xtype: 'toolbar',
- dock: 'bottom',
- items: [ this.addLogoButton, this.deleteLogoButton ]
- }],
- items: this.iclogoGrid
- }]
-
- }];
-
-
- this.on("itemSaved", this._onItemSaved, this);
- this.callParent();
-
- },
- _onItemSaved: function (record) {
- this.iclogoGrid.bindStore(record.icLogos());
- },
- onFileUploaded: function (response) {
- this.iclogoGrid.getStore().add(response);
- },
- uploadImage: function () {
- var j = Ext.create("PartKeepr.FileUploadDialog", { imageUpload: true });
- j.on("fileUploaded", Ext.bind(this.onFileUploaded, this));
- j.show();
- },
- deleteImage: function () {
- this.iclogoGrid.getStore().remove(this.iclogoGrid.getSelectionModel().getLastSelected());
- },
- onEditStart: function () {
- var store = this.record.icLogos();
- this.iclogoGrid.bindStore(store);
- }
-});-
\ No newline at end of file
+ this.tpl = new Ext.XTemplate(
+ '<tpl for=".">',
+ '<div class="dataview-multisort-item iclogo"><img src="{[values["@id"]]}/getImage?maxWidth=100&maxHeight=100"/></div>',
+ '</tpl>');
+
+ this.addLogoButton = Ext.create("Ext.button.Button", {
+ icon: "resources/silkicons/add.png",
+ text: i18n("Add Logo"),
+ handler: Ext.bind(this.uploadImage, this)
+ });
+
+ this.deleteLogoButton = Ext.create("Ext.button.Button", {
+ icon: "resources/silkicons/delete.png",
+ text: i18n("Delete Logo"),
+ disabled: true,
+ handler: Ext.bind(this.deleteImage, this)
+ });
+
+ this.iclogoGrid = Ext.create("Ext.view.View", {
+ store: null,
+ border: true,
+ frame: true,
+ style: 'background-color: white',
+ emptyText: 'No images to display',
+ height: 200,
+ fieldLabel: i18n("Logos"),
+ componentCls: 'manufacturer-ic-logos',
+ itemSelector: 'div.dataview-multisort-item',
+ singleSelect: true,
+ anchor: '100%',
+ tpl: this.tpl,
+ listeners: {
+ selectionchange: Ext.bind(function (view, selections)
+ {
+ if (selections.length > 0) {
+ this.deleteLogoButton.enable();
+ } else {
+ this.deleteLogoButton.disable();
+ }
+ }, this)
+ }
+ });
+
+ this.items = [
+ {
+ xtype: 'textfield',
+ name: 'name',
+ fieldLabel: i18n("Manufacturer Name")
+ }, {
+ xtype: 'textarea',
+ name: 'address',
+ fieldLabel: i18n("Address")
+ }, {
+ xtype: 'urltextfield',
+ name: 'url',
+ fieldLabel: i18n("Website")
+ }, {
+ xtype: 'textfield',
+ name: 'email',
+ fieldLabel: i18n("Email")
+ }, {
+ xtype: 'textfield',
+ name: 'phone',
+ fieldLabel: i18n("Phone")
+ }, {
+ xtype: 'textfield',
+ name: 'fax',
+ fieldLabel: i18n("Fax")
+ }, {
+ xtype: 'textarea',
+ name: 'comment',
+ fieldLabel: i18n("Comment")
+ }, {
+ xtype: 'fieldcontainer',
+ fieldLabel: i18n("Manufacturer Logos"),
+ items: [
+ {
+ xtype: 'panel',
+ dockedItems: [
+ {
+ xtype: 'toolbar',
+ dock: 'bottom',
+ items: [this.addLogoButton, this.deleteLogoButton]
+ }
+ ],
+ items: this.iclogoGrid
+ }
+ ]
+
+ }
+ ];
+
+
+ this.on("itemSaved", this._onItemSaved, this);
+ this.callParent();
+
+ },
+ _onItemSaved: function (record)
+ {
+ this.iclogoGrid.bindStore(record.icLogos());
+ },
+ onFileUploaded: function (response)
+ {
+ this.iclogoGrid.getStore().add(response);
+ },
+ uploadImage: function ()
+ {
+ var j = Ext.create("PartKeepr.FileUploadDialog", {imageUpload: true});
+ j.on("fileUploaded", Ext.bind(this.onFileUploaded, this));
+ j.show();
+ },
+ deleteImage: function ()
+ {
+ this.iclogoGrid.getStore().remove(this.iclogoGrid.getSelectionModel().getLastSelected());
+ },
+ onEditStart: function ()
+ {
+ var store = this.record.icLogos();
+ this.iclogoGrid.bindStore(store);
+ }
+});
diff --git a/src/PartKeepr/ImageBundle/Controller/TemporaryImageController.php b/src/PartKeepr/ImageBundle/Controller/TemporaryImageController.php
@@ -1,6 +1,8 @@
<?php
namespace PartKeepr\ImageBundle\Controller;
+use Dunglas\ApiBundle\Action\ActionUtilTrait;
+use Dunglas\ApiBundle\Api\ResourceInterface;
use FOS\RestBundle\Controller\Annotations\RequestParam;
use FOS\RestBundle\Controller\Annotations\View;
use PartKeepr\ImageBundle\Entity\TempImage;
@@ -13,6 +15,7 @@ use Symfony\Component\HttpFoundation\Response;
class TemporaryImageController extends ImageController
{
+ use ActionUtilTrait;
/**
* Handles a temporary image upload
@@ -47,11 +50,15 @@ class TemporaryImageController extends ImageController
$this->getDoctrine()->getManager()->persist($image);
$this->getDoctrine()->getManager()->flush();
- $resource = $this->getResource($request);
+ /**
+ * @var ResourceInterface $resourceType
+ */
+ list($resourceType) = $this->extractAttributes($request);
+
$serializedData = $this->get('serializer')->normalize(
$image,
- 'json-ld',
- $resource->getNormalizationContext()
+ 'jsonld',
+ $resourceType->getNormalizationContext()
);
return new JsonResponse(new TemporaryImageUploadResponse($serializedData));
@@ -61,6 +68,7 @@ class TemporaryImageController extends ImageController
* Uploads a webcam image
*
* @param Request $request The request to process
+ *
* @return Response
*/
public function webcamUploadAction(Request $request)
@@ -77,9 +85,7 @@ class TemporaryImageController extends ImageController
$this->getDoctrine()->getManager()->persist($image);
$this->getDoctrine()->getManager()->flush();
- $resource = $this->getResource($request);
-
- return $this->getSuccessResponse($resource, $image, 201);
+ return $image;
}
/**