diff --git a/src/Controller/Admin/DashboardController.php b/src/Controller/Admin/DashboardController.php index 0321621..3632a09 100644 --- a/src/Controller/Admin/DashboardController.php +++ b/src/Controller/Admin/DashboardController.php @@ -2,11 +2,19 @@ namespace App\Controller\Admin; +use App\Entity\Degree; +use App\Entity\Group; +use App\Entity\User; +use EasyCorp\Bundle\EasyAdminBundle\Config\Action; +use EasyCorp\Bundle\EasyAdminBundle\Config\Actions; +use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard; use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem; +use EasyCorp\Bundle\EasyAdminBundle\Config\UserMenu; use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Security\Core\User\UserInterface; class DashboardController extends AbstractDashboardController { @@ -25,9 +33,33 @@ public function configureDashboard(): Dashboard ->setTitle('Idea'); } + public function configureActions(): Actions + { + return parent::configureActions() + ->add(Crud::PAGE_INDEX, Action::DETAIL) + ; + } + public function configureMenuItems(): iterable { yield MenuItem::linktoDashboard('Dashboard', 'fa fa-home'); - // yield MenuItem::linkToCrud('The Label', 'fas fa-list', EntityClass::class); + yield MenuItem::section('Organization'); + yield MenuItem::linkToCrud('Users', 'fas fa-user', User::class); + yield MenuItem::linkToCrud('Groups', 'fas fa-users', Group::class); + yield MenuItem::linkToCrud('Degrees', 'fas fa-graduation-cap', Degree::class); + } + + public function configureUserMenu(UserInterface $user): UserMenu + { + $userMenu = parent::configureUserMenu($user); + + /** @var User $user */ + if (!$user->getImage()) { + return $userMenu; + } + + return $userMenu + ->setAvatarUrl('/images/avatars/'.$user->getImage()->getName()) + ; } } diff --git a/src/Controller/Admin/DegreeCrudController.php b/src/Controller/Admin/DegreeCrudController.php new file mode 100644 index 0000000..5494432 --- /dev/null +++ b/src/Controller/Admin/DegreeCrudController.php @@ -0,0 +1,38 @@ +setEntityLabelInPlural('Degrees') + ->setEntityLabelInSingular('Degree') + ; + } + + public function configureFields(string $pageName): iterable + { + yield FormField::addPanel('General'); + yield IdField::new('id') + ->onlyOnIndex() + ; + yield TextField::new('name'); + yield TextField::new('slug') + ->onlyOnDetail() + ; + } +} diff --git a/src/Controller/Admin/GroupCrudController.php b/src/Controller/Admin/GroupCrudController.php new file mode 100644 index 0000000..79f99b2 --- /dev/null +++ b/src/Controller/Admin/GroupCrudController.php @@ -0,0 +1,39 @@ +setEntityLabelInPlural('Groups') + ->setEntityLabelInSingular('Group') + ; + } + + public function configureFields(string $pageName): iterable + { + yield FormField::addPanel('General'); + yield IdField::new('id') + ->onlyOnIndex() + ; + yield TextField::new('name'); + yield TextField::new('icon'); + yield TextField::new('slug') + ->onlyOnDetail() + ; + } +} diff --git a/src/Controller/Admin/UserCrudController.php b/src/Controller/Admin/UserCrudController.php new file mode 100644 index 0000000..bc9f3c4 --- /dev/null +++ b/src/Controller/Admin/UserCrudController.php @@ -0,0 +1,98 @@ +setEntityLabelInPlural('Users') + ->setEntityLabelInSingular('User') + ; + } + + public function configureFields(string $pageName): iterable + { + yield FormField::addPanel('General'); + yield TextField::new('username'); + yield TextField::new('email') + ->hideOnIndex() + ; + + + yield FormField::addPanel('Security'); + yield BooleanField::new('enabled'); + yield ChoiceField::new('roles') + ->setChoices([ + 'Usuario' => 'ROLE_USER', + 'Gestor' => 'ROLE_ADMIN', + 'Administrador' => 'ROLE_SUPER_ADMIN', + ]) + ->allowMultipleChoices() + ; + yield AssociationField::new('versions') + ->setLabel('Policies') + ->setTemplatePath('admin/user/policies.html.twig') + ->onlyOnDetail(); + + yield FormField::addPanel('Profile'); + yield IdField::new('id') + ->onlyOnIndex() + ; + yield TextField::new('firstname'); + yield TextField::new('lastname'); + yield ChoiceField::new('collective') + ->setChoices(User::getCollectives()) + ; + yield TextField::new('nic') + ->hideOnIndex() + ; + yield AssociationField::new('degree') + ->hideOnIndex() + ; + yield TextField::new('year') + ->hideOnIndex() + ; + yield TextareaField::new('imageFile') + ->setFormType(VichImageType::class) + ->onlyOnForms() + ; + yield ImageField::new('image.name') + ->setBasePath('/images/avatars') + ->setCssClass('ea-vich-image') + ->onlyOnDetail() + ; + } + + /* + public function configureFields(string $pageName): iterable + { + return [ + IdField::new('id'), + TextField::new('title'), + TextEditorField::new('description'), + ]; + } + */ +} diff --git a/src/Entity/Group.php b/src/Entity/Group.php index 9282e1e..b39e676 100644 --- a/src/Entity/Group.php +++ b/src/Entity/Group.php @@ -68,6 +68,12 @@ public function __toString(): string return (string) $this->name; } + public function getId(): ?int + { + return $this->id; + } + + /** * @return Idea[]|Collection */ diff --git a/templates/admin/user/policies.html.twig b/templates/admin/user/policies.html.twig new file mode 100644 index 0000000..6fb979b --- /dev/null +++ b/templates/admin/user/policies.html.twig @@ -0,0 +1,7 @@ +