From 580dc712181c12df5390b10c8f5e6066baf9535f Mon Sep 17 00:00:00 2001 From: Jean-Francois Monfort Date: Thu, 1 Apr 2021 16:22:33 +0200 Subject: [PATCH] ActivityType replace Admin Conroller with Crud system --- .../Controller/ActivityTypeController.php | 178 ------------------ .../AdminActivityTypeCategoryController.php | 2 - .../AdminActivityTypeController.php | 23 +++ .../ChillActivityExtension.php | 21 +++ .../Form/ActivityTypeType.php | 10 +- .../views/ActivityType/edit.html.twig | 46 +---- .../views/ActivityType/index.html.twig | 9 +- .../views/ActivityType/new.html.twig | 43 +---- .../views/ActivityType/show.html.twig | 42 ----- .../ChillActivityBundle/config/routes.yaml | 14 +- .../config/routes/activitytype.yaml | 35 ---- .../translations/messages.fr.yml | 26 +-- 12 files changed, 88 insertions(+), 361 deletions(-) delete mode 100644 src/Bundle/ChillActivityBundle/Controller/ActivityTypeController.php create mode 100644 src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeController.php delete mode 100644 src/Bundle/ChillActivityBundle/Resources/views/ActivityType/show.html.twig delete mode 100644 src/Bundle/ChillActivityBundle/config/routes/activitytype.yaml diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityTypeController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityTypeController.php deleted file mode 100644 index f27bea0ae..000000000 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityTypeController.php +++ /dev/null @@ -1,178 +0,0 @@ -getDoctrine()->getManager(); - - $entities = $em->getRepository('ChillActivityBundle:ActivityType')->findAll(); - - return $this->render('ChillActivityBundle:ActivityType:index.html.twig', array( - 'entities' => $entities, - )); - } - /** - * Creates a new ActivityType entity. - * - */ - public function createAction(Request $request) - { - $entity = new ActivityType(); - $form = $this->createCreateForm($entity); - $form->handleRequest($request); - - if ($form->isValid()) { - $em = $this->getDoctrine()->getManager(); - $em->persist($entity); - $em->flush(); - - return $this->redirect($this->generateUrl('chill_activity_activitytype_show', array('id' => $entity->getId()))); - } - - return $this->render('ChillActivityBundle:ActivityType:new.html.twig', array( - 'entity' => $entity, - 'form' => $form->createView(), - )); - } - - /** - * Creates a form to create a ActivityType entity. - * - * @param ActivityType $entity The entity - * - * @return \Symfony\Component\Form\Form The form - */ - private function createCreateForm(ActivityType $entity) - { - $form = $this->createForm(ActivityTypeType::class, $entity, array( - 'action' => $this->generateUrl('chill_activity_activitytype_create'), - 'method' => 'POST', - )); - - $form->add('submit', SubmitType::class, array('label' => 'Create')); - - return $form; - } - - /** - * Displays a form to create a new ActivityType entity. - * - */ - public function newAction() - { - $entity = new ActivityType(); - $form = $this->createCreateForm($entity); - - return $this->render('ChillActivityBundle:ActivityType:new.html.twig', array( - 'entity' => $entity, - 'form' => $form->createView(), - )); - } - - /** - * Finds and displays a ActivityType entity. - * - */ - public function showAction($id) - { - $em = $this->getDoctrine()->getManager(); - - $entity = $em->getRepository('ChillActivityBundle:ActivityType')->find($id); - - if (!$entity) { - throw $this->createNotFoundException('Unable to find ActivityType entity.'); - } - - return $this->render('ChillActivityBundle:ActivityType:show.html.twig', array( - 'entity' => $entity, - )); - } - - /** - * Displays a form to edit an existing ActivityType entity. - * - */ - public function editAction($id) - { - $em = $this->getDoctrine()->getManager(); - - $entity = $em->getRepository('ChillActivityBundle:ActivityType')->find($id); - - if (!$entity) { - throw $this->createNotFoundException('Unable to find ActivityType entity.'); - } - - $editForm = $this->createEditForm($entity); - - return $this->render('ChillActivityBundle:ActivityType:edit.html.twig', array( - 'entity' => $entity, - 'edit_form' => $editForm->createView() - )); - } - - /** - * Creates a form to edit a ActivityType entity. - * - * @param ActivityType $entity The entity - * - * @return \Symfony\Component\Form\Form The form - */ - private function createEditForm(ActivityType $entity) - { - $form = $this->createForm(ActivityTypeType::class, $entity, array( - 'action' => $this->generateUrl('chill_activity_activitytype_update', array('id' => $entity->getId())), - 'method' => 'PUT', - )); - - $form->add('submit', SubmitType::class, array('label' => 'Update')); - - return $form; - } - /** - * Edits an existing ActivityType entity. - * - */ - public function updateAction(Request $request, $id) - { - $em = $this->getDoctrine()->getManager(); - - $entity = $em->getRepository('ChillActivityBundle:ActivityType')->find($id); - - if (!$entity) { - throw $this->createNotFoundException('Unable to find ActivityType entity.'); - } - - $editForm = $this->createEditForm($entity); - $editForm->handleRequest($request); - - if ($editForm->isValid()) { - $em->flush(); - - return $this->redirect($this->generateUrl('chill_activity_activitytype_edit', array('id' => $id))); - } - - return $this->render('ChillActivityBundle:ActivityType:edit.html.twig', array( - 'entity' => $entity, - 'edit_form' => $editForm->createView(), - )); - } -} diff --git a/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeCategoryController.php b/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeCategoryController.php index 6abc3ac65..149e83d28 100644 --- a/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeCategoryController.php +++ b/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeCategoryController.php @@ -1,9 +1,7 @@ orderBy('e.id', 'ASC'); + } +} diff --git a/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php b/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php index 6007a6267..3107c9705 100644 --- a/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php +++ b/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php @@ -96,6 +96,27 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf { $container->prependExtensionConfig('chill_main', [ 'cruds' => [ + [ + 'class' => \Chill\ActivityBundle\Entity\ActivityType::class, + 'name' => 'activity_type', + 'base_path' => '/admin/activity_type', + 'form_class' => \Chill\ActivityBundle\Form\ActivityTypeType::class, + 'controller' => \Chill\ActivityBundle\Controller\AdminActivityTypeController::class, + 'actions' => [ + 'index' => [ + 'template' => '@ChillActivity/ActivityType/index.html.twig', + 'role' => 'ROLE_ADMIN' + ], + 'new' => [ + 'role' => 'ROLE_ADMIN', + 'template' => '@ChillActivity/ActivityType/new.html.twig', + ], + 'edit' => [ + 'role' => 'ROLE_ADMIN', + 'template' => '@ChillActivity/ActivityType/edit.html.twig', + ] + ] + ], [ 'class' => \Chill\ActivityBundle\Entity\ActivityTypeCategory::class, 'name' => 'activity_type_category', diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php b/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php index a402f584c..f241509ef 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php @@ -33,15 +33,7 @@ class ActivityTypeType extends AbstractType public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( - 'data_class' => 'Chill\ActivityBundle\Entity\ActivityType' + 'data_class' => \Chill\ActivityBundle\Entity\ActivityType::class )); } - - /** - * @return string - */ - public function getBlockPrefix() - { - return 'chill_activitybundle_activitytype'; - } } diff --git a/src/Bundle/ChillActivityBundle/Resources/views/ActivityType/edit.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/ActivityType/edit.html.twig index 99bc71057..dacee767c 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/ActivityType/edit.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/ActivityType/edit.html.twig @@ -1,40 +1,12 @@ -{# - * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . -#} {% extends "@ChillActivity/Admin/layout_activity.html.twig" %} -{% block admin_content %} -

{{ 'ActivityType edit'|trans }}

- - {{ form_start(edit_form) }} - {{ form_row(edit_form.active) }} - {{ form_row(edit_form.name) }} - - - - - - {{ form_end(edit_form) }} +{% block title %} + {% include('@ChillMain/CRUD/_edit_title.html.twig') %} +{% endblock %} + +{% block layout_wvm_content %} + {% embed '@ChillMain/CRUD/_edit_content.html.twig' %} + {% block content_form_actions_view %}{% endblock %} + {% block content_form_actions_save_and_show %}{% endblock %} + {% endembed %} {% endblock %} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/ActivityType/index.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/ActivityType/index.html.twig index d9f0cbca6..fd1fd8e29 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/ActivityType/index.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/ActivityType/index.html.twig @@ -30,7 +30,7 @@ {% for entity in entities %} - {{ entity.name|localize_translatable_string }} + {{ entity.name|localize_translatable_string }} {%- if entity.active -%} @@ -41,10 +41,7 @@
  • - -
  • -
  • - +
@@ -55,7 +52,7 @@
  • - + {{ 'Create a new activity type'|trans }}
  • diff --git a/src/Bundle/ChillActivityBundle/Resources/views/ActivityType/new.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/ActivityType/new.html.twig index efc294efd..d7ac89752 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/ActivityType/new.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/ActivityType/new.html.twig @@ -1,38 +1,11 @@ -{# - * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . -#} {% extends "@ChillActivity/Admin/layout_activity.html.twig" %} -{% block admin_content %} -

    {{ 'ActivityType creation'|trans }}

    - - {{ form_start(form) }} - {{ form_row(form.active) }} - {{ form_row(form.name) }} - - - {{ form_end(form) }} - +{% block title %} + {% include('@ChillMain/CRUD/_new_title.html.twig') %} +{% endblock %} + +{% block layout_wvm_content %} + {% embed '@ChillMain/CRUD/_new_content.html.twig' %} + {% block content_form_actions_save_and_show %}{% endblock %} + {% endembed %} {% endblock %} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/ActivityType/show.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/ActivityType/show.html.twig deleted file mode 100644 index bce0ed95b..000000000 --- a/src/Bundle/ChillActivityBundle/Resources/views/ActivityType/show.html.twig +++ /dev/null @@ -1,42 +0,0 @@ -{# - * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . -#} -{% extends "@ChillActivity/Admin/layout_activity.html.twig" %} - -{% block admin_content %} -

    {{ 'ActivityType'|trans }}

    - - - - - - - - -
    {{ 'Name'|trans }}{{ entity.name|localize_translatable_string }}
    - -{% endblock %} diff --git a/src/Bundle/ChillActivityBundle/config/routes.yaml b/src/Bundle/ChillActivityBundle/config/routes.yaml index 4940d8df3..3e1766adf 100644 --- a/src/Bundle/ChillActivityBundle/config/routes.yaml +++ b/src/Bundle/ChillActivityBundle/config/routes.yaml @@ -10,11 +10,6 @@ chill_activity_activityreasoncategory: resource: "@ChillActivityBundle/config/routes/activityreasoncategory.yaml" prefix: / -chill_activity_activitytype: - resource: "@ChillActivityBundle/config/routes/activitytype.yaml" - prefix: / - - chill_admin_activity_index: path: /{_locale}/admin/activity controller: Chill\ActivityBundle\Controller\AdminController::indexActivityAction @@ -34,6 +29,15 @@ chill_admin_activity_redirect_to_admin_index: order: 0 label: Main admin menu +chill_activity_type_admin: + path: /{_locale}/admin/activity/type + controller: cscrud_activity_type_controller:index + options: + menus: + admin_activity: + order: 2020 + label: 'Activity Types' + chill_activity_type_category_admin: path: /{_locale}/admin/activity/type_category controller: cscrud_activity_type_category_controller:index diff --git a/src/Bundle/ChillActivityBundle/config/routes/activitytype.yaml b/src/Bundle/ChillActivityBundle/config/routes/activitytype.yaml deleted file mode 100644 index 2995458f1..000000000 --- a/src/Bundle/ChillActivityBundle/config/routes/activitytype.yaml +++ /dev/null @@ -1,35 +0,0 @@ -chill_activity_activitytype: - path: /{_locale}/admin/activitytype/ - controller: Chill\ActivityBundle\Controller\ActivityTypeController::indexAction - options: - menus: - admin_activity: - order: 2020 - label: "Activity Types" - -chill_activity_activitytype_show: - path: /{_locale}/admin/activitytype/{id}/show - controller: Chill\ActivityBundle\Controller\ActivityTypeController::showAction - -chill_activity_activitytype_new: - path: /{_locale}/admin/activitytype/new - controller: Chill\ActivityBundle\Controller\ActivityTypeController::newAction - -chill_activity_activitytype_create: - path: /{_locale}/admin/activitytype/create - controller: Chill\ActivityBundle\Controller\ActivityTypeController::createAction - methods: POST - -chill_activity_activitytype_edit: - path: /{_locale}/admin/activitytype/{id}/edit - controller: Chill\ActivityBundle\Controller\ActivityTypeController::editAction - -chill_activity_activitytype_update: - path: /{_locale}/admin/activitytype/{id}/update - controller: Chill\ActivityBundle\Controller\ActivityTypeController::updateAction - methods: [POST, PUT] - -chill_activity_activitytype_delete: - path: /{_locale}/admin/activitytype/{id}/delete - controller: Chill\ActivityBundle\Controller\ActivityTypeController::deleteAction - methods: [POST, DELETE] diff --git a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml index b038269b9..cac24b314 100644 --- a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml @@ -79,6 +79,15 @@ Activity Reasons: Sujets d'une activité Activity Reasons Category: Catégories de sujet d'activités Activity Types Categories: Catégories des types d'activité +# Crud +crud: + activity_type: + title_new: Nouveau type d'activité + title_edit: Edition d'un type d'activité + activity_type_category: + title_new: Nouvelle catégorie de type d'activité + title_edit: Edition d'une catégorie de type d'activité + # activity reason admin ActivityReason list: Liste des sujets Create a new activity reason: Créer un nouveau sujet @@ -99,20 +108,13 @@ ActivityReasonCategory: Catégorie de sujet d'activité ActivityReasonCategory is active and will be proposed: La catégorie est active et sera proposée ActivityReasonCategory is inactive and won't be proposed: La catégorie est inactive et ne sera pas proposée -# activity type admin -ActivityTypeCategory list: Liste des catégories des types d'activité -Create a new activity type category: Créer une nouvelle catégorie de type d'activité -crud: - activity_type_category: - title_new: Nouvelle catégorie de type d'activité - title_edit: Edition d'une catégorie de type d'activité - -# activitycategory type admin +# activity type type admin ActivityType list: Types d'activités Create a new activity type: Créer un nouveau type d'activité -ActivityType creation: Nouveau type d'activité -ActivityType: Type d'activité -ActivityType edit: Modifier une activité + +# activity type category admin +ActivityTypeCategory list: Liste des catégories des types d'activité +Create a new activity type category: Créer une nouvelle catégorie de type d'activité # activity delete Remove activity: Supprimer une activité