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

Admin improvements #31

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ See [keep a changelog](https://keepachangelog.com/en/1.0.0/) for information abo

## [Unreleased]

- [PR-31](https://github.com/itk-dev/aapodwalk_api/pull/31)
Admin improvements
- [PR-28](https://github.com/itk-dev/aapodwalk_api/pull/28)
Route edit UX. Sticky content header fix.
- [PR-25](https://github.com/itk-dev/aapodwalk_api/pull/25)
Expand Down
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,11 @@ See [Serving Assets in dev vs
prod](https://symfony.com/doc/current/frontend/asset_mapper.html#serving-assets-in-dev-vs-prod) for details on how to
handle assets for the `prod` environment.

Check the assets

`docker compose exec phpfpm bin/console biomejs:check .`

Apply coding style to the assets

`docker compose exec phpfpm bin/console biomejs:check . --write`
Apply and check coding standards for assets:

``` shell
task coding-standards:assets:check
```

## Commands

Expand Down
22 changes: 22 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ tasks:
- docker run --volume "$PWD:/code" --rm pipelinecomponents/yamllint yamllint fixtures/
- task console -- biomejs:check .

coding-standards:assets:apply:
desc: "Apply coding standards for assets"
cmds:
- task console -- biomejs:check . --write

coding-standards:assets:check:
desc: "Apply and check coding standards for assets"
cmds:
- task: coding-standards:assets:apply
- task console -- biomejs:check .

coding-standards:markdown:apply:
desc: "Apply coding standards for Markdown"
cmds:
- docker run --rm --volume "$PWD:/md" peterdavehello/markdownlint markdownlint '**/*.md' --fix

coding-standards:markdown:check:
desc: "Apply and check coding standards for Markdown"
cmds:
- task: coding-standards:markdown:apply
- docker run --rm --volume "$PWD:/md" peterdavehello/markdownlint markdownlint '**/*.md'

# prettier:
# desc: "Run Prettier on tests source"
# cmds:
Expand Down
16 changes: 16 additions & 0 deletions assets/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,20 @@ window.addEventListener("load", () => {
});
}
}

// Hack/workaround to make file element required (cf. https://github.com/EasyCorp/EasyAdminBundle/issues/3424). See also PointOfInterestCrudController::configureFields().
document.addEventListener("ea.collection.item-added", (event) => {
const el = event.detail.newElement ?? null;
if (el) {
const file = el.querySelector('[type="file"]');
if (file) {
const group = file?.closest(".form-group");
if (group) {
const label = group?.querySelector("legend");
label.classList.add("required");
file.required = true;
}
}
}
});
});
32 changes: 17 additions & 15 deletions assets/styles/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,23 @@
}
}

/* Avoid content so wide it pushes the add entry button above datatable out of the viewport. */
.wrapper {
grid-template-columns: var(--sidebar-max-width) calc(
100% -
var(--sidebar-max-width)
);
}
.content-wrapper {
display: block;
}
.content-body {
overflow-x: auto;
}
#content-resizer-handler {
display: none !important; /* Hide the resizer handle */
.ea-index {
/* Avoid content so wide it pushes the add entry button above datatable out of the viewport. */
.wrapper {
grid-template-columns: var(--sidebar-max-width) calc(
100% -
var(--sidebar-max-width)
);
}
.content-wrapper {
display: block;
}
.content-body {
overflow-x: auto;
}
#content-resizer-handler {
display: none !important; /* Hide the resizer handle */
}
}

/* Add a border below the content header to visually separate the content from the header(sticky) when scrolling */
Expand Down
3 changes: 3 additions & 0 deletions src/Controller/Admin/PointOfInterestCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ public function configureFields(string $pageName): iterable
$context = $this->getContext();
if (in_array($pageName, [Crud::PAGE_NEW, Crud::PAGE_EDIT], true) && null !== $context) {
$entity = $context->getEntity()->getInstance();
// @todo This assertion is not true since entity is a Route (cf. https://github.com/EasyCorp/EasyAdminBundle/issues/3424).
assert($entity instanceof PointOfInterest);

$imageAttr = EasyAdminHelper::getFileInputAttributes($entity, 'imageFile');
yield VichImageField::new('imageFile')
// @todo Replace the hack assets/admin.js.
// ->setRequired(null === $entity->getImage())
->setLabel(new TranslatableMessage('Image', [], 'admin'))
->setFormTypeOption('allow_delete', false)
->setFormTypeOption('attr', $imageAttr)->setColumns(12);
Expand Down
1 change: 1 addition & 0 deletions src/Controller/Admin/RouteCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function configureFields(string $pageName): iterable
$attr = EasyAdminHelper::getFileInputAttributes($entity, 'imageFile');

yield VichImageField::new('imageFile')
->setRequired(null === $entity->getImage())
->setLabel(new TranslatableMessage('Image', [], 'admin'))
->setFormTypeOption('allow_delete', false)
->setFormTypeOption('attr', $attr)
Expand Down
Loading