Skip to content

Commit

Permalink
EV-318: More easy admin entity field configurtation
Browse files Browse the repository at this point in the history
  • Loading branch information
cableman committed Nov 22, 2023
1 parent 119959e commit c36a6bd
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 34 deletions.
31 changes: 31 additions & 0 deletions migrations/Version20231122130740.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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 Version20231122130740 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 image ADD title VARCHAR(255) NOT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE image DROP title');
}
}
15 changes: 11 additions & 4 deletions src/Controller/Admin/AddressCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ public function configureFields(string $pageName): iterable
TextField::new('postalCode'),

FormField::addFieldset('Geo location'),
NumberField::new('latitude')->setNumDecimals(8)->setColumns(2)->hideOnIndex(),
NumberField::new('longitude')->setNumDecimals(8)->setColumns(2)->hideOnIndex(),

FormField::addFieldset('Edited'),
NumberField::new('latitude')
->setNumDecimals(8)
->setColumns(2)
->hideOnIndex(),
NumberField::new('longitude')
->setNumDecimals(8)
->setColumns(2)
->hideOnIndex(),

FormField::addFieldset('Edited')
->hideWhenCreating(),
DateTimeField::new('updated_at')
->setLabel('Last updated')
->setDisabled()
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/Admin/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Entity\Address;
use App\Entity\Event;
use App\Entity\Feed;
use App\Entity\Image;
use App\Entity\Location;
use App\Entity\Occurrence;
use App\Entity\Organization;
Expand Down Expand Up @@ -45,6 +46,7 @@ public function configureMenuItems(): iterable
yield MenuItem::linkToCrud('Occurrences', 'fa fa-repeat', Occurrence::class);
yield MenuItem::linkToCrud('Location', 'fa fa-location-dot', Location::class);
yield MenuItem::linkToCrud('Address', 'fa fa-address-book', Address::class);
yield MenuItem::linkToCrud('Image', 'fa fa-image', Image::class);
yield MenuItem::linkToCrud('Feeds', 'fa fa-rss', Feed::class);
yield MenuItem::linkToCrud('Tags', 'fa fa-tags', Tag::class);
yield MenuItem::linkToCrud('Organizer', 'fa fa-sitemap', Organization::class);
Expand Down
32 changes: 28 additions & 4 deletions src/Controller/Admin/EventCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
use App\Entity\Event;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Field\UrlField;

class EventCrudController extends AbstractCrudController
{
Expand All @@ -22,14 +26,34 @@ public function configureCrud(Crud $crud): Crud
->setDefaultSort(['id' => 'DESC']);
}

/*
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id'),
IdField::new('id')
->setDisabled()
->hideWhenCreating(),

FormField::addFieldset('Basic information'),
TextField::new('title'),
TextEditorField::new('description'),
TextEditorField::new('excerpt')
->hideOnIndex(),
TextEditorField::new('description')
->hideOnIndex(),

AssociationField::new('image'),

FormField::addFieldset('Location information'),
UrlField::new('url'),
UrlField::new('ticketUrl'),
AssociationField::new('location'),

FormField::addFieldset('Edited'),
AssociationField::new('organization'),
DateTimeField::new('updated_at')
->setLabel('Last updated')
->setDisabled()
->hideWhenCreating()
->setFormat(DashboardController::DATETIME_FORMAT),
];
}
*/
}
31 changes: 25 additions & 6 deletions src/Controller/Admin/FeedCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

use App\Entity\Feed;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\CodeEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;

class FeedCrudController extends AbstractCrudController
Expand All @@ -15,14 +17,31 @@ public static function getEntityFqcn(): string
return Feed::class;
}

/*
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id'),
TextField::new('title'),
TextEditorField::new('description'),
IdField::new('id')
->setDisabled()
->hideWhenCreating(),

TextField::new('name'),
CodeEditorField::new('configurationField')
->setLanguage('js')
->hideOnIndex(),

FormField::addFieldset('Edited')
->hideWhenCreating(),
DateTimeField::new('last_read')
->setLabel('Last parsed')
->setDisabled()
->hideWhenCreating()
->setFormat(DashboardController::DATETIME_FORMAT),

DateTimeField::new('updated_at')
->setLabel('Last updated')
->setDisabled()
->hideWhenCreating()
->setFormat(DashboardController::DATETIME_FORMAT),
];
}
*/
}
38 changes: 38 additions & 0 deletions src/Controller/Admin/ImageCrudController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Controller\Admin;

use App\Entity\Image;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Field\UrlField;

class ImageCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Image::class;
}

