Commit d8ce89bc authored by Piotr Borek's avatar Piotr Borek Committed by Damian Kryger
Browse files

#789 Label in drafts view

parent 3e50b130
......@@ -12,6 +12,7 @@ namespace PcmtDraftBundle\Normalizer;
use Akeneo\Pim\Enrichment\Component\Product\Model\ProductInterface;
use Akeneo\Pim\Enrichment\Component\Product\Model\ValueInterface;
use Akeneo\Platform\Bundle\UIBundle\Provider\Form\FormProviderInterface;
use Akeneo\UserManagement\Bundle\Context\UserContext;
use PcmtDraftBundle\Entity\ExistingProductDraft;
use PcmtDraftBundle\Entity\ProductDraftInterface;
use PcmtDraftBundle\Service\AttributeChange\AttributeChangeService;
......@@ -45,6 +46,9 @@ class ProductDraftNormalizer implements NormalizerInterface
/** @var PermissionsHelper */
private $permissionsHelper;
/** @var UserContext */
private $userContext;
public function __construct(
AttributeChangeService $attributeChangeService,
AttributeChangeNormalizer $attributeChangeNormalizer,
......@@ -53,7 +57,8 @@ class ProductDraftNormalizer implements NormalizerInterface
GeneralDraftNormalizer $generalDraftNormalizer,
GeneralObjectFromDraftCreator $productFromDraftCreator,
NormalizerInterface $valuesNormalizer,
PermissionsHelper $permissionsHelper
PermissionsHelper $permissionsHelper,
UserContext $userContext
) {
$this->attributeChangeService = $attributeChangeService;
$this->attributeChangeNormalizer = $attributeChangeNormalizer;
......@@ -63,6 +68,7 @@ class ProductDraftNormalizer implements NormalizerInterface
$this->productFromDraftCreator = $productFromDraftCreator;
$this->valuesNormalizer = $valuesNormalizer;
$this->permissionsHelper = $permissionsHelper;
$this->userContext = $userContext;
}
/**
......@@ -116,10 +122,10 @@ class ProductDraftNormalizer implements NormalizerInterface
private function getLabel(ProductDraftInterface $draft, ProductInterface $newProduct): string
{
if ($draft instanceof ExistingProductDraft) {
return $draft->getProduct()->getIdentifier() ?? '-';
return $draft->getProduct()->getLabel($this->userContext->getUiLocaleCode()) ?? '-';
}
return $newProduct->getIdentifier() ?? '-';
return $newProduct->getLabel($this->userContext->getUiLocaleCode()) ?? '-';
}
/**
......
......@@ -12,6 +12,7 @@ namespace PcmtDraftBundle\Normalizer;
use Akeneo\Pim\Enrichment\Component\Product\Model\ProductModelInterface;
use Akeneo\Pim\Enrichment\Component\Product\Model\ValueInterface;
use Akeneo\Platform\Bundle\UIBundle\Provider\Form\FormProviderInterface;
use Akeneo\UserManagement\Bundle\Context\UserContext;
use PcmtDraftBundle\Entity\ExistingProductModelDraft;
use PcmtDraftBundle\Entity\ProductModelDraftInterface;
use PcmtDraftBundle\Service\AttributeChange\AttributeChangeService;
......@@ -45,6 +46,9 @@ class ProductModelDraftNormalizer implements NormalizerInterface
/** @var PermissionsHelper */
private $permissionsHelper;
/** @var UserContext */
private $userContext;
public function __construct(
AttributeChangeService $attributeChangeService,
AttributeChangeNormalizer $attributeChangeNormalizer,
......@@ -53,7 +57,8 @@ class ProductModelDraftNormalizer implements NormalizerInterface
GeneralDraftNormalizer $generalDraftNormalizer,
GeneralObjectFromDraftCreator $productModelFromDraftCreator,
NormalizerInterface $valuesNormalizer,
PermissionsHelper $permissionsHelper
PermissionsHelper $permissionsHelper,
UserContext $userContext
) {
$this->attributeChangeService = $attributeChangeService;
$this->attributeChangeNormalizer = $attributeChangeNormalizer;
......@@ -63,6 +68,7 @@ class ProductModelDraftNormalizer implements NormalizerInterface
$this->productModelFromDraftCreator = $productModelFromDraftCreator;
$this->valuesNormalizer = $valuesNormalizer;
$this->permissionsHelper = $permissionsHelper;
$this->userContext = $userContext;
}
/**
......@@ -94,6 +100,7 @@ class ProductModelDraftNormalizer implements NormalizerInterface
'family_variant' => $newProductModel->getFamilyVariant()->getCode(),
'parentId' => $newProductModel->getParent() ? $newProductModel->getParent()->getId() : null,
'parent' => $newProductModel->getParent() ? $newProductModel->getParent()->getCode() : null,
'identifier' => $newProductModel->getCode(),
];
if ($context['include_product'] ?? false) {
......@@ -118,10 +125,10 @@ class ProductModelDraftNormalizer implements NormalizerInterface
private function getLabel(ProductModelDraftInterface $draft, ProductModelInterface $newProductModel): string
{
if ($draft instanceof ExistingProductModelDraft) {
return $draft->getProductModel()->getCode() ?? '-';
return $draft->getProductModel()->getLabel($this->userContext->getUiLocaleCode());
}
return $newProductModel->getCode() ?? '-';
return $newProductModel->getLabel($this->userContext->getUiLocaleCode()) ?? '-';
}
/**
......
......@@ -39,6 +39,7 @@ services:
- '@pcmt.service.general_object_from_draft_creator'
- '@pim_catalog.normalizer.standard.product.product_value'
- '@pcmt_draft.normalizer.permissions_helper'
- '@pim_user.context.user'
tags:
- { name: pim_internal_api_serializer.normalizer, priority: 110 }
......@@ -53,6 +54,7 @@ services:
- '@pcmt.service.general_object_from_draft_creator'
- '@pim_catalog.normalizer.standard.product.product_value'
- '@pcmt_draft.normalizer.permissions_helper'
- '@pim_user.context.user'
tags:
- { name: pim_internal_api_serializer.normalizer, priority: 110 }
......
......@@ -30,6 +30,9 @@
<th class="AknGrid-headerCell">
<%- __('pcmt_core.drafts_list.product') %>
</th>
<th class="AknGrid-headerCell">
<%- __('pcmt_core.drafts_list.label') %>
</th>
<th class="AknGrid-headerCell">
<%- __('pcmt_core.drafts_list.author') %>
</th>
......@@ -61,64 +64,69 @@
</td>
<td class="AknGrid-bodyCell">
<%- __(draft.typeName) %><br>
<%- draft.label %>
<%- draft.values.identifier %>
</td>
<td class="AknGrid-bodyCell"><%- draft.label %></td>
<td class="AknGrid-bodyCell"><%- draft.author %></td>
<td class="AknGrid-bodyCell">
<div id="draft-changes-shortcut-<%- draft.id %>"
class="draft-changes-shortcut"
data-draft-id="<%- draft.id %>"
style="cursor:pointer">
<% if (draft.changes.length > 0) { %>
<div id="draft-changes-shortcut-<%- draft.id %>"
class="draft-changes-shortcut"
data-draft-id="<%- draft.id %>"
style="cursor:pointer">
<div class="AknButtonList AknButtonList--right" style="float:right;">
<button class="AknActionButton">
<%- __('pcmt_core.drafts_list.show_more') %>
<span class="AknActionButton-caret AknCaret"></span>
</button>
</div>
<div class="AknButtonList AknButtonList--right">
<button class="AknActionButton">
<%- __('pcmt_core.drafts_list.show_more') %>
<span class="AknActionButton-caret AknCaret"></span>
</button>
</div>
<% firstChange = _.first(draft.changes) %>
<% if (firstChange) { %>
<div style="margin-bottom:10px;">
<b><%- firstChange.attribute %></b><br>
<span class="AknDiff--remove">
<%- __('pcmt_core.drafts_list.previous_value') %>:
</span>
<%- firstChange.previousValue %><br>
<span class="AknDiff--add">
<%- __('pcmt_core.drafts_list.new_value') %>:
</span>
<%- firstChange.newValue %>
<% firstChange = _.first(draft.changes) %>
<% if (firstChange) { %>
<div style="margin-bottom:10px;">
<b><%- firstChange.attribute %></b><br>
<span class="AknDiff--remove">
<%- __('pcmt_core.drafts_list.previous_value') %>:
</span>
<%- firstChange.previousValue %><br>
<span class="AknDiff--add">
<%- __('pcmt_core.drafts_list.new_value') %>:
</span>
<%- firstChange.newValue %>
</div>
<% } %>
</div>
<% } %>
</div>
<div id="draft-changes-full-<%- draft.id %>"
class="draft-changes-full"
data-draft-id="<%- draft.id %>"
style="cursor:pointer; display:none">
<div id="draft-changes-full-<%- draft.id %>"
class="draft-changes-full"
data-draft-id="<%- draft.id %>"
style="cursor:pointer; display:none">
<div class="AknButtonList AknButtonList--right" style="float:right;">
<button class="AknActionButton" data-toggle="dropdown">
<%- __('pcmt_core.drafts_list.collapse') %>
<span class="AknActionButton-caret AknCaret"></span>
</button>
</div>
<div class="AknButtonList AknButtonList--right" style="float:right;">
<button class="AknActionButton" data-toggle="dropdown">
<%- __('pcmt_core.drafts_list.collapse') %>
<span class="AknActionButton-caret AknCaret"></span>
</button>
</div>
<% _.each(draft.changes, function (change) { %>
<div style="margin-bottom:10px;">
<b><%- change.attribute %></b><br>
<span class="AknDiff--remove">
<%- __('pcmt_core.drafts_list.previous_value') %>:
</span>
<%- change.previousValue %><br>
<span class="AknDiff--add">
<%- __('pcmt_core.drafts_list.new_value') %>:
</span>
<%- change.newValue %>
</div>
<% }); %>
<% _.each(draft.changes, function (change) { %>
<div style="margin-bottom:10px;">
<b><%- change.attribute %></b><br>
<span class="AknDiff--remove">
<%- __('pcmt_core.drafts_list.previous_value') %>:
</span>
<%- change.previousValue %><br>
<span class="AknDiff--add">
<%- __('pcmt_core.drafts_list.new_value') %>:
</span>
<%- change.newValue %>
</div>
<% }); %>
</div>
</div>
<% } else { %>
<%- __('pcmt_core.drafts_list.no_changes') %>
<% } %>
</td>
<td class="AknGrid-bodyCell"><%- draft.createdAt %></td>
<td class="AknGrid-bodyCell">
......
......@@ -19,6 +19,8 @@ pcmt_core:
show_more: Show more
page_title:
index: "]-Inf, 1]{{ count }} draft|]1, Inf[{{ count }} drafts"
label: Label
no_changes: No changes
drafts_editing:
new_product_draft:
breadcrumb: New product draft
......
......@@ -19,6 +19,8 @@ pcmt_core:
show_more: FR Show more
page_title:
index: "]-Inf, 1]{{ count }} FR draft|]1, Inf[{{ count }} FR drafts"
label: FR Label
no_changes: FR No changes
drafts_editing:
new_product_draft:
breadcrumb: FR New product draft
......
......@@ -12,6 +12,7 @@ namespace PcmtDraftBundle\Tests\Normalizer;
use Akeneo\Pim\Enrichment\Component\Product\Model\Product;
use Akeneo\Pim\Enrichment\Component\Product\Model\ValueInterface;
use Akeneo\Platform\Bundle\UIBundle\Provider\Form\FormProviderInterface;
use Akeneo\UserManagement\Bundle\Context\UserContext;
use PcmtDraftBundle\Entity\AttributeChange;
use PcmtDraftBundle\Normalizer\AttributeChangeNormalizer;
use PcmtDraftBundle\Normalizer\GeneralDraftNormalizer;
......@@ -53,6 +54,9 @@ class ProductDraftNormalizerTest extends TestCase
/** @var PermissionsHelper|MockObject */
private $permissionsHelperMock;
/** @var UserContext|MockObject */
private $userContextMock;
protected function setUp(): void
{
$this->generalDraftNormalizerMock = $this->createMock(GeneralDraftNormalizer::class);
......@@ -77,6 +81,8 @@ class ProductDraftNormalizerTest extends TestCase
$this->permissionsHelperMock = $this->createMock(PermissionsHelper::class);
$this->userContextMock = $this->createMock(UserContext::class);
parent::setUp();
}
......@@ -205,7 +211,8 @@ class ProductDraftNormalizerTest extends TestCase
$this->generalDraftNormalizerMock,
$this->creatorMock,
$this->valuesNormalizerMock,
$this->permissionsHelperMock
$this->permissionsHelperMock,
$this->userContextMock
);
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ namespace PcmtDraftBundle\Tests\Normalizer;
use Akeneo\Pim\Enrichment\Component\Product\Model\ValueInterface;
use Akeneo\Platform\Bundle\UIBundle\Provider\Form\FormProviderInterface;
use Akeneo\UserManagement\Bundle\Context\UserContext;
use PcmtDraftBundle\Entity\ProductModelDraftInterface;
use PcmtDraftBundle\Normalizer\AttributeChangeNormalizer;
use PcmtDraftBundle\Normalizer\GeneralDraftNormalizer;
......@@ -53,6 +54,9 @@ class ProductModelDraftNormalizerTest extends TestCase
/** @var PermissionsHelper|MockObject */
private $permissionsHelperMock;
/** @var UserContext|MockObject */
private $userContextMock;
protected function setUp(): void
{
$this->generalDraftNormalizerMock = $this->createMock(GeneralDraftNormalizer::class);
......@@ -78,6 +82,8 @@ class ProductModelDraftNormalizerTest extends TestCase
$this->permissionsHelperMock = $this->createMock(PermissionsHelper::class);
$this->userContextMock = $this->createMock(UserContext::class);
parent::setUp();
}
......@@ -206,7 +212,8 @@ class ProductModelDraftNormalizerTest extends TestCase
$this->generalDraftNormalizerMock,
$this->creatorMock,
$this->valuesNormalizerMock,
$this->permissionsHelperMock
$this->permissionsHelperMock,
$this->userContextMock
);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment