Skip to content

Commit

Permalink
Merge pull request #25 from webgriffe/issue-7
Browse files Browse the repository at this point in the history
Add queue items grid to admin panel
  • Loading branch information
mmenozzi authored Dec 7, 2020
2 parents f8b6f56 + 2a8b8cb commit 3bc2144
Show file tree
Hide file tree
Showing 18 changed files with 400 additions and 35 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
+ [Enqueue command](#enqueue-command)
+ [Consume command](#consume-command)
* [Automatically import data with cron jobs](#automatically-import-data-with-cron-jobs)
* [Browsing queue items in the admin](#browsing-queue-items-in-the-admin)
- [Architecture & customization](#architecture---customization)
* [Product Importer](#product-importer)
+ [Taxons resolver](#taxons-resolver)
Expand Down Expand Up @@ -405,6 +406,12 @@ It will enqueue the update of all attribute options every hour and it will impor

Both enqueue and consume commands uses a [lock mechanism](https://symfony.com/doc/current/console/lockable_trait.html) which prevents to run them multiple times.

### Browsing queue items in the admin

You can examine the Akeneo import queue from the admin panel at **Catalog -> Akeneo PIM import**. You can filter and sort items and see their error message:

![Akeneo queue items grid](queue_items_grid.png)

## Architecture & customization

This plugin has basically two main entry points:
Expand Down
44 changes: 44 additions & 0 deletions features/browsing_queue_items.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@browsing_queue_items
Feature: Browsing queue items
In order to see the status of imported and not imported items from Akeneo
As an Administrator
I want to browse the Akeneo items queue

Background:
Given I am logged in as an administrator
And there is a not imported item with identifier "braided-hat-m" for the "Product" importer in the Akeneo queue
And there is a not imported item with identifier "braided-hat-l" for the "ProductAssociations" importer in the Akeneo queue
And there is an already imported item with identifier "braided-hat-s" for the "Product" importer in the Akeneo queue

@ui
Scenario: Browsing all items
When I browse Akeneo queue items
Then I should see 3 queue items in the list

@ui
Scenario: Browsing not imported items
When I browse Akeneo queue items
And I choose "No" as an imported filter
And I filter
Then I should see 2, not imported, queue items in the list

@ui
Scenario: Browsing imported items
When I browse Akeneo queue items
And I choose "Yes" as an imported filter
And I filter
Then I should see 1, imported, queue item in the list

@ui
Scenario: Filtering items by importer
When I browse Akeneo queue items
And I specify "Associations" as an importer filter
And I filter
Then I should see 1 queue item in the list

@ui
Scenario: Filtering items by identifier
When I browse Akeneo queue items
And I specify "hat-l" as an identifier filter
And I filter
Then I should see 1 queue item in the list
Binary file added queue_items_grid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions src/Menu/AdminMenuListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Webgriffe\SyliusAkeneoPlugin\Menu;

use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent;

final class AdminMenuListener
{
public function addAdminMenuItems(MenuBuilderEvent $event): void
{
$menu = $event->getMenu();
$catalogMenu = $menu->getChild('catalog');
if ($catalogMenu === null) {
return;
}

$catalogMenu
->addChild('webgriffe_sylius_akeneo.queue_item', ['route' => 'webgriffe_sylius_akeneo_admin_queue_item_index'])
->setLabel('webgriffe_sylius_akeneo.ui.queue_items')
->setLabelAttribute('icon', 'cloud download')
;
}
}
15 changes: 15 additions & 0 deletions src/Resources/config/admin_routing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
webgriffe_sylius_akeneo_admin_queue_item:
resource: |
alias: webgriffe_sylius_akeneo.queue_item
section: admin
path: akeneo_queue_items
except: ['delete', 'update', 'create', 'show', 'bulkDelete']
templates: "@SyliusAdmin\\Crud"
redirect: update
grid: webgriffe_sylius_akeneo_admin_queue_item
vars:
all:
subheader: webgriffe_sylius_akeneo.ui.manage_akeneo_queue_items
index:
icon: 'cloud download'
type: sylius.resource
56 changes: 56 additions & 0 deletions src/Resources/config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
sylius_resource:
resources:
webgriffe_sylius_akeneo.queue_item:
classes:
model: Webgriffe\SyliusAkeneoPlugin\Entity\QueueItem
repository: Webgriffe\SyliusAkeneoPlugin\Doctrine\ORM\QueueItemRepository

sylius_grid:
grids:
webgriffe_sylius_akeneo_admin_queue_item:
driver:
name: doctrine/orm
options:
class: Webgriffe\SyliusAkeneoPlugin\Entity\QueueItem
sorting:
createdAt: desc
fields:
akeneoEntity:
type: string
label: webgriffe_sylius_akeneo.ui.importer
sortable: ~
akeneoIdentifier:
type: string
label: webgriffe_sylius_akeneo.ui.identifier
sortable: ~
createdAt:
type: datetime
label: sylius.ui.created_at
sortable: ~
importedAt:
type: twig
label: webgriffe_sylius_akeneo.ui.imported
sortable: ~
options:
template: '@WebgriffeSyliusAkeneoPlugin\QueueItem\Grid\importedAt.html.twig'
errorMessage:
type: string
label: webgriffe_sylius_akeneo.ui.error_message
filters:
akeneoEntity:
type: string
label: webgriffe_sylius_akeneo.ui.importer
akeneoIdentifier:
type: string
label: webgriffe_sylius_akeneo.ui.identifier
imported:
type: exists
label: webgriffe_sylius_akeneo.ui.imported
options:
field: importedAt
errorMessage:
type: string
label: webgriffe_sylius_akeneo.ui.error_message
actions:
main: ~
item: ~
4 changes: 4 additions & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
<tag name="kernel.event_subscriber" />
</service>

<service id="webgriffe_sylius_akeneo.event_listener.admin_menu_listener" class="Webgriffe\SyliusAkeneoPlugin\Menu\AdminMenuListener">
<tag name="kernel.event_listener" event="sylius.menu.admin.main" method="addAdminMenuItems" />
</service>

<!-- Product Importer -->
<service id="webgriffe_sylius_akeneo.product.taxons_resolver" class="Webgriffe\SyliusAkeneoPlugin\Product\AlreadyExistingTaxonsResolver">
<argument type="service" id="sylius.repository.taxon" />
Expand Down
10 changes: 10 additions & 0 deletions src/Resources/translations/messages.en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
webgriffe_sylius_akeneo:
ui:
queue_items: Akeneo PIM import
manage_akeneo_queue_items: Manage Akeneo PIM import items
importer: Importer type
identifier: Identifier
imported: Imported
imported_yes: Yes, at %date%
imported_no: No
error_message: Error message
10 changes: 10 additions & 0 deletions src/Resources/translations/messages.it.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
webgriffe_sylius_akeneo:
ui:
queue_items: Importazione da Akeneo PIM
manage_akeneo_queue_items: Gestisci gli elementi di importazione da Akeneo PIM
importer: Tipo di import
identifier: Identificatore
imported: Importato
imported_yes: Si, il %date%
imported_no: No
error_message: Messaggio d'errore
11 changes: 11 additions & 0 deletions src/Resources/views/QueueItem/Grid/importedAt.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% if data %}
<span class="ui green label">
<i class="check icon"></i>
{{ 'webgriffe_sylius_akeneo.ui.imported_yes'|trans({'%date%': data|date('Y-m-d H:i:s')}) }}
</span>
{% else %}
<span class="ui red label">
<i class="remove icon"></i>
{{ 'webgriffe_sylius_akeneo.ui.imported_no'|trans }}
</span>
{% endif %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
imports:
- { resource: "@WebgriffeSyliusAkeneoPlugin/Resources/config/config.yaml" }

webgriffe_sylius_akeneo:
api_client:
base_url: 'http://demo.akeneo.com/'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
webgriffe_sylius_akeneo_plugin_admin:
resource: "@WebgriffeSyliusAkeneoPlugin/Resources/config/admin_routing.yaml"
prefix: /admin
15 changes: 15 additions & 0 deletions tests/Behat/Context/Setup/QueueContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function __construct(

/**
* @Given /^there is one item to import with identifier "([^"]*)" for the "([^"]*)" importer in the Akeneo queue$/
* @Given /^there is a not imported item with identifier "([^"]*)" for the "([^"]*)" importer in the Akeneo queue$/
*/
public function thereIsOneProductToImportWithIdentifierInTheAkeneoQueue(string $identifier, string $importer)
{
Expand All @@ -50,4 +51,18 @@ public function thereIsOneProductAssociationsToImportWithIdentifierInTheAkeneoQu
$queueItem->setCreatedAt(new \DateTime());
$this->queueItemRepository->add($queueItem);
}

/**
* @Given /^there is an already imported item with identifier "([^"]*)" for the "([^"]*)" importer in the Akeneo queue$/
*/
public function thereIsAnAlreadyImportedItemWithIdentifierForTheImporterInTheAkeneoQueue(string $identifier, string $importer)
{
/** @var QueueItemInterface $queueItem */
$queueItem = $this->queueItemFactory->createNew();
$queueItem->setAkeneoEntity($importer);
$queueItem->setAkeneoIdentifier($identifier);
$queueItem->setCreatedAt(new \DateTime());
$queueItem->setImportedAt(new \DateTime());
$this->queueItemRepository->add($queueItem);
}
}
90 changes: 90 additions & 0 deletions tests/Behat/Context/Ui/Admin/ManagingQueueItems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

declare(strict_types=1);

namespace Tests\Webgriffe\SyliusAkeneoPlugin\Behat\Context\Ui\Admin;

use Behat\Behat\Context\Context;
use Tests\Webgriffe\SyliusAkeneoPlugin\Behat\Page\Admin\QueueItem\IndexPageInterface;
use Webmozart\Assert\Assert;

final class ManagingQueueItems implements Context
{
/** @var IndexPageInterface */
private $indexPage;

public function __construct(IndexPageInterface $indexPage)
{
$this->indexPage = $indexPage;
}

/**
* @When /^I browse Akeneo queue items$/
*/
public function iBrowseAkeneoQueueItems(): void
{
$this->indexPage->open();
}

/**
* @Then /^I should see (\d+), not imported, queue items in the list$/
*/
public function iShouldSeeQueueItemsInTheList(int $numberOfItems): void
{
Assert::same($this->indexPage->countItems(), $numberOfItems);
foreach ($this->indexPage->getColumnFields('importedAt') as $columnField) {
Assert::eq($columnField, 'No');
}
}

/**
* @Given /^I choose "([^"]*)" as an imported filter$/
*/
public function iChooseAsAnImportedFilter(string $imported): void
{
$this->indexPage->chooseImportedFilter($imported);
}

/**
* @When /^I filter$/
*/
public function iFilter(): void
{
$this->indexPage->filter();
}

/**
* @Then /^I should see (\d+), imported, queue items? in the list$/
*/
public function iShouldSeeImportedQueueItemInTheList(int $numberOfItems): void
{
Assert::same($this->indexPage->countItems(), $numberOfItems);
foreach ($this->indexPage->getColumnFields('importedAt') as $columnField) {
Assert::contains($columnField, 'Yes');
}
}

/**
* @When /^I specify "([^"]*)" as an importer filter$/
*/
public function iSpecifyAsAnImporterFilter(string $importer): void
{
$this->indexPage->specifyImporterFilter($importer);
}

/**
* @Then /^I should see (\d+) queue items? in the list$/
*/
public function iShouldSeeQueueItemInTheList(int $numberOfItems): void
{
Assert::same($this->indexPage->countItems(), $numberOfItems);
}

/**
* @Given /^I specify "([^"]*)" as an identifier filter$/
*/
public function iSpecifyAsAnIdentifierFilter(string $identifier): void
{
$this->indexPage->specifyIdentifierFilter($identifier);
}
}
37 changes: 37 additions & 0 deletions tests/Behat/Page/Admin/QueueItem/IndexPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Tests\Webgriffe\SyliusAkeneoPlugin\Behat\Page\Admin\QueueItem;

use Sylius\Behat\Page\Admin\Crud\IndexPage as BaseIndexPage;

class IndexPage extends BaseIndexPage implements IndexPageInterface
{
public function chooseImportedFilter(string $imported): void
{
$this->getElement('filter_imported')->selectOption($imported);
}

public function specifyImporterFilter(string $importer): void
{
$this->getElement('filter_importer')->setValue($importer);
}

public function specifyIdentifierFilter(string $identifier): void
{
$this->getElement('filter_identifier')->setValue($identifier);
}

protected function getDefinedElements(): array
{
return array_merge(
parent::getDefinedElements(),
[
'filter_imported' => '#criteria_imported',
'filter_importer' => '#criteria_akeneoEntity_value',
'filter_identifier' => '#criteria_akeneoIdentifier_value',
]
);
}
}
16 changes: 16 additions & 0 deletions tests/Behat/Page/Admin/QueueItem/IndexPageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Tests\Webgriffe\SyliusAkeneoPlugin\Behat\Page\Admin\QueueItem;

use Sylius\Behat\Page\Admin\Crud\IndexPageInterface as BaseIndexPageInterface;

interface IndexPageInterface extends BaseIndexPageInterface
{
public function chooseImportedFilter(string $imported): void;

public function specifyImporterFilter(string $importer): void;

public function specifyIdentifierFilter(string $identifier): void;
}
Loading

0 comments on commit 3bc2144

Please sign in to comment.