Skip to content

Commit

Permalink
PS-609 add labels field on definitions, index phraseanet definition i…
Browse files Browse the repository at this point in the history
…nto labels
  • Loading branch information
4rthem committed Jan 15, 2024
1 parent 0085e35 commit 93ea7cd
Show file tree
Hide file tree
Showing 17 changed files with 231 additions and 65 deletions.
38 changes: 38 additions & 0 deletions databox/api/migrations/Version20240115123246.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240115123246 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE attribute_class ADD labels JSON DEFAULT NULL');
$this->addSql('ALTER TABLE attribute_definition ADD labels JSON DEFAULT NULL');
$this->addSql('ALTER TABLE rendition_class ADD labels JSON DEFAULT NULL');
$this->addSql('ALTER TABLE rendition_definition ADD labels JSON DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE attribute_class DROP labels');
$this->addSql('ALTER TABLE rendition_class DROP labels');
$this->addSql('ALTER TABLE attribute_definition DROP labels');
$this->addSql('ALTER TABLE rendition_definition DROP labels');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public function transform(object $data, string $resourceClass, array $context =
if (null !== $data->public) {
$object->setPublic($data->public);
}
if (null !== $data->labels) {
$object->setLabels($data->labels);
}

return $object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public function transform(object $data, string $resourceClass, array $context =
if (null !== $data->translatable) {
$object->setTranslatable($data->translatable);
}
if (null !== $data->labels) {
$object->setLabels($data->labels);
}

return $object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public function transform(object $data, string $resourceClass, array $context =
if (null !== $data->priority) {
$object->setPriority($data->priority);
}
if (null !== $data->labels) {
$object->setLabels($data->labels);
}

return $object;
}
Expand Down
7 changes: 6 additions & 1 deletion databox/api/src/Api/Model/Input/AttributeClassInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ class AttributeClassInput
public $editable;

/**
* @var string
* @var string|null
*/
public $key;

/**
* @var array|null
*/
public $labels;
}
7 changes: 6 additions & 1 deletion databox/api/src/Api/Model/Input/AttributeDefinitionInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ class AttributeDefinitionInput
public $fallback;

/**
* @var string
* @var string|null
*/
public $key;

/**
* @var array|null
*/
public $labels;
}
6 changes: 6 additions & 0 deletions databox/api/src/Api/Model/Input/RenditionDefinitionInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,10 @@ class RenditionDefinitionInput
*/
#[Groups([RenditionDefinition::GROUP_WRITE])]
public $key;

/**
* @var array|null
*/
#[Groups([RenditionDefinition::GROUP_WRITE])]
public $labels;
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class AttributeDefinitionOutput extends AbstractUuidOutput
*/
public ?string $key = null;

#[Groups([AttributeDefinition::GROUP_READ])]
public ?array $labels = null;

#[Groups([AttributeDefinition::GROUP_LIST])]
public ?bool $canEdit = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function transform(object $data, string $outputClass, array &$context = [
$output->fallback = $data->getFallback();
$output->initialValues = $data->getInitialValues();
$output->key = $data->getKey();
$output->labels = $data->getLabels();
$output->canEdit = $data->getClass()->isEditable()
|| $this->isGranted(PermissionInterface::EDIT, $data->getClass());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

use Alchemy\AdminBundle\Controller\AbstractAdminCrudController;
use Alchemy\AdminBundle\Field\IdField;
use Alchemy\AdminBundle\Field\JsonField;
use App\Attribute\AttributeTypeRegistry;
use App\Entity\Core\AttributeDefinition;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField;
Expand All @@ -30,11 +33,17 @@ public static function getEntityFqcn(): string
return AttributeDefinition::class;
}

public function configureActions(Actions $actions): Actions
{
return $actions
->add(Crud::PAGE_INDEX, Action::DETAIL);
}

public function configureCrud(Crud $crud): Crud
{
return parent::configureCrud($crud)
->setEntityLabelInSingular('AttributeDefinition')
->setEntityLabelInPlural('AttributeDefinition')
->setEntityLabelInSingular('Attribute Definition')
->setEntityLabelInPlural('Attribute Definitions')
->setSearchFields(['id', 'name', 'slug', 'fileType', 'fieldType', 'searchBoost', 'fallback', 'key', 'position'])
->setPaginatorPageSize(100);
}
Expand All @@ -56,40 +65,55 @@ public function configureFields(string $pageName): iterable
$fileTypeChoices[$name] = $name;
}

$workspace = AssociationField::new('workspace');
$class = AssociationField::new('class');
$name = TextField::new('name');
$fileType = TextField::new('fileType');
$fieldType = ChoiceField::new('fieldType')->setChoices($fileTypeChoices);
$allowInvalid = BooleanField::new('allowInvalid')->renderAsSwitch(false);
$translatable = BooleanField::new('translatable')->renderAsSwitch(false);
$sortable = BooleanField::new('sortable');
$multiple = BooleanField::new('multiple')->renderAsSwitch(false);
$searchable = BooleanField::new('searchable')->renderAsSwitch(false);
$searchBoost = IntegerField::new('searchBoost');
$initialValuesAll = TextareaField::new('initialValuesAll');
$fallbackAll = TextareaField::new('fallbackAll')->setHelp('e.g. Dimensions are: {{ file.width }}x{{ file.height }}');
$fallbackEN = TextareaField::new('fallbackEN', 'Fallback value template EN')->setHelp('e.g. Dimensions are: {{ file.width }}x{{ file.height }}');
$fallbackFR = TextareaField::new('fallbackFR', 'Fallback value template FR')->setHelp('ex. Les dimensions sont : {{ file.width }}x{{ file.height }}');
$id = IdField::new();
$slug = TextField::new('slug');
$facetEnabled = Field::new('facetEnabled');
$fallback = ArrayField::new('fallback');
$key = TextField::new('key');
$position = IntegerField::new('position');
$createdAt = DateTimeField::new('createdAt');
$updatedAt = DateTimeField::new('updatedAt');
$attributes = AssociationField::new('attributes');

if (Crud::PAGE_INDEX === $pageName) {
return [$id, $workspace, $class, $name, $fileType, $fieldType, $multiple, $facetEnabled, $sortable, $searchable, $createdAt];
} elseif (Crud::PAGE_DETAIL === $pageName) {
return [$id, $name, $slug, $fileType, $fieldType, $searchable, $facetEnabled, $sortable, $translatable, $multiple, $allowInvalid, $searchBoost, $fallback, $key, $position, $createdAt, $updatedAt, $workspace, $class, $attributes];
} elseif (Crud::PAGE_NEW === $pageName) {
return [$workspace, $class, $name, $fileType, $fieldType, $allowInvalid, $sortable, $translatable, $multiple, $searchable, $searchBoost, $initialValuesAll, $fallbackAll, $fallbackEN, $fallbackFR];
} elseif (Crud::PAGE_EDIT === $pageName) {
return [$workspace, $class, $name, $fileType, $fieldType, $allowInvalid, $sortable, $translatable, $multiple, $searchable, $searchBoost, $initialValuesAll, $fallbackAll, $fallbackEN, $fallbackFR];
}
yield IdField::new();
yield TextField::new('name');
yield TextField::new('slug');
yield AssociationField::new('workspace');
yield AssociationField::new('class');
yield TextField::new('fileType');
yield ChoiceField::new('fieldType')
->setChoices($fileTypeChoices);
yield BooleanField::new('allowInvalid')
->hideOnIndex()
->renderAsSwitch(false);
yield BooleanField::new('translatable')
->hideOnIndex()
->renderAsSwitch(false);
yield BooleanField::new('sortable')
->hideOnIndex();
yield BooleanField::new('multiple')
->renderAsSwitch(false);
yield BooleanField::new('searchable')
->hideOnIndex()
->renderAsSwitch(false);
yield IntegerField::new('searchBoost')
->hideOnIndex();
yield TextareaField::new('initialValuesAll')
->hideOnIndex();
yield TextareaField::new('fallbackAll')
->hideOnIndex()
->setHelp('e.g. Dimensions are: {{ file.width }}x{{ file.height }}');
yield TextareaField::new('fallbackEN', 'Fallback value template EN')
->hideOnIndex()
->setHelp('e.g. Dimensions are: {{ file.width }}x{{ file.height }}');
yield TextareaField::new('fallbackFR', 'Fallback value template FR')
->hideOnIndex()
->setHelp('ex. Les dimensions sont : {{ file.width }}x{{ file.height }}');
yield Field::new('facetEnabled')
->hideOnIndex();
yield ArrayField::new('fallback')
->hideOnIndex();
yield TextField::new('key')
->hideOnIndex();
yield IntegerField::new('position');
yield DateTimeField::new('createdAt')
->hideOnForm();
yield DateTimeField::new('updatedAt')
->hideOnForm();
yield JsonField::new('labels')
->hideOnForm()
->hideOnIndex()
;

return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

use Alchemy\AdminBundle\Controller\AbstractAdminCrudController;
use Alchemy\AdminBundle\Field\IdField;
use Alchemy\AdminBundle\Field\JsonField;
use App\Entity\Core\RenditionDefinition;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
Expand All @@ -22,6 +25,12 @@ public static function getEntityFqcn(): string
return RenditionDefinition::class;
}

public function configureActions(Actions $actions): Actions
{
return $actions
->add(Crud::PAGE_INDEX, Action::DETAIL);
}

public function configureCrud(Crud $crud): Crud
{
return parent::configureCrud($crud)
Expand All @@ -40,33 +49,35 @@ public function configureFilters(Filters $filters): Filters

public function configureFields(string $pageName): iterable
{
$id = IdField::new();
$workspace = AssociationField::new('workspace');
$name = TextField::new('name');
$key = TextField::new('key');
$class = AssociationField::new('class');
$pickSourceFile = Field::new('pickSourceFile');
$useAsOriginal = Field::new('useAsOriginal');
$useAsPreview = Field::new('useAsPreview');
$useAsThumbnail = Field::new('useAsThumbnail');
$useAsThumbnailActive = Field::new('useAsThumbnailActive', 'Thumb Active');
$priority = IntegerField::new('priority');
$download = Field::new('download');
$definition = TextareaField::new('definition');
$createdAt = DateTimeField::new('createdAt');
$updatedAt = DateTimeField::new('updatedAt');
$renditions = AssociationField::new('renditions');

if (Crud::PAGE_INDEX === $pageName) {
return [$id, $workspace, $name, $class, $pickSourceFile, $useAsOriginal, $useAsPreview, $useAsThumbnail, $useAsThumbnailActive, $priority, $createdAt];
} elseif (Crud::PAGE_DETAIL === $pageName) {
return [$id, $name, $key, $download, $pickSourceFile, $useAsOriginal, $useAsPreview, $useAsThumbnail, $useAsThumbnailActive, $definition, $priority, $createdAt, $updatedAt, $workspace, $class, $renditions];
} elseif (Crud::PAGE_NEW === $pageName) {
return [$workspace, $name, $class, $pickSourceFile, $useAsOriginal, $useAsPreview, $useAsThumbnail, $useAsThumbnailActive, $priority];
} elseif (Crud::PAGE_EDIT === $pageName) {
return [$workspace, $name, $key, $class, $pickSourceFile, $useAsOriginal, $useAsPreview, $useAsThumbnail, $useAsThumbnailActive, $priority];
}
yield IdField::new();
yield TextField::new('name');
yield AssociationField::new('class');
yield AssociationField::new('workspace');
yield TextField::new('key')
->hideOnIndex()
;
yield Field::new('pickSourceFile')
->hideOnIndex();
yield Field::new('useAsOriginal');
yield Field::new('useAsPreview');
yield Field::new('useAsThumbnail');
yield Field::new('useAsThumbnailActive', 'Thumb Active')
->hideOnIndex();
yield IntegerField::new('priority');
yield Field::new('download')
->hideOnIndex()
;
// yield TextareaField::new('definition')
// ->hideOnIndex()
// ;
yield DateTimeField::new('createdAt')
->hideOnForm();
yield DateTimeField::new('updatedAt')
->hideOnForm();

return [];
yield JsonField::new('labels')
->hideOnForm()
->hideOnIndex()
;
}
}
14 changes: 14 additions & 0 deletions databox/api/src/Entity/Core/AttributeClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class AttributeClass extends AbstractUuidEntity implements AclObjectInterface, \
#[ORM\Column(type: Types::STRING, length: 150, nullable: true)]
private ?string $key = null;

#[Groups([AttributeClass::GROUP_READ])]
#[ORM\Column(type: Types::JSON, nullable: true)]
private ?array $labels = null;

public function __construct()
{
parent::__construct();
Expand Down Expand Up @@ -139,4 +143,14 @@ public function setKey(?string $key): void
{
$this->key = $key;
}

public function getLabels(): ?array
{
return $this->labels;
}

public function setLabels(?array $labels): void
{
$this->labels = $labels;
}
}
13 changes: 13 additions & 0 deletions databox/api/src/Entity/Core/AttributeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ class AttributeDefinition extends AbstractUuidEntity implements \Stringable
#[ORM\Column(type: Types::STRING, length: 150, nullable: true)]
private ?string $key = null;

#[ORM\Column(type: Types::JSON, nullable: true)]
private ?array $labels = null;

#[Groups([RenditionDefinition::GROUP_LIST, RenditionDefinition::GROUP_READ, RenditionDefinition::GROUP_WRITE])]
#[ORM\Column(type: Types::SMALLINT, nullable: false)]
#[ApiProperty(security: "is_granted('READ_ADMIN', object)")]
Expand Down Expand Up @@ -398,4 +401,14 @@ public function setSortable(bool $sortable): void
{
$this->sortable = $sortable;
}

public function getLabels(): ?array
{
return $this->labels;
}

public function setLabels(?array $labels): void
{
$this->labels = $labels;
}
}
Loading

0 comments on commit 93ea7cd

Please sign in to comment.