From df417366f6f1ec8646874df32fb9d7611e188e1f Mon Sep 17 00:00:00 2001 From: Jailson Dias Date: Sat, 29 Apr 2017 17:05:46 -0300 Subject: [PATCH] colocando opção para enviar mensagens na webpage --- webpage/templates/webpages/relatorios.html | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------- webpage/urls.py | 1 + webpage/views.py | 25 +++++++++++++++++++++---- 3 files changed, 156 insertions(+), 68 deletions(-) diff --git a/webpage/templates/webpages/relatorios.html b/webpage/templates/webpages/relatorios.html index 90e6d09..8cac3df 100644 --- a/webpage/templates/webpages/relatorios.html +++ b/webpage/templates/webpages/relatorios.html @@ -7,6 +7,8 @@ {{ block.super }} @@ -58,28 +67,22 @@ var selectedItem = chart.getSelection()[0]; if (selectedItem) { var col = data.getColumnLabel(selectedItem.column); - var element = ''; - if (col == "{{n_did_table}}" && text("#title-table") != "{{n_did_table}}"){ - if (length("#link-history") <= 0){ - add(element,"#view-table",true); - } - altertitle("{{n_did_table}}"); + if (col == "{{n_did_table}}"){ + tabela_atual = false; search = []; for (var i in json_n_did["data"]){ - search.push([json_n_did["data"][i][0],json_n_did["data"][i][1]]); + search.push([json_n_did["data"][i][0],json_n_did["data"][i][1], + json_n_did["data"][i][2],json_n_did["data"][i][3]]); } - drawTable(column_n_did,pagination(json_n_did["data"],1),false); - putpagination(json_n_did["data"]); - - } else if (col == "{{did_table}}" && text("#title-table") != "{{did_table}}"){ + searcher(col, tabela_atual,true); + } else if (col == "{{did_table}}"){ + tabela_atual = true; search = []; for (var i in json_history["data"]){ search.push([json_history["data"][i][0],json_history["data"][i][1], json_history["data"][i][2],json_history["data"][i][3]]); } - searcher(col, true); + searcher(col, tabela_atual,true); } } chart.setSelection([]) @@ -90,6 +93,7 @@ chart.draw(data, options); } + var sortAscending = {0:false,1:false,2:false,3:false}; function drawTable(columns = column_history,rows = pagination(json_history["data"],1),isdate = true,columndate = 3) { var data_table = new google.visualization.DataTable(); for (var i in columns){ @@ -109,10 +113,34 @@ // } // } // console.log(methods.join(",")); + var options = { + sort: "event", + allowHtml: true, + cssClassNames : { + tableRow: 'text-center', + tableCell: 'text-center', + headerCell: 'text-center' + }, + showRowNumber: true, + width: '100%', + height: '100%', + } + function ordenar(properties){ + var columnIndex = properties['column']; + if (columnIndex > 0) { + options["sortColumn"] = columnIndex; + options["sortAscending"] = sortAscending[columnIndex]; + data_table.sort({column:columnIndex,desc:sortAscending[columnIndex]}); + sortAscending = {0:false,1:false,2:false,3:false}; + sortAscending[columnIndex] = !sortAscending[columnIndex]; + // console.log(sortAscending); + table.draw(data_table, options); + } + } var table = new google.visualization.Table(document.getElementById('table_div')); - - table.draw(data_table, {allowHtml: true, cssClassNames : {tableRow: 'text-center',tableCell: 'text-center', headerCell: 'text-center'},showRowNumber: true, width: '100%', height: '100%'}); + google.visualization.events.addListener(table, 'sort', function(e) {ordenar(e)}); + table.draw(data_table, options); } {% endblock%} @@ -148,24 +176,26 @@

{% trans "Report of the resource " %}{{webpage}}

-
-

{% trans "Select the period: " %}

-
-
+
+
+
+ +
+
@@ -191,8 +221,9 @@
- -
+
+
+
+ + +


{% endblock %} diff --git a/webpage/urls.py b/webpage/urls.py index 2172935..57aa88a 100644 --- a/webpage/urls.py +++ b/webpage/urls.py @@ -10,4 +10,5 @@ urlpatterns = [ url(r'^window_view/(?P[\w_-]+)/$', views.NewWindowView.as_view(), name = 'window_view'), url(r'^view/(?P[\w_-]+)/$', views.InsideView.as_view(), name = 'view'), url(r'^chart/(?P[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), + url(r'^send-message/(?P[\w_-]+)/$', views.sendMessage, name = 'send_message'), ] diff --git a/webpage/views.py b/webpage/views.py index d8fb452..a0c157c 100644 --- a/webpage/views.py +++ b/webpage/views.py @@ -469,7 +469,6 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): else : start_date = datetime.datetime.strptime(self.request.GET.get('init_date',''),date_format) end_date = datetime.datetime.strptime(self.request.GET.get('end_date',''),date_format) - print (start_date," depois") context["init_date"] = start_date context["end_date"] = end_date alunos = webpage.students.all() @@ -491,9 +490,10 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): json_history["data"] = data_history not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) - + index = 0 for alun in not_view: - data_n_did.append([str(alun),", ".join([str(x) for x in webpage.topic.subject.group_subject.filter(participants__email=alun.email)]),str(_('View'))]) + data_n_did.append([index,str(alun),", ".join([str(x) for x in webpage.topic.subject.group_subject.filter(participants__email=alun.email)]),str(_('View')), str(alun.email)]) + index += 1 json_n_did["data"] = data_n_did @@ -505,10 +505,27 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): context['topic'] = webpage.topic context['subject'] = webpage.topic.subject context['db_data'] = re - context['title_chart'] = _('Students viewing the webpage') + context['title_chart'] = _('Actions about resource') context['title_vAxis'] = _('Quantity') context["n_did_table"] = n_did context["did_table"] = did context["history_table"] = history return context + + +from chat.models import Conversation, TalkMessages +from users.models import User +from subjects.models import Subject +def sendMessage(request, slug): + message = request.GET.get('message','') + users = request.GET.getlist('users[]','') + user = request.user + subject = get_object_or_404(Subject,slug = slug) + + for u in users: + to_user = User.objects.get(email=u) + talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) + created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject) + + return JsonResponse({"message":"ok"}) -- libgit2 0.21.2