diff --git a/amadeus/static/js/pendencies.js b/amadeus/static/js/pendencies.js new file mode 100644 index 0000000..9d2634d --- /dev/null +++ b/amadeus/static/js/pendencies.js @@ -0,0 +1,296 @@ +$('.pendencies-content').on('show.bs.collapse', function(e) { + if($(this).is(e.target)){ + var panel_id = $(this).data('id'), + pendencies = $(this).find('.pendencies'), + history = $(this).find('.history'), + btn = $(this).parent().find('.fa-angle-right'); + + btn = btn[0]; + + $(btn).switchClass("fa-angle-right", "fa-angle-down", 250, "easeInOutQuad"); + + getPendencies(panel_id); + } +}); + +$('.pendencies-content').on('hidden.bs.collapse', function(e) { + if($(this).is(e.target)){ + var btn = $(this).parent().find('.fa-angle-down'); + + btn = btn[0]; + + $(btn).switchClass("fa-angle-down", "fa-angle-right", 250, "easeInOutQuad"); + } +}); + +$('.pendencies-content').on('hidden.bs.collapse', function(e) { + if($(this).is(e.target)){ + var panel_id = $(this).data('id'), + pendencies = $(this).find('.pendencies'), + history = $(this).find('.history'), + p_holder = pendencies.find('.holder'), + h_holder = history.find('.holder'); + + + var p_items = pendencies.find('.pendencies-cards').children(":visible").length; + + if (p_items > 10) { + p_holder.jPages("destroy"); + } + + var h_items = history.find("#history_table_" + panel_id).children(":visible").length; + + if (h_items > 10) { + h_holder.jPages("destroy"); + } + } +}); + +function getPendencies(panel_id) { + var list = $("#pendencies_list_" + panel_id), + holder = list.parent().find('.holder'); + + if (list.children().length == 0) { + var url = list.parent().data('url'); + + $.ajax({ + url: url, + success: function (data) { + list.html(data); + + var items = list.children(":visible").length; + + if (items > 10) { + holder.jPages({ + containerID : "pendencies_list_" + panel_id, + perPage: 10, + previous: "«", + next: "»", + midRange: 5 + }); + } + + metaFunctions(); + } + }); + } else { + var items = list.children(":visible").length; + + if (items > 10) { + holder.jPages({ + containerID : "pendencies_list_" + panel_id, + perPage: 10, + previous: "«", + next: "»", + midRange: 5 + }); + } + + metaFunctions(); + } + + list.parent().parent().find('.history').attr('style', 'display: none'); + list.parent().attr('style', 'display: block'); + + list.parent().parent().find('.pendencies_link').addClass('active'); + list.parent().parent().find('.history_link').removeClass('active'); +} + +function getHistory(panel_id) { + var container = $("#subject_" + panel_id), + list = container.find('.history_data'), + holder = container.find('.holder'); + + if (list.children().length == 0) { + var url = list.parent().data('url'); + + $.ajax({ + url: url, + success: function (data) { + list.html(data); + + var form = list.find('.form_search'); + + form.submit(function () { + searchHistory(panel_id); + + return false; + }); + + var items = $("#history_table_" + panel_id).children(":visible").length; + + if (items > 10) { + holder.jPages({ + containerID : "history_table_" + panel_id, + perPage: 10, + previous: "«", + next: "»", + midRange: 5 + }); + } + } + }); + } else { + var items = $("#history_table_" + panel_id).children(":visible").length; + + if (items > 10) { + holder.jPages({ + containerID : "history_table_" + panel_id, + perPage: 10, + previous: "«", + next: "»", + midRange: 5 + }); + } + } + + container.find('.pendencies_link').removeClass('active'); + container.find('.history_link').addClass('active'); + + container.find('.history').attr('style', 'display: block'); + container.find('.pendencies').attr('style', 'display: none'); +} + +function searchHistory(panel_id) { + var container = $("#subject_" + panel_id), + url = container.find('.history').data('url'), + list = container.find('.history_data'), + form = container.find('.form_search'), + holder = container.find('.holder'); + + $.ajax({ + url: url, + data: form.serialize(), + success: function (data) { + list.html(data); + + var form = list.find('.form_search'); + + form.submit(function () { + searchHistory(panel_id); + + return false; + }); + + var items = $("#history_table_" + panel_id).children(":visible").length; + + if (items > 10) { + holder.jPages({ + containerID : "history_table_" + panel_id, + perPage: 10, + previous: "«", + next: "»", + midRange: 5 + }); + } + } + }); +} + +function orderBy(panel_id, order) { + var container = $("#subject_" + panel_id), + url = container.find('.history').data('url'), + list = container.find('.history_data'), + search = container.find('input[name="search"]').val(), + holder = container.find('.holder'); + + $.ajax({ + url: url, + data: {'order_by': order, 'search': search}, + success: function (data) { + list.html(data); + + var form = list.find('.form_search'); + + form.submit(function () { + searchHistory(panel_id); + + return false; + }); + + var items = $("#history_table_" + panel_id).children(":visible").length; + + if (items > 10) { + holder.jPages({ + containerID : "history_table_" + panel_id, + perPage: 10, + previous: "«", + next: "»", + midRange: 5 + }); + } + } + }); +} + +function metaFunctions() { + var locale = navigator.language || navigator.userLanguage; + + $('[data-toggle="popover"]').popover({ + html: true, + content: function () { + return $(".popover").html(); + } + }).on('show.bs.popover', function (e) { + $('[data-toggle="popover"]').not(e.target).popover('hide'); + }).on('shown.bs.popover', function (e) { + if($(this).is(e.target)){ + var popover = $(this), + datetime = popover.parent().find('.datetimepicker'), + form = popover.parent().find('form:visible'), + cancel = popover.parent().find('.cancel:visible'), + save = popover.parent().find('.save:visible'); + + if (typeof(datetime.data("DateTimePicker")) != "undefined") { + datetime.data("DateTimePicker").destroy(); + } + + datetime.datetimepicker({ + format: "YYYY-MM-DD HH:mm", + locale: locale, + inline: true, + sideBySide: false + }); + + cancel.on("click", function () { + popover.popover('hide'); + }); + + save.on("click", function () { + var meta = datetime.data('date'), + url = form.attr('action'), + method = form.attr('method'), + token = form.find('input[name="csrfmiddlewaretoken"]').val(), + notification = form.find('input[name="id"]').val(); + + $.ajax({ + url: url, + method: method, + data: {'csrfmiddlewaretoken': token, 'meta': meta, 'id': notification}, + dataType: 'json', + success: function (response) { + if (response.error) { + alertify.error(response.message); + } else { + alertify.success(response.message); + popover.popover('hide'); + } + } + }); + }); + } + }).on('hide.bs.popover', function (e) { + if($(this).is(e.target)){ + var popover = $(this), + datetime = popover.parent().find('.datetimepicker'); + + if (typeof(datetime.data("DateTimePicker")) != "undefined") { + datetime.data("DateTimePicker").destroy(); + } + + datetime.html(''); + } + }).on('hidden.bs.popover', function (e) { + $(e.target).data("bs.popover").inState.click = false; + }); +} \ No newline at end of file diff --git a/amadeus/templates/base.html b/amadeus/templates/base.html index b68b2c4..5c2806a 100644 --- a/amadeus/templates/base.html +++ b/amadeus/templates/base.html @@ -186,7 +186,7 @@
  • - + {% if notifications_count > 0 %} {% if notifications_count > 99 %} +99 {% else %} {{ notifications_count }} {% endif %} diff --git a/notifications/templates/notifications/_ajax_history.html b/notifications/templates/notifications/_ajax_history.html new file mode 100644 index 0000000..dae0518 --- /dev/null +++ b/notifications/templates/notifications/_ajax_history.html @@ -0,0 +1,72 @@ +{% load i18n notification_filters %} + +
    +
    +
    +

    {{ rows }} {% trans 'rows' %}

    +
    +
    + +
    + + + + + + + + + + + {% if rows > 0 %} + {% for notification in notifications %} + + + + + + + + + {% endfor %} + {% else %} + + + + {% endif %} + +
    + + {% trans 'Date' %} + + + + {% trans 'Resource' %} + + + + {% trans 'Task' %} + + + + {% trans 'Final Date' %} + + + + {% trans 'Notification' %} + + + + {% trans 'Observation' %} + +
    {{ notification.creation_date|date:"SHORT_DATE_FORMAT" }}{{ notification.task.resource }}{{ notification.task.get_action_display }}{{ notification.task.end_date|date:"SHORT_DATE_FORMAT"|default:_('Not Informed') }}{{ notification.level|warning_msg }}{{ notification|observation }}
    {% trans 'No results found' %}
    +
    +
    \ No newline at end of file diff --git a/notifications/templates/notifications/_history.html b/notifications/templates/notifications/_history.html index c15dd33..38c9471 100644 --- a/notifications/templates/notifications/_history.html +++ b/notifications/templates/notifications/_history.html @@ -10,7 +10,7 @@
    - +
    diff --git a/notifications/templates/notifications/_view.html b/notifications/templates/notifications/_view.html index 5cad20f..c5d510b 100644 --- a/notifications/templates/notifications/_view.html +++ b/notifications/templates/notifications/_view.html @@ -1,93 +1,95 @@ {% load i18n notification_filters %} -
    -
    -
    -
    - -
    -
    -

    {{ notification }}

    -

    {% trans 'Final Date/Time' %}: {{ notification.task.end_date|default:_('Not Informed') }}

    +{% for notification in notifications %} +
    +
    +
    +
    + +
    +
    +

    {{ notification }}

    +

    {% trans 'Final Date/Time' %}: {{ notification.task.end_date|default:_('Not Informed') }}

    - {% if notification.level == 2 %} -

    {% trans 'Your goal was to realize this in' %}: {{ notification.meta }}

    - {% elif notification.level == 4 %} -

    {% trans 'Task finished in' %}: {{ notification.task.limit_date }}

    - {% endif %} + {% if notification.level == 2 %} +

    {% trans 'Your goal was to realize this in' %}: {{ notification.meta }}

    + {% elif notification.level == 4 %} +

    {% trans 'Task finished in' %}: {{ notification.task.limit_date }}

    + {% endif %} - {{ notification|done_percent|floatformat:2 }}% {% trans 'of the participants already realized this task.' %} -
    -
    -
    - - {{ notification.level|warning_msg }} + {{ notification|done_percent|floatformat:2 }}% {% trans 'of the participants already realized this task.' %} +
    +
    +
    + + {{ notification.level|warning_msg }} +
    -
    -
    - - {% if notification.level == 4 %} - {% trans 'Access the task' %} - {% else %} - {% trans 'Realize the task' %} - {% endif %} - - - {% if notification.level < 3 %} - - + + + {% if notification.level < 3 %} + + -
    -
    -
    - {% csrf_token %} -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    -
    - -
    - {% endif %} +
    +
    +
    + {% csrf_token %} +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    + +
    + {% endif %} +
    -
    +{% endfor %} \ No newline at end of file diff --git a/notifications/templates/notifications/index.html b/notifications/templates/notifications/index.html new file mode 100644 index 0000000..d72dad8 --- /dev/null +++ b/notifications/templates/notifications/index.html @@ -0,0 +1,61 @@ +{% extends 'base.html' %} + +{% load static i18n pagination permissions_tags subject_counter %} +{% load django_bootstrap_breadcrumbs %} + +{% block breadcrumbs %} + {{ block.super }} + + {% breadcrumb 'Pendencies' 'notifications:manage' %} +{% endblock %} + +{% block content %} + {% if notifications.count > 0 %} +
    + {% for notification in notifications %} + + {% endfor %} + + {% pagination request paginator page_obj %} +
    + {% else %} +
    + +

    {% trans 'You do not posses any pendency in this subject' %}

    +
    + {% endif %} + + +{% endblock %} \ No newline at end of file diff --git a/notifications/templates/notifications/subject.html b/notifications/templates/notifications/subject.html index 5480d43..d3fe8eb 100644 --- a/notifications/templates/notifications/subject.html +++ b/notifications/templates/notifications/subject.html @@ -29,15 +29,13 @@ {% if not history %} {% if notifications.count > 0 %} - {% for notification in notifications %} - {% include 'notifications/_view.html' %} - {% endfor %} + {% include 'notifications/_view.html' %} {% pagination request paginator page_obj %} {% else %} @@ -52,77 +50,10 @@
    + {% endblock %} \ No newline at end of file diff --git a/notifications/templatetags/notification_filters.py b/notifications/templatetags/notification_filters.py index b972395..d9369b5 100644 --- a/notifications/templatetags/notification_filters.py +++ b/notifications/templatetags/notification_filters.py @@ -90,6 +90,27 @@ def order_href(request, column): return "?order_by=" + order_href + params +@register.filter(name = 'order_ajax') +def order_ajax(request, column): + getvars = request.GET.copy() + order_href = "-" + column + order = None + params = "" + + if 'order_by' in getvars: + order = getvars['order_by'] + del getvars['order_by'] + + if not order: + if column == "creation_date": + order_href = "creation_date" + else: + if column in order: + if "-" in order: + order_href = column + + return order_href + @register.filter(name = 'observation') def observation(notification): msg = '' diff --git a/notifications/urls.py b/notifications/urls.py index 870e24e..2feb177 100644 --- a/notifications/urls.py +++ b/notifications/urls.py @@ -2,7 +2,10 @@ from django.conf.urls import url from . import views urlpatterns = [ + url(r'^$', views.IndexView.as_view(), name='manage'), url(r'^set_goal/$', views.set_goal, name='set_goal'), + url(r'^ajax/(?P[\w_-]+)/$', views.AjaxNotifications.as_view(), name='ajax_view'), + url(r'^ajax_history/(?P[\w_-]+)/$', views.AjaxHistory.as_view(), name='ajax_history'), url(r'^(?P[\w_-]+)/$', views.SubjectNotifications.as_view(), name='view'), url(r'^(?P[\w_-]+)/history/$', views.SubjectHistory.as_view(), name='history'), ] \ No newline at end of file diff --git a/notifications/utils.py b/notifications/utils.py index 6380f65..2a9f625 100644 --- a/notifications/utils.py +++ b/notifications/utils.py @@ -64,7 +64,7 @@ def set_notifications(): notification.save() def get_order_by(order): - if not order: + if order is None or order == "": return ["-creation_date"] if "creation_date" in order: diff --git a/notifications/views.py b/notifications/views.py index 22320c1..7f37e3e 100644 --- a/notifications/views.py +++ b/notifications/views.py @@ -6,7 +6,7 @@ from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.decorators import login_required from django.http import JsonResponse -from django.db.models import Q +from django.db.models import Q, Count from dateutil import parser from datetime import datetime @@ -105,7 +105,6 @@ class SubjectHistory(LoginRequiredMixin, generic.ListView): queries |= Q(task__end_date = search_date) queries |= Q(meta__date = search_date) - notifications = notifications.filter(queries).order_by(*order) self.num_rows = notifications.count() @@ -127,6 +126,89 @@ class SubjectHistory(LoginRequiredMixin, generic.ListView): return context +class IndexView(LoginRequiredMixin, generic.ListView): + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + context_object_name = 'notifications' + template_name = 'notifications/index.html' + paginate_by = 10 + + def get_queryset(self): + notifications = Notification.objects.filter(user = self.request.user, viewed = False, creation_date = datetime.now()).values('task__resource__topic__subject', 'task__resource__topic__subject__name').annotate(total = Count('task__resource__topic__subject')) + + return notifications + + def get_context_data(self, **kwargs): + context = super(IndexView, self).get_context_data(**kwargs) + + context['title'] = _('Pendencies') + + return context + +class AjaxNotifications(LoginRequiredMixin, generic.ListView): + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + context_object_name = 'notifications' + template_name = 'notifications/_view.html' + + def get_queryset(self): + subject_id = self.kwargs.get('id', '') + + notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject__id = subject_id, creation_date = datetime.now()).order_by("task__limit_date", "task__end_date") + + return notifications + +class AjaxHistory(LoginRequiredMixin, generic.ListView): + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + context_object_name = 'notifications' + template_name = 'notifications/_ajax_history.html' + + def get_queryset(self): + subject_id = self.kwargs.get('id', '') + + order = get_order_by(self.request.GET.get("order_by", None)) + search = self.request.GET.get("search", None) + + notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject__id = subject_id).order_by(*order) + + if search: + queries = Q(task__resource__name__icontains = search) + queries |= Q(task__action__icontains = search) + + if search.isdigit(): + queries |= Q(level = search) + + if is_date(search): + search_date = parser.parse(search) + search_date = timezone.make_aware(search_date, timezone.get_current_timezone()) + + queries |= Q(creation_date = search_date) + queries |= Q(task__limit_date = search_date) + queries |= Q(task__end_date = search_date) + queries |= Q(meta__date = search_date) + + notifications = notifications.filter(queries).order_by(*order) + + self.num_rows = notifications.count() + + return notifications + + def get_context_data(self, **kwargs): + context = super(AjaxHistory, self).get_context_data(**kwargs) + + subject_id = self.kwargs.get('id', '') + + context['subject_id'] = subject_id + context['rows'] = self.num_rows + context['searched'] = self.request.GET.get("search", "") + context['order_by'] = self.request.GET.get("order_by", "") + + return context + @login_required def set_goal(request): if request.method == "POST" and request.is_ajax(): -- libgit2 0.21.2