Skip to content

Commit

Permalink
Membre & Profil : améliorations de la gestion des badges (elefan-gren…
Browse files Browse the repository at this point in the history
…oble#978)

* Profile: move template to beneficiary partials

* Create member partial

* Refactor add_modal template

* Common image template

* Cleanup enable, disable and delete views
  • Loading branch information
raphodn authored and OursDesCavernes committed Jan 20, 2024
1 parent b9bbf8d commit 4dfbae6
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 286 deletions.
2 changes: 1 addition & 1 deletion app/Resources/views/Profile/show_content.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<i class="material-icons">credit_card</i>Badge{% if beneficiary.swipeCards | length > 1 %}s{% endif %}
</div>
<div class="collapsible-body">
{% include "member/_partial/swipe_card.html.twig" with { member: member, show_badge_image: true } %}
{% include "beneficiary/_partial/swipe_cards.html.twig" with { beneficiary: beneficiary, show_badge_image: true } %}
</div>
</li>
{% endif %}
Expand Down
30 changes: 30 additions & 0 deletions app/Resources/views/beneficiary/_partial/swipe_cards.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% if beneficiary.getEnabledSwipeCards | length %}
{% if (show_badge_image ?? false) %}
{% include "swipeCard/_partial/image.html.twig" with { card: beneficiary.getEnabledSwipeCards.first, with_badge_card: true } %}
{% endif %}
<a href="#swipe_disable_{{ beneficiary.getEnabledSwipeCards.first.id }}" class="red-text modal-trigger">Badge perdu ?</a>
{% include "swipeCard/_partial/disable_modal.html.twig" with { card: beneficiary.getEnabledSwipeCards.first } %}
{% else %}
<p><b class="red-text">Aucun badge actif</b></p>
<a href="#swipe_add" class="btn waves-effect waves-light modal-trigger">
<i class="material-icons left">add</i>Associer un badge à ton compte
</a>
{% include "swipeCard/_partial/add_modal.html.twig" with { beneficiary: beneficiary } %}
{% endif %}

{% if beneficiary.getSwipeCards | length %}
<br />
<br />
<a class="waves-effect waves-light btn modal-trigger blue-grey" href="#all_swipecards">
<i class="material-icons left">credit_card</i>{% if beneficiary.getSwipeCards | length > 1 %}Vos badges{% else %}Ton badge{% endif %}
</a>
<div id="all_swipecards" class="modal bottom-sheet">
<div class="modal-content">
<h4>Tous vos badges</h4>
{% include "swipeCard/_partial/list.html.twig" with { beneficiairy: beneficiary } %}
</div>
<div class="modal-footer">
<a href="#!" class="modal-close waves-effect waves-green btn-flat red-text">Fermer</a>
</div>
</div>
{% endif %}
95 changes: 0 additions & 95 deletions app/Resources/views/member/_partial/swipe_card.html.twig

This file was deleted.

33 changes: 33 additions & 0 deletions app/Resources/views/member/_partial/swipe_cards.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="row">
{% for beneficiary in member.beneficiaries %}
<div class="col s12 m6">
<h4>{{ beneficiary.firstname }}</h4>
{% if beneficiary.getEnabledSwipeCards | length %}
{% include "swipeCard/_partial/image.html.twig" with { card: beneficiary.getEnabledSwipeCards.first, with_badge_card: true } %}
{% else %}
<p><b class="red-text">Aucun badge actif</b></p>
<a href="#swipe_add_b{{ beneficiary.id }}" class="btn waves-effect waves-light modal-trigger">
<i class="material-icons left">add</i>Associer un badge à ce compte
</a>
{% include "swipeCard/_partial/add_modal.html.twig" with { beneficiary: beneficiary, from_admin: true } %}
{% endif %}

{% if beneficiary.getSwipeCards | length %}
<br />
<br />
<a class="waves-effect waves-light btn modal-trigger blue-grey" href="#all_swipecards_b{{ beneficiary.id }}">
<i class="material-icons left">credit_card</i>Badges de {{ beneficiary.firstname }}
</a>
<div id="all_swipecards_b{{ beneficiary.id }}" class="modal bottom-sheet">
<div class="modal-content">
<h4>Tous les badges {{ beneficiary.firstname }}</h4>
{% include "swipeCard/_partial/list.html.twig" with { beneficiary: beneficiary, from_admin: true } %}
</div>
<div class="modal-footer">
<a href="#!" class="modal-close waves-effect waves-green btn-flat red-text">Fermer</a>
</div>
</div>
{% endif %}
</div>
{% endfor %}
</div>
49 changes: 1 addition & 48 deletions app/Resources/views/member/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -113,54 +113,7 @@
<i class="material-icons">credit_card</i>Badges
</div>
<div class="collapsible-body white">
<div class="row">
{% for beneficiary in member.beneficiaries %}
<div class="col s12 m6">
<h4>{{ beneficiary.firstname }}</h4>
{% if (beneficiary.getEnabledSwipeCards | length == 0) %}
<p><b class="red-text">Aucun badge actif</b></p>
<a href="#swipe_add_b{{ beneficiary.id }}" class="btn waves-effect waves-light modal-trigger"><i class="material-icons left">add</i>Associer un badge à ce compte</a>
<div id="swipe_add_b{{ beneficiary.id }}" class="modal">
<div class="modal-content">
<h4>Associer un badge</h4>
<form action="{{ path('active_swipe_for_beneficiary',{id:beneficiary.id})}}" method="post">
<div class="row">
<div class="col s12 m6 input-field">
<input type="hidden" name="beneficiary" value="{{ beneficiary.id }}" />
<label for="code">Code du badge à 13 chiffres</label>
<input pattern=".{13,13}" type="text" name="code" autocomplete="off" />
</div>
</div>
<div>
<button type="submit" class="btn green"><i class="material-icons left">check</i>Associer le badge</button>
</div>
</form>
</div>
<div class="modal-footer">
<a href="#!" class="modal-close waves-effect red-text btn-flat">Fermer</a>
</div>
</div>
{% else %}
<div class="badge">
<img src="{{ absolute_url(path('swipe_br',{"code": beneficiary.getEnabledSwipeCards.first.code | vigenere_encode | url_encode})) }}" alt="barecode" />
</div>
<br>
{% endif %}
{% if beneficiary.getSwipeCards | length %}
<a class="waves-effect waves-light btn modal-trigger blue-grey" href="#all_swipecards_b{{ beneficiary.id }}"><i class="material-icons left">credit_card</i>Badges de {{ beneficiary.firstname }}</a>
<div id="all_swipecards_b{{ beneficiary.id }}" class="modal bottom-sheet">
<div class="modal-content">
<h4>Tous les badges {{ beneficiary.firstname }}</h4>
{% include "swipeCard/_partial/list.html.twig" with { swipeCards: beneficiary.swipeCards | reverse, beneficiary_id: beneficiary.id } %}
</div>
<div class="modal-footer">
<a href="#!" class="modal-close waves-effect waves-green btn-flat red-text">Fermer</a>
</div>
</div>
{% endif %}
</div>
{% endfor %}
</div>
{% include "member/_partial/swipe_cards.html.twig" with { member: member } %}
</div>
</li>
{% endif %}
Expand Down
51 changes: 51 additions & 0 deletions app/Resources/views/swipeCard/_partial/add_modal.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% set from_admin = from_admin ?? false %}

<div id="swipe_add{% if from_admin %}_b{{ beneficiary.id }}{% endif %}" class="modal">
<form action="{{ path('activate_swipe')}}" method="POST">
<div class="modal-content">
<h4>Entrez {% if from_admin %}le{% else %}votre{% endif %} numéro de badge</h4>
<div class="row">
<div class="col s12 m6 input-field">
<input type="hidden" name="beneficiary" value="{{ beneficiary.id }}" />
<input pattern=".{13,13}" type="text" name="code" autocomplete="off" />
<span class="helper-text" data-error="wrong" data-success="right">Code du badge à 13 chiffres</span>
</div>
<div class="col s12 m6">
<div class="swiftcard_exemple">
{{ ("421234567890" | barcode | raw) }}
<canvas id="badge_canvas" class="focus" width="300" height="60"></canvas>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<a href="#!" class="modal-close waves-effect red-text btn-flat">Annuler</a>
<button type="submit" class="btn green">
<i class="material-icons left">check</i>Associer
</button>
</div>
</form>
</div>

<script>
var canvas = document.getElementById('badge_canvas');
var context = canvas.getContext('2d');
var centerX = 0;
var centerY = 0;
var radius = 25;
// save state
context.save();
// translate context
context.translate(canvas.width / 2, canvas.height / 2);
// scale context horizontally
context.scale(4, 1);
// draw circle which will be stretched into an oval
context.beginPath();
context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
// restore to original state
context.restore();
// apply styling
context.lineWidth = 3;
context.strokeStyle = 'red';
context.stroke();
</script>
18 changes: 18 additions & 0 deletions app/Resources/views/swipeCard/_partial/disable_modal.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div id="swipe_disable_{{ card.id }}" class="modal">
<form action="{{ path('disable_swipe')}}" method="POST">
<div class="modal-content">
<h4>Badge n°{{ card.number }}</h4>
{% include "swipeCard/_partial/image.html.twig" with { card: card, with_badge_card: true } %}
<p>
Alors comme ça tu ne retrouves plus ton badge ? Désactive-le ici.
</p>
<input type="hidden" name="code" value="{{ card.code | vigenere_encode }}"/>
</div>
<div class="modal-footer">
<a href="#!" class="modal-close waves-effect red-text btn-flat">Annuler</a>
<button type="submit" class="waves-effect waves-light btn-flat red white-text">
<i class="material-icons left">close</i>Désactiver<span class="hide-on-small-only"> ce badge</span>
</button>
</div>
</form>
</div>
5 changes: 5 additions & 0 deletions app/Resources/views/swipeCard/_partial/image.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% set with_badge_card = with_badge_card ?? false %}

<div {% if with_badge_card %}class="badge_card"{% endif %}>
<img src="{{ absolute_url(path('swipe_br', {"code": card.code | vigenere_encode | url_encode})) }}" alt="barcode">
</div>
Loading

0 comments on commit 4dfbae6

Please sign in to comment.