Skip to content

Commit

Permalink
Merge pull request #68 from kiloutyg/66-need-to-change-lastmodifier-t…
Browse files Browse the repository at this point in the history
…o-be-just-a-string-and-not-a-relation-to-eliminate-issue-with-user-deletioln-in-the-future-and-keep-tracebility

 added  archiving commentary logic, changed the lastmodifier value type
  • Loading branch information
kiloutyg authored Mar 15, 2024
2 parents 4dfdd67 + 27fd1d5 commit 83c325c
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 85 deletions.
46 changes: 46 additions & 0 deletions assets/controllers/archiving_commentary_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export default class extends Controller {

static targets = ['archivingCommentary', 'archivingCommentaryMessage', 'archivingButton'];

connect() {
// Initialization code or leave empty if not needed
}

archivingCommentary() {
console.log("archivingCommentary" + this.archivingCommentaryTarget.value);
const commentary = this.archivingCommentaryTarget.value.trim();
Expand All @@ -18,4 +22,46 @@ export default class extends Controller {
this.archivingCommentaryMessageTarget.style.color = "red"; // Display the message in red color.
}
}


archiveWithCommentary(event) {

const entityType = this.trainingOperatorCodeTarget.dataset.entityType;
const efncid = this.trainingOperatorCodeTarget.dataset.efncid;

// Prevent default form submission behavior
event.preventDefault();

// Validate commentary as per your logic; here directly using validateCommentary method
this.validateCommentary();

if (!this.archivingButtonTarget.disabled) {
const url = '/efnc/admin/archive/'; // Replace with your actual endpoint
const commentary = this.archivingCommentaryTarget.value;

fetch(url, {
method: 'POST',
body: JSON.stringify({ archivingCommentary: commentary }),
headers: {
'Content-Type': 'application/json',
// Add other headers like CSRF token if necessary
}
})
.then(response => {
// Handle successful response
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json(); // Or `response.text()` if your server sends something other than JSON
})
.then(data => {
// Do something with the data
console.log(data);
})
.catch(error => {
// Handle errors here
console.error('Fetch error:', error);
});
}
}
}
9 changes: 7 additions & 2 deletions src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,13 @@ public function productVersionCreation(Request $request): Response
public function archiveEntity(Request $request, string $entityType, int $id): Response
{
$originUrl = $request->headers->get('referer');
$this->logger->info('Archive entity: ' . $entityType . ' ' . $id . ' full request: ' . json_encode($request->getContent()));
$result = $this->entityDeletionService->archivedEntity($entityType, $id, $request);
$user = $this->getUser()->getUsername();
$commentary = $request->request->get('archivingCommentary');

$this->logger->info($user . ' archived entity: ' . $entityType . ' ' . $id . ' ' . 'commentaire: ' . $commentary . ' full request: ' . json_encode($request->getContent()));

$result = $this->entityDeletionService->archivedEntity($entityType, $id, $commentary, $user);

if ($result == false) {
$this->addFlash('danger', 'L\'élément n\'a pas pu être archivé');
return $this->redirect($originUrl);
Expand Down
8 changes: 4 additions & 4 deletions src/Entity/EFNC.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class EFNC
#[ORM\Column(nullable: true)]
private ?bool $archived = null;

#[ORM\ManyToOne(inversedBy: 'eFNCs')]
private ?User $lastModifier = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $lastModifier = null;

#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $archivingCommentary = null;
Expand Down Expand Up @@ -530,12 +530,12 @@ public function setArchived(?bool $archived): static
return $this;
}

public function getLastModifier(): ?User
public function getLastModifier(): ?string
{
return $this->lastModifier;
}

public function setLastModifier(?User $lastModifier): static
public function setLastModifier(?string $lastModifier): static
{
$this->lastModifier = $lastModifier;

Expand Down
37 changes: 0 additions & 37 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column(length: 255, nullable: true)]
private ?string $emailAddress = null;

#[ORM\OneToMany(mappedBy: 'lastModifier', targetEntity: EFNC::class)]
private Collection $eFNCs;

public function __construct()
{
$this->eFNCs = new ArrayCollection();
}

public function getId(): ?int
{
Expand Down Expand Up @@ -129,34 +122,4 @@ public function setEmailAddress(?string $emailAddress): static

return $this;
}

/**
* @return Collection<int, EFNC>
*/
public function getEFNCs(): Collection
{
return $this->eFNCs;
}

public function addEFNC(EFNC $eFNC): static
{
if (!$this->eFNCs->contains($eFNC)) {
$this->eFNCs->add($eFNC);
$eFNC->setLastModifier($this);
}

return $this;
}

public function removeEFNC(EFNC $eFNC): static
{
if ($this->eFNCs->removeElement($eFNC)) {
// set the owning side to null (unless already changed)
if ($eFNC->getLastModifier() === $this) {
$eFNC->setLastModifier(null);
}
}

return $this;
}
}
3 changes: 1 addition & 2 deletions src/Service/FormModificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public function __construct(
public function modifyNCForm(
EFNC $efnc,
Request $request,
FormInterface $form1,
User $user
FormInterface $form1
) {
$now = new \DateTime();

Expand Down
85 changes: 45 additions & 40 deletions templates/services/efnc/modification/form_modification.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -183,53 +183,58 @@
Modifier
</button>
</div>


{% endif %}
</div>
{{ form_end(form1) }}
<form
method="post"
action="{{ path('app_archive_entity', {entityType: 'efnc', id: EFNC.id}) }}">

<div
class="container mt-2 mb-2"
data-controller="archiving-commentary">
<div
class="container mt-5"
data-controller="archiving-commentary">
class="row justify-content-md-center">
<div
class="row justify-content-md-center">
<div
class="col-md-12">
<label
for="archivingCommentary"
class="form-label text-white">
Commentaire d'archivage obligatoire
<div
data-archiving-commentary-target="archivingCommentaryMessage"
class="archivingCommentaryMessage-message d-flex justify-content-evenly"></div>
</label>
<textarea
class="form-control"
id="archivingCommentary"
name="archivingCommentary"
data-archiving-commentary-target="archivingCommentary"
data-action="keyup->archiving-commentary#archivingCommentary"></textarea>
</div>
class="col-md-12">
<label
for="archivingCommentary"
class="form-label text-white">
Commentaire d'archivage obligatoire
<div
data-archiving-commentary-target="archivingCommentaryMessage"
class="archivingCommentaryMessage-message d-flex justify-content-evenly"></div>
</label>
<textarea
class="form-control"
id="archivingCommentary"
name="archivingCommentary"
data-archiving-commentary-target="archivingCommentary"
data-action="keyup->archiving-commentary#archivingCommentary"></textarea>
</div>
<div
class="d-grid gap-2 d-md-flex justify-content-md-center mt-2">
</div>
<div
class="d-grid gap-2 d-md-flex justify-content-md-center mt-2">
<button
type="submit"
class="btn btn-danger archive-EFNC"
data-archiving-commentary-target="archivingButton"
hidden
disabled>
Archiver
</button>
{% if is_granted('ROLE_MASTER_ADMIN') %}
<a
id="archivingButton"
name="archivingButton"
data-archiving-commentary-target="archivingButton"
class="btn btn-danger archive-EFNC"
href="{{path('app_archive_entity', {entityType: 'efnc', id: EFNC.id})}}" hidden
disabled>
Archiver
href="{{path('app_close_entity', {entityType: 'efnc', id: EFNC.id})}}">
Cloturer
</a>
{% if is_granted('ROLE_MASTER_ADMIN') %}
<a
class="btn btn-danger archive-EFNC"
href="{{path('app_close_entity', {entityType: 'efnc', id: EFNC.id})}}">
Cloturer
</a>
{% endif %}
</div>
{% endif %}
</div>

{% endif %}
</div>
{{ form_end(form1) }}
</div>
</form>
</div>
</div>
{% endblock %}

0 comments on commit 83c325c

Please sign in to comment.