Skip to content

Commit

Permalink
Permettre d'ajouter un lien libre depuis la fiche Zone
Browse files Browse the repository at this point in the history
Permet d'ajouter et de voir les liens libres depuis la fiche Zone
delimitée.
  • Loading branch information
Anto59290 committed Oct 31, 2024
1 parent 2450ed6 commit e709f8f
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 56 deletions.
2 changes: 0 additions & 2 deletions core/static/core/liens_libres.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.fiche-detail__liens {
grid-column: span 3;
background-color: var(--fiche-detail-bloc-background-color);
padding: var(--fiche-detail-bloc-padding);
}
14 changes: 14 additions & 0 deletions sv/static/sv/common.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.fiche-action {
display: flex;
}

.fiche-action .fr-translate__btn {
line-height: 1.5rem;
min-height: 2.5rem;
padding: .5rem 1rem;
}

.fiche-action .fr-translate .fr-translate__btn::before {
-webkit-mask-image: url(../../../static/icons/system/add-line.svg);
mask-image: url(../../../static/icons/system/add-line.svg);
}
15 changes: 0 additions & 15 deletions sv/static/sv/fichedetection_detail.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@ main{
}


.fiche-action {
display: flex;
}

.fiche-action .fr-translate__btn {
line-height: 1.5rem;
min-height: 2.5rem;
padding: .5rem 1rem;
}

.fiche-action .fr-translate .fr-translate__btn::before {
-webkit-mask-image: url(../../../static/icons/system/add-line.svg);
mask-image: url(../../../static/icons/system/add-line.svg);
}

/* Bloc Informations */
.fiche-detail__informations{
grid-column: span 3;
Expand Down
8 changes: 8 additions & 0 deletions sv/static/sv/fichezone_detail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
document.addEventListener('DOMContentLoaded', function() {
new Choices(document.getElementById('id_object_choice'), {
classNames: {
containerInner: 'fr-select',
},
itemSelectText: ''
});
});
File renamed without changes.
2 changes: 1 addition & 1 deletion sv/templates/sv/_lienlibre_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1 id="fr-modal-title-modal-1" class="fr-modal__title"><span class="fr-icon-arr
<form method="post" action="{% url 'free-link-add' %}">
{{ free_link_form.as_dsfr_div }}
{% csrf_token %}
<input type="hidden" value="{{ fichedetection.get_absolute_url }}" name="next">
<input type="hidden" value="{{ fiche.get_absolute_url }}" name="next">
<div class="fr-btns-group fr-btns-group--left fr-btns-group--inline-lg">
<button type="button" class="fr-btn fr-btn--secondary" aria-controls="fr-modal-freelink">Annuler</button>
<button type="submit" class="fr-btn" data-testid="submit-freelink">Valider</button>
Expand Down
13 changes: 13 additions & 0 deletions sv/templates/sv/_list_free_links.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="fiche-detail__liens white-container {{ classes }}">
<h2>Liens libres</h2>
{% for link in free_links_list %}
{% if link.related_object_1 == fiche and not link.related_object_2.is_deleted %}
<a class="fr-link fr-mr-2v" href="{{ link.related_object_2.get_absolute_url }}">{{ link.related_object_2 }}</a>
{% endif %}
{% if link.related_object_2 == fiche and not link.related_object_1.is_deleted %}
<a class="fr-link fr-mr-2v" href="{{ link.related_object_1.get_absolute_url }}">{{ link.related_object_1 }}</a>
{% endif %}
{% empty %}
<p>Pas de liens pour cette fiche.</p>
{% endfor %}
</div>
11 changes: 11 additions & 0 deletions sv/templates/sv/_zone_action_navigation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<nav role="navigation" class="fr-translate fr-nav">
<div class="fr-nav__item">
<button class="fr-translate__btn fr-btn fr-btn--lg" aria-controls="action-1"
aria-expanded="false" title="Sélectionner une action">Actions</button>
<div class="fr-collapse fr-translate__menu fr-menu" id="action-1">
<ul class="fr-menu__list">
<li><a class="fr-translate__language fr-nav__link" href="#" data-fr-opened="false" aria-controls="fr-modal-freelink"><span class="fr-icon-git-pull-request-fill fr-mr-2v fr-icon--sm" aria-hidden="true"></span>Ajouter un lien libre</a></li>
</ul>
</div>
</div>
</nav>
19 changes: 4 additions & 15 deletions sv/templates/sv/fichedetection_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{% load etat_tags %}

{% block extrahead %}
<link rel="stylesheet" href="{% static 'sv/common.css' %}">
<link rel="stylesheet" href="{% static 'sv/fichedetection_detail.css' %}">
{% endblock %}

Expand Down Expand Up @@ -44,8 +45,8 @@ <h1 class="fiche-header__title">Fiche détection n° {{ fichedetection.numero }}
<button class="fr-btn fr-btn--secondary fr-mr-2w">
<a href="{% url 'fiche-detection-modification' fichedetection.pk %}"><span class="fr-icon-edit-fill">Modifier</span></a>
</button>
{% include "sv/_action_navigation.html" %}
{% include "sv/_lienlibre_modal.html" %}
{% include "sv/_detection_action_navigation.html" %}
{% include "sv/_lienlibre_modal.html" with fiche=fichedetection %}
{% include "sv/_delete_fiche_modal.html" %}
{% include "sv/_fichedetection_cloturer_modal.html" %}
{% if can_update_visibilite %}
Expand Down Expand Up @@ -205,19 +206,7 @@ <h2>Mesures de gestion</h2>
</div>
</div>
</div>
<div class="fiche-detail__liens">
<h2>Liens libres</h2>
{% for link in free_links_list %}
{% if link.related_object_1 == fichedetection and not link.related_object_2.is_deleted %}
<a class="fr-link fr-mr-2v" href="{{ link.related_object_2.get_absolute_url }}">{{ link.related_object_2 }}</a>
{% endif %}
{% if link.related_object_2 == fichedetection and not link.related_object_1.is_deleted %}
<a class="fr-link fr-mr-2v" href="{{ link.related_object_1.get_absolute_url }}">{{ link.related_object_1 }}</a>
{% endif %}
{% empty %}
<p>Pas de liens pour cette fiche.</p>
{% endfor %}
</div>
{% include "sv/_list_free_links.html" with fiche=fichedetection %}
</div>
</div>
{% include "sv/_fichedetection_synthese.html" %}
Expand Down
32 changes: 11 additions & 21 deletions sv/templates/sv/fichezonedelimitee_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,25 @@
{% load remove_trailing_zero %}

{% block extrahead %}
<link rel="stylesheet" href="{% static 'sv/common.css' %}">
<link rel="stylesheet" href="{% static 'sv/fichezonedelimitee_detail.css' %}">
{% endblock %}

{% block scripts %}
<script type="text/javascript" src="{% static 'sv/fichezone_detail.js' %}"></script>
{% endblock %}

{% block content %}
<div class="fr-container--fluid fr-m-4w ">

<div class="fr-grid-row fr-mb-3w">
<div class="fr-col">
<h1 class="fr-mb-0-5v">Fiche zone délimitée n° {{ fiche.numero }}</h1>
</div>
<ul class="fichezonedelimitee__actions fr-btns-group fr-btns-group--inline fr-btns-group--right">
<li>
<button class="fr-btn fr-btn--secondary">
Modifier
</button>
</li>
<li>
<nav role="navigation" class="fr-translate fr-nav">
<div class="fr-nav__item">
<button class="fr-btn fr-btn--lg" aria-controls="actions" aria-expanded="false" title="Sélectionner une action">Actions</button>
<div class="fr-collapse fr-translate__menu fr-menu" id="actions">
<ul class="fr-menu__list">
<li>
<a class="fr-translate__language fr-nav__link" ref="#">test</a>
</li>
</ul>
</div>
</div>
</nav>
</li>
</ul>
<div class="fiche-action">
{% include "sv/_zone_action_navigation.html" %}
{% include "sv/_lienlibre_modal.html" %}
</div>
</div>

<div class="fr-grid-row fr-grid-row--gutters">
Expand Down Expand Up @@ -180,5 +168,7 @@ <h2>Zones infestées {% if zones_infestees|length %}({{ zones_infestees|length }
<p>Aucune zone infestée</p>
{% endif %}
</div>

{% include "sv/_list_free_links.html" with classes="fr-mt-8v" %}
</div>
{% endblock %}
12 changes: 11 additions & 1 deletion sv/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from playwright.sync_api import Page
from model_bakery import baker
from model_bakery.recipe import Recipe, foreign_key
from sv.models import Etat, FicheDetection
from sv.models import Etat, FicheDetection, FicheZoneDelimitee

User = get_user_model()

Expand Down Expand Up @@ -44,6 +44,16 @@ def add_basic_etat_objects():
Etat.objects.get_or_create(libelle="clôturé")


@pytest.fixture
def fiche_zone_bakery(db, mocked_authentification_user):
def _fiche_zone_bakery():
return baker.make(
FicheZoneDelimitee, _fill_optional=True, createur=mocked_authentification_user.agent.structure
)

return _fiche_zone_bakery


@pytest.fixture
def fiche_detection_bakery(db, mocked_authentification_user):
def _fiche_detection_bakery():
Expand Down
33 changes: 33 additions & 0 deletions sv/tests/test_fichezone_liens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest
from django.contrib.contenttypes.models import ContentType

from core.models import LienLibre
from playwright.sync_api import expect


@pytest.mark.django_db
def test_can_add_free_link(live_server, page, fiche_zone_bakery, choice_js_fill):
fiche = fiche_zone_bakery()
other_fiche = fiche_zone_bakery()
page.goto(f"{live_server.url}{fiche.get_absolute_url()}")

page.get_by_role("button", name="Actions").click()
page.get_by_role("link", name="Ajouter un lien libre").click()
page.wait_for_selector("#fr-modal-freelink .choices__list--single")
choice_js_fill(
page,
"#fr-modal-freelink .choices__list--single",
f"Fiche Zone Delimitee: {str(other_fiche.numero)}",
f"Fiche Zone Delimitee: {str(other_fiche.numero)}",
)
page.get_by_test_id("submit-freelink").click()

expect(page.get_by_text("Le lien a été créé avec succès.")).to_be_visible()

link = LienLibre.objects.get()
assert link.content_type_1 == ContentType.objects.get_for_model(other_fiche)
assert link.content_type_2 == ContentType.objects.get_for_model(other_fiche)
assert link.object_id_1 == fiche.pk
assert link.object_id_2 == other_fiche.pk

expect(page.get_by_role("link", name=str(other_fiche.numero))).to_be_visible()
8 changes: 7 additions & 1 deletion sv/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,10 +751,15 @@ def formset_invalid(self):
return self.render_to_response(self.get_context_data())


class FicheZoneDelimiteeDetailView(DetailView):
class FicheZoneDelimiteeDetailView(WithFreeLinksListInContextMixin, DetailView):
model = FicheZoneDelimitee
context_object_name = "fiche"

def _get_free_link_form(self):
return FreeLinkForm(
content_type_1=ContentType.objects.get_for_model(self.get_object()).pk, object_id_1=self.get_object().pk
)

def get_queryset(self):
zone_infestee_detections_prefetch = Prefetch(
"fichedetection_set", queryset=FicheDetection.objects.select_related("numero")
Expand All @@ -770,6 +775,7 @@ def get_queryset(self):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
fichezonedelimitee = self.get_object()
context["free_link_form"] = self._get_free_link_form()
context["detections_hors_zone_infestee"] = fichezonedelimitee.fichedetection_set.select_related("numero").all()
context["zones_infestees"] = [
(zone_infestee, zone_infestee.fichedetection_set.all())
Expand Down

0 comments on commit e709f8f

Please sign in to comment.