From 387cea0aaa81a3961a1b90c962284554e18e94c7 Mon Sep 17 00:00:00 2001 From: SFDKHISSI Date: Tue, 10 Oct 2023 09:51:49 +0200 Subject: [PATCH 1/3] added the list to every admin view --- .../category_manager_index.html.twig | 34 +++++++++++++++++++ .../productline_admin.html.twig | 33 ++++++++++++++++++ .../services/uploads/uploaded_list.html.twig | 2 +- .../zone_admin/zone_admin_index.html.twig | 27 ++++++--------- 4 files changed, 78 insertions(+), 18 deletions(-) diff --git a/templates/category_manager/category_manager_index.html.twig b/templates/category_manager/category_manager_index.html.twig index 51659938..00303885 100755 --- a/templates/category_manager/category_manager_index.html.twig +++ b/templates/category_manager/category_manager_index.html.twig @@ -161,7 +161,41 @@ let buttonIdFromServer = null;{% if zone is defined and zone is not null %}zoneI {% endif %} +
+

+ +

+
+
+
+
+ {% include "services/uploads/uploaded_list.html.twig" %} +
+ +
+
+
+
+
+

+ +

+
+
+
+
+ {% include "services/validation/validation_list.html.twig" %} +
+
+
+
+
+ {% endif %} {% endblock %} diff --git a/templates/productline_admin/productline_admin.html.twig b/templates/productline_admin/productline_admin.html.twig index deba8f0e..c149ce5a 100755 --- a/templates/productline_admin/productline_admin.html.twig +++ b/templates/productline_admin/productline_admin.html.twig @@ -156,6 +156,39 @@ let buttonIdFromServer = null;{% if zone is defined and zone is not null %}zoneI +
+

+ +

+
+
+
+
+ {% include "services/uploads/uploaded_list.html.twig" %} +
+ +
+
+
+
+
+

+ +

