diff --git a/amadeus/static/js/goals_reports.js b/amadeus/static/js/goals_reports.js index 9cb8333..9dd7b0a 100644 --- a/amadeus/static/js/goals_reports.js +++ b/amadeus/static/js/goals_reports.js @@ -4,8 +4,7 @@ $(function () { function getAnswered() { var container = $("#reports"), - list = container.find('.answered_data'), - holder = list.parent().find('.holder'); + list = container.find('.answered_data'); if (list.children().length == 0) { var url = list.parent().data('url'); @@ -15,13 +14,6 @@ function getAnswered() { success: function (data) { list.html(data); - // var form = list.find('.form_search'); - - // form.submit(function () { - // searchHistory(panel_id); - - // return false; - // }); $('#answered_table').DataTable({ "dom": "Bfrtip", "language": dataTablei18n, @@ -44,35 +36,82 @@ function getAnswered() { ] } }); - // var items = $("#answered_table").children(":visible").length; - - // if (items > 10) { - // holder.jPages({ - // containerID : "answered_table", - // perPage: 10, - // previous: "«", - // next: "»", - // midRange: 5 - // }); - // } } }); - } else { - $('#answered_table').DataTable(); - // var items = $("#answered_table").children(":visible").length; - - // if (items > 10) { - // holder.jPages({ - // containerID : "answered_table", - // perPage: 10, - // previous: "«", - // next: "»", - // midRange: 5 - // }); - // } } container.find('.answered_link').addClass('active'); + container.find('.answered').show(); + + container.find('.unanswered_link').removeClass('active'); + container.find('.unanswered').hide(); + + setBreadcrumb(answeredBread); +} + +function getUnanswered() { + var container = $("#reports"), + list = container.find('.unanswered_data'); + + if (list.children().length == 0) { + var url = list.parent().data('url'); + + $.ajax({ + url: url, + success: function (data) { + list.html(data); + + $('#unanswered_table').DataTable({ + "dom": "Bfrtip", + "language": dataTablei18n, + buttons: { + dom: { + container: { + className: 'col-md-3' + }, + buttonContainer: { + tag: 'h4', + className: 'history-header' + }, + }, + buttons: [ + { + extend: 'csv', + text: csvBtnLabeli18n, + filename: 'report-unanswered' + } + ], + }, + "columns": [ + null, + null, + { "orderable": false }, + ] + }); + + $("#check_all_rows").click(function () { + var checked = this.checked; + + $('#unanswered_table').find('input[type="checkbox"]').each(function() { + this.checked = checked; + }); + }); + } + }); + } + + container.find('.answered_link').removeClass('active'); + container.find('.answered').hide(); + + container.find('.unanswered_link').addClass('active'); + container.find('.unanswered').show(); + + setBreadcrumb(unansweredBread); +} - container.find('.answered').attr('style', 'display: block'); +function setBreadcrumb(text) { + var breadcrumb = $(".breadcrumb")[0], + li = $(breadcrumb).find('li:last-child'); + + $(li).html(text); } \ No newline at end of file diff --git a/goals/templates/goals/_unanswered.html b/goals/templates/goals/_unanswered.html new file mode 100644 index 0000000..43657b3 --- /dev/null +++ b/goals/templates/goals/_unanswered.html @@ -0,0 +1,28 @@ +{% load i18n goals_filters %} + +
+
+ + + + + + + + {% for student in students %} + + + + + + {% endfor %} + +
+ {% trans 'Student' %} + + {% trans 'Group' %} + + {% trans 'Select All' %} +
{{ student }}{{ student|groups }}
+
+
\ No newline at end of file diff --git a/goals/templates/goals/reports.html b/goals/templates/goals/reports.html index 4287251..25ba529 100644 --- a/goals/templates/goals/reports.html +++ b/goals/templates/goals/reports.html @@ -54,8 +54,8 @@
@@ -66,6 +66,13 @@
+ +
+
+
+
+
+
@@ -95,7 +102,9 @@ } }; - var csvBtnLabeli18n = " {% trans 'Download .csv file' %}"; + var csvBtnLabeli18n = " {% trans 'Download .csv file' %}", + answeredBread = "{% trans 'Reports: Answered' %}", + unansweredBread = "{% trans 'Reports: Unanswered' %}"; {% endblock %} \ No newline at end of file diff --git a/goals/urls.py b/goals/urls.py index a59d78d..fd93433 100644 --- a/goals/urls.py +++ b/goals/urls.py @@ -13,4 +13,5 @@ urlpatterns = [ url(r'^update_submit/(?P[\w_-]+)/$', views.UpdateSubmit.as_view(), name = 'update_submit'), url(r'^reports/(?P[\w_-]+)/$', views.Reports.as_view(), name = 'reports'), url(r'^answered_report/(?P[\w_-]+)/$', views.AnsweredReport.as_view(), name = 'answered_report'), + url(r'^unanswered_report/(?P[\w_-]+)/$', views.UnansweredReport.as_view(), name = 'unanswered_report'), ] diff --git a/goals/views.py b/goals/views.py index 5e4c7b1..4e4b201 100644 --- a/goals/views.py +++ b/goals/views.py @@ -105,6 +105,47 @@ class AnsweredReport(LoginRequiredMixin, generic.ListView): return context +class UnansweredReport(LoginRequiredMixin, generic.ListView): + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + template_name = 'goals/_unanswered.html' + model = MyGoals + context_object_name = 'students' + + def get_queryset(self): + slug = self.kwargs.get('slug', '') + goal = get_object_or_404(Goals, slug = slug) + + users = goal.topic.subject.students.values_list('id', flat = True) + + submited = Log.objects.filter(user_id__in = users, action = 'submit', resource = 'goals', context__contains = {"goals_id": goal.id}).values_list('user_id', flat = True) + + users = [i for i in users if i not in submited] + + submited_users = User.objects.filter(id__in = users) + + return submited_users + + def dispatch(self, request, *args, **kwargs): + slug = self.kwargs.get('slug', '') + goals = get_object_or_404(Goals, slug = slug) + + if not has_resource_permissions(request.user, goals): + return redirect(reverse_lazy('subjects:home')) + + return super(UnansweredReport, self).dispatch(request, *args, **kwargs) + + def get_context_data(self, **kwargs): + context = super(UnansweredReport, self).get_context_data(**kwargs) + + slug = self.kwargs.get('slug', '') + goals = get_object_or_404(Goals, slug = slug) + + context['goal'] = goals + + return context + class InsideView(LoginRequiredMixin, LogMixin, generic.ListView): log_component = "resources" log_action = "view" -- libgit2 0.21.2