Skip to content

Commit

Permalink
ajout addNavire pour navpro
Browse files Browse the repository at this point in the history
  • Loading branch information
aleckvincent committed Feb 20, 2025
1 parent a9f077a commit 43a8d6f
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 57 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ assets/js/params.json
### docker
.docker/data
docker-compose.yml
/public/.htaccess
/public/.htaccess

/metabase_questions/
22 changes: 22 additions & 0 deletions src/Controller/NavPro/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Controller\NavPro;

use App\Entity\Navire;
use App\Entity\NavPro\ControleLot;
use App\Entity\NavPro\ControleUnitaire;
use App\Form\NavPro\ControleLotType;
Expand Down Expand Up @@ -86,7 +87,28 @@ public function ajoutControleUnitaire(Request $request, EntityManagerInterface $
$controleUnitaire->setType($type);
$form = $this->createForm(ControleUnitaireType::class, $controleUnitaire);
$form->handleRequest($request);

// dd($form->has('nouveauNavire'));
if($form->isSubmitted() && $form->isValid()) {
if($form->has('nouveauNavire')) {
$nouveauNavireForm = $form->get('nouveauNavire');
$data = $nouveauNavireForm->getData();
$navire = $em->getRepository(Navire::class)->findOneBy(['immatriculation' => $data->getImmatriculation()]);
if(!$navire) {
$navire = new Navire();
$navire->setNom($data->getNom())
->setImmatriculation($data->getImmatriculation())
->setPavillon($data->getPavillon())
->setEtranger($data->getEtranger());
}
$em->persist($navire);
$em->flush();
}



$controleUnitaire->setNavire($navire);

if($request->query->get('brouillon')) {
$controleUnitaire->setBrouillon(true);
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/Form/NavPro/ControleUnitaireType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Entity\Navire;
use App\Entity\NavPro\ControleUnitaire;
use App\Form\DocumentType;
use App\Form\NavireNavProType;
use App\Form\NavireType;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
Expand Down Expand Up @@ -96,6 +98,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'allow_add' => true,
'prototype' => true
])
->add('nouveauNavire', NavireNavProType::class, [
'mapped' => false,
'label' => false,
])
;
}

Expand Down
56 changes: 56 additions & 0 deletions src/Form/NavireNavProType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Form;

use App\Entity\CategorieUsageNavire;
use App\Entity\Navire;
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;
use Symfony\Component\OptionsResolver\OptionsResolver;

class NavireNavProType extends AbstractType {

public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('immatriculation', TextType::class, [
'attr' => ['class' => "immatriculation fr-input fr-mb-2w"],
'label' => "Immatriculation du navire"
])
->add('pavillon', TextType::class, [
'required' => true,
'label' => "Pavillon du navire",
'attr' => [
'class' => 'fr-input fr-mb-2w'
]
])
->add('nom', TextType::class, [
'required' => true,
'label' => "Nom du navire",
'attr' => [
'class' => 'fr-input fr-mb-2w'
]
]
)
->add('categorieUsageNavire', EntityType::class, [
'required' => true,
'class' => CategorieUsageNavire::class,
'multiple' => false,
'expanded' => false,
'placeholder' => "Sélectionnez une catégorie",
'choice_label' => "nom",
'label' => "Catégorie du navire contrôlé",
'attr' => [
'class' => 'fr-select fr-mb-2w'
]
]);
}

public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults([
'data_class' => Navire::class,
]);
}

}
24 changes: 18 additions & 6 deletions templates/navPro/base.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html lang="fr" data-fr-scheme="system">
<html lang="fr" data-fr-theme="light" >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
Expand Down Expand Up @@ -28,8 +28,12 @@
<div class="fr-header__brand-top">
<div class="fr-header__logo">
<p class="fr-logo">
Secretariat d'état
<br>chargé de la mer
Ministère
<br>de la transition
<br>écologique
<br>de la biodiversité,
<br>de la forêt, de la mer
<br>et de la pêche
</p>
</div>
</div>
Expand Down Expand Up @@ -78,10 +82,14 @@
<div class="fr-container">
<div class="fr-footer__body">
<div class="fr-footer__brand fr-enlarge-link">
<a href="{{ path('app_navpro_accueil') }}" title="Retour à l’accueil du site - Secrétariat d'état chargé de la Mer">
<a href="{{ path('app_navpro_accueil') }}" title="Retour à l’accueil du site">
<p class="fr-logo">
Secrétariat d'état
<br>chargé de la mer
Ministère
<br>de la transition
<br>écologique
<br>de ka biodiversité,
<br>de la forêt, de la mer
<br>et de la pêche
</p>
</a>
</div>
Expand All @@ -107,5 +115,9 @@

