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 @login_required
def card_add_tab(request, tab_slug): def card_add_tab(request, tab_slug):
total = 0
categoria = tab_slug
for card in Cards.objects.all(): for card in Cards.objects.all():
if slugify(card.categoria) == tab_slug: if slugify(card.categoria) == tab_slug:
Dashboard( categoria = card.categoria
__, created = Dashboard.objects.update_or_create(
defaults={"ordem": card.ordem},
usuario=request.user, usuario=request.user,
card=card, card=card,
categoria=card.categoria, 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")) return HttpResponseRedirect(reverse("admin:index"))
@ -280,17 +286,15 @@ def card_reorder(request):
Dashboard.objects.filter( Dashboard.objects.filter(
usuario=request.user, card__codigo=codigo, categoria=categoria usuario=request.user, card__codigo=codigo, categoria=categoria
).update(ordem=nova_ordem) ).update(ordem=nova_ordem)
return JsonResponse({"result": "Done"}) return JsonResponse({"result": _("Ordem alterada")})
@login_required @login_required
def card_remove(request, categoria, codigo): def card_remove(request, categoria, codigo):
dash = get_object_or_404( count, *__ = Dashboard.objects.filter(
Dashboard, categoria=categoria, card__codigo=codigo categoria=categoria, card__codigo=codigo
) ).delete()
dash.delete() return JsonResponse({"result": _(f"{count} card(s) removido(s)")})
messages.success(request, _("Card removido"))
return HttpResponseRedirect(reverse("admin:index"))
@login_required @login_required

25
sigi/static/js/dashboard.js

@ -1,6 +1,24 @@
$(document).ready(function () { $(document).ready(function () {
M.Tabs.init($('.tabs'), {});
$(".dash-control").hide(); $(".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) { $(".tab-edit a").off("click").on("click", function (e) {
e.preventDefault(); e.preventDefault();
$(".dash-control").toggle(); $(".dash-control").toggle();
@ -13,11 +31,12 @@ $(document).ready(function () {
parent.children().each(function (pos) { parent.children().each(function (pos) {
dados[$(this).attr("data-card-id")] = pos + 1; dados[$(this).attr("data-card-id")] = pos + 1;
}) })
$.get(url, dados, function () { $.get(url, dados, function (data) {
M.toast({ html: 'Ordem alterada' }) M.toast({ html: data.response })
}); });
} }
}); });
$(".sortable").sortable("enable");
} else { } else {
$(".sortable").sortable("disable"); $(".sortable").sortable("disable");
} }

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

@ -43,7 +43,7 @@
</ul> </ul>
</div> </div>
<div class="modal-footer"> <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>
</div> </div>
{% for dash in sigi_dashes %} {% for dash in sigi_dashes %}

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

@ -21,7 +21,7 @@
<div class="card-title"> <div class="card-title">
<i class="material-icons left dash-control" style="cursor: move;">drag_handle</i> <i class="material-icons left dash-control" style="cursor: move;">drag_handle</i>
{% block card-title %}{% translate card_title|default:"" %}{% endblock %} {% 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>
<div class="card-content-wrapper"> <div class="card-content-wrapper">
{% block card-content %}{% endblock card-content %} {% block card-content %}{% endblock card-content %}

Loading…
Cancel
Save