Browse Source

Ajustes na interface do dashboard

pull/159/head
Sesostris Vieira 3 years ago
parent
commit
b2a4c2247b
  1. 24
      sigi/apps/home/views.py
  2. 25
      sigi/static/js/dashboard.js
  3. 2
      sigi/templates/material/admin/index.html
  4. 2
      sigi/templates/sigi/snippets/base_card.html

24
sigi/apps/home/views.py

@ -245,14 +245,20 @@ def card_snippet(request, card_code):
@login_required
def card_add_tab(request, tab_slug):
total = 0
categoria = tab_slug
for card in Cards.objects.all():
if slugify(card.categoria) == tab_slug:
Dashboard(
categoria = card.categoria
__, created = Dashboard.objects.update_or_create(
defaults={"ordem": card.ordem},
usuario=request.user,
card=card,
categoria=card.categoria,
ordem=card.ordem,
).save()
)
if created:
total += 1
messages.info(request, _(f"{total} cards adicionados na aba {categoria}"))
return HttpResponseRedirect(reverse("admin:index"))
@ -280,17 +286,15 @@ def card_reorder(request):
Dashboard.objects.filter(
usuario=request.user, card__codigo=codigo, categoria=categoria
).update(ordem=nova_ordem)
return JsonResponse({"result": "Done"})
return JsonResponse({"result": _("Ordem alterada")})
@login_required
def card_remove(request, categoria, codigo):
dash = get_object_or_404(
Dashboard, categoria=categoria, card__codigo=codigo
)
dash.delete()
messages.success(request, _("Card removido"))
return HttpResponseRedirect(reverse("admin:index"))
count, *__ = Dashboard.objects.filter(
categoria=categoria, card__codigo=codigo
).delete()
return JsonResponse({"result": _(f"{count} card(s) removido(s)")})
@login_required

25
sigi/static/js/dashboard.js

@ -1,6 +1,24 @@
$(document).ready(function () {
M.Tabs.init($('.tabs'), {});
$(".dash-control").hide();
M.Tabs.init($('.tabs'), {});
$(".remove-card").off("click").on("click", function (e) {
e.preventDefault();
var $this = $(this);
var context = $this.parents("li");
$.ajax({
url: $this.attr("href"),
method: 'GET',
context: context,
success: function (data) {
$(this).remove();
M.toast({ html: data.result })
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
M.toast({ html: `${textStatus}: ${errorThrown}` });
}
})
});
$(".tab-edit a").off("click").on("click", function (e) {
e.preventDefault();
$(".dash-control").toggle();
@ -13,11 +31,12 @@ $(document).ready(function () {
parent.children().each(function (pos) {
dados[$(this).attr("data-card-id")] = pos + 1;
})
$.get(url, dados, function () {
M.toast({ html: 'Ordem alterada' })
$.get(url, dados, function (data) {
M.toast({ html: data.response })
});
}
});
$(".sortable").sortable("enable");
} else {
$(".sortable").sortable("disable");
}

2
sigi/templates/material/admin/index.html

@ -43,7 +43,7 @@
</ul>
</div>
<div class="modal-footer">
<a href="#!" class="modal-close waves-effect waves-green btn-flat">Agree</a>
<a href="#!" class="modal-close waves-effect waves-green btn-flat">{% trans 'Cancelar' %}</a>
</div>
</div>
{% for dash in sigi_dashes %}

2
sigi/templates/sigi/snippets/base_card.html

@ -21,7 +21,7 @@
<div class="card-title">
<i class="material-icons left dash-control" style="cursor: move;">drag_handle</i>
{% block card-title %}{% translate card_title|default:"" %}{% endblock %}
<a href="{% url 'home_card_remove' dash.label card.codigo %}" class="dash-control" title="{% trans 'Remove este card' %}"><i class="material-icons right">close</i></a>
<a href="{% url 'home_card_remove' dash.label card.codigo %}" class="dash-control remove-card" title="{% trans 'Remove este card' %}"><i class="material-icons right">close</i></a>
</div>
<div class="card-content-wrapper">
{% block card-content %}{% endblock card-content %}

Loading…
Cancel
Save