Skip to content

Commit

Permalink
add admin UI optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
cieslix committed Jun 18, 2020
1 parent 0c948c0 commit 6b0ec0b
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Api/Data/ParameterDefinitionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public function setId(string $id);
*/
public function setName(string $label);

/**
* @param string $unit
* @return void
*/
public function setUnit(?string $unit);

/**
* @param string $type
* @return void
Expand Down Expand Up @@ -64,6 +70,11 @@ public function getName(): ?string;
*/
public function getType(): ?string;

/**
* @return string
*/
public function getUnit(): ?string;

/**
* @return bool
*/
Expand Down
72 changes: 72 additions & 0 deletions Block/Adminhtml/Offer/BackButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Macopedia\Allegro\Block\Adminhtml\Offer;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
* Back button configuration provider
*/
class BackButton implements ButtonProviderInterface
{
/**
* Url Builder
*
* @var \Magento\Framework\UrlInterface
*/
protected $urlBuilder;

/**
* Registry
*
* @var \Magento\Framework\Registry
*/
protected $registry;

/**
* Constructor
*
* @param \Magento\Backend\Block\Widget\Context $context
* @param \Magento\Framework\Registry $registry
*/
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
\Magento\Framework\Registry $registry
) {
$this->urlBuilder = $context->getUrlBuilder();
$this->registry = $registry;
}

/**
* Return button attributes array
*/
public function getButtonData()
{
return [
'label' => __('Back'),
'class' => 'action- scalable back',
'on_click' => $this->getOnclick(),
'sort_order' => 10,
];
}

/**
* @return string
*/
protected function getOnClick()
{
return sprintf(
"location.href = '%s';",
$this->urlBuilder->getUrl('catalog/product/edit', ['id' => $this->getProduct()->getId()])
);
}

/**
* @return ProductInterface
*/
private function getProduct()
{
return $this->registry->registry('product');
}
}
1 change: 0 additions & 1 deletion Block/Adminhtml/Offer/SaveButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function getButtonData()
return [
'label' => __('Save'),
'class' => 'save primary',
'on_click' => "location.href = '" . $this->urlBuilder->getUrl('allegro/offer/save') . "';",
'data_attribute' => [
'mage-init' => ['button' => ['event' => 'save']],
'form-role' => 'save',
Expand Down
32 changes: 32 additions & 0 deletions Model/Config/CommentText/CallbackUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright © Macopedia. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Macopedia\Allegro\Model\Config\CommentText;

use Magento\Config\Model\Config\CommentInterface;

class CallbackUrl implements CommentInterface
{
/**
* @var \Magento\Backend\Model\UrlInterface
*/
protected $url;

/**
* CallbackUrl constructor.
* @param \Magento\Backend\Model\UrlInterface $url
*/
public function __construct(\Magento\Backend\Model\UrlInterface $url)
{
$this->url = $url;
}

public function getCommentText($elementValue)
{
$this->url->setNoSecret(true);
return $this->url->getUrl('allegro/system/authenticate');
}
}
21 changes: 21 additions & 0 deletions Model/Data/ParameterDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ParameterDefinition extends DataObject implements ParameterDefinitionInter

const ID_FIELD_NAME = 'id';
const NAME_FIELD_NAME = 'name';
const UNIT_FIELD_NAME = 'unit';
const REQUIRED_FIELD_NAME = 'required';
const VALUES_COUNT_FIELD_NAME = 'values_count';
const TYPE_FIELD_NAME = 'type';
Expand Down Expand Up @@ -66,6 +67,15 @@ public function setType(string $type)
$this->setData(self::TYPE_FIELD_NAME, $type);
}

/**
* @param string $type
* @return void
*/
public function setUnit(?string $type)
{
$this->setData(self::UNIT_FIELD_NAME, $type);
}

/**
* @param bool $required
* @return void
Expand Down Expand Up @@ -117,6 +127,14 @@ public function getType(): ?string
return $this->getData(self::TYPE_FIELD_NAME);
}

/**
* @return string
*/
public function getUnit(): ?string
{
return $this->getData(self::UNIT_FIELD_NAME);
}

/**
* @return bool
*/
Expand Down Expand Up @@ -199,6 +217,9 @@ public function setRawData(array $rawData)
if (isset($rawData['type'])) {
$this->setType($rawData['type']);
}
if (isset($rawData['unit'])) {
$this->setUnit($rawData['unit']);
}

$this->setRequired($rawData['required'] ?? false);
$this->setRestrictions($this->mapRestrictionsData($rawData['restrictions'] ?? []));
Expand Down
15 changes: 14 additions & 1 deletion Ui/AllegroOffer/Form/CreateDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ public function __construct(
$this->config = $config;
}

/**
* @param Product $product
* @return string
*/
protected function getAllegroImage(Product $product)
{
if ($product->getAllegroImage() && $product->getAllegroImage() !== 'no_selection') {
return $product->getAllegroImage();
}

return $product->getImage();
}

/**
* Get data
*
Expand All @@ -86,7 +99,7 @@ public function getData()
$product = $this->registry->registry('product');
$stock = $this->getSalableQuantityDataBySku->execute($product->getSku());
$images = $product->getMediaGalleryImages()->toArray();
$allegroImage = $product->getAllegroImage();
$allegroImage = $this->getAllegroImage($product);
foreach ($images['items'] as $key => $image) {
if ($image['file'] !== $allegroImage) {
unset($images['items'][$key]);
Expand Down
12 changes: 12 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,24 @@
<depends>
<field id="sandbox">0</field>
</depends>
<comment><![CDATA[
Register App in <a target="_blank" href="https://apps.developer.allegro.pl/">https://apps.developer.allegro.pl/</a>
]]></comment>
</field>
<field id="sandbox_authentication_url" translate="label comment" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Sandbox Authentication Url</label>
<depends>
<field id="sandbox">1</field>
</depends>
<comment><![CDATA[
Register App in <a target="_blank" href="https://apps.developer.allegro.pl.allegrosandbox.pl/">https://apps.developer.allegro.pl.allegrosandbox.pl/</a>
]]></comment>
</field>
<field id="callback_url" translate="label comment" type="label" sortOrder="35" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Use following callback</label>
<comment>
<model>\Macopedia\Allegro\Model\Config\CommentText\CallbackUrl</model>
</comment>
</field>
</group>
<group id="credentials" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="20" translate="label">
Expand Down
1 change: 1 addition & 0 deletions view/adminhtml/ui_component/allegro_offer_form_create.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<settings>
<buttons>
<button name="back" class="Macopedia\Allegro\Block\Adminhtml\Offer\BackButton"/>
<button name="save" class="Macopedia\Allegro\Block\Adminhtml\Offer\SaveButton"/>
</buttons>
<namespace>allegro_offer_form_create</namespace>
Expand Down
1 change: 1 addition & 0 deletions view/adminhtml/ui_component/allegro_offer_form_edit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<settings>
<buttons>
<button name="back" class="Macopedia\Allegro\Block\Adminhtml\Offer\BackButton"/>
<button name="save" class="Macopedia\Allegro\Block\Adminhtml\Offer\SaveButton"/>
<button name="publish" class="Macopedia\Allegro\Block\Adminhtml\Offer\PublishButton"/>
<button name="end" class="Macopedia\Allegro\Block\Adminhtml\Offer\EndButton"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<div>
<label data-bind="attr: { for: $parent.uid + definition.id }">
<span data-bind="text: definition.name"></span>
<span if="unit" data-bind="text: ' ( ' + unit + ' ) '"></span>
</label>
</div>
<div>
Expand Down

0 comments on commit 6b0ec0b

Please sign in to comment.