+
+
+
+
+ {% include "services/validation/validation_list.html.twig" %} +
+
+
+
+
{% endblock %} diff --git a/templates/services/uploads/uploaded_list.html.twig b/templates/services/uploads/uploaded_list.html.twig index 999ae06d..9ebefaeb 100755 --- a/templates/services/uploads/uploaded_list.html.twig +++ b/templates/services/uploads/uploaded_list.html.twig @@ -59,7 +59,7 @@ {% if upload.validated is same as(false) %} {{upload.validated ? 'Validé' : 'Non validé'}} - | + {% else %} {{upload.validated ? 'Validé' : 'Non validé'}} | diff --git a/templates/zone_admin/zone_admin_index.html.twig b/templates/zone_admin/zone_admin_index.html.twig index 41763134..245c67be 100755 --- a/templates/zone_admin/zone_admin_index.html.twig +++ b/templates/zone_admin/zone_admin_index.html.twig @@ -162,14 +162,11 @@ let buttonIdFromServer = null;{% if zone is defined and zone is not null %}zoneI
- {#
-
#} -
-
- {% include "services/uploads/uploaded_list.html.twig" %} -
- {#
-
#} +
+
+ {% include "services/uploads/uploaded_list.html.twig" %} +
+
@@ -182,15 +179,11 @@ let buttonIdFromServer = null;{% if zone is defined and zone is not null %}zoneI
- {#
-
#} -
-
- {% include "services/validation/validation_list.html.twig" %} -
-
- {#
-
#} +
+
+ {% include "services/validation/validation_list.html.twig" %} +
+
From 46edbf295eadd92f9b93d030db26470feb6dfbaa Mon Sep 17 00:00:00 2001 From: SFDKHISSI Date: Tue, 10 Oct 2023 16:04:31 +0200 Subject: [PATCH 2/3] added the modification comment field to the validation table, modified approbation and upload modifcation view to display the comment --- assets/js/department-creation.js | 21 +++++ assets/js/document-validator.js | 2 +- src/Entity/Validation.php | 15 ++++ src/Form/UploadType.php | 33 ++----- src/Service/UploadService.php | 2 +- src/Service/ValidationService.php | 68 ++++++++------ .../uploads/uploads_modification.html.twig | 88 ++++++++++++++----- .../services/validation/approbation.html.twig | 18 +++- .../disapprovedModification.html.twig | 6 +- .../validation/validation_list.html.twig | 0 yarn.lock | 31 ++++--- 11 files changed, 187 insertions(+), 97 deletions(-) mode change 100644 => 100755 templates/services/validation/validation_list.html.twig diff --git a/assets/js/department-creation.js b/assets/js/department-creation.js index 433210da..487dca24 100755 --- a/assets/js/department-creation.js +++ b/assets/js/department-creation.js @@ -37,6 +37,26 @@ function populateDropdown(dropdown, data, selectedId) { }); } +// Methods use to force the user to add a comment to the form in case of specific event, here the upload of a file +document.addEventListener("turbo:load", function () { + // Get the radio button and the textarea + const fileInput = document.getElementById('upload_file'); + const textareaComment = document.querySelector('textarea[name="modificationComment"]'); + console.log(textareaComment); + // Listen for changes on the radio button + fileInput.addEventListener('change', function () { + if (this.files && this.files.length > 0) { + // Make the textarea required if a file has been selected + textareaComment.required = true; + console.log('required'); + } else { + // Remove the 'required' attribute when "upload_file" is empty + textareaComment.required = false; + console.log('not required'); + } +}); +}); + // This is a function named populateDropdown that takes three parameters: dropdown, data, and selectedId. // It populates the given dropdown element with options based on the provided data array. // It clears the dropdown before populating it, creates a default "Select" option, and adds it to the dropdown. @@ -265,3 +285,4 @@ function createSelectElement() { createNewSelect(e.target.value, e.target.id); }); } + diff --git a/assets/js/document-validator.js b/assets/js/document-validator.js index 46db29ff..fc2798ee 100755 --- a/assets/js/document-validator.js +++ b/assets/js/document-validator.js @@ -226,7 +226,7 @@ function createSelectElement() { // Overall, this code handles the population, reset, and creation of cascading dropdowns based on user data. -// document.addEventListener("DOMContentLoaded", function () { +// Methods use to force the user to add a comment to the form in case of specific event, here the selection of the radio button "Désapprouver" which emits a danger-outlined document.addEventListener("turbo:load", function () { // Get the radio button and the textarea const radioDisapprove = document.getElementById('danger-outlined'); diff --git a/src/Entity/Validation.php b/src/Entity/Validation.php index 334bdbe8..b77e966f 100755 --- a/src/Entity/Validation.php +++ b/src/Entity/Validation.php @@ -29,6 +29,9 @@ class Validation #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)] private ?\DateTimeInterface $validated_at = null; + #[ORM\Column(type: Types::TEXT, nullable: true)] + private ?string $Comment = null; + public function __construct() { $this->approbations = new ArrayCollection(); @@ -104,4 +107,16 @@ public function setValidatedAt(?\DateTimeInterface $validated_at): static return $this; } + + public function getComment(): ?string + { + return $this->Comment; + } + + public function setComment(?string $Comment): static + { + $this->Comment = $Comment; + + return $this; + } } \ No newline at end of file diff --git a/src/Form/UploadType.php b/src/Form/UploadType.php index 19aacb85..67835fe4 100755 --- a/src/Form/UploadType.php +++ b/src/Form/UploadType.php @@ -82,38 +82,17 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'multiple' => false, ] ) - // // Adds an entity field for selecting approbators to the form + // // Add a comment section for the modifcation page for the file that went through the validation cycle // ->add( - // 'approbator', - // EntityType::class, + // 'comment', + // TextType::class, // [ - // 'class' => User::class, // Adjust this to match your User entity namespace - // 'query_builder' => function (EntityRepository $er) use ($currentUserId, $currentApprobationId) { - // return $er->createQueryBuilder('u') - // ->leftJoin('u.approbations', 'a') // Assuming 'approbations' is a relationship in your User entity - // ->where('u.roles NOT LIKE :role') - // ->andWhere('a.id = :currentApprobationId') - // ->andWhere('u.id != :currentUserId') - // ->setParameter('role', '%ROLE_SUPER_ADMIN%') - // ->setParameter('currentUserId', $currentUserId) - // ->setParameter('currentApprobationId', $currentApprobationId) - // ->orderBy('u.username', 'ASC'); - // }, - // 'choice_label' => 'username', // Assuming your user entity has a 'username' property - // 'label' => 'Select approbators:', + // 'label' => 'Commentaire:', // 'required' => false, - // 'multiple' => true, // Now the form can accept multiple approbators - // 'mapped' => false // This is the important part + // 'empty_data' => null, // ] // ) - // // Adds a choice field for selecting the modification type to the form - // ->add('modificationType', ChoiceType::class, [ - // 'mapped' => false, // this tells Symfony not to expect the `modificationType` property on the entity - // 'choices' => [ - // 'Modification Mineure' => 'light-modification', - // 'Modification Majeure' => 'heavy-modification', - // ], - // ]) + ; // Event listener triggered before form submission diff --git a/src/Service/UploadService.php b/src/Service/UploadService.php index e01dbc00..df0413ee 100755 --- a/src/Service/UploadService.php +++ b/src/Service/UploadService.php @@ -213,7 +213,7 @@ public function modifyFile(Upload $upload, User $user, Request $request, string $Path = $folderPath . '/' . $upload->getFilename(); - ////////////// Part mainly important for the intriduction of the validation process in the production environment + ////////////// Part mainly important for the introduction of the validation process in the production environment // Check if the file need to be validated or not, by checking if there is a validator_department or a validator_user string in the request if ($request->request->get('validatorRequired') == 'true') { foreach ($request->request->keys() as $key) { diff --git a/src/Service/ValidationService.php b/src/Service/ValidationService.php index 56f13677..3b80eb14 100755 --- a/src/Service/ValidationService.php +++ b/src/Service/ValidationService.php @@ -60,7 +60,7 @@ public function createValidation(Upload $upload, Request $request) { // Create empty arrays to store values for validator_department and validator_user $validator_user_values = []; - $this->logger->info('request: ' . json_encode($request->request->all())); + // Iterate through the keys in the request foreach ($request->request->keys() as $key) { // If the key contains 'validator_user', add its value to the validator_user_values array @@ -69,6 +69,7 @@ public function createValidation(Upload $upload, Request $request) } } + // Create a new Validation instance $validation = new Validation(); @@ -78,6 +79,11 @@ public function createValidation(Upload $upload, Request $request) // Set the status of the Validation instance to false $validation->setStatus(null); + // Store the comment in a variable + $comment = $request->request->get('modificationComment'); + // If the user added a comment persist the comment + $validation->setComment($comment); + // Persist the Validation instance to the database $this->em->persist($validation); @@ -251,42 +257,52 @@ public function resetApprobation(Upload $upload, Request $request, ?bool $global $upload->setValidated(null); // Get the ID of the validation instance $validation = $upload->getValidation(); - // Remove the Validation instance from the database + // Remove the Validation status from the database $validation->setStatus(null); + // Store the comment in a variable + $comment = $request->request->get('modificationComment'); + // If the user added a comment persist the comment + $validation->setComment($comment); // Persist the Validation instance to the database $this->em->persist($validation); // Flush changes to the database $this->em->flush(); - // Create an empty array to store Approbation instances - $approbations = []; - // Get the ID of the Validation instance - $approbations = $validation->getApprobations(); - // Loop through each Approbation instance - foreach ($approbations as $approbation) { - //If it's a major modification reset all approbations - if ($request->request->get('modification-outlined') == 'heavy-modification') { - // Remove the Approbation instance from the database - $approbation->setApproval(null); - $approbation->setApprovedAt(null); - $approbation->setComment(null); - if (!$globalModification) { + + // If the Validation instance has Approbation instances + if ($validation->getApprobations() != null) { + // Create an empty array to store Approbation instances + $approbations = []; + // Get the ID of the Validation instance + $approbations = $validation->getApprobations(); + // Loop through each Approbation instance + foreach ($approbations as $approbation) { + //If it's a major modification reset all approbations + if ($request->request->get('modification-outlined') == 'heavy-modification') { + // Remove the Approbation instance from the database + $approbation->setApproval(null); + $approbation->setApprovedAt(null); + $approbation->setComment(null); + if (!$globalModification) { + $this->disapprovedModifiedEmail($approbation); + } + } + // If the Approbation is not approved or the Approval property is null + elseif ($approbation->isApproval() == false) { + // Remove the Approbation instance from the database + $approbation->setApproval(null); + $approbation->setApprovedAt(null); + $approbation->setComment(null); $this->disapprovedModifiedEmail($approbation); } } - // If the Approbation is not approved or the Approval property is null - elseif ($approbation->isApproval() == false) { - // Remove the Approbation instance from the database - $approbation->setApproval(null); - $approbation->setApprovedAt(null); - $approbation->setComment(null); - $this->disapprovedModifiedEmail($approbation); - } + // Persist the Approbation instance to the database + $this->em->persist($approbation); } + if ($globalModification) { $this->approbationEmail($validation); } - // Persist the Approbation instance to the database - $this->em->persist($approbation); + // Flush changes to the database $this->em->flush(); // Return early @@ -330,4 +346,4 @@ public function approvalEmail(Validation $validation) { $this->mailerService->sendApprovalEmail($validation); } -} \ No newline at end of file +} diff --git a/templates/services/uploads/uploads_modification.html.twig b/templates/services/uploads/uploads_modification.html.twig index 5acfce38..51af7d33 100755 --- a/templates/services/uploads/uploads_modification.html.twig +++ b/templates/services/uploads/uploads_modification.html.twig @@ -21,13 +21,15 @@ zoneIdFromServer = parseInt('{{ zone.getId() }}');{% endif %}{% if productLine i

Modification du fichier - {{upload.filename}} + {{upload.filename}} :

- +
Revision n°{{upload.revision}}
{{ form_start(form, {'attr': {'class': 'form-floating justify-content-center', 'id': 'modifyForm','method' : 'POST', 'enctype': 'multipart/form-data'}, 'action': path('app_modify_file', {'uploadId': upload.id})}) }}
+ {% if upload.validation is not empty %} + {% if upload.validated is same as(null)%}
@@ -51,6 +53,14 @@ zoneIdFromServer = parseInt('{{ zone.getId() }}');{% endif %}{% if productLine i {% endfor %} + {% if upload.revision is same as (1) %} + {% else %} + Le fichier a été modifié le {{upload.uploadedAt|date('d/m/y')}} + {% if upload.validation.comment is defined %} + avec le commentaire suivant : +
    "{{upload.validation.comment}}"
+ {% endif %} + {% endif %}
{% elseif upload.validated is same as(false) %} @@ -63,21 +73,39 @@ zoneIdFromServer = parseInt('{{ zone.getId() }}');{% endif %}{% if productLine i
- {% else %} - {% if upload.validation is not defined %} + {% if upload.validated is same as (true) %}
+ {% if upload.revision is same as (1) %} + {% else %} + Le fichier a été modifié le {{upload.uploadedAt|date('d/m/y')}} + {% if upload.validation.comment is defined %} + avec le commentaire suivant : +
    "{{upload.validation.comment}}"
+ {% endif %} + {% endif %} {% for approbation in upload.validation.approbations %} +
  • {{ approbation.userapprobator.username|capitalize|split('.')|first }} {{ approbation.userapprobator.username|upper|split('.')|last }} {{ approbation.approval is same as(true) ? ' a validé ce document le ' ~ approbation.approvedAt|date('d/m/Y') ~ ' à ' ~ approbation.approvedAt|date('H') ~ 'h' ~ approbation.approvedAt|date('i')}}.
  • +
{% endfor %}
- {% endif %} + {% endif %} {% endif %} + + {% else %} +
+ Ce document n'a pas necessité de validation. +
+ + {% endif %} + +
{{ form_label(form.file, 'Choisissez un nouveau ficher:', {'label_attr': {'class': 'form-label', 'style': 'color:white'}}) }} {{ form_widget(form.file, {'attr': {'class': 'form-control', 'id': 'file', 'accept' : '.pdf'}}) }} @@ -146,33 +174,47 @@ zoneIdFromServer = parseInt('{{ zone.getId() }}');{% endif %}{% if productLine i
-
+
{{ form_widget(form.button,{'attr': {'class': 'form-select', 'name': 'button', 'id': 'upload_button', 'required': true}}) }}
- {% if upload.uploadedAt < date('2023-09-19 00:00:00') %} -
-
-
- - - -
-
-
-
- +
+ + {% if upload.uploadedAt < date('2023-10-19 00:00:00') %} +
+
+ + + +
+
+
+
+ +
+
+ +
+
-
- +
+ {% endif %} + +
+ {% if upload.validation is not empty %} + +
+
+
+ Commentaire +
+ + {% endif %}
- {% endif %} -
-
diff --git a/templates/services/validation/approbation.html.twig b/templates/services/validation/approbation.html.twig index 7a54aa69..2059d452 100755 --- a/templates/services/validation/approbation.html.twig +++ b/templates/services/validation/approbation.html.twig @@ -27,14 +27,24 @@
- {% block title %}Page de validation de document par + {% block title %} + + Page de validation de document par {{user.username|capitalize|split('.')|first }} {{user.username|upper|split('.')|last }}
+ + {% if approbation.validation.comment is defined %} + Validation faisant suite à modification du document par {{approbation.validation.upload.uploader.username|capitalize|split('.')|first }} + {{approbation.validation.upload.uploader.username|upper|split('.')|last }}
avec le commentaire suivant : +
+
"{{approbation.validation.comment}}"
+ {% endif %} +