Commit aaba22304bbc3a5de24b8be46ba375bcd7269bb9
1 parent
4a391dc8
Exists in
master
and in
2 other branches
organizando os dados em duas tabelas e com a quantidade de registros em webpage
Showing
2 changed files
with
33 additions
and
63 deletions
Show diff stats
webpage/templates/webpages/relatorios.html
... | ... | @@ -21,14 +21,6 @@ |
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 | 26 | array_n_did.push(["{{data_json.0}}","{{data_json.1}}"]); |
... | ... | @@ -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%} |
... | ... | @@ -193,7 +180,7 @@ |
193 | 180 | <ul class="list-inline nav-justified"> |
194 | 181 | <li> |
195 | 182 | <ul id="view-table" class="list-inline text-right"> |
196 | - <li><h3 id="title-table">{{history_table}}</h3></li> | |
183 | + <li><h3 id="title-table"></h3></li> | |
197 | 184 | </ul> |
198 | 185 | </li> |
199 | 186 | <li> |
... | ... | @@ -219,6 +206,7 @@ |
219 | 206 | </div> |
220 | 207 | |
221 | 208 | <script type="text/javascript"> |
209 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | |
222 | 210 | function putpagination(data = json_history["data"]){ |
223 | 211 | var len = Math.ceil(data.length / 20); |
224 | 212 | $(".pagination").empty(); |
... | ... | @@ -257,51 +245,49 @@ |
257 | 245 | } |
258 | 246 | function backhistory(){ |
259 | 247 | drawTable(column_history,json_history["data"],true,3); |
260 | - $("#title-table").text("{{history_table}}"); | |
261 | 248 | $("#link-history").remove(); |
262 | 249 | search = []; |
263 | 250 | for (var i in json_history["data"]){ |
264 | 251 | search.push([json_history["data"][i][0],json_history["data"][i][1], |
265 | 252 | json_history["data"][i][2],json_history["data"][i][3]]); |
266 | 253 | } |
254 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | |
267 | 255 | putpagination(json_history["data"]); |
268 | 256 | } |
269 | - // $("#search-input").on("keyup",function(){ | |
270 | - // console.log($("#search-input").val()); | |
271 | - // }); | |
257 | + | |
258 | + | |
272 | 259 | $("#search-input").on("keyup",function(){ |
273 | 260 | search = []; |
274 | 261 | var text = $("#search-input").val(); |
262 | + searcher(text); | |
263 | + }); | |
264 | + | |
265 | + function searcher(text, load_histoty = false){ | |
266 | + if (load_histoty){ | |
267 | + $("#link-history").remove(); | |
268 | + } | |
275 | 269 | var data = []; |
276 | - if ($("#title-table").text() == "{{n_did_table}}"){ | |
270 | + if ($("#title-table").text() == "{{n_did_table}}" && !load_histoty){ | |
277 | 271 | data = $.map(json_n_did["data"], function (obj) { |
278 | 272 | return $.extend(true, {}, obj); |
279 | 273 | }); |
280 | - } else if ($("#title-table").text() == "{{did_table}}") { | |
281 | - data = $.map(json_did["data"], function (obj) { | |
282 | - return $.extend(true, {}, obj); | |
283 | - }); | |
284 | 274 | } else { |
285 | 275 | data = $.map(json_history["data"], function (obj) { |
286 | 276 | return $.extend(true, {}, obj); |
287 | 277 | }); |
288 | 278 | } |
289 | - if ($("#title-table").text() != "{{n_did_table}}"){ | |
279 | + if (load_histoty || $("#title-table").text() != "{{n_did_table}}"){ | |
290 | 280 | for (var i in data){ |
291 | 281 | data[i][3] = moment(data[i][3]).format("DD/MM/YYYY HH:mm"); |
292 | 282 | } |
293 | 283 | } |
294 | - if ($("#title-table").text() != "{{n_did_table}}"){ | |
284 | + if (load_histoty || $("#title-table").text() != "{{n_did_table}}"){ | |
295 | 285 | for (var i in data){ |
296 | 286 | if (data[i][0].toLowerCase().includes(text.toLowerCase()) |
297 | 287 | || data[i][1].toLowerCase().includes(text.toLowerCase()) |
298 | 288 | || data[i][2].toLowerCase().includes(text.toLowerCase()) |
299 | 289 | || data[i][3].toLowerCase().includes(text.toLowerCase())){ |
300 | - if ($("#title-table").text() == "{{did_table}}"){ | |
301 | - search.push(json_did["data"][i]); | |
302 | - } else { | |
303 | - search.push(json_history["data"][i]); | |
304 | - } | |
290 | + search.push(json_history["data"][i]); | |
305 | 291 | } |
306 | 292 | } |
307 | 293 | } |
... | ... | @@ -313,16 +299,16 @@ |
313 | 299 | } |
314 | 300 | } |
315 | 301 | } |
316 | - // console.log(search,"busca"); | |
317 | - if (($("#title-table").text() == "{{did_table}}")){ | |
318 | - drawTable(column_did,pagination(search,1),true,3); | |
319 | - } else if (($("#title-table").text() == "{{n_did_table}}")){ | |
302 | + if (!load_histoty && ($("#title-table").text() == "{{n_did_table}}")){ | |
320 | 303 | drawTable(column_n_did,pagination(search,1),false); |
321 | 304 | } else { |
322 | 305 | drawTable(column_history,pagination(search,1),true,3); |
323 | 306 | } |
307 | + if (load_histoty || ($("#title-table").text() != "{{n_did_table}}")){ | |
308 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | |
309 | + } | |
324 | 310 | putpagination(search); |
325 | - }); | |
311 | + } | |
326 | 312 | |
327 | 313 | function pagination(data,pag){ |
328 | 314 | var len = data.length; |
... | ... | @@ -330,16 +316,12 @@ |
330 | 316 | var end = (pag * 20 < len) ? pag * 20:len; |
331 | 317 | var search = data.slice(first,end); |
332 | 318 | return search; |
333 | - // $(".pagination > .disabled").css("color","red"); | |
334 | 319 | } |
335 | 320 | function clickPagination(pag){ |
336 | 321 | $(".pagination > li").last().remove(); |
337 | 322 | $(".pagination > li").first().remove(); |
338 | 323 | |
339 | - // console.log(search,"texto"); | |
340 | - if (($("#title-table").text() == "{{did_table}}")){ | |
341 | - drawTable(column_did,pagination(search,pag),true,3); | |
342 | - } else if (($("#title-table").text() == "{{n_did_table}}")){ | |
324 | + if (($("#title-table").text() == "{{n_did_table}}")){ | |
343 | 325 | drawTable(column_n_did,pagination(search,pag),false); |
344 | 326 | } else { |
345 | 327 | drawTable(column_history,pagination(search,pag),true,3); | ... | ... |
webpage/views.py
... | ... | @@ -475,27 +475,15 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
475 | 475 | alunos = webpage.students.all() |
476 | 476 | |
477 | 477 | vis_ou = Log.objects.filter(context__contains={'webpage_id':webpage.id},resource="webpage",action="view",user_email__in=(aluno.email for aluno in alunos), datetime__range=(start_date,end_date + datetime.timedelta(minutes = 1))) |
478 | - did,n_did,history = str(_("Users who viewed")),str(_("Users who did not viewed")),str(_("Historic")) | |
478 | + did,n_did,history = str(_("Realized")),str(_("Unrealized")),str(_("Historic")) | |
479 | 479 | re = [] |
480 | - data_did, data_n_did,data_history = [],[],[] | |
481 | - json_did, json_n_did, json_history = {},{},{} | |
482 | - # column = [] | |
483 | - # column.append([str(_("User")),"string"]) | |
484 | - # column.append([str(_("Group")),"string"]) | |
480 | + data_n_did,data_history = [],[] | |
481 | + json_n_did, json_history = {},{} | |
485 | 482 | |
486 | 483 | from django.db.models import Count, Max |
487 | 484 | views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) |
488 | 485 | date_last = vis_ou.values("user_email").annotate(last=Max("datetime")) |
489 | - # column.append([str(_("Number of views")),"string"]) | |
490 | - # column.append([str(_("Date of last view")),"date"]) | |
491 | - for i in range(0,len(views_user)): | |
492 | - data_did.append([str(alunos.get(email=views_user[i].get("user_email"))), | |
493 | - ", ".join([str(x) for x in webpage.topic.subject.group_subject.filter(participants__email=views_user[i].get("user_email"))]), | |
494 | - views_user[i].get("views"),date_last.get(user_email=views_user[i].get("user_email")).get("last")]) | |
495 | - json_did["data"] = data_did | |
496 | - | |
497 | - # column.append([str(_("Action")),"string"]) | |
498 | - # column.append([str(_("Date of action")),"date"]) | |
486 | + | |
499 | 487 | for log_al in vis_ou.order_by("datetime"): |
500 | 488 | data_history.append([str(alunos.get(email=log_al.user_email)), |
501 | 489 | ", ".join([str(x) for x in webpage.topic.subject.group_subject.filter(participants__email=log_al.user_email)]), |
... | ... | @@ -503,12 +491,12 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
503 | 491 | json_history["data"] = data_history |
504 | 492 | |
505 | 493 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) |
494 | + | |
506 | 495 | for alun in not_view: |
507 | - data_n_did.append([str(alun),", ".join([str(x) for x in webpage.topic.subject.group_subject.filter(participants__email=alun.email)])]) | |
496 | + data_n_did.append([str(alun),", ".join([str(x) for x in webpage.topic.subject.group_subject.filter(participants__email=alun.email)]),str(_('View'))]) | |
508 | 497 | json_n_did["data"] = data_n_did |
509 | 498 | |
510 | 499 | |
511 | - context["json_did"] = json_did | |
512 | 500 | context["json_n_did"] = json_n_did |
513 | 501 | context["json_history"] = json_history |
514 | 502 | c_visualizou = vis_ou.distinct("user_email").count() | ... | ... |