Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add status icons to list #41

Merged
merged 4 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions Metadata/ListMetadataLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\AutomationBundle\Metadata;

use Sulu\Bundle\AdminBundle\Metadata\ListMetadata\FieldMetadata;
use Sulu\Bundle\AdminBundle\Metadata\ListMetadata\ListMetadata;
use Sulu\Bundle\AdminBundle\Metadata\ListMetadata\ListMetadataLoaderInterface;
use Sulu\Bundle\AdminBundle\Metadata\ListMetadata\XmlListMetadataLoader;
use Sulu\Bundle\AdminBundle\Metadata\MetadataInterface;

class ListMetadataLoader implements ListMetadataLoaderInterface
{
/**
* @var XmlListMetadataLoader
*/
private $xmlListMetadataLoader;

public function __construct(XmlListMetadataLoader $xmlListMetadataLoader)
{
$this->xmlListMetadataLoader = $xmlListMetadataLoader;
}

/**
* @param mixed[] $metadataOptions
*/
public function getMetadata(string $key, string $locale, array $metadataOptions = []): ?MetadataInterface
{
if ('tasks' !== $key) {
return null;
}

if (!method_exists(FieldMetadata::class, 'setTransformerTypeParameters')) {
return null;
}

$list = $this->xmlListMetadataLoader->getMetadata($key, $locale, $metadataOptions);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this 👍


if (!$list instanceof ListMetadata) {
return $list;
}

foreach ($list->getFields() as $field) {
if ('status' !== $field->getName()) {
continue;
}

$field->setType('icon');
$field->setVisibility('always');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the status not also be displayed always also when not having the status with icons /cc @wachterjohannes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right - @luca-rath can you add this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be okay for me, but i wanted to keep it like it was before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its the most important information on the list so it should always be displayed

$field->setTransformerTypeParameters([
'mapping' => [
'planned' => 'su-clock',
'running' => 'su-process',
'completed' => [
'icon' => 'su-check-circle',
'color' => '#6ac86b',
],
'failed' => [
'icon' => 'su-ban',
'color' => '#cf3939',
],
],
]);

break;
}

return $list;
}
}
6 changes: 6 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
<tag name="sulu_admin.form_metadata_loader"/>
</service>

<service id="sulu_automation.metadata.list_metadata_loader" class="Sulu\Bundle\AutomationBundle\Metadata\ListMetadataLoader">
<argument type="service" id="sulu_admin.xml_list_metadata_loader"/>

<tag name="sulu_admin.list_metadata_loader" priority="1024"/>
</service>

<service id="sulu_automation.admin" class="Sulu\Bundle\AutomationBundle\Admin\AutomationAdmin">
<argument type="service" id="sulu_admin.view_builder_factory"/>
<argument type="service" id="sulu_core.webspace.webspace_manager"/>
Expand Down