public function configureFields(string $pageName): iterable
{
return [
IdField::new('id')
->setDisabled()
->hideWhenCreating(),

TextField::new('title'),
UrlField::new('source'),

FormField::addFieldset('Edited')
->hideWhenCreating(),
DateTimeField::new('updated_at')
->setLabel('Last updated')
->setDisabled()
->hideWhenCreating()
->setFormat(DashboardController::DATETIME_FORMAT), ];
}
}
5 changes: 2 additions & 3 deletions src/Controller/Admin/LocationCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TelephoneField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Field\UrlField;

Expand Down Expand Up @@ -51,7 +49,8 @@ public function configureFields(string $pageName): iterable
->hideOnIndex(),
BooleanField::new('disabilityAccess'),

FormField::addFieldset('Edited'),
FormField::addFieldset('Edited')
->hideWhenCreating(),
DateTimeField::new('updated_at')
->setLabel('Last updated')
->setDisabled()
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/Admin/OccurrenceCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public function configureFields(string $pageName): iterable
TextField::new('ticketPriceRange'),
TextField::new('room'),

FormField::addFieldset('Edited'),
FormField::addFieldset('Edited')
->hideWhenCreating(),
DateTimeField::new('updated_at')
->setLabel('Last updated')
->setDisabled()
Expand Down
26 changes: 19 additions & 7 deletions src/Controller/Admin/OrganizationCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use App\Entity\Organization;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Field\UrlField;

class OrganizationCrudController extends AbstractCrudController
{
Expand All @@ -15,14 +18,23 @@ public static function getEntityFqcn(): string
return Organization::class;
}

/*
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id'),
TextField::new('title'),
TextEditorField::new('description'),
];
IdField::new('id')
->setDisabled()
->hideWhenCreating(),

TextField::new('name'),
EmailField::new('mail'),
UrlField::new('url'),

FormField::addFieldset('Edited')
->hideWhenCreating(),
DateTimeField::new('updated_at')
->setLabel('Last updated')
->setDisabled()
->hideWhenCreating()
->setFormat(DashboardController::DATETIME_FORMAT), ];
}
*/
}
22 changes: 15 additions & 7 deletions src/Controller/Admin/TagCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

use App\Entity\Tag;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;

class TagCrudController extends AbstractCrudController
Expand All @@ -15,14 +16,21 @@ public static function getEntityFqcn(): string
return Tag::class;
}

/*
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id'),
TextField::new('title'),
TextEditorField::new('description'),
];
IdField::new('id')
->setDisabled()
->hideWhenCreating(),

TextField::new('name'),

FormField::addFieldset('Edited')
->hideWhenCreating(),
DateTimeField::new('updated_at')
->setLabel('Last updated')
->setDisabled()
->hideWhenCreating()
->setFormat(DashboardController::DATETIME_FORMAT), ];
}
*/
}
2 changes: 1 addition & 1 deletion src/Entity/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct()

public function __toString(): string
{
return sprintf('%s, %s (%d)', $this->street, $this->city, $this->id);
return sprintf('%s, %s (%d)', $this->street ?? '', $this->city ?? '', $this->id ?? -1);
}

public function getId(): ?int
Expand Down
18 changes: 17 additions & 1 deletion src/Entity/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Feed
#[ORM\Column(length: 255)]
private ?string $name = null;

#[ORM\Column]
#[ORM\Column(type: 'json')]
private array $configuration = [];

#[ORM\Column(nullable: true)]
Expand Down Expand Up @@ -77,6 +77,22 @@ public function setConfiguration(array $configuration): static
return $this;
}

/**
* Helper function to display data in code-editor in easy admin.
*/
public function getConfigurationField(): string
{
return json_encode($this->configuration, JSON_PRETTY_PRINT);
}

/**
* Helper function store data from code-editor in easy admin.
*/
public function setConfigurationField(string $configuration): static
{
return $this->setConfiguration(json_decode($configuration, true));
}

public function getLastRead(): ?\DateTimeImmutable
{
return $this->lastRead;
Expand Down
20 changes: 20 additions & 0 deletions src/Entity/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class Image
#[ORM\OneToOne(mappedBy: 'image', cascade: ['persist', 'remove'])]
private ?Event $event = null;

#[ORM\Column(length: 255)]
private ?string $title = null;

public function __toString(): string
{
return sprintf('%s (%d)', $this->title ?? 'Missing', $this->id ?? -1);
}

public function getId(): ?int
{
return $this->id;
Expand Down Expand Up @@ -85,4 +93,16 @@ public function setEvent(?Event $event): static

return $this;
}

public function getTitle(): ?string
{
return $this->title;
}

public function setTitle(string $title): static
{
$this->title = $title;

return $this;
}
}
Loading

0 comments on commit c36a6bd

Please sign in to comment.