Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

108 add the posibility to comment when modifying an upload destined to pass through the validation cycle #129

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions assets/js/department-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -265,3 +285,4 @@ function createSelectElement() {
createNewSelect(e.target.value, e.target.id);
});
}

2 changes: 1 addition & 1 deletion assets/js/document-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
15 changes: 15 additions & 0 deletions src/Entity/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
33 changes: 6 additions & 27 deletions src/Form/UploadType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Service/UploadService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
72 changes: 46 additions & 26 deletions src/Service/ValidationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -69,6 +69,7 @@ public function createValidation(Upload $upload, Request $request)
}
}


// Create a new Validation instance
$validation = new Validation();

Expand All @@ -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);

Expand Down Expand Up @@ -251,42 +257,56 @@ 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
if ($comment != null) {
$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
Expand Down Expand Up @@ -330,4 +350,4 @@ public function approvalEmail(Validation $validation)
{
$this->mailerService->sendApprovalEmail($validation);
}
}
}
34 changes: 34 additions & 0 deletions templates/category_manager/category_manager_index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,41 @@ let buttonIdFromServer = null;{% if zone is defined and zone is not null %}zoneI
</div>
</div>
{% endif %}
<div class="accordion-item">
<h2 class="accordion-header" id="headingUploadedList">
<button class="accordion-button fs-3 collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseUploadedList" aria-expanded="false" aria-controls="collapseUploadedList">
<strong>Liste des fichiers chargés :</strong>
</button>
</h2>
<div id="collapseUploadedList" class="accordion-collapse collapse" aria-labelledby="headingUploadedList" data-bs-parent="#accordionCategory">
<div class="accordion-body accordion-bg shadow shadow-inset">
<div class="row">
<div>
{% include "services/uploads/uploaded_list.html.twig" %}
</div>

</div>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingValidatedList">
<button class="accordion-button fs-3 collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseValidatedList" aria-expanded="false" aria-controls="collapseValidatedList">
<strong>Liste des validations :</strong>
</button>
</h2>
<div id="collapseValidatedList" class="accordion-collapse collapse" aria-labelledby="headingValidatedList" data-bs-parent="#accordionCategory">
<div class="accordion-body accordion-bg shadow shadow-inset">
<div class="row">
<div>
{% include "services/validation/validation_list.html.twig" %}
</div>
</div>
</div>
</div>
</div>
</div>

{% endif %}

{% endblock %}
33 changes: 33 additions & 0 deletions templates/productline_admin/productline_admin.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,39 @@ let buttonIdFromServer = null;{% if zone is defined and zone is not null %}zoneI
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingUploadedList">
<button class="accordion-button fs-3 collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseUploadedList" aria-expanded="false" aria-controls="collapseUploadedList">
<strong>Liste des fichiers chargés :</strong>
</button>
</h2>
<div id="collapseUploadedList" class="accordion-collapse collapse" aria-labelledby="headingUploadedList" data-bs-parent="#accordionLineAdmin">
<div class="accordion-body accordion-bg shadow shadow-inset">
<div class="row">
<div>
{% include "services/uploads/uploaded_list.html.twig" %}
</div>

</div>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingValidatedList">
<button class="accordion-button fs-3 collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseValidatedList" aria-expanded="false" aria-controls="collapseValidatedList">
<strong>Liste des validations :</strong>
</button>
</h2>
<div id="collapseValidatedList" class="accordion-collapse collapse" aria-labelledby="headingValidatedList" data-bs-parent="#accordionLineAdmin">
<div class="accordion-body accordion-bg shadow shadow-inset">
<div class="row">
<div>
{% include "services/validation/validation_list.html.twig" %}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion templates/services/uploads/uploaded_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
{% if upload.validated is same as(false) %}
<a href="{{path('app_validation', {'uploadId' : upload.id} )}}">{{upload.validated ? 'Validé' : 'Non validé'}}
<a>
|

{% else %}
{{upload.validated ? 'Validé' : 'Non validé'}}
|
Expand Down
Loading
Loading