Skip to content

Commit

Permalink
edit desordres slug on photo #2222
Browse files Browse the repository at this point in the history
  • Loading branch information
hmeneuvrier committed Feb 14, 2024
1 parent 1e86f7c commit 7d5fe79
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 67 deletions.
2 changes: 1 addition & 1 deletion assets/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ import './controllers/view_signalement';
import './controllers/cookie_banner';
import './controllers/maintenance_banner';
import './controllers/activate_account/activate_account';
import './controllers/form_file';
import './controllers/back_signalement_edit_file/back_signalement_edit_file';

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
function histoUpdateDesordreSelect(target, selectedDocumentType) {
let desordreSelectBox = document.querySelector('#desordre-slug-select');
if ('SITUATION' === selectedDocumentType ){
const selectedDesordreSlug = target.getAttribute('data-desordreSlug')
let desordres = JSON.parse(target.getAttribute('data-signalement-desordres'))
desordreSelectBox.innerHTML = '';
let option = new Option('Sélectionnez le désordre associé', '');
if ('' === selectedDesordreSlug) {
option.selected = true;
}
desordreSelectBox.appendChild(option);
for (let key in desordres) {
if (desordres.hasOwnProperty(key)) {
let label = desordres[key];
let option = new Option(label, key);
if (key.startsWith(selectedDesordreSlug) && '' !== selectedDesordreSlug) {
option.selected = true;
}
desordreSelectBox.appendChild(option);
}
}
desordreSelectBox.classList.remove('fr-hidden')
}else{
desordreSelectBox.classList.add('fr-hidden')
}
}

document.querySelectorAll('.btn-signalement-file-edit').forEach(swbtn => {
swbtn.addEventListener('click', evt => {
const target = evt.target

if ( target.getAttribute('data-type') === 'photo') {
document.querySelector('.fr-modal-file-edit-type').innerHTML = ' la photo'
} else {
document.querySelector('.fr-modal-file-edit-type').innerHTML = ' le document'
}
document.querySelector('.fr-modal-file-edit-filename').innerHTML = target.getAttribute('data-filename')
document.querySelector('.fr-modal-file-edit-infos').innerHTML = 'Ajouté le '+target.getAttribute('data-createdAt')
+ ' par '+ target.getAttribute('data-partner-name')+target.getAttribute('data-user-name')
document.querySelector('#file-edit-fileid').value = target.getAttribute('data-file-id')

const documentTypes = JSON.parse(target.getAttribute('data-documentType-list'));
const selectedDocumentType = target.getAttribute('data-documentType');
let typeSelectBox = document.querySelector('#document-type-select');
typeSelectBox.innerHTML = '';
let option = new Option('Sélectionnez un type', '');
if ('' === selectedDocumentType) {
option.selected = true;
}
typeSelectBox.appendChild(option);
for (let key in documentTypes) {
if (documentTypes.hasOwnProperty(key)) {
let label = documentTypes[key];
let option = new Option(label, key);
if (key === selectedDocumentType) {
option.selected = true;
}
typeSelectBox.appendChild(option);
}
}
histoUpdateDesordreSelect(target, selectedDocumentType)

document.querySelector('#document-type-select').addEventListener('change', function () {
const selectedValue = this.value;
histoUpdateDesordreSelect(target, selectedValue)
});
})
})
46 changes: 0 additions & 46 deletions assets/controllers/form_file.js

This file was deleted.

