Commit 4a391dc8db07bddab1605312782ec21f26344e25
1 parent
9727e86c
Exists in
master
and in
2 other branches
organizando os dados em duas tabelas e com a quantidade de registros em pdf file
Showing
2 changed files
with
33 additions
and
59 deletions
Show diff stats
pdf_file/templates/pdf_file/relatorios.html
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | array_history.push(["{{data_json.0}}","{{data_json.1}}","{{data_json.2}}",{% if data_json.3 is not None %}new Date('{{data_json.3.isoformat}}'){% else%}null{% endif %}]); |
14 | 14 | {% endfor%} |
15 | 15 | var json_history = {"data":array_history}; |
16 | - var column_history = [{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":'{% trans "Action" %}'},{"date":'{% trans "Date of Action" %}'}]; | |
16 | + var column_history = [{"string":"{% trans 'User' %}"},{"string":"{% trans 'Group' %}"},{"string":"{% trans 'Action' %}"},{"date":"{% trans 'Date of Action' %}"}]; | |
17 | 17 | |
18 | 18 | var search = []; |
19 | 19 | for (var i in json_history["data"]){ |
... | ... | @@ -21,20 +21,12 @@ |
21 | 21 | json_history["data"][i][2],json_history["data"][i][3]]); |
22 | 22 | } |
23 | 23 | |
24 | - | |
25 | - var array_did = []; | |
26 | - {%for data_json in json_did.data%} | |
27 | - array_did.push(["{{data_json.0}}","{{data_json.1}}","{{data_json.2}}",{% if data_json.3 is not None %}new Date('{{data_json.3.isoformat}}'){% else%}null{% endif %}]); | |
28 | - {% endfor%} | |
29 | - var json_did = {"data":array_did}; | |
30 | - var column_did = [{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":'{% trans "Action" %}'},{"date":'{% trans "Date of Action" %}'}]; | |
31 | - | |
32 | 24 | var array_n_did = []; |
33 | 25 | {%for data_json in json_n_did.data%} |
34 | - array_n_did.push(["{{data_json.0}}","{{data_json.1}}"]); | |
26 | + array_n_did.push(['<input type="checkbox" value="">',"{{data_json.0}}","{{data_json.1}}", "{{data_json.2}}"]); | |
35 | 27 | {% endfor%} |
36 | 28 | var json_n_did = {"data":array_n_did}; |
37 | - var column_n_did = [{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'}]; | |
29 | + var column_n_did = [{"string":'{% trans "Enviar mensagem" %}'},{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":"Action don't realized"}]; | |
38 | 30 | </script> |
39 | 31 | |
40 | 32 | |
... | ... | @@ -82,17 +74,12 @@ |
82 | 74 | putpagination(json_n_did["data"]); |
83 | 75 | |
84 | 76 | } else if (col == "{{did_table}}" && text("#title-table") != "{{did_table}}"){ |
85 | - if (length("#link-history") <= 0){ | |
86 | - add(element,"#view-table",true); | |
87 | - } | |
88 | - altertitle("{{did_table}}"); | |
89 | 77 | search = []; |
90 | - for (var i in json_did["data"]){ | |
91 | - search.push([json_did["data"][i][0],json_did["data"][i][1], | |
92 | - json_did["data"][i][2],json_did["data"][i][3]]); | |
78 | + for (var i in json_history["data"]){ | |
79 | + search.push([json_history["data"][i][0],json_history["data"][i][1], | |
80 | + json_history["data"][i][2],json_history["data"][i][3]]); | |
93 | 81 | } |
94 | - drawTable(column_did,pagination(json_did["data"],1),true,3); | |
95 | - putpagination(json_did["data"]); | |
82 | + searcher(col, true); | |
96 | 83 | } |
97 | 84 | } |
98 | 85 | chart.setSelection([]) |
... | ... | @@ -125,7 +112,7 @@ |
125 | 112 | |
126 | 113 | var table = new google.visualization.Table(document.getElementById('table_div')); |
127 | 114 | |
128 | - table.draw(data_table, {showRowNumber: true, width: '100%', height: '100%'}); | |
115 | + table.draw(data_table, {allowHtml: true, cssClassNames : {tableRow: 'text-center',tableCell: 'text-center', headerCell: 'text-center'},showRowNumber: true, width: '100%', height: '100%'}); | |
129 | 116 | } |
130 | 117 | </script> |
131 | 118 | {% endblock%} |
... | ... | @@ -218,6 +205,7 @@ |
218 | 205 | </div> |
219 | 206 | |
220 | 207 | <script type="text/javascript"> |
208 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | |
221 | 209 | function putpagination(data = json_history["data"]){ |
222 | 210 | var len = Math.ceil(data.length / 20); |
223 | 211 | $(".pagination").empty(); |
... | ... | @@ -256,51 +244,48 @@ |
256 | 244 | } |
257 | 245 | function backhistory(){ |
258 | 246 | drawTable(column_history,json_history["data"],true,3); |
259 | - $("#title-table").text("{{history_table}}"); | |
260 | 247 | $("#link-history").remove(); |
261 | 248 | search = []; |
262 | 249 | for (var i in json_history["data"]){ |
263 | 250 | search.push([json_history["data"][i][0],json_history["data"][i][1], |
264 | 251 | json_history["data"][i][2],json_history["data"][i][3]]); |
265 | 252 | } |
253 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | |
266 | 254 | putpagination(json_history["data"]); |
267 | 255 | } |
268 | - // $("#search-input").on("keyup",function(){ | |
269 | - // console.log($("#search-input").val()); | |
270 | - // }); | |
256 | + | |
271 | 257 | $("#search-input").on("keyup",function(){ |
272 | 258 | search = []; |
273 | 259 | var text = $("#search-input").val(); |
260 | + searcher(text); | |
261 | + }); | |
262 | + | |
263 | + function searcher(text, load_histoty = false){ | |
264 | + if (load_histoty){ | |
265 | + $("#link-history").remove(); | |
266 | + } | |
274 | 267 | var data = []; |
275 | - if ($("#title-table").text() == "{{n_did_table}}"){ | |
268 | + if ($("#title-table").text() == "{{n_did_table}}" && !load_histoty){ | |
276 | 269 | data = $.map(json_n_did["data"], function (obj) { |
277 | 270 | return $.extend(true, {}, obj); |
278 | 271 | }); |
279 | - } else if ($("#title-table").text() == "{{did_table}}") { | |
280 | - data = $.map(json_did["data"], function (obj) { | |
281 | - return $.extend(true, {}, obj); | |
282 | - }); | |
283 | 272 | } else { |
284 | 273 | data = $.map(json_history["data"], function (obj) { |
285 | 274 | return $.extend(true, {}, obj); |
286 | 275 | }); |
287 | 276 | } |
288 | - if ($("#title-table").text() != "{{n_did_table}}"){ | |
277 | + if (load_histoty || $("#title-table").text() != "{{n_did_table}}"){ | |
289 | 278 | for (var i in data){ |
290 | 279 | data[i][3] = moment(data[i][3]).format("DD/MM/YYYY HH:mm"); |
291 | 280 | } |
292 | 281 | } |
293 | - if ($("#title-table").text() != "{{n_did_table}}"){ | |
282 | + if (load_histoty || $("#title-table").text() != "{{n_did_table}}"){ | |
294 | 283 | for (var i in data){ |
295 | 284 | if (data[i][0].toLowerCase().includes(text.toLowerCase()) |
296 | 285 | || data[i][1].toLowerCase().includes(text.toLowerCase()) |
297 | 286 | || data[i][2].toLowerCase().includes(text.toLowerCase()) |
298 | 287 | || data[i][3].toLowerCase().includes(text.toLowerCase())){ |
299 | - if ($("#title-table").text() == "{{did_table}}"){ | |
300 | - search.push(json_did["data"][i]); | |
301 | - } else { | |
302 | - search.push(json_history["data"][i]); | |
303 | - } | |
288 | + search.push(json_history["data"][i]); | |
304 | 289 | } |
305 | 290 | } |
306 | 291 | } |
... | ... | @@ -312,16 +297,16 @@ |
312 | 297 | } |
313 | 298 | } |
314 | 299 | } |
315 | - // console.log(search,"busca"); | |
316 | - if (($("#title-table").text() == "{{did_table}}")){ | |
317 | - drawTable(column_did,pagination(search,1),true,3); | |
318 | - } else if (($("#title-table").text() == "{{n_did_table}}")){ | |
300 | + if (!load_histoty && ($("#title-table").text() == "{{n_did_table}}")){ | |
319 | 301 | drawTable(column_n_did,pagination(search,1),false); |
320 | 302 | } else { |
321 | 303 | drawTable(column_history,pagination(search,1),true,3); |
322 | 304 | } |
305 | + if (load_histoty || ($("#title-table").text() != "{{n_did_table}}")){ | |
306 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | |
307 | + } | |
323 | 308 | putpagination(search); |
324 | - }); | |
309 | + } | |
325 | 310 | |
326 | 311 | function pagination(data,pag){ |
327 | 312 | var len = data.length; |
... | ... | @@ -329,16 +314,12 @@ |
329 | 314 | var end = (pag * 20 < len) ? pag * 20:len; |
330 | 315 | var search = data.slice(first,end); |
331 | 316 | return search; |
332 | - // $(".pagination > .disabled").css("color","red"); | |
333 | 317 | } |
334 | 318 | function clickPagination(pag){ |
335 | 319 | $(".pagination > li").last().remove(); |
336 | 320 | $(".pagination > li").first().remove(); |
337 | 321 | |
338 | - // console.log(search,"texto"); | |
339 | - if (($("#title-table").text() == "{{did_table}}")){ | |
340 | - drawTable(column_did,pagination(search,pag),true,3); | |
341 | - } else if (($("#title-table").text() == "{{n_did_table}}")){ | |
322 | + if (($("#title-table").text() == "{{n_did_table}}")){ | |
342 | 323 | drawTable(column_n_did,pagination(search,pag),false); |
343 | 324 | } else { |
344 | 325 | drawTable(column_history,pagination(search,pag),true,3); | ... | ... |
pdf_file/views.py
... | ... | @@ -405,27 +405,21 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
405 | 405 | else : |
406 | 406 | start_date = datetime.datetime.strptime(self.request.GET.get('init_date',''),date_format) |
407 | 407 | end_date = datetime.datetime.strptime(self.request.GET.get('end_date',''),date_format) |
408 | - # print (start_date," depois") | |
408 | + | |
409 | 409 | context["init_date"] = start_date |
410 | 410 | context["end_date"] = end_date |
411 | 411 | alunos = pdf_file.students.all() |
412 | 412 | |
413 | 413 | vis_ou = Log.objects.filter(context__contains={'pdffile_id':pdf_file.id},resource="pdffile",action="view",user_email__in=(aluno.email for aluno in alunos), datetime__range=(start_date,end_date + datetime.timedelta(minutes = 1))) |
414 | - did,n_did,history = str(_("Users who viewed")),str(_("Users who did not viewed")),str(_("Historic")) | |
414 | + did,n_did,history = str(_("Realized")),str(_("Unrealized")),str(_("Historic")) | |
415 | 415 | re = [] |
416 | - data_did, data_n_did,data_history = [],[],[] | |
417 | - json_did, json_n_did, json_history = {},{},{} | |
416 | + data_n_did,data_history = [],[] | |
417 | + json_n_did, json_history = {},{} | |
418 | 418 | |
419 | 419 | from django.db.models import Count, Max |
420 | 420 | views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) |
421 | 421 | date_last = vis_ou.values("user_email").annotate(last=Max("datetime")) |
422 | 422 | |
423 | - for i in range(0,len(views_user)): | |
424 | - data_did.append([str(alunos.get(email=views_user[i].get("user_email"))), | |
425 | - ", ".join([str(x) for x in pdf_file.topic.subject.group_subject.filter(participants__email=views_user[i].get("user_email"))]), | |
426 | - views_user[i].get("views"),date_last.get(user_email=views_user[i].get("user_email")).get("last")]) | |
427 | - json_did["data"] = data_did | |
428 | - | |
429 | 423 | |
430 | 424 | for log_al in vis_ou.order_by("datetime"): |
431 | 425 | data_history.append([str(alunos.get(email=log_al.user_email)), |
... | ... | @@ -435,11 +429,10 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
435 | 429 | |
436 | 430 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) |
437 | 431 | for alun in not_view: |
438 | - data_n_did.append([str(alun),", ".join([str(x) for x in pdf_file.topic.subject.group_subject.filter(participants__email=alun.email)])]) | |
432 | + data_n_did.append([str(alun),", ".join([str(x) for x in pdf_file.topic.subject.group_subject.filter(participants__email=alun.email)]),str(_('View'))]) | |
439 | 433 | json_n_did["data"] = data_n_did |
440 | 434 | |
441 | 435 | |
442 | - context["json_did"] = json_did | |
443 | 436 | context["json_n_did"] = json_n_did |
444 | 437 | context["json_history"] = json_history |
445 | 438 | c_visualizou = vis_ou.distinct("user_email").count() | ... | ... |