Skip to content

Commit

Permalink
Refactored attribute group js to use 2 separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
JevgenijVisockij committed Mar 10, 2023
1 parent b8b4ea6 commit 13a400b
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 30 deletions.
1 change: 1 addition & 0 deletions admin-dev/themes/new-theme/.webpack/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = {
attachment: './js/pages/attachment',
attribute: './js/pages/attribute',
attribute_group: './js/pages/attribute-group',
attribute_group_form: './js/pages/attribute-group/form',
authorization_server: './js/pages/authorization-server',
backup: './js/pages/backup',
carrier: './js/pages/carrier',
Expand Down
38 changes: 38 additions & 0 deletions admin-dev/themes/new-theme/js/pages/attribute-group/form/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

// @ts-ignore
const {$} = window;

$(() => {
window.prestashop.component.initComponents(
[
'TranslatableInput',
'TranslatableField',
],
);

new window.prestashop.component.ChoiceTree('#attribute_group_shop_association').enableAutoCheckChildren();
});
9 changes: 0 additions & 9 deletions admin-dev/themes/new-theme/js/pages/attribute-group/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,4 @@ $(() => {

const showcaseCard = new ShowcaseCard('attributesShowcaseCard');
showcaseCard.addExtension(new ShowcaseCardCloseExtension());

window.prestashop.component.initComponents(
[
'TranslatableInput',
'TranslatableField',
],
);

new window.prestashop.component.ChoiceTree('#attribute_group_shop_association').enableAutoCheckChildren();
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
use Doctrine\DBAL\Connection;
use PrestaShop\PrestaShop\Adapter\AttributeGroup\Validate\AttributeGroupValidator;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Exception\CannotAddAttributeGroupException;
use PrestaShop\PrestaShop\Core\Domain\Product\AttributeGroup\Exception\AttributeGroupNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\ValueObject\AttributeGroupId;
use PrestaShop\PrestaShop\Core\Domain\Product\AttributeGroup\Exception\AttributeGroupNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Shop\Exception\InvalidShopConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Shop\Exception\ShopAssociationNotFound;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

namespace PrestaShop\PrestaShop\Adapter\AttributeGroup\Validate;

use AttributeGroup;
use PrestaShop\PrestaShop\Adapter\AbstractObjectModelValidator;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Exception\AttributeGroupConstraintException;
use AttributeGroup;
use PrestaShop\PrestaShop\Core\Exception\CoreException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
namespace PrestaShop\PrestaShop\Core\Domain\AttributeGroup\CommandHandler;

use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Command\EditAttributeGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\ValueObject\AttributeGroupId;

/**
* Describes a service that handles attribute group edit command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function getValue(): string
private function assertTypeExists(string $type): void
{
$types = [static::ATTRIBUTE_GROUP_TYPE_COLOR, static::ATTRIBUTE_GROUP_TYPE_SELECT, static::ATTRIBUTE_GROUP_TYPE_RADIO];
if (!in_array($type, $types)){
if (!in_array($type, $types)) {
throw new InvalidAttributeGroupTypeException(
sprintf(
'Invalid attributeGroup type %s supplied.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function create(array $data)
*/
public function update($id, array $data)
{
/** @var AttributeGroupId $attributeGroupId */
/* @var AttributeGroupId $attributeGroupId */
$this->commandBus->handle(new EditAttributeGroupCommand(
(int) $id,
$data['name'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Exception\AttributeGroupConstraintException;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Exception\CannotAddAttributeGroupException;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Exception\CannotUpdateAttributeGroupException;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Query\GetAttributeGroupForEditing;
use PrestaShop\PrestaShop\Core\Domain\Product\AttributeGroup\Command\BulkDeleteAttributeGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\AttributeGroup\Command\DeleteAttributeGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\AttributeGroup\Exception\AttributeGroupNotFoundException;
Expand Down
24 changes: 12 additions & 12 deletions src/PrestaShopBundle/Form/Admin/Sell/Catalog/AttributeGroupType.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\TypedRegex;
use PrestaShop\PrestaShop\Core\ConstraintValidator\TypedRegexValidator;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\ValueObject\AttributeGroupType as GroupType;
use PrestaShopBundle\Form\Admin\Type\ShopChoiceTreeType;
use PrestaShopBundle\Form\Admin\Type\TranslatableType;
use PrestaShopBundle\Form\Admin\Type\TranslatorAwareType;
Expand All @@ -39,7 +40,6 @@
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Contracts\Translation\TranslatorInterface;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\ValueObject\AttributeGroupType as GroupType;

/**
* Form type for attribute add/edit
Expand Down Expand Up @@ -79,18 +79,18 @@ public function buildForm(FormBuilderInterface $builder, array $options)

$builder
->add('name', TranslatableType::class, [
'type' => TextType::class,
'label' => $this->trans('Name', 'Admin.Global'),
'options' => [
'constraints' => [
new TypedRegex([
'type' => TypedRegex::TYPE_CATALOG_NAME,
]),
'type' => TextType::class,
'label' => $this->trans('Name', 'Admin.Global'),
'options' => [
'constraints' => [
new TypedRegex([
'type' => TypedRegex::TYPE_CATALOG_NAME,
]),
],
],
],
'help' => $this->trans('Your internal name for this attribute.', 'Admin.Catalog.Help')
. '&nbsp;' . $this->trans('Invalid characters:', 'Admin.Notifications.Info')
. ' ' . TypedRegexValidator::CATALOG_CHARS,
'help' => $this->trans('Your internal name for this attribute.', 'Admin.Catalog.Help')
. '&nbsp;' . $this->trans('Invalid characters:', 'Admin.Notifications.Info')
. ' ' . TypedRegexValidator::CATALOG_CHARS,
])
->add('public_name', TranslatableType::class, [
'type' => TextType::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
*#}

{% block feature_javascript_block %}
<script src="{{ asset('themes/new-theme/public/attribute_group.bundle.js') }}"></script>
<script src="{{ asset('themes/new-theme/public/attribute_group_form.bundle.js') }}"></script>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

use Behat\Gherkin\Node\TableNode;
use PHPUnit\Framework\Assert;
use PrestaShop\PrestaShop\Core\Domain\Attachment\Query\GetAttachmentInformation;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Command\AddAttributeGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Command\EditAttributeGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Exception\AttributeGroupConstraintException;
Expand Down Expand Up @@ -122,7 +121,6 @@ public function assertFieldWithLangValue(string $reference, string $field, strin
$attributeGroupId = $this->referenceToId($reference);
$attributeGroup = new \AttributeGroup($attributeGroupId);


if ($attributeGroup->$field[$this->getDefaultLangId()] !== $value) {
throw new RuntimeException(sprintf('Attribute group "%s" has "%s" %s, but "%s" was expected.', $reference, $attributeGroup->$field[$this->getDefaultLangId()], $field, $value));
}
Expand Down

0 comments on commit 13a400b

Please sign in to comment.