Skip to content

Commit

Permalink
changes based on comments #2198
Browse files Browse the repository at this point in the history
  • Loading branch information
hmeneuvrier committed Mar 27, 2024
1 parent 7263294 commit 4a27845
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,8 @@ document.querySelectorAll('.btn-signalement-file-edit').forEach(swbtn => {
document.querySelector('#file-edit-fileid').value = target.getAttribute('data-file-id')

const selectedDocumentType = target.getAttribute('data-documentType');
// if (target.getAttribute('data-description') || selectedDocumentType === 'PHOTO_VISITE') {
document.querySelector('#fileDescription').value = target.getAttribute('data-description')
document.querySelector('#fr-modal-edit-file-description').classList.remove('fr-hidden')
// }else {
// document.querySelector('#fileDescription').value = ''
// document.querySelector('#fr-modal-edit-file-description').classList.remove('fr-hidden')
// }
document.querySelector('#fileDescription').value = target.getAttribute('data-description')
document.querySelector('#fr-modal-edit-file-description').classList.remove('fr-hidden')

const documentTypes = JSON.parse(target.getAttribute('data-documentType-list'));
let typeSelectBox = document.querySelector('#document-type-select');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ function initializeUploadModal(
clone = selectDesordreToClone.cloneNode(true)
clone.id = 'select-desordre-' + response.response
}else{
console.log(modal.dataset.fileFilter)
console.log(selectTypeSituationToClone)
console.log(selectTypeProcedureToClone)
if ('situation' === modal.dataset.fileFilter ){
clone = selectTypeSituationToClone.cloneNode(true)
} else {
Expand All @@ -142,7 +139,6 @@ function initializeUploadModal(
clone.id = 'select-type-' + response.response
}
clone.dataset.fileId = response.response
console.log(clone)
if (clone.querySelectorAll('option').length == 1) {
clone.remove()
} else {
Expand Down Expand Up @@ -313,7 +309,7 @@ function initializeUploadModal(
document.querySelectorAll('.open-modal-upload-files-btn').forEach((button) => {
button.addEventListener('click', (e) => {
fileType = e.target.dataset.fileType
fileFilter = e.target.dataset.fileFilter
fileFilter = e.target.dataset.fileFilter ?? null
documentType = e.target.dataset.documentType ?? null
interventionId = e.target.dataset.interventionId ?? null
})
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Back/SignalementFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ public function editFileSignalement(
$file->setDesordreSlug($desordreSlug);
$interventionId = $request->get('interventionId');
if (null !== $interventionId) {
$intervention = $interventionRepository->findOneBy(['id' => $interventionId]);
if ($intervention->getSignalement() === $file->getSignalement()) {
$intervention = $interventionRepository->find($interventionId);
if ($intervention?->getSignalement() === $file->getSignalement()) {
$file->setIntervention($intervention);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Entity/Enum/DocumentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public static function getPhotosList(): array
{
return [
self::PHOTO_SITUATION->name => self::PHOTO_SITUATION->label(),
self::PHOTO_VISITE->name => self::PHOTO_VISITE->label(), // TODO, garder ?
self::AUTRE->name => self::AUTRE->label(),
];
}
Expand Down
7 changes: 7 additions & 0 deletions src/Entity/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,11 @@ public function setIsWaitingSuivi(bool $isWaitingSuivi): self

return $this;
}

public function isSituationPhoto(): bool
{
return $this->fileType === $this::FILE_TYPE_PHOTO
&& \array_key_exists($this->documentType->value, DocumentType::getSituationList())
&& null === $this->intervention;
}
}
37 changes: 17 additions & 20 deletions src/Manager/SignalementManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,27 +813,26 @@ public function getPhotosBySlug(Signalement $signalement, string $desordrePrecis

public function getAllPhotosOrdered(Signalement $signalement): ?array
{
$photos = $signalement->getPhotos();
$photosArray = $photos->toArray();
$photoArraysByType = [
$photoList = $signalement->getPhotos()->toArray();
$photoListByType = [
DocumentType::PHOTO_SITUATION->value => [],
DocumentType::PHOTO_VISITE->value => [],
DocumentType::AUTRE->value => [],
];

foreach ($photosArray as $photo) {
$type = $photo->getDocumentType();
$photoArraysByType[$type->value][] = $photo;
foreach ($photoList as $photoItem) {
$type = $photoItem->getDocumentType();
$photoListByType[$type->value][] = $photoItem;
}

foreach ($photoArraysByType as &$photoArray) {
usort($photoArray, function (File $a, File $b) {
if (DocumentType::PHOTO_SITUATION === $a->getDocumentType()) {
return $a->getId() <=> $b->getId();
foreach ($photoListByType as &$photoArray) {
usort($photoArray, function (File $fileA, File $fileB) {
if (DocumentType::PHOTO_SITUATION === $fileA->getDocumentType()) {
return $fileA->getId() <=> $fileB->getId();
}
if (DocumentType::PHOTO_VISITE === $a->getDocumentType()) {
$interventionA = $a->getIntervention();
$interventionB = $b->getIntervention();
if (DocumentType::PHOTO_VISITE === $fileA->getDocumentType()) {
$interventionA = $fileA->getIntervention();
$interventionB = $fileB->getIntervention();
if (null === $interventionA && null === $interventionB) {
return 0;
}
Expand All @@ -847,17 +846,15 @@ public function getAllPhotosOrdered(Signalement $signalement): ?array
return $interventionA->getId() <=> $interventionB->getId();
}

return $a->getId() <=> $b->getId();
return $fileA->getId() <=> $fileB->getId();
});
}

$sortedPhotos = array_merge(
$photoArraysByType[DocumentType::PHOTO_SITUATION->value],
$photoArraysByType[DocumentType::AUTRE->value],
$photoArraysByType[DocumentType::PHOTO_VISITE->value]
return array_merge(
$photoListByType[DocumentType::PHOTO_SITUATION->value],
$photoListByType[DocumentType::AUTRE->value],
$photoListByType[DocumentType::PHOTO_VISITE->value]
);

return $sortedPhotos;
}

/**
Expand Down
22 changes: 14 additions & 8 deletions src/Manager/SuiviManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,26 @@ public function createInstanceForFilesSignalement(User $user, Signalement $signa
if (DocumentType::PROCEDURE_RAPPORT_DE_VISITE === $documentType && null !== $intervention) {
$isVisibleUsager = true;
if ($nbDocs > 0) {
$description .= $user->getPartner()->getNom().' a ajouté ';
$description .= $nbDocs;
$description .= $nbDocs > 1 ? ' rapports de visite' : ' rapport de visite';
$description .= ' de la visite du '.$intervention->getScheduledAt()->format('d/m/Y').' :';
$description .= sprintf(
'%s a ajouté %s %s de la visite du %s :',
$user->getPartner()->getNom(),
$nbDocs,
$nbDocs > 1 ? ' rapports de visite' : ' rapport de visite',
$intervention->getScheduledAt()->format('d/m/Y')
);
}
}

if (DocumentType::PHOTO_VISITE === $documentType) {
$isVisibleUsager = true;
if ($nbPhotos > 0) {
$description .= $user->getPartner()->getNom().' a ajouté ';
$description .= $nbPhotos;
$description .= $nbPhotos > 1 ? ' photos' : ' photo';
$description .= ' de la visite du '.$intervention->getScheduledAt()->format('d/m/Y').' :';
$description .= sprintf(
'%s a ajouté %s %s de la visite du %s :',
$user->getPartner()->getNom(),
$nbDocs,
$nbDocs > 1 ? ' photos' : ' photo',
$intervention->getScheduledAt()->format('d/m/Y')
);
}
}

Expand Down
4 changes: 1 addition & 3 deletions templates/back/signalement/view/photos-documents.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@
{% if filesFilter is same as 'situation' %}
<div class="fr-grid-row fr-grid-row--middle fr-grid-row--gutters fr-mb-3v">
{% for index, photo in signalement.files|filter(
photo => photo.fileType == 'photo'
and photo.intervention is null
photo => photo.isSituationPhoto
and filesFilter is same as 'situation'
and photo.documentType.label() in DocumentType.getSituationList
) %}
<div class="fr-col-6 fr-col-md-2 fr-rounded signalement-file-item">
<div class="fr-px-5w fr-py-8w fr-rounded fr-border fr-text--center part-infos-hover"
Expand Down
8 changes: 0 additions & 8 deletions templates/back/signalement/view/visites/visite-item.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@
data-signalement-desordres="{{ criteres | json_encode }}"
></button>
{% endif %}
{# {% if is_granted('FILE_DELETE', photo) %}
<button
title="Supprimer la photo {{ photo.filename }}"
data-delete="{{ path('back_signalement_delete_file',{uuid:signalement.uuid,type:'photos',filename:photo.filename}) }}"
data-token="{{ csrf_token('signalement_delete_file_'~signalement.id) }}"
class="fr-btn fr-btn--sm fr-btn--secondary fr-background--white fr-fi-delete-line signalement-file-delete"
></button>
{% endif %} #}
</div>
</div>
{% endfor %}
Expand Down
19 changes: 9 additions & 10 deletions templates/back/signalement/view/visites/visites-buttons.html.twig
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
<div class="signalement-visites-buttons fr-text--right">
<div class="signalement-visites-buttons fr-text--right fr-btns-group fr-btns-group--inline fr-btns-group--sm fr-btns-group--right fr-btns-group--icon-left">
{% if signalement.interventions is empty %}
<button class="fr-btn fr-btn--sm fr-fi-calendar-line fr-btn--icon-left" aria-controls="add-visite-modal" data-fr-opened="false">
<button class="fr-btn fr-fi-calendar-line" aria-controls="add-visite-modal" data-fr-opened="false">
Ajouter une visite
</button>
{% elseif intervention.status is same as constant('App\\Entity\\Intervention::STATUS_PLANNED') %}
{% if is_granted('INTERVENTION_EDIT_VISITE', intervention) %}
{% if workflow_can(intervention, 'cancel') %}
<button class="fr-btn fr-btn--sm fr-btn--danger fr-fi-close-line fr-btn--icon-left" aria-controls="cancel-visite-modal-{{intervention.id}}" data-fr-opened="false">
<button class="fr-btn fr-btn--danger fr-fi-close-line" aria-controls="cancel-visite-modal-{{intervention.id}}" data-fr-opened="false">
Annuler la visite
</button>
{% endif %}
<button class="fr-btn fr-btn--sm fr-btn--secondary fr-fi-edit-line fr-btn--icon-left" aria-controls="reschedule-visite-modal-{{intervention.id}}" data-fr-opened="false">
<button class="fr-btn fr-btn--secondary fr-fi-edit-line" aria-controls="reschedule-visite-modal-{{intervention.id}}" data-fr-opened="false">
Modifier la date
</button>
{% if workflow_can(intervention, 'confirm') %}
<button class="fr-btn fr-btn--sm fr-fi-check-line fr-btn--icon-left" aria-controls="confirm-visite-modal-{{intervention.id}}" data-fr-opened="false">
<button class="fr-btn fr-fi-check-line" aria-controls="confirm-visite-modal-{{intervention.id}}" data-fr-opened="false">
Confirmer la visite
</button>
{% endif %}
{% endif %}
{% elseif intervention.status is same as constant('App\\Entity\\Intervention::STATUS_DONE') %}
{% if signalement.interventions is empty or intervention.files is empty or intervention.getRapportDeVisite is empty%}
{# TODO les photos de visite sont considétées dans ce cas commme un rapport de visite #}
{% if isDocumentsEnabled and is_granted('INTERVENTION_EDIT_VISITE', intervention) %}
<button
class="fr-btn fr-btn--sm fr-fi-file-fill fr-btn--icon-left open-modal-upload-files-btn"
class="fr-btn fr-fi-file-fill open-modal-upload-files-btn"
data-fr-opened="false"
aria-controls="visites-upload-files-{{intervention.id}}"
data-file-type="document"
Expand All @@ -36,14 +35,14 @@
{% else %}
{% if is_granted('INTERVENTION_EDIT_VISITE', intervention) %}
<button
class="fr-btn fr-btn--sm fr-btn--secondary fr-fi-edit-line fr-btn--icon-left"
class="fr-btn fr-btn--secondary fr-fi-edit-line"
aria-controls="edit-visite-modal-{{intervention.id}}"
data-fr-opened="false">
Editer le rapport
</button>
{% endif %}
<a href="{{ asset('_up/'~intervention.getRapportDeVisite[0].filename)~'/' ~ signalement.uuid }}"
class="fr-btn fr-btn--sm"
class="fr-btn"
title="Afficher le document"
rel="noopener"
target="_blank">
Expand All @@ -52,7 +51,7 @@
{% endif %}
{% if isDocumentsEnabled and is_granted('INTERVENTION_EDIT_VISITE', intervention)%}
<button
class="fr-btn fr-btn--sm fr-btn--secondary fr-btn--icon-left fr-icon-camera-fill open-modal-upload-files-btn"
class="fr-btn fr-btn--secondary fr-icon-camera-fill open-modal-upload-files-btn"
data-fr-opened="false"
aria-controls="visites-upload-files-{{intervention.id}}"
data-file-type="photo"
Expand Down

0 comments on commit 4a27845

Please sign in to comment.