location admin: admin crud for location

This commit is contained in:
nobohan 2021-10-21 21:39:32 +02:00
parent 92843677f9
commit e9322e61d4
8 changed files with 190 additions and 1 deletions

View File

@ -0,0 +1,19 @@
<?php
namespace Chill\MainBundle\Controller;
use Chill\MainBundle\CRUD\Controller\CRUDController;
use Symfony\Component\HttpFoundation\Request;
class LocationController extends CRUDController
{
public function customizeQuery(string $action, Request $request, $query): void
{
$query->where('e.availableForUsers', "'TRUE'");
}
// public function createEntity(string $action, Request $request): object
// {
// }
}

View File

@ -20,6 +20,7 @@
namespace Chill\MainBundle\DependencyInjection;
use Chill\MainBundle\Controller\AddressApiController;
use Chill\MainBundle\Controller\LocationController;
use Chill\MainBundle\Controller\LocationTypeController;
use Chill\MainBundle\Controller\UserController;
use Chill\MainBundle\Doctrine\DQL\STContains;
@ -45,8 +46,10 @@ use Chill\MainBundle\Doctrine\DQL\Replace;
use Chill\MainBundle\Doctrine\ORM\Hydration\FlatHierarchyEntityHydrator;
use Chill\MainBundle\Doctrine\Type\NativeDateIntervalType;
use Chill\MainBundle\Doctrine\Type\PointType;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\LocationType;
use Chill\MainBundle\Form\LocationTypeType;
use Chill\MainBundle\Form\LocationType as LocationFormType;
use Symfony\Component\HttpFoundation\Request;
/**
@ -319,6 +322,28 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
]
]
],
[
'class' => Location::class,
'name' => 'main_location',
'base_path' => '/admin/main/location',
'base_role' => 'ROLE_ADMIN',
'form_class' => LocationFormType::class,
'controller' => LocationController::class,
'actions' => [
'index' => [
'role' => 'ROLE_ADMIN',
'template' => '@ChillMain/Location/index.html.twig',
],
'new' => [
'role' => 'ROLE_ADMIN',
'template' => '@ChillMain/Location/new.html.twig',
],
'edit' => [
'role' => 'ROLE_ADMIN',
'template' => '@ChillMain/Location/edit.html.twig',
]
]
],
[
'class' => LocationType::class,
'name' => 'main_location_type',

View File

@ -0,0 +1,47 @@
<?php
namespace Chill\MainBundle\Form;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\LocationType as EntityLocationType;
use Chill\MainBundle\Form\Type\PickAddressType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
final class LocationType extends AbstractType
{
// private TranslatableStringHelper $translatableStringHelper;
// public function __construct(
// TranslatableStringHelper $translatableStringHelper
// ) {
// $this->translatableStringHelper = $translatableStringHelper;
// }
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextType::class)
->add('phonenumber1', TextType::class, ['required' => false])
->add('phonenumber2', TextType::class, ['required' => false])
->add('email', TextType::class, ['required' => false])
->add('locationType', EntityType::class, [
'class' => EntityLocationType::class,
'choice_label' => function (EntityLocationType $entity) {
//return $this->translatableStringHelper->localize($entity->getTitle());
return $entity->getTitle()['fr'];
},
])
->add('address', PickAddressType::class, [
'label' => 'Address',
'use_valid_from' => false,
'use_valid_to' => false,
'mapped' => false,
]);
}
}

View File

@ -0,0 +1,22 @@
{% extends '@ChillMain/Admin/layout.html.twig' %}
{% block title %}
{% include('@ChillMain/CRUD/_edit_title.html.twig') %}
{% endblock %}
{% block admin_content %}
{# {% as we are in the admin layout, we override the admin content with the CRUD content %} #}
{% embed '@ChillMain/CRUD/_edit_content.html.twig' %}
{# we do not have "view" page. We empty the corresponding block #}
{% block content_form_actions_view %}{% endblock %}
{% block content_form_actions_save_and_show %}{% endblock %}
{% endembed %}
{% endblock %}
{% block js %}
{{ encore_entry_script_tags('mod_input_address') }}
{% endblock %}
{% block css %}
{{ encore_entry_link_tags('mod_input_address') }}
{% endblock %}

View File

@ -0,0 +1,48 @@
{% extends "@ChillAsideActivity/Admin/layout_asideactivity.html.twig" %}
{% block admin_content %}
<h1>{{ 'Location list'|trans }}</h1>
<table class="records_list table table-bordered border-dark">
<thead>
<tr>
<th>{{ 'Name'|trans }}</th>
<th>{{ 'phonenumber1'|trans }}</th>
<th>{{ 'phonenumber2'|trans }}</th>
<th>{{ 'email'|trans }}</th>
<th>{{ 'address'|trans }}</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td>{{ entity.name }}</td>
<td>{{ entity.phonenumber1 }}</td>
<td>{{ entity.phonenumber2 }}</td>
<td>{{ entity.email }}</td>
<td>
{% if entity.address is not null %}
{{ entity.address.street}}, {{ entity.address.streetnumber }}
{% endif %}
</td>
<td>
<ul class="record_actions">
<li>
<a href="{{ path('chill_crud_main_location_edit', { 'id': entity.id }) }}" class="btn btn-edit" title="{{ 'edit'|trans }}"></a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul class="record_actions">
<li>
<a href="{{ path('chill_crud_main_location_new') }}" class="btn btn-create">
{{ 'Create a new location'|trans }}
</a>
</li>
</ul>
{% endblock %}

View File

@ -0,0 +1,19 @@
{% extends '@ChillMain/Admin/layout.html.twig' %}
{% block title %}
{% include('@ChillMain/CRUD/_new_title.html.twig') %}
{% endblock %}
{% block admin_content %}
{% embed '@ChillMain/CRUD/_new_content.html.twig' %}
{% block content_form_actions_save_and_show %}{% endblock %}
{% endembed %}
{% endblock %}
{% block js %}
{{ encore_entry_script_tags('mod_input_address') }}
{% endblock %}
{% block css %}
{{ encore_entry_link_tags('mod_input_address') }}
{% endblock %}

View File

@ -137,3 +137,7 @@ services:
Chill\MainBundle\Form\DataTransform\AddressToIdDataTransformer:
autoconfigure: true
autowire: true
Chill\MainBundle\Form\Type\LocationType:
autowire: true
autoconfigure: true

View File

@ -182,13 +182,15 @@ Create a new circle: Créer un nouveau cercle
#admin section for location
Location type list: Liste des types de localisation
Create a new location type: Créer un nouveau type de lieu
Create a new location type: Créer un nouveau type de localisation
Available for users: Disponible aux utilisateurs
Address required: Adresse requise?
Contact data: Données de contact?
optional: optionnel
required: requis
never: jamais
Create a new location: Créer une nouvelle localisation
Location list: Liste des localisations
# circles / scopes
Choose the circle: Choisir le cercle
@ -307,6 +309,9 @@ crud:
main_location_type:
title_new: Nouveau type de localisation
title_edit: Modifier un type de localisation
main_location:
title_new: Nouvelle localisation
title_edit: Modifier une localisation
No entities: Aucun élément