From 93ea7cd43b1c0609b8e781728d1f719cf20bf805 Mon Sep 17 00:00:00 2001 From: Arthur de Moulins Date: Mon, 15 Jan 2024 14:10:27 +0100 Subject: [PATCH] PS-609 add labels field on definitions, index phraseanet definition into labels --- .../api/migrations/Version20240115123246.php | 38 ++++++++ .../AttributeClassInputTransformer.php | 3 + .../AttributeDefinitionInputTransformer.php | 3 + .../RenditionDefinitionInputTransformer.php | 3 + .../Api/Model/Input/AttributeClassInput.php | 7 +- .../Model/Input/AttributeDefinitionInput.php | 7 +- .../Model/Input/RenditionDefinitionInput.php | 6 ++ .../Output/AttributeDefinitionOutput.php | 3 + .../AttributeDefinitionOutputTransformer.php | 1 + .../AttributeDefinitionCrudController.php | 96 ++++++++++++------- .../RenditionDefinitionCrudController.php | 65 +++++++------ .../api/src/Entity/Core/AttributeClass.php | 14 +++ .../src/Entity/Core/AttributeDefinition.php | 13 +++ .../api/src/Entity/Core/RenditionClass.php | 14 +++ .../src/Entity/Core/RenditionDefinition.php | 14 +++ databox/indexer/src/databox/types.d.ts | 3 + .../src/handlers/phraseanet/indexer.ts | 6 ++ 17 files changed, 231 insertions(+), 65 deletions(-) create mode 100644 databox/api/migrations/Version20240115123246.php diff --git a/databox/api/migrations/Version20240115123246.php b/databox/api/migrations/Version20240115123246.php new file mode 100644 index 000000000..9ca3b2252 --- /dev/null +++ b/databox/api/migrations/Version20240115123246.php @@ -0,0 +1,38 @@ +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'); + } +} diff --git a/databox/api/src/Api/InputTransformer/AttributeClassInputTransformer.php b/databox/api/src/Api/InputTransformer/AttributeClassInputTransformer.php index 868f91f76..ef202d72e 100644 --- a/databox/api/src/Api/InputTransformer/AttributeClassInputTransformer.php +++ b/databox/api/src/Api/InputTransformer/AttributeClassInputTransformer.php @@ -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; } diff --git a/databox/api/src/Api/InputTransformer/AttributeDefinitionInputTransformer.php b/databox/api/src/Api/InputTransformer/AttributeDefinitionInputTransformer.php index 08abf9aaa..62714ce49 100644 --- a/databox/api/src/Api/InputTransformer/AttributeDefinitionInputTransformer.php +++ b/databox/api/src/Api/InputTransformer/AttributeDefinitionInputTransformer.php @@ -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; } diff --git a/databox/api/src/Api/InputTransformer/RenditionDefinitionInputTransformer.php b/databox/api/src/Api/InputTransformer/RenditionDefinitionInputTransformer.php index 704186ae5..26082b78b 100644 --- a/databox/api/src/Api/InputTransformer/RenditionDefinitionInputTransformer.php +++ b/databox/api/src/Api/InputTransformer/RenditionDefinitionInputTransformer.php @@ -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; } diff --git a/databox/api/src/Api/Model/Input/AttributeClassInput.php b/databox/api/src/Api/Model/Input/AttributeClassInput.php index bcfc12d29..e927219e5 100644 --- a/databox/api/src/Api/Model/Input/AttributeClassInput.php +++ b/databox/api/src/Api/Model/Input/AttributeClassInput.php @@ -31,7 +31,12 @@ class AttributeClassInput public $editable; /** - * @var string + * @var string|null */ public $key; + + /** + * @var array|null + */ + public $labels; } diff --git a/databox/api/src/Api/Model/Input/AttributeDefinitionInput.php b/databox/api/src/Api/Model/Input/AttributeDefinitionInput.php index c5dcb19c5..db5bae076 100644 --- a/databox/api/src/Api/Model/Input/AttributeDefinitionInput.php +++ b/databox/api/src/Api/Model/Input/AttributeDefinitionInput.php @@ -80,7 +80,12 @@ class AttributeDefinitionInput public $fallback; /** - * @var string + * @var string|null */ public $key; + + /** + * @var array|null + */ + public $labels; } diff --git a/databox/api/src/Api/Model/Input/RenditionDefinitionInput.php b/databox/api/src/Api/Model/Input/RenditionDefinitionInput.php index d4e17a03e..aabac4036 100644 --- a/databox/api/src/Api/Model/Input/RenditionDefinitionInput.php +++ b/databox/api/src/Api/Model/Input/RenditionDefinitionInput.php @@ -82,4 +82,10 @@ class RenditionDefinitionInput */ #[Groups([RenditionDefinition::GROUP_WRITE])] public $key; + + /** + * @var array|null + */ + #[Groups([RenditionDefinition::GROUP_WRITE])] + public $labels; } diff --git a/databox/api/src/Api/Model/Output/AttributeDefinitionOutput.php b/databox/api/src/Api/Model/Output/AttributeDefinitionOutput.php index 6627c72db..03ad036e8 100644 --- a/databox/api/src/Api/Model/Output/AttributeDefinitionOutput.php +++ b/databox/api/src/Api/Model/Output/AttributeDefinitionOutput.php @@ -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; diff --git a/databox/api/src/Api/OutputTransformer/AttributeDefinitionOutputTransformer.php b/databox/api/src/Api/OutputTransformer/AttributeDefinitionOutputTransformer.php index 6a1ce0880..ca1f46fac 100644 --- a/databox/api/src/Api/OutputTransformer/AttributeDefinitionOutputTransformer.php +++ b/databox/api/src/Api/OutputTransformer/AttributeDefinitionOutputTransformer.php @@ -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()); diff --git a/databox/api/src/Controller/Admin/AttributeDefinitionCrudController.php b/databox/api/src/Controller/Admin/AttributeDefinitionCrudController.php index 547a7b0be..19891599f 100644 --- a/databox/api/src/Controller/Admin/AttributeDefinitionCrudController.php +++ b/databox/api/src/Controller/Admin/AttributeDefinitionCrudController.php @@ -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; @@ -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); } @@ -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 []; } diff --git a/databox/api/src/Controller/Admin/RenditionDefinitionCrudController.php b/databox/api/src/Controller/Admin/RenditionDefinitionCrudController.php index 852274cfe..eeb4eb02d 100644 --- a/databox/api/src/Controller/Admin/RenditionDefinitionCrudController.php +++ b/databox/api/src/Controller/Admin/RenditionDefinitionCrudController.php @@ -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; @@ -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) @@ -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() + ; } } diff --git a/databox/api/src/Entity/Core/AttributeClass.php b/databox/api/src/Entity/Core/AttributeClass.php index fff3c7fbe..75004a9ea 100644 --- a/databox/api/src/Entity/Core/AttributeClass.php +++ b/databox/api/src/Entity/Core/AttributeClass.php @@ -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(); @@ -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; + } } diff --git a/databox/api/src/Entity/Core/AttributeDefinition.php b/databox/api/src/Entity/Core/AttributeDefinition.php index 39ba15de5..0052c2245 100644 --- a/databox/api/src/Entity/Core/AttributeDefinition.php +++ b/databox/api/src/Entity/Core/AttributeDefinition.php @@ -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)")] @@ -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; + } } diff --git a/databox/api/src/Entity/Core/RenditionClass.php b/databox/api/src/Entity/Core/RenditionClass.php index e4eeb4cfc..c3f632898 100644 --- a/databox/api/src/Entity/Core/RenditionClass.php +++ b/databox/api/src/Entity/Core/RenditionClass.php @@ -65,6 +65,10 @@ class RenditionClass extends AbstractUuidEntity implements \Stringable #[ORM\Column(type: Types::BOOLEAN, nullable: false)] private bool $public = false; + #[Groups([RenditionClass::GROUP_LIST, RenditionClass::GROUP_READ])] + #[ORM\Column(type: Types::JSON, nullable: true)] + private ?array $labels = null; + /** * @var RenditionDefinition[] */ @@ -101,4 +105,14 @@ public function setPublic(bool $public): void { $this->public = $public; } + + public function getLabels(): ?array + { + return $this->labels; + } + + public function setLabels(?array $labels): void + { + $this->labels = $labels; + } } diff --git a/databox/api/src/Entity/Core/RenditionDefinition.php b/databox/api/src/Entity/Core/RenditionDefinition.php index 8f016ba08..a115a1f15 100644 --- a/databox/api/src/Entity/Core/RenditionDefinition.php +++ b/databox/api/src/Entity/Core/RenditionDefinition.php @@ -142,6 +142,10 @@ class RenditionDefinition extends AbstractUuidEntity implements \Stringable #[ApiProperty(security: self::GRANT_ADMIN_PROP)] private ?string $definition = ''; + #[Groups([RenditionDefinition::GROUP_READ])] + #[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: self::GRANT_ADMIN_PROP)] @@ -274,4 +278,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; + } } diff --git a/databox/indexer/src/databox/types.d.ts b/databox/indexer/src/databox/types.d.ts index d1968dcd8..c314ab04b 100644 --- a/databox/indexer/src/databox/types.d.ts +++ b/databox/indexer/src/databox/types.d.ts @@ -53,6 +53,8 @@ export type RenditionClass = { name: string; }; +type Labels = Record; + export type AttributeDefinition = { id: string; multiple: boolean; @@ -62,6 +64,7 @@ export type AttributeDefinition = { fieldType: string; workspace: string; class: string; + labels?: Labels | undefined; }; export type AttributeClass = { diff --git a/databox/indexer/src/handlers/phraseanet/indexer.ts b/databox/indexer/src/handlers/phraseanet/indexer.ts index 719c88ae2..3fca98d7b 100644 --- a/databox/indexer/src/handlers/phraseanet/indexer.ts +++ b/databox/indexer/src/handlers/phraseanet/indexer.ts @@ -90,6 +90,9 @@ export const phraseanetIndexer: IndexIterator = attributeTypesEquivalence[m.type] || m.type, workspace: `/workspaces/${workspaceId}`, class: attrClassIndex[defaultPublicClass]['@id'], + labels: { + phraseanetDefinition: m, + }, } ); } @@ -127,6 +130,9 @@ export const phraseanetIndexer: IndexIterator = useAsThumbnailActive: sd.name === 'thumbnailgif', priority: 0, workspace: `/workspaces/${workspaceId}`, + labels: { + phraseanetDefinition: sd, + }, }); }