1 change: 1 addition & 0 deletions src/Controller/Back/SignalementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public function viewSignalement(
'createdFromDraft' => $signalement->getCreatedFrom(),
'situations' => $infoDesordres['criticitesArranged'],
'photos' => $infoDesordres['photos'],
'precisions' => $infoDesordres['precisions'],
'needValidation' => Signalement::STATUS_NEED_VALIDATION === $signalement->getStatut(),
'canEditSignalement' => $canEditSignalement,
'canExportSignalement' => $canExportSignalement,
Expand Down
12 changes: 12 additions & 0 deletions src/Controller/Back/SignalementFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,20 @@ public function editFileSignalement(
$documentType = DocumentType::tryFrom($request->get('documentType'));
if (null !== $documentType) {
$file->setDocumentType($documentType);
if (DocumentType::SITUATION === $documentType) {
$desordreSlug = $request->get('desordreSlug');
if ($desordreSlug !== $file->getDesordreSlug()) {
$file->setDesordreSlug($desordreSlug);
}
} else {
if (null !== $file->getDesordreSlug()) {
$file->setDesordreSlug(null);
}
}

$entityManager->persist($file);
$entityManager->flush();

if ('document' === $file->getFileType()) {
$this->addFlash('success', 'Le document a bien été modifié.');
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/Service/Signalement/SignalementDesordresProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function process(
$isDanger = false;
$criticitesArranged = [];
$photos = [];
$precisions = [];
if (null == $signalement->getCreatedFrom()) {
foreach ($signalement->getCriticites() as $criticite) {
$situationLabel = $criticite->getCritere()->getSituation()->getLabel();
Expand All @@ -42,13 +43,16 @@ public function process(
$this->addPhotoBySlug($photos, $signalement, $desordreCritereSlug, $desordrePrecisionSlug);
$this->addPhotoBySlug($photos, $signalement, $desordreCritereSlug, $desordreCritereSlug);
$this->addPhotoBySlug($photos, $signalement, $labelCategorieBO, $desordreCategorieSlug);

$precisions[$desordrePrecisionSlug] = $labelCritere.' '.$desordrePrecision->getLabel();
}
}

return [
'criticitesArranged' => $criticitesArranged,
'photos' => $photos,
'isDanger' => $isDanger,
'precisions' => $precisions,
];
}

Expand Down
16 changes: 16 additions & 0 deletions src/Twig/AppExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function getFilters(): array
new TwigFilter('status_to_css', [$this, 'getCssFromStatus']),
new TwigFilter('signalement_lien_declarant_occupant', [$this, 'getLabelLienDeclarantOccupant']),
new TwigFilter('image64', [ImageBase64Encoder::class, 'encode']),
new TwigFilter('truncate_filename', [$this, 'getTruncatedFilename']),
];
}

Expand Down Expand Up @@ -49,6 +50,21 @@ public function getLabelLienDeclarantOccupant(string $lienDeclarantOccupant): st
return '';
}

public function getTruncatedFilename(string $fileName, int $maxCharacters = 50): string
{
if (\strlen($fileName) > $maxCharacters) {
$extensionLength = \strlen(pathinfo($fileName, \PATHINFO_EXTENSION));
$fileNameLength = $maxCharacters - 4 - $extensionLength;
$truncatedFileName = substr($fileName, 0, $fileNameLength);
$truncatedFileName .= '....';
$truncatedFileName .= pathinfo($fileName, \PATHINFO_EXTENSION);

return $truncatedFileName;
}

return $fileName;
}

public function getFunctions(): array
{
return [
Expand Down
18 changes: 11 additions & 7 deletions templates/back/signalement/view/edit-modals/edit-file.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@
</div>
<div class="fr-modal__content">
<h1 id="fr-modal-title-modal-edit-file" class="fr-modal__title">
Editer <span class="fr-modal-file-edit_type"></span>
Editer <span class="fr-modal-file-edit-type"></span>
</h1>

<b><span class="fr-modal-file-edit_filename"></span></b>
<b><span class="fr-modal-file-edit-filename"></span></b>
<br>
<span class="fr-modal-file-edit_infos"></span>

<span class="fr-modal-file-edit-infos"></span>

<div class="fr-select-group">
<select class="fr-select" name="documentType" id="document-type-select">
</select>
</div>
</div>

<div class="fr-select-group">
<select class="fr-select fr-hidden" name="desordreSlug" id="desordre-slug-select">
</select>
</div>
</div>

<div class="fr-modal__footer">
Expand All @@ -33,15 +36,16 @@
</button>
</li>
<li>
<button class="fr-btn fr-icon-checkbox-line" type="submit">
<button class="fr-btn fr-icon-checkbox-line" type="submit" form="form-edit-file"
id="form-edit-file-submit">
Valider
</button>
</li>
</ul>
</div>
</div>
<input type="hidden" name="_token" value="{{ csrf_token('signalement_edit_file_'~signalement.id) }}">
<input type="hidden" name="file_id" id="file_edit_fileid">
<input type="hidden" name="file_id" id="file-edit-fileid">
</form>
</div>
</div>
Expand Down
28 changes: 15 additions & 13 deletions templates/back/signalement/view/photos-documents.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@
aria-controls="fr-modal-edit-file"
data-fr-opened="false"
data-filename="{{ photo.filename }}"
data-type="photos"
data-fileid="{{ photo.id}}"
data-type="photo"
data-file-id="{{ photo.id}}"
data-documentType="{{ photo.documentType.name }}"
data-documentType-list="{{ DocumentType.getPhotosList() | json_encode }}"
data-createdAt="{{ photo.createdAt is defined ? photo.createdAt|date('d.m.Y') : 'N/R' }}"
data-partner="{{ photo.uploadedBy.partner.nom ?? '' }}"
data-user="{{ photo.uploadedBy.nomComplet ?? 'N/R' }}"
data-document-types="{{ DocumentType.getPhotosList() | json_encode }}"
data-partner-name="{{ photo.uploadedBy.partner ? photo.uploadedBy.partner.nom ~ ' - ' : '' }}"
data-user-name="{{ photo.uploadedBy.nomComplet ?? 'N/R' }}"
data-desordreSlug="{{ photo.desordreSlug}}"
data-signalement-desordres="{{ precisions | json_encode }}"
></a>
{% endif %}
{% if (importedBy is not same as 'user' and (photo.uploadedBy is not null and photo.isPartnerFile))
Expand Down Expand Up @@ -116,14 +118,14 @@
<div class="fr-col-12 fr-col-lg-1">
{{ doc.createdAt is defined ? doc.createdAt|date('d.m.Y') : 'N/R' }}
</div>
<div class="fr-col-12 fr-col-lg-1">
<div class="fr-col-12 fr-col-lg-2">
<span class="fr-badge fr-badge--blue-ecume fr-mb-1v">{{ doc.documentType.label() }}</span>
</div>
<div class="fr-col-12 fr-col-lg-5">
{{ doc.uploadedBy.partner.nom ?? '' }} - {{ doc.uploadedBy.nomComplet ?? 'N/R' }}
{{ doc.uploadedBy.partner ? doc.uploadedBy.partner.nom ~ ' - ' : '' }}{{ doc.uploadedBy.nomComplet ?? 'N/R' }}
</div>
<div class="fr-col-12 fr-col-lg-5">
{{ doc.title }}
<div class="fr-col-12 fr-col-lg-4">
<i>{{ doc.title|truncate_filename(45) }}</i>
</div>
</div>
</div>
Expand All @@ -142,12 +144,12 @@
data-fr-opened="false"
data-filename="{{ doc.filename }}"
data-type="document"
data-fileid="{{ doc.id}}"
data-file-id="{{ doc.id}}"
data-documentType="{{ doc.documentType.name }}"
data-documentType-list="{{ DocumentType.getDocumentsList() | json_encode }}"
data-createdAt="{{ doc.createdAt is defined ? doc.createdAt|date('d.m.Y') : 'N/R' }}"
data-partner="{{ doc.uploadedBy.partner.nom ?? '' }}"
data-user="{{ doc.uploadedBy.nomComplet ?? 'N/R' }}"
data-document-types="{{ DocumentType.getDocumentsList() | json_encode }}"
data-partner-name="{{ doc.uploadedBy.partner ? doc.uploadedBy.partner.nom ~ ' - ' : '' }}"
data-user-name="{{ doc.uploadedBy.nomComplet ?? 'N/R' }}"
></a>
{% endif %}
{% if (importedBy is not same as 'user' and (doc.uploadedBy is not null and doc.isPartnerFile))
Expand Down

0 comments on commit 7d5fe79

Please sign in to comment.