{% block javascripts %}{% endblock %}
{% block modals %}{% endblock %}

<script>
localStorage.setItem('scheme', 'light');
</script>
</body>
</html>
164 changes: 114 additions & 50 deletions templates/navPro/controle_unitaire.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,31 @@
</div>
</div>
<div class="fr-grid-row fr-mt-3w">
<div class="fr-col-5">
<div class="fr-col-6">
<div class="fr-grid-row fr-mt-4w">
<div class="fr-col-12">
<div class="fr-col-12" id="enregistrementNavireForm">
{{ form_label(form.navire) }}
<small><em>Si le navire est sans immatriculation, cochez "Navire étrangers" </em></small>
{{ form_widget(form.navire) }}
</div>
<div class="fr-col-12 fr-hidden" id="newVesselCheckboxSection">
<div class="fr-grid-row fr-mt-3w">
<fieldset class="fr-fieldset" id="checkboxes-inline" aria-labelledby="checkboxes-inline-legend checkboxes-inline-messages">
<div class="fr-fieldset__element fr-fieldset__element--inline">
<div class="fr-checkbox-group">
<input type="checkbox" id="new-vessel" name="new-vessel"> <label for="new-vessel">Ajouter un nouveau navire</label>
</div>
</div>
</fieldset>
</div>
</div>
<div class="fr-col-12 fr-hidden" id="newVesselSection">
<div class="fr-grid-row fr-mt-3w fr-background-contrast--beige-gris-galet fr-p-2w">
{{ form_widget(form.nouveauNavire) }}
</div>
</div>
</div>
<div class="fr-grid-row fr-mt-3w">
<div class="fr-grid-row fr-mt-3w" id="foreignVesselSection">
<fieldset class="fr-fieldset" id="checkboxes-inline" aria-labelledby="checkboxes-inline-legend checkboxes-inline-messages">
<div class="fr-fieldset__element fr-fieldset__element--inline">
<div class="fr-checkbox-group">
Expand Down Expand Up @@ -194,87 +210,135 @@

{% block javascripts %}
<script>
let $checkbox = document.getElementsByClassName('pv-emis-checkbox');
$checkbox = $checkbox[0];
const $downloadDocx = document.getElementById('download-rapport-docx');
const $downloadOdt = document.getElementById('download-rapport-odt');
const $downloadModelesPV = document.getElementById('downloadModelesPV');
const $nbPv = document.getElementById('nbPV');
const $nbPVInput = document.getElementById('controle_unitaire_nbPv');
const $btnUpload = document.getElementById('btnUpload');
handleCheckbox($checkbox, $downloadModelesPV, $nbPv)
handleCheckbox($checkbox, $downloadModelesPV, $nbPv)
$checkbox.addEventListener('change', function(){
$(document).ready(function () {
const $enregistrement = $('.fr-input-enregistrement')
let $checkbox = document.getElementsByClassName('pv-emis-checkbox');
$checkbox = $checkbox[0];
const $downloadDocx = document.getElementById('download-rapport-docx');
const $downloadOdt = document.getElementById('download-rapport-odt');
const $downloadModelesPV = document.getElementById('downloadModelesPV');
const $nbPv = document.getElementById('nbPV');
const $nbPVInput = document.getElementById('controle_unitaire_nbPv');
const $btnUpload = document.getElementById('btnUpload');
handleCheckbox($checkbox, $downloadModelesPV, $nbPv)
handleCheckbox($checkbox, $downloadModelesPV, $nbPv)
$checkbox.addEventListener('change', function(){
handleCheckbox($checkbox, $downloadModelesPV, $nbPv)
handleCheckbox($checkbox, $downloadModelesPV, $nbPv)
})
})
function handleCheckbox(checkbox, download, nbPv) {
function handleCheckbox(checkbox, download, nbPv) {
if(checkbox.checked) {
download.style.display = 'block';
nbPv.style.display = 'block';
download.style.display = 'block';
nbPv.style.display = 'block';
} else {
download.style.display = 'none';
nbPv.style.display = 'none';
download.style.display = 'none';
nbPv.style.display = 'none';
}
}
}
const $btnBrouillon = document.getElementById("btn-brouillon");
const $form = document.getElementById("form-controle");
$btnBrouillon.addEventListener('click', function(e) {
const $btnBrouillon = document.getElementById("btn-brouillon");
const $form = document.getElementById("form-controle");
$btnBrouillon.addEventListener('click', function(e) {
e.preventDefault();
$form.action = "{{ action }}" + "?brouillon=true"
$form.submit()
})
})
const $btnReset = document.getElementById("btn-reset");
const $fermerModale = document.getElementById("fermer-modale");
const $btnReset = document.getElementById("btn-reset");
const $fermerModale = document.getElementById("fermer-modale");
$btnReset.addEventListener('click', function(e) {
$btnReset.addEventListener('click', function(e) {
$form.reset();
$fermerModale.click();
})
})
$('.fr-input-enregistrement').select2({
$enregistrement.select2({
minimumInputLength: 2,
allowClear: true,
placeholder: "Immatriculation du navire",
language: { inputTooShort: function () { return 'Merci de renseigner l\'immatriculation du navire'; } },
});
});
const $collectionHolder = $("#collectionHolder");
const $collectionHolder = $("#collectionHolder");
$($btnUpload).on('click', function(e){
$($btnUpload).on('click', function(e){
const nbPv = $($nbPVInput).val()
for(let i=1; i <= nbPv; i++){
addFormToCollection($collectionHolder, i)
addFormToCollection($collectionHolder, i)
}
})
})
const addFormToCollection = (collectionHolder, index) => {
const addFormToCollection = (collectionHolder, index) => {
const lengthUploadSection = $('.uploadSection').length;
if(lengthUploadSection < index) {
let prototype = collectionHolder.data('prototype');
prototype = prototype.replace(/__name__/g, index);
prototype = prototype.replace(/__index__/g, index);
prototype = prototype.replace(/__numeropv__/g, index);
collectionHolder.append(prototype);
const $suppUpload = $('.suppUpload' + index);
const $section = $('.section' + index);
$suppUpload.click(function(e) {
e.preventDefault();
$section.remove()
})
let prototype = collectionHolder.data('prototype');
prototype = prototype.replace(/__name__/g, index);
prototype = prototype.replace(/__index__/g, index);
prototype = prototype.replace(/__numeropv__/g, index);
collectionHolder.append(prototype);
const $suppUpload = $('.suppUpload' + index);
const $section = $('.section' + index);
$suppUpload.click(function(e) {
e.preventDefault();
$section.remove()
})
}
};
};
$enregistrement.on('select2:open', function() {
let searchField = $('.select2-search__field');
searchField.on('input', function() {
let searchValue = $(this).val().toLowerCase();
let availableOptions = [];
$('.fr-input-enregistrement option').each(function() {
let optionText = $(this).text().toLowerCase();
if (optionText.includes(searchValue)) {
availableOptions.push($(this).text());
}
});
if(searchValue.length >= 6 && availableOptions.length === 0) {
let scrollPosition = $(window).scrollTop();
$("#newVesselCheckboxSection").toggleClass('fr-hidden')
$enregistrement.select2('close');
setTimeout(() => {
$(window).scrollTop(scrollPosition);
}, 1);
$('#newVesselCheckboxSection').attr('tabindex', '-1').focus();
const $newVesselCheckbox = $("#new-vessel")
$newVesselCheckbox.on('change', function(e) {
$("#enregistrementNavireForm").toggleClass('fr-hidden')
const $newVesselFormSection = $("#newVesselSection")
$newVesselFormSection.toggleClass('fr-hidden')
$("#foreignVesselSection").toggleClass("fr-hidden")
if(!$newVesselCheckbox.prop('checked')) {
$("#newVesselCheckboxSection").removeClass('fr-hidden')
}
})
}
});
});
})
</script>

Expand Down

0 comments on commit 43a8d6f

Please sign in to comment.