Skip to content

Commit

Permalink
add remove label
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktMKuehne committed Feb 27, 2024
1 parent 73580ba commit 74e06e5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
3 changes: 2 additions & 1 deletion embark/dashboard/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
path('dashboard/log/<uuid:analysis_id>', views.show_log, name='embark-show-log'),
path('dashboard/logviewer/<uuid:analysis_id>', views.show_logviewer, name='embark-show-logviewer'),
path('dashboard/report/createlabel/', views.create_label, name='embark-dashboard-create-label'),
path('dashboard/report/addlabel/<uuid:analysis_id>', views.add_label, name='embark-dashboard-add-label')
path('dashboard/report/addlabel/<uuid:analysis_id>', views.add_label, name='embark-dashboard-add-label'),
path('dashboard/report/rmlabel/<uuid:analysis_id><str:label_name>', views.rm_label, name='embark-dashboard-remove-label'),
]
15 changes: 15 additions & 0 deletions embark/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,18 @@ def add_label(request, analysis_id):
logger.error("label form invalid %s ", request.POST)
messages.error(request, 'Adding Label failed')
return redirect('..')


@csrf_protect
@require_http_methods(["POST"])
@login_required(login_url='/' + settings.LOGIN_URL)
def rm_label(request, analysis_id, label_name):
req_logger.info("User %s called rm label", request.user.username)

logger.info("User %s tryied to rm label %s", request.user.username, label_name)
# get analysis obj
analysis = FirmwareAnalysis.objects.get(id=analysis_id)
analysis.label.remove(label_name)
analysis.save()
messages.info(request, 'removing successful of ' + str(label_name))
return redirect('..')
12 changes: 11 additions & 1 deletion embark/templates/dashboard/label.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
{% load django_bootstrap5 %}

<form action="{% url 'embark-dashboard-add-label' firmware.id %}" method="post" id="form">
{% csrf_token %}
<div class="innerBlock">
{% load filters %}
{% bootstrap_form label_select_form %}
{% bootstrap_button "Add" button_type="submit" button_class="btn-primary" %}
</div>
</form>


<form action="{% url 'embark-dashboard-create-label' %}" method="post" id="form">
{% csrf_token %}
<div class="innerBlock">
{% load filters %}
{% bootstrap_form label_form layout='grid' %}
{% bootstrap_button "Create" button_type="submit" button_class="btn-primary" %}
</div>
</form>
</form>
16 changes: 7 additions & 9 deletions embark/templates/dashboard/reportDashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
{% for label in firmware.label.all %}
<div class="col-sm">
<button onclick="onclick_label('label={{ label.label_name }}');" class="label badge rounded-pill bg-info">{{ label.label_name }}</button>
<!-- TODO add hover and remove -->

<form action="{% url 'embark-dashboard-remove-label' firmware.id label.label_name %}" method="post" id="form">
{% csrf_token %}
</form>

{{ label.label_name }}
</div>
{% endfor %}
{% endif %}
Expand Down Expand Up @@ -194,15 +201,6 @@ <h5 class="modal-title" id="AddLabelModal-{{ firmware.id }}-Label">Add Label to
</button>
</div>
<div class="modal-body">
<!-- TODO click select with all options-->
<form action="{% url 'embark-dashboard-add-label' firmware.id %}" method="post" id="form">
{% csrf_token %}
<div class="innerBlock">
{% load filters %}
{% bootstrap_form label_select_form %}
{% bootstrap_button "Add" button_type="submit" button_class="btn-primary" %}
</div>
</form>
{% block label %}{% include "dashboard/label.html" %}{% endblock label %}
</div>
<div class="modal-footer">
Expand Down

0 comments on commit 74e06e5

Please sign in to comment.