Skip to content

Commit

Permalink
Asset list (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem authored Apr 15, 2024
1 parent 55879fe commit 1a2ed2e
Show file tree
Hide file tree
Showing 54 changed files with 973 additions and 672 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ jobs:
steps:
- name: Install mkcert
run: |
sudo apt-get update
sudo apt-get install wget libnss3-tools
wget https://github.com/FiloSottile/mkcert/releases/download/v1.4.3/mkcert-v1.4.3-linux-amd64
sudo mv mkcert-v1.4.3-linux-amd64 /usr/bin/mkcert
Expand Down
4 changes: 2 additions & 2 deletions databox/api/src/Admin/Field/IntegrationChoiceField.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use App\Integration\IntegrationRegistry;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;

class IntegrationChoiceField
final readonly class IntegrationChoiceField
{
public function __construct(private readonly IntegrationRegistry $integrationRegistry)
public function __construct(private IntegrationRegistry $integrationRegistry)
{
}

Expand Down
13 changes: 9 additions & 4 deletions databox/api/src/Admin/Field/PrivacyField.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@

use App\Entity\Core\WorkspaceItemPrivacyInterface;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use Symfony\Contracts\Translation\TranslatorInterface;

class PrivacyField
final readonly class PrivacyField
{
public static function new(string $propertyName, ?string $label = null): ChoiceField
public function __construct(private TranslatorInterface $translator)
{
}

public function create(string $propertyName, ?string $label = null): ChoiceField
{
$choices = [];
foreach (WorkspaceItemPrivacyInterface::LABELS as $value => $l) {
$choices[$l] = $value;
foreach (WorkspaceItemPrivacyInterface::KEYS as $value => $l) {
$choices[$this->translator->trans(sprintf('privacy.%s', $l))] = $value;
}

return ChoiceField::new($propertyName, $label)->setChoices($choices);
Expand Down
3 changes: 2 additions & 1 deletion databox/api/src/Controller/Admin/AssetCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static function getEntityFqcn(): string
public function __construct(
private readonly UserChoiceField $userChoiceField,
private readonly WorkflowOrchestrator $workflowOrchestrator,
private readonly PrivacyField $privacyField,
) {
}

Expand Down Expand Up @@ -90,7 +91,7 @@ public function configureFields(string $pageName): iterable
$title = TextField::new('title');
$workspace = AssociationField::new('workspace');
$tags = AssociationField::new('tags');
$privacy = PrivacyField::new('privacy');
$privacy = $this->privacyField->create('privacy');
$ownerUser = $this->userChoiceField->create('ownerId', 'Owner');
$id = IdField::new();
$key = TextField::new('key');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public static function getEntityFqcn(): string
return AssetDataTemplate::class;
}

public function __construct(private readonly UserChoiceField $userChoiceField)
{
public function __construct(
private readonly UserChoiceField $userChoiceField,
private readonly PrivacyField $privacyField,
) {
}

public function configureCrud(Crud $crud): Crud
Expand All @@ -50,7 +52,7 @@ public function configureFields(string $pageName): iterable
$workspace = AssociationField::new('workspace');
$collection = AssociationField::new('collection');
$tags = AssociationField::new('tags');
$privacy = PrivacyField::new('privacy');
$privacy = $this->privacyField->create('privacy');
$ownerUser = $this->userChoiceField->create('ownerId', 'Owner');
$public = BooleanField::new('public');
$includeCollectionChildren = BooleanField::new('includeCollectionChildren', 'Include children');
Expand Down
22 changes: 8 additions & 14 deletions databox/api/src/Controller/Admin/CollectionCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
use Alchemy\AdminBundle\Controller\Acl\AbstractAclAdminCrudController;
use Alchemy\AdminBundle\Field\IdField;
use Alchemy\AdminBundle\Field\UserChoiceField;
use App\Admin\Field\PrivacyField;
use App\Entity\Core\Collection;
use App\Entity\Core\WorkspaceItemPrivacyInterface;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Filter\EntityFilter;

class CollectionCrudController extends AbstractAclAdminCrudController
{
public function __construct(private readonly UserChoiceField $userChoiceField)
{
public function __construct(
private readonly UserChoiceField $userChoiceField,
private readonly PrivacyField $privacyField,
) {
}

public static function getEntityFqcn(): string
Expand All @@ -44,16 +44,10 @@ public function configureFilters(Filters $filters): Filters

public function configureFields(string $pageName): iterable
{
$privacyChoices = [];
foreach (WorkspaceItemPrivacyInterface::LABELS as $value => $label) {
$privacyChoices[$label] = $value;
}

$title = TextField::new('title');
$workspace = AssociationField::new('workspace');
$parent = AssociationField::new('parent');
$privacyTxt = IntegerField::new('privacy')->setTemplatePath('admin/field_privacy.html.twig');
$privacy = ChoiceField::new('privacy')->setChoices($privacyChoices);
$privacy = $this->privacyField->create('privacy');
$ownerId = TextField::new('ownerId');
$ownerUser = $this->userChoiceField->create('ownerId', 'Owner');
$id = IdField::new();
Expand All @@ -67,9 +61,9 @@ public function configureFields(string $pageName): iterable
$referenceAssets = AssociationField::new('referenceAssets');

if (Crud::PAGE_INDEX === $pageName) {
return [$id, $title, $parent, $workspace, $privacyTxt, $createdAt];
return [$id, $title, $parent, $workspace, $privacy, $createdAt];
} elseif (Crud::PAGE_DETAIL === $pageName) {
return [$id, $title, $ownerId, $key, $createdAt, $updatedAt, $deletedAt, $locale, $privacyTxt, $parent, $children, $assets, $referenceAssets, $workspace];
return [$id, $title, $ownerId, $key, $createdAt, $updatedAt, $deletedAt, $locale, $privacy, $parent, $children, $assets, $referenceAssets, $workspace];
} elseif (Crud::PAGE_NEW === $pageName) {
return [$title, $workspace, $parent, $privacy, $ownerUser];
} elseif (Crud::PAGE_EDIT === $pageName) {
Expand Down
6 changes: 3 additions & 3 deletions databox/api/src/Elasticsearch/BasketSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ public function search(

/** @var FantaPaginatorAdapter $adapter */
$adapter = $this->finder->findPaginated($query)->getAdapter();
$result = new Pagerfanta(new FilteredPager(fn(Basket $basket): bool => $this->isGranted(AbstractVoter::READ, $basket), $adapter));
$result->setMaxPerPage((int)$limit);
$result = new Pagerfanta(new FilteredPager(fn (Basket $basket): bool => $this->isGranted(AbstractVoter::READ, $basket), $adapter));
$result->setMaxPerPage((int) $limit);
if ($options['page'] ?? false) {
$result->setAllowOutOfRangePages(true);
$result->setCurrentPage((int)$options['page']);
$result->setCurrentPage((int) $options['page']);
}
$result->getCurrentPageResults();

Expand Down
9 changes: 7 additions & 2 deletions databox/api/src/Elasticsearch/Facet/PrivacyFacet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@

use App\Entity\Core\Asset;
use App\Entity\Core\WorkspaceItemPrivacyInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

final class PrivacyFacet extends AbstractLabelledFacet
{
public function __construct(private readonly TranslatorInterface $translator)
{
}

/**
* @param int $value
*/
public function resolveLabel($value): string
{
return WorkspaceItemPrivacyInterface::LABELS[$value];
return $this->translator->trans(sprintf('privacy.%s', WorkspaceItemPrivacyInterface::KEYS[$value]));
}

protected function resolveKey($value): string
Expand Down Expand Up @@ -44,6 +49,6 @@ protected function getAggregationTitle(): string

protected function getAggregationSize(): int
{
return count(WorkspaceItemPrivacyInterface::LABELS);
return count(WorkspaceItemPrivacyInterface::KEYS);
}
}
14 changes: 13 additions & 1 deletion databox/api/src/Elasticsearch/Facet/TagFacet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@

namespace App\Elasticsearch\Facet;

use Alchemy\CoreBundle\Util\LocaleUtil;
use App\Api\Traits\UserLocaleTrait;
use App\Entity\Core\Asset;
use App\Entity\Core\Tag;

final class TagFacet extends AbstractEntityFacet
{
use UserLocaleTrait;

/**
* @param Tag $value
*/
public function resolveItem($value): array
{
return [
'name' => $value->getName(),
'name' => $this->resolveLabel($value),
'color' => $value->getColor(),
];
}
Expand All @@ -25,6 +29,14 @@ public function resolveItem($value): array
*/
protected function resolveLabel($value): string
{
$preferredLocales = $this->getPreferredLocales($value->getWorkspace());

$translations = $value->getTranslations()['name'] ?? [];
$key = LocaleUtil::getBestLocale(array_keys($translations), $preferredLocales);
if (null !== $key) {
return $translations[$key];
}

return $value->getName();
}

Expand Down
14 changes: 7 additions & 7 deletions databox/api/src/Entity/Core/WorkspaceItemPrivacyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ interface WorkspaceItemPrivacyInterface
// Public to everyone
public const PUBLIC = 5;

public const LABELS = [
WorkspaceItemPrivacyInterface::SECRET => 'Secret',
WorkspaceItemPrivacyInterface::PRIVATE_IN_WORKSPACE => 'Private in workspace',
WorkspaceItemPrivacyInterface::PUBLIC_IN_WORKSPACE => 'Public in workspace',
WorkspaceItemPrivacyInterface::PRIVATE => 'Private',
WorkspaceItemPrivacyInterface::PUBLIC_FOR_USERS => 'Public for users',
WorkspaceItemPrivacyInterface::PUBLIC => 'Public',
public const KEYS = [
WorkspaceItemPrivacyInterface::SECRET => 'secret',
WorkspaceItemPrivacyInterface::PRIVATE_IN_WORKSPACE => 'private_in_workspace',
WorkspaceItemPrivacyInterface::PUBLIC_IN_WORKSPACE => 'public_in_workspace',
WorkspaceItemPrivacyInterface::PRIVATE => 'private',
WorkspaceItemPrivacyInterface::PUBLIC_FOR_USERS => 'public_for_users',
WorkspaceItemPrivacyInterface::PUBLIC => 'public',
];
}
25 changes: 0 additions & 25 deletions databox/api/src/Form/PrivacyChoiceType.php

This file was deleted.

26 changes: 0 additions & 26 deletions databox/api/src/Listener/LocaleListener.php

This file was deleted.

8 changes: 8 additions & 0 deletions databox/api/translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ field_type:
date: Date
date_time: Date & Time
geo_point: Geo point

privacy:
secret: Secret
private_in_workspace: Private in workspace
public_in_workspace: Public in workspace
private: Private
public_for_users: Public for users
public: Public
23 changes: 23 additions & 0 deletions databox/api/translations/messages.fr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
field_type:
types:
text: Text
textarea: Textarea
json: JSON
ip: IP
code: Code
html: HTML
boolean: Boolean
color: Color
keyword: Keyword
number: Number
date: Date
date_time: Date & Time
geo_point: Geo point

privacy:
secret: Secret
private_in_workspace: Privé dans l'espace de travail
public_in_workspace: Public dans l'espace de travail
private: Privé
public_for_users: Ouvert aux utilisateurs
public: Ouvert
1 change: 0 additions & 1 deletion databox/client/src/classes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export enum Classes {
ellipsisText = 'ellipsis-text',
}
Loading

0 comments on commit 1a2ed2e

Please sign in to comment.