Commit 4a391dc8db07bddab1605312782ec21f26344e25

Authored by Jailson Dias
1 parent 9727e86c

organizando os dados em duas tabelas e com a quantidade de registros em pdf file

pdf_file/templates/pdf_file/relatorios.html
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
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 %}]); 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 {% endfor%} 14 {% endfor%}
15 var json_history = {"data":array_history}; 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 var search = []; 18 var search = [];
19 for (var i in json_history["data"]){ 19 for (var i in json_history["data"]){
@@ -21,20 +21,12 @@ @@ -21,20 +21,12 @@
21 json_history["data"][i][2],json_history["data"][i][3]]); 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 var array_n_did = []; 24 var array_n_did = [];
33 {%for data_json in json_n_did.data%} 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 {% endfor%} 27 {% endfor%}
36 var json_n_did = {"data":array_n_did}; 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 </script> 30 </script>
39 31
40 32
@@ -82,17 +74,12 @@ @@ -82,17 +74,12 @@
82 putpagination(json_n_did["data"]); 74 putpagination(json_n_did["data"]);
83 75
84 } else if (col == "{{did_table}}" && text("#title-table") != "{{did_table}}"){ 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 search = []; 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 chart.setSelection([]) 85 chart.setSelection([])
@@ -125,7 +112,7 @@ @@ -125,7 +112,7 @@
125 112
126 var table = new google.visualization.Table(document.getElementById('table_div')); 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 </script> 117 </script>
131 {% endblock%} 118 {% endblock%}
@@ -218,6 +205,7 @@ @@ -218,6 +205,7 @@
218 </div> 205 </div>
219 206
220 <script type="text/javascript"> 207 <script type="text/javascript">
  208 + $("#title-table").text(search.length + " {% trans 'record(s)' %}");
221 function putpagination(data = json_history["data"]){ 209 function putpagination(data = json_history["data"]){
222 var len = Math.ceil(data.length / 20); 210 var len = Math.ceil(data.length / 20);
223 $(".pagination").empty(); 211 $(".pagination").empty();
@@ -256,51 +244,48 @@ @@ -256,51 +244,48 @@
256 } 244 }
257 function backhistory(){ 245 function backhistory(){
258 drawTable(column_history,json_history["data"],true,3); 246 drawTable(column_history,json_history["data"],true,3);
259 - $("#title-table").text("{{history_table}}");  
260 $("#link-history").remove(); 247 $("#link-history").remove();
261 search = []; 248 search = [];
262 for (var i in json_history["data"]){ 249 for (var i in json_history["data"]){
263 search.push([json_history["data"][i][0],json_history["data"][i][1], 250 search.push([json_history["data"][i][0],json_history["data"][i][1],
264 json_history["data"][i][2],json_history["data"][i][3]]); 251 json_history["data"][i][2],json_history["data"][i][3]]);
265 } 252 }
  253 + $("#title-table").text(search.length + " {% trans 'record(s)' %}");
266 putpagination(json_history["data"]); 254 putpagination(json_history["data"]);
267 } 255 }
268 - // $("#search-input").on("keyup",function(){  
269 - // console.log($("#search-input").val());  
270 - // }); 256 +
271 $("#search-input").on("keyup",function(){ 257 $("#search-input").on("keyup",function(){
272 search = []; 258 search = [];
273 var text = $("#search-input").val(); 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 var data = []; 267 var data = [];
275 - if ($("#title-table").text() == "{{n_did_table}}"){ 268 + if ($("#title-table").text() == "{{n_did_table}}" && !load_histoty){
276 data = $.map(json_n_did["data"], function (obj) { 269 data = $.map(json_n_did["data"], function (obj) {
277 return $.extend(true, {}, obj); 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 } else { 272 } else {
284 data = $.map(json_history["data"], function (obj) { 273 data = $.map(json_history["data"], function (obj) {
285 return $.extend(true, {}, obj); 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 for (var i in data){ 278 for (var i in data){
290 data[i][3] = moment(data[i][3]).format("DD/MM/YYYY HH:mm"); 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 for (var i in data){ 283 for (var i in data){
295 if (data[i][0].toLowerCase().includes(text.toLowerCase()) 284 if (data[i][0].toLowerCase().includes(text.toLowerCase())
296 || data[i][1].toLowerCase().includes(text.toLowerCase()) 285 || data[i][1].toLowerCase().includes(text.toLowerCase())
297 || data[i][2].toLowerCase().includes(text.toLowerCase()) 286 || data[i][2].toLowerCase().includes(text.toLowerCase())
298 || data[i][3].toLowerCase().includes(text.toLowerCase())){ 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,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 drawTable(column_n_did,pagination(search,1),false); 301 drawTable(column_n_did,pagination(search,1),false);
320 } else { 302 } else {
321 drawTable(column_history,pagination(search,1),true,3); 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 putpagination(search); 308 putpagination(search);
324 - }); 309 + }
325 310
326 function pagination(data,pag){ 311 function pagination(data,pag){
327 var len = data.length; 312 var len = data.length;
@@ -329,16 +314,12 @@ @@ -329,16 +314,12 @@
329 var end = (pag * 20 < len) ? pag * 20:len; 314 var end = (pag * 20 < len) ? pag * 20:len;
330 var search = data.slice(first,end); 315 var search = data.slice(first,end);
331 return search; 316 return search;
332 - // $(".pagination > .disabled").css("color","red");  
333 } 317 }
334 function clickPagination(pag){ 318 function clickPagination(pag){
335 $(".pagination > li").last().remove(); 319 $(".pagination > li").last().remove();
336 $(".pagination > li").first().remove(); 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 drawTable(column_n_did,pagination(search,pag),false); 323 drawTable(column_n_did,pagination(search,pag),false);
343 } else { 324 } else {
344 drawTable(column_history,pagination(search,pag),true,3); 325 drawTable(column_history,pagination(search,pag),true,3);
pdf_file/views.py
@@ -405,27 +405,21 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): @@ -405,27 +405,21 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView):
405 else : 405 else :
406 start_date = datetime.datetime.strptime(self.request.GET.get('init_date',''),date_format) 406 start_date = datetime.datetime.strptime(self.request.GET.get('init_date',''),date_format)
407 end_date = datetime.datetime.strptime(self.request.GET.get('end_date',''),date_format) 407 end_date = datetime.datetime.strptime(self.request.GET.get('end_date',''),date_format)
408 - # print (start_date," depois") 408 +
409 context["init_date"] = start_date 409 context["init_date"] = start_date
410 context["end_date"] = end_date 410 context["end_date"] = end_date
411 alunos = pdf_file.students.all() 411 alunos = pdf_file.students.all()
412 412
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))) 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 re = [] 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 from django.db.models import Count, Max 419 from django.db.models import Count, Max
420 views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) 420 views_user = vis_ou.values("user_email").annotate(views=Count("user_email"))
421 date_last = vis_ou.values("user_email").annotate(last=Max("datetime")) 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 for log_al in vis_ou.order_by("datetime"): 424 for log_al in vis_ou.order_by("datetime"):
431 data_history.append([str(alunos.get(email=log_al.user_email)), 425 data_history.append([str(alunos.get(email=log_al.user_email)),
@@ -435,11 +429,10 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): @@ -435,11 +429,10 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView):
435 429
436 not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) 430 not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")])
437 for alun in not_view: 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 json_n_did["data"] = data_n_did 433 json_n_did["data"] = data_n_did
440 434
441 435
442 - context["json_did"] = json_did  
443 context["json_n_did"] = json_n_did 436 context["json_n_did"] = json_n_did
444 context["json_history"] = json_history 437 context["json_history"] = json_history
445 c_visualizou = vis_ou.distinct("user_email").count() 438 c_visualizou = vis_ou.distinct("user_email").count()