Commit 9a7c3160a4f2f79fec10a990de9f784f5e9b1d99
Exists in
master
and in
2 other branches
Merge branch 'refactoring' of https://github.com/amadeusproject/amadeuslms into refactoring
Showing
6 changed files
with
340 additions
and
217 deletions
Show diff stats
pdf_file/templates/pdf_file/relatorios.html
... | ... | @@ -7,13 +7,14 @@ |
7 | 7 | {{ block.super }} |
8 | 8 | <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> |
9 | 9 | <script type="text/javascript"> |
10 | + var tabela_atual = true; | |
10 | 11 | |
11 | 12 | var array_history = []; |
12 | 13 | {%for data_json in json_history.data%} |
13 | 14 | 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 | 15 | {% endfor%} |
15 | 16 | var json_history = {"data":array_history}; |
16 | - var column_history = [{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":'{% trans "Action" %}'},{"date":'{% trans "Date of Action" %}'}]; | |
17 | + var column_history = [{"string":"{% trans 'User' %}"},{"string":"{% trans 'Group' %}"},{"string":"{% trans 'Action' %}"},{"date":"{% trans 'Date of Action' %}"}]; | |
17 | 18 | |
18 | 19 | var search = []; |
19 | 20 | for (var i in json_history["data"]){ |
... | ... | @@ -21,20 +22,19 @@ |
21 | 22 | json_history["data"][i][2],json_history["data"][i][3]]); |
22 | 23 | } |
23 | 24 | |
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 | 25 | var array_n_did = []; |
26 | + var checkbox = {}; | |
33 | 27 | {%for data_json in json_n_did.data%} |
34 | - array_n_did.push(["{{data_json.0}}","{{data_json.1}}"]); | |
28 | + var input = '<div class="checkbox">\ | |
29 | + <label for="{{data_json.0}}_google_table">\ | |
30 | + <input id="{{data_json.0}}_google_table" name="{{data_json.0}}_google_table" type="checkbox"><span class="checkbox-material"><span class="check"></span></span>\ | |
31 | + </label>\ | |
32 | + </div>' | |
33 | + checkbox["{{data_json.0}}_google_table"] = "{{data_json.4}}"; | |
34 | + array_n_did.push([input,"{{data_json.1}}","{{data_json.2}}", "{{data_json.3}}"]); | |
35 | 35 | {% endfor%} |
36 | 36 | var json_n_did = {"data":array_n_did}; |
37 | - var column_n_did = [{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'}]; | |
37 | + var column_n_did = [{"string":'<a href="javascript:void(0);" onclick="return openmodal();"> {% trans "Send message" %}</a>'},{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":"Action don't realized"}]; | |
38 | 38 | </script> |
39 | 39 | |
40 | 40 | |
... | ... | @@ -66,43 +66,35 @@ |
66 | 66 | var selectedItem = chart.getSelection()[0]; |
67 | 67 | if (selectedItem) { |
68 | 68 | var col = data.getColumnLabel(selectedItem.column); |
69 | - var element = '<li id="link-history">\ | |
70 | - <a id="call-history" href="javascript:void(0);" onclick="return backhistory();"> <i class="fa fa-arrow-left ta-fw"> </i> {{history_table}}</a>\ | |
71 | - </li>'; | |
72 | - if (col == "{{n_did_table}}" && text("#title-table") != "{{n_did_table}}"){ | |
73 | - if (length("#link-history") <= 0){ | |
74 | - add(element,"#view-table",true); | |
75 | - } | |
76 | - altertitle("{{n_did_table}}"); | |
69 | + if (col == "{{n_did_table}}"){ | |
70 | + tabela_atual = false; | |
77 | 71 | search = []; |
78 | 72 | for (var i in json_n_did["data"]){ |
79 | - search.push([json_n_did["data"][i][0],json_n_did["data"][i][1]]); | |
73 | + search.push([json_n_did["data"][i][0],json_n_did["data"][i][1], | |
74 | + json_n_did["data"][i][2],json_n_did["data"][i][3]]); | |
80 | 75 | } |
81 | - drawTable(column_n_did,pagination(json_n_did["data"],1),false); | |
82 | - putpagination(json_n_did["data"]); | |
76 | + searcher(col, tabela_atual,true); | |
83 | 77 | |
84 | - } 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}}"); | |
78 | + } else if (col == "{{did_table}}"){ | |
79 | + tabela_atual = true; | |
89 | 80 | 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]]); | |
81 | + for (var i in json_history["data"]){ | |
82 | + search.push([json_history["data"][i][0],json_history["data"][i][1], | |
83 | + json_history["data"][i][2],json_history["data"][i][3]]); | |
93 | 84 | } |
94 | - drawTable(column_did,pagination(json_did["data"],1),true,3); | |
95 | - putpagination(json_did["data"]); | |
85 | + searcher(col, tabela_atual,true); | |
96 | 86 | } |
97 | 87 | } |
98 | 88 | chart.setSelection([]) |
99 | - } | |
89 | + } | |
100 | 90 | |
101 | 91 | var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); |
102 | 92 | google.visualization.events.addListener(chart, 'select', selectHandler); |
103 | 93 | chart.draw(data, options); |
104 | 94 | |
105 | 95 | } |
96 | + | |
97 | + var sortAscending = {0:false,1:false,2:false,3:false}; | |
106 | 98 | function drawTable(columns = column_history,rows = pagination(json_history["data"],1),isdate = true,columndate = 3) { |
107 | 99 | var data_table = new google.visualization.DataTable(); |
108 | 100 | for (var i in columns){ |
... | ... | @@ -122,10 +114,33 @@ |
122 | 114 | // } |
123 | 115 | // } |
124 | 116 | // console.log(methods.join(",")); |
125 | - | |
117 | + var options = { | |
118 | + sort: "event", | |
119 | + allowHtml: true, | |
120 | + cssClassNames : { | |
121 | + tableRow: 'text-center', | |
122 | + tableCell: 'text-center', | |
123 | + headerCell: 'text-center' | |
124 | + }, | |
125 | + showRowNumber: true, | |
126 | + width: '100%', | |
127 | + height: '100%', | |
128 | + } | |
129 | + function ordenar(properties){ | |
130 | + var columnIndex = properties['column']; | |
131 | + if (columnIndex > 0) { | |
132 | + options["sortColumn"] = columnIndex; | |
133 | + options["sortAscending"] = sortAscending[columnIndex]; | |
134 | + data_table.sort({column:columnIndex,desc:sortAscending[columnIndex]}); | |
135 | + sortAscending = {0:false,1:false,2:false,3:false}; | |
136 | + sortAscending[columnIndex] = !sortAscending[columnIndex]; | |
137 | + // console.log(sortAscending); | |
138 | + table.draw(data_table, options); | |
139 | + } | |
140 | + } | |
126 | 141 | var table = new google.visualization.Table(document.getElementById('table_div')); |
127 | - | |
128 | - table.draw(data_table, {showRowNumber: true, width: '100%', height: '100%'}); | |
142 | + google.visualization.events.addListener(table, 'sort', function(e) {ordenar(e)}); | |
143 | + table.draw(data_table, options); | |
129 | 144 | } |
130 | 145 | </script> |
131 | 146 | {% endblock%} |
... | ... | @@ -161,25 +176,29 @@ |
161 | 176 | <div class="col-md-12 text-center"> |
162 | 177 | <h4 style="margin-top: 15px; margin-bottom: 10px" ><strong>{% trans "Report of the resource " %}{{pdf_file}}</strong></h4> |
163 | 178 | </div> |
164 | - <div class="col-md-2 text-right"> | |
165 | - <h4>{% trans "Select the period: " %}</h4> | |
166 | - </div> | |
167 | - <div class="col-md-8"> | |
179 | + </div> | |
180 | + <div class="row"> | |
181 | + <div class="col-md-12"> | |
182 | + | |
183 | + <ul class="list-inline nav-justified"> | |
168 | 184 | <div id="general-parameters-div"> |
185 | + <div class="general-parameters-field"> | |
186 | + <li class="text-right"><h4>{% trans "Select the period: " %}</h4></li> | |
187 | + </div> | |
169 | 188 | <form id="period-form" action="" method="get"> |
170 | 189 | <div class="general-parameters-field"> |
171 | - <input class="form-control datetime-picker" name="init_date" type="text" required="" value="{% if LANGUAGE_CODE == 'pt-br' %}{{init_date|date:'d/m/Y H:i'}} {% else %} {{init_date|date:'m/d/Y H:i P'}} {% endif %}"> | |
172 | - </div> | |
173 | - | |
174 | - <div class="general-parameters-field"> | |
175 | - {# <label class="form-field-report"> {% trans "Final Date" %} </label> #} | |
176 | - <input id="inputdate" class="form-control datetime-picker" name="end_date" type="text" required="" value="{% if LANGUAGE_CODE == 'pt-br' %}{{end_date|date:'d/m/Y H:i'}} {% else %} {{end_date|date:'m/d/Y H:i P'}} {% endif %}"> | |
177 | - </div> | |
178 | - <input type="submit" value="{% trans 'Search' %}" style="margin-left: 15px;" class="btn btn-success btn-raised"> | |
179 | - </form> | |
190 | + <li> <input class="form-control datetime-picker" name="init_date" type="text" required="" value="{% if LANGUAGE_CODE == 'pt-br' %}{{init_date|date:'d/m/Y H:i'}} {% else %} {{init_date|date:'m/d/Y H:i P'}} {% endif %}"></li> | |
191 | + </div> | |
192 | + <div class="general-parameters-field"> | |
193 | + <li><input id="inputdate" class="form-control datetime-picker" name="end_date" type="text" required="" value="{% if LANGUAGE_CODE == 'pt-br' %}{{end_date|date:'d/m/Y H:i'}} {% else %} {{end_date|date:'m/d/Y H:i P'}} {% endif %}"></li> | |
194 | + </div> | |
195 | + <li><input type="submit" value="{% trans 'Search' %}" style="margin-left: 15px;" class="btn btn-success btn-raised"></li> | |
196 | + </form> | |
180 | 197 | </div> |
198 | + <ul> | |
181 | 199 | </div> |
182 | 200 | </div> |
201 | + | |
183 | 202 | <div class="row"> |
184 | 203 | <div class="col-md-10 col-md-offset-1"> |
185 | 204 | <div id="chart_div" style="height: 500px; margin-top: -50px;"></div> |
... | ... | @@ -212,12 +231,45 @@ |
212 | 231 | </div> |
213 | 232 | </div> |
214 | 233 | </div> |
234 | + <!-- Modal (remember to change the ids!!!) --> | |
235 | + <div class="modal fade" id="send-message-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
236 | + <div class="modal-dialog" role="document"> | |
237 | + <div class="modal-content"> | |
238 | + <!-- Modal Body --> | |
239 | + <div class="modal-body"> | |
240 | + <!-- Put ONLY your content here!!! --> | |
241 | + <h3>{% trans "Message: " %}</h3> | |
242 | + <form id="text_chat_form" action="" method="GET"> | |
243 | + <textarea id="message" name="message" rows="5" cols="80"></textarea> | |
244 | + </form> | |
245 | + </div> | |
246 | + <!-- Modal Footer --> | |
247 | + <div id="delete-category-footer"class="modal-footer"> | |
248 | + <!-- Don't remove that!!! --> | |
249 | + <button type="button" class="btn btn-default btn-raised" data-dismiss="modal">{% trans "Close" %}</button> | |
250 | + <a href="javascript:void(0)" onclick="return sendMessage()" form="text_chat_form" class="btn btn-success btn-raised erase-button">{% trans "Send" %}</a> | |
251 | + </div> | |
252 | + </div> | |
253 | + </div> | |
254 | + </div> | |
255 | + | |
215 | 256 | <div class="row"> |
216 | 257 | <br><br> |
217 | 258 | </div> |
218 | 259 | </div> |
219 | 260 | |
220 | 261 | <script type="text/javascript"> |
262 | + $('#message').summernote({ | |
263 | + dialogsInBody: true, | |
264 | + disableDragAndDrop: true, | |
265 | + height: 150, | |
266 | + toolbar: [ | |
267 | + // [groupName, [list of button]] | |
268 | + ['style', ['bold', 'italic']], | |
269 | + ['insert', ['link']] | |
270 | + ] | |
271 | + }); | |
272 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | |
221 | 273 | function putpagination(data = json_history["data"]){ |
222 | 274 | var len = Math.ceil(data.length / 20); |
223 | 275 | $(".pagination").empty(); |
... | ... | @@ -241,9 +293,6 @@ |
241 | 293 | .attr('value', '{{ LANGUAGE_CODE }}') |
242 | 294 | .appendTo('#period-form'); |
243 | 295 | }); |
244 | - function altertitle(value) { | |
245 | - $("#title-table").text(value); | |
246 | - } | |
247 | 296 | function add(element,local, first = false){ |
248 | 297 | if (first) $(local).prepend(element); |
249 | 298 | else $(local).append(element); |
... | ... | @@ -254,74 +303,60 @@ |
254 | 303 | function length(element) { |
255 | 304 | return $(element).length; |
256 | 305 | } |
257 | - function backhistory(){ | |
258 | - drawTable(column_history,json_history["data"],true,3); | |
259 | - $("#title-table").text("{{history_table}}"); | |
260 | - $("#link-history").remove(); | |
261 | - search = []; | |
262 | - for (var i in json_history["data"]){ | |
263 | - search.push([json_history["data"][i][0],json_history["data"][i][1], | |
264 | - json_history["data"][i][2],json_history["data"][i][3]]); | |
265 | - } | |
266 | - putpagination(json_history["data"]); | |
267 | - } | |
268 | - // $("#search-input").on("keyup",function(){ | |
269 | - // console.log($("#search-input").val()); | |
270 | - // }); | |
306 | + | |
271 | 307 | $("#search-input").on("keyup",function(){ |
272 | 308 | search = []; |
273 | 309 | var text = $("#search-input").val(); |
310 | + searcher(text,tabela_atual); | |
311 | + }); | |
312 | + | |
313 | + function searcher(text, load_histoty = false,apaga=false){ | |
314 | + if(apaga){ | |
315 | + $("#search-input").val(""); | |
316 | + } | |
274 | 317 | var data = []; |
275 | - if ($("#title-table").text() == "{{n_did_table}}"){ | |
318 | + if (!load_histoty){ | |
276 | 319 | data = $.map(json_n_did["data"], function (obj) { |
277 | 320 | return $.extend(true, {}, obj); |
278 | 321 | }); |
279 | - } else if ($("#title-table").text() == "{{did_table}}") { | |
280 | - data = $.map(json_did["data"], function (obj) { | |
281 | - return $.extend(true, {}, obj); | |
282 | - }); | |
283 | 322 | } else { |
284 | 323 | data = $.map(json_history["data"], function (obj) { |
285 | 324 | return $.extend(true, {}, obj); |
286 | 325 | }); |
287 | 326 | } |
288 | - if ($("#title-table").text() != "{{n_did_table}}"){ | |
327 | + if (load_histoty){ | |
289 | 328 | for (var i in data){ |
290 | 329 | data[i][3] = moment(data[i][3]).format("DD/MM/YYYY HH:mm"); |
291 | 330 | } |
292 | 331 | } |
293 | - if ($("#title-table").text() != "{{n_did_table}}"){ | |
332 | + if (load_histoty){ | |
294 | 333 | for (var i in data){ |
295 | 334 | if (data[i][0].toLowerCase().includes(text.toLowerCase()) |
296 | 335 | || data[i][1].toLowerCase().includes(text.toLowerCase()) |
297 | 336 | || data[i][2].toLowerCase().includes(text.toLowerCase()) |
298 | 337 | || 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 | - } | |
338 | + search.push(json_history["data"][i]); | |
304 | 339 | } |
305 | 340 | } |
306 | 341 | } |
307 | 342 | else { |
308 | 343 | for (var i in data){ |
309 | - if (data[i][0].toLowerCase().includes(text.toLowerCase()) | |
310 | - || data[i][1].toLowerCase().includes(text.toLowerCase())){ | |
344 | + if (data[i][1].toLowerCase().includes(text.toLowerCase()) | |
345 | + || data[i][2].toLowerCase().includes(text.toLowerCase()) | |
346 | + || data[i][3].toLowerCase().includes(text.toLowerCase())){ | |
311 | 347 | search.push(json_n_did["data"][i]); |
312 | 348 | } |
313 | 349 | } |
314 | 350 | } |
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}}")){ | |
351 | + console.log(search); | |
352 | + if (!load_histoty){ | |
319 | 353 | drawTable(column_n_did,pagination(search,1),false); |
320 | 354 | } else { |
321 | 355 | drawTable(column_history,pagination(search,1),true,3); |
322 | 356 | } |
357 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | |
323 | 358 | putpagination(search); |
324 | - }); | |
359 | + } | |
325 | 360 | |
326 | 361 | function pagination(data,pag){ |
327 | 362 | var len = data.length; |
... | ... | @@ -329,16 +364,12 @@ |
329 | 364 | var end = (pag * 20 < len) ? pag * 20:len; |
330 | 365 | var search = data.slice(first,end); |
331 | 366 | return search; |
332 | - // $(".pagination > .disabled").css("color","red"); | |
333 | 367 | } |
334 | - function clickPagination(pag){ | |
368 | + function clickPagination(pag, load_histoty = false){ | |
335 | 369 | $(".pagination > li").last().remove(); |
336 | 370 | $(".pagination > li").first().remove(); |
337 | 371 | |
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}}")){ | |
372 | + if (!load_histoty){ | |
342 | 373 | drawTable(column_n_did,pagination(search,pag),false); |
343 | 374 | } else { |
344 | 375 | drawTable(column_history,pagination(search,pag),true,3); |
... | ... | @@ -353,5 +384,26 @@ |
353 | 384 | $(".active").removeClass("active"); |
354 | 385 | $("#" + pag).addClass("active"); |
355 | 386 | } |
387 | + function sendMessage(){ | |
388 | + $("#send-message-modal").modal("hide"); | |
389 | + var checked = $("#google-chart-checkbox").serializeArray(); | |
390 | + var email = []; | |
391 | + for (var i in checked){ | |
392 | + email.push(checkbox[checked[i]["name"]]); | |
393 | + } | |
394 | + var message = $("#text_chat_form").serializeArray()[0]["value"]; | |
395 | + $.ajax({ | |
396 | + type: "GET", | |
397 | + data: {"message":message,"users[]":email}, | |
398 | + url: "{% url 'pdf_files:send_message' subject.slug %}", | |
399 | + success: function(msg){ | |
400 | + console.log(msg); | |
401 | + $('#message').summernote("reset"); | |
402 | + } | |
403 | + }); | |
404 | + } | |
405 | + function openmodal(){ | |
406 | + $("#send-message-modal").modal("show"); | |
407 | + } | |
356 | 408 | </script> |
357 | 409 | {% endblock %} | ... | ... |
pdf_file/urls.py
... | ... | @@ -9,4 +9,5 @@ urlpatterns = [ |
9 | 9 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteView.as_view(), name = 'delete'), |
10 | 10 | url(r'^view/(?P<slug>[\w_-]+)/$', views.ViewPDFFile.as_view(), name = 'view'), |
11 | 11 | url(r'^chart/(?P<slug>[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), |
12 | + url(r'^send-message/(?P<slug>[\w_-]+)/$', views.sendMessage, name = 'send_message'), | |
12 | 13 | ] | ... | ... |
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)), |
... | ... | @@ -434,12 +428,13 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
434 | 428 | json_history["data"] = data_history |
435 | 429 | |
436 | 430 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) |
431 | + index = 0 | |
437 | 432 | 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)])]) | |
433 | + data_n_did.append([index,str(alun),", ".join([str(x) for x in pdf_file.topic.subject.group_subject.filter(participants__email=alun.email)]),str(_('View')), str(alun.email)]) | |
434 | + index += 1 | |
439 | 435 | json_n_did["data"] = data_n_did |
440 | 436 | |
441 | 437 | |
442 | - context["json_did"] = json_did | |
443 | 438 | context["json_n_did"] = json_n_did |
444 | 439 | context["json_history"] = json_history |
445 | 440 | c_visualizou = vis_ou.distinct("user_email").count() |
... | ... | @@ -448,10 +443,27 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
448 | 443 | context['topic'] = pdf_file.topic |
449 | 444 | context['subject'] = pdf_file.topic.subject |
450 | 445 | context['db_data'] = re |
451 | - context['title_chart'] = _('Students viewing the PDF File') | |
446 | + context['title_chart'] = _('Actions about resource') | |
452 | 447 | context['title_vAxis'] = _('Quantity') |
453 | 448 | |
454 | 449 | context["n_did_table"] = n_did |
455 | 450 | context["did_table"] = did |
456 | 451 | context["history_table"] = history |
457 | 452 | return context |
453 | + | |
454 | + | |
455 | +from chat.models import Conversation, TalkMessages | |
456 | +from users.models import User | |
457 | +from subjects.models import Subject | |
458 | +def sendMessage(request, slug): | |
459 | + message = request.GET.get('message','') | |
460 | + users = request.GET.getlist('users[]','') | |
461 | + user = request.user | |
462 | + subject = get_object_or_404(Subject,slug = slug) | |
463 | + | |
464 | + for u in users: | |
465 | + to_user = User.objects.get(email=u) | |
466 | + talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) | |
467 | + created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject) | |
468 | + | |
469 | + return JsonResponse({"message":"ok"}) | ... | ... |
webpage/templates/webpages/relatorios.html
... | ... | @@ -7,6 +7,8 @@ |
7 | 7 | {{ block.super }} |
8 | 8 | <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> |
9 | 9 | <script type="text/javascript"> |
10 | + var tabela_atual = true; | |
11 | + | |
10 | 12 | |
11 | 13 | var array_history = []; |
12 | 14 | {%for data_json in json_history.data%} |
... | ... | @@ -21,20 +23,19 @@ |
21 | 23 | json_history["data"][i][2],json_history["data"][i][3]]); |
22 | 24 | } |
23 | 25 | |
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 | 26 | var array_n_did = []; |
27 | + var checkbox = {}; | |
33 | 28 | {%for data_json in json_n_did.data%} |
34 | - array_n_did.push(["{{data_json.0}}","{{data_json.1}}"]); | |
29 | + var input = '<div class="checkbox">\ | |
30 | + <label for="{{data_json.0}}_google_table">\ | |
31 | + <input id="{{data_json.0}}_google_table" name="{{data_json.0}}_google_table" type="checkbox"><span class="checkbox-material"><span class="check"></span></span>\ | |
32 | + </label>\ | |
33 | + </div>' | |
34 | + checkbox["{{data_json.0}}_google_table"] = "{{data_json.4}}"; | |
35 | + array_n_did.push([input,"{{data_json.1}}","{{data_json.2}}","{{data_json.3}}"]); | |
35 | 36 | {% endfor%} |
36 | 37 | var json_n_did = {"data":array_n_did}; |
37 | - var column_n_did = [{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'}]; | |
38 | + var column_n_did = [{"string":'<a href="javascript:void(0);" onclick="return openmodal();"> {% trans "Send message" %}</a>'},{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":"Action don't realized"}]; | |
38 | 39 | </script> |
39 | 40 | |
40 | 41 | |
... | ... | @@ -66,33 +67,22 @@ |
66 | 67 | var selectedItem = chart.getSelection()[0]; |
67 | 68 | if (selectedItem) { |
68 | 69 | var col = data.getColumnLabel(selectedItem.column); |
69 | - var element = '<li id="link-history">\ | |
70 | - <a id="call-history" href="javascript:void(0);" onclick="return backhistory();"> <i class="fa fa-arrow-left ta-fw"> </i> {{history_table}}</a>\ | |
71 | - </li>'; | |
72 | - if (col == "{{n_did_table}}" && text("#title-table") != "{{n_did_table}}"){ | |
73 | - if (length("#link-history") <= 0){ | |
74 | - add(element,"#view-table",true); | |
75 | - } | |
76 | - altertitle("{{n_did_table}}"); | |
70 | + if (col == "{{n_did_table}}"){ | |
71 | + tabela_atual = false; | |
77 | 72 | search = []; |
78 | 73 | for (var i in json_n_did["data"]){ |
79 | - search.push([json_n_did["data"][i][0],json_n_did["data"][i][1]]); | |
74 | + search.push([json_n_did["data"][i][0],json_n_did["data"][i][1], | |
75 | + json_n_did["data"][i][2],json_n_did["data"][i][3]]); | |
80 | 76 | } |
81 | - drawTable(column_n_did,pagination(json_n_did["data"],1),false); | |
82 | - putpagination(json_n_did["data"]); | |
83 | - | |
84 | - } 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}}"); | |
77 | + searcher(col, tabela_atual,true); | |
78 | + } else if (col == "{{did_table}}"){ | |
79 | + tabela_atual = true; | |
89 | 80 | 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]]); | |
81 | + for (var i in json_history["data"]){ | |
82 | + search.push([json_history["data"][i][0],json_history["data"][i][1], | |
83 | + json_history["data"][i][2],json_history["data"][i][3]]); | |
93 | 84 | } |
94 | - drawTable(column_did,pagination(json_did["data"],1),true,3); | |
95 | - putpagination(json_did["data"]); | |
85 | + searcher(col, tabela_atual,true); | |
96 | 86 | } |
97 | 87 | } |
98 | 88 | chart.setSelection([]) |
... | ... | @@ -103,6 +93,7 @@ |
103 | 93 | chart.draw(data, options); |
104 | 94 | |
105 | 95 | } |
96 | + var sortAscending = {0:false,1:false,2:false,3:false}; | |
106 | 97 | function drawTable(columns = column_history,rows = pagination(json_history["data"],1),isdate = true,columndate = 3) { |
107 | 98 | var data_table = new google.visualization.DataTable(); |
108 | 99 | for (var i in columns){ |
... | ... | @@ -122,10 +113,34 @@ |
122 | 113 | // } |
123 | 114 | // } |
124 | 115 | // console.log(methods.join(",")); |
116 | + var options = { | |
117 | + sort: "event", | |
118 | + allowHtml: true, | |
119 | + cssClassNames : { | |
120 | + tableRow: 'text-center', | |
121 | + tableCell: 'text-center', | |
122 | + headerCell: 'text-center' | |
123 | + }, | |
124 | + showRowNumber: true, | |
125 | + width: '100%', | |
126 | + height: '100%', | |
127 | + } | |
128 | + function ordenar(properties){ | |
129 | + var columnIndex = properties['column']; | |
130 | + if (columnIndex > 0) { | |
131 | + options["sortColumn"] = columnIndex; | |
132 | + options["sortAscending"] = sortAscending[columnIndex]; | |
133 | + data_table.sort({column:columnIndex,desc:sortAscending[columnIndex]}); | |
134 | + sortAscending = {0:false,1:false,2:false,3:false}; | |
135 | + sortAscending[columnIndex] = !sortAscending[columnIndex]; | |
136 | + // console.log(sortAscending); | |
137 | + table.draw(data_table, options); | |
138 | + } | |
139 | + } | |
125 | 140 | |
126 | 141 | var table = new google.visualization.Table(document.getElementById('table_div')); |
127 | - | |
128 | - table.draw(data_table, {showRowNumber: true, width: '100%', height: '100%'}); | |
142 | + google.visualization.events.addListener(table, 'sort', function(e) {ordenar(e)}); | |
143 | + table.draw(data_table, options); | |
129 | 144 | } |
130 | 145 | </script> |
131 | 146 | {% endblock%} |
... | ... | @@ -161,24 +176,26 @@ |
161 | 176 | <div class="col-md-12 text-center"> |
162 | 177 | <h4 style="margin-top: 15px; margin-bottom: 10px" ><strong>{% trans "Report of the resource " %}{{webpage}}</strong></h4> |
163 | 178 | </div> |
164 | - <div class="col-md-2 text-right"> | |
165 | - <h4>{% trans "Select the period: " %}</h4> | |
166 | - </div> | |
167 | - <div class="col-md-8"> | |
179 | + </div> | |
180 | + <div class="row"> | |
181 | + <div class="col-md-12"> | |
182 | + | |
183 | + <ul class="list-inline nav-justified"> | |
168 | 184 | <div id="general-parameters-div"> |
185 | + <div class="general-parameters-field"> | |
186 | + <li class="text-right"><h4>{% trans "Select the period: " %}</h4></li> | |
187 | + </div> | |
169 | 188 | <form id="period-form" action="" method="get"> |
170 | 189 | <div class="general-parameters-field"> |
171 | - {# <label class="form-field-report"> {% trans "Initial Date" %} </label> #} | |
172 | - <input class="form-control datetime-picker" name="init_date" type="text" required="" value="{% if LANGUAGE_CODE == 'pt-br' %}{{init_date|date:'d/m/Y H:i'}} {% else %} {{init_date|date:'m/d/Y H:i P'}} {% endif %}"> | |
173 | - </div> | |
174 | - | |
175 | - <div class="general-parameters-field"> | |
176 | - {# <label class="form-field-report"> {% trans "Final Date" %} </label> #} | |
177 | - <input id="inputdate" class="form-control datetime-picker" name="end_date" type="text" required="" value="{% if LANGUAGE_CODE == 'pt-br' %}{{end_date|date:'d/m/Y H:i'}} {% else %} {{end_date|date:'m/d/Y H:i P'}} {% endif %}"> | |
178 | - </div> | |
179 | - <input type="submit" value="{% trans 'Search' %}" style="margin-left: 15px;" class="btn btn-success btn-raised"> | |
180 | - </form> | |
190 | + <li> <input class="form-control datetime-picker" name="init_date" type="text" required="" value="{% if LANGUAGE_CODE == 'pt-br' %}{{init_date|date:'d/m/Y H:i'}} {% else %} {{init_date|date:'m/d/Y H:i P'}} {% endif %}"></li> | |
191 | + </div> | |
192 | + <div class="general-parameters-field"> | |
193 | + <li><input id="inputdate" class="form-control datetime-picker" name="end_date" type="text" required="" value="{% if LANGUAGE_CODE == 'pt-br' %}{{end_date|date:'d/m/Y H:i'}} {% else %} {{end_date|date:'m/d/Y H:i P'}} {% endif %}"></li> | |
194 | + </div> | |
195 | + <li><input type="submit" value="{% trans 'Search' %}" style="margin-left: 15px;" class="btn btn-success btn-raised"></li> | |
196 | + </form> | |
181 | 197 | </div> |
198 | + <ul> | |
182 | 199 | </div> |
183 | 200 | </div> |
184 | 201 | <div class="row"> |
... | ... | @@ -193,7 +210,7 @@ |
193 | 210 | <ul class="list-inline nav-justified"> |
194 | 211 | <li> |
195 | 212 | <ul id="view-table" class="list-inline text-right"> |
196 | - <li><h3 id="title-table">{{history_table}}</h3></li> | |
213 | + <li><h3 id="title-table"></h3></li> | |
197 | 214 | </ul> |
198 | 215 | </li> |
199 | 216 | <li> |
... | ... | @@ -204,8 +221,9 @@ |
204 | 221 | </li> |
205 | 222 | </ul> |
206 | 223 | </div> |
207 | - | |
208 | - <div id="table_div"></div> | |
224 | + <form id="google-chart-checkbox" action="" method="get"> | |
225 | + <div id="table_div"></div> | |
226 | + </form> | |
209 | 227 | <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12 text-center"> |
210 | 228 | <ul class="pagination"> |
211 | 229 | |
... | ... | @@ -213,12 +231,45 @@ |
213 | 231 | </div> |
214 | 232 | </div> |
215 | 233 | </div> |
234 | + | |
235 | + <!-- Modal (remember to change the ids!!!) --> | |
236 | + <div class="modal fade" id="send-message-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
237 | + <div class="modal-dialog" role="document"> | |
238 | + <div class="modal-content"> | |
239 | + <!-- Modal Body --> | |
240 | + <div class="modal-body"> | |
241 | + <!-- Put ONLY your content here!!! --> | |
242 | + <h3>{% trans "Message: " %}</h3> | |
243 | + <form id="text_chat_form" action="" method="GET"> | |
244 | + <textarea id="message" name="message" rows="5" cols="80"></textarea> | |
245 | + </form> | |
246 | + </div> | |
247 | + <!-- Modal Footer --> | |
248 | + <div id="delete-category-footer"class="modal-footer"> | |
249 | + <!-- Don't remove that!!! --> | |
250 | + <button type="button" class="btn btn-default btn-raised" data-dismiss="modal">{% trans "Close" %}</button> | |
251 | + <a href="javascript:void(0)" onclick="return sendMessage()" form="text_chat_form" class="btn btn-success btn-raised erase-button">{% trans "Send" %}</a> | |
252 | + </div> | |
253 | + </div> | |
254 | + </div> | |
255 | + </div> | |
216 | 256 | <div class="row"> |
217 | 257 | <br><br> |
218 | 258 | </div> |
219 | 259 | </div> |
220 | 260 | |
221 | 261 | <script type="text/javascript"> |
262 | + $('#message').summernote({ | |
263 | + dialogsInBody: true, | |
264 | + disableDragAndDrop: true, | |
265 | + height: 150, | |
266 | + toolbar: [ | |
267 | + // [groupName, [list of button]] | |
268 | + ['style', ['bold', 'italic']], | |
269 | + ['insert', ['link']] | |
270 | + ] | |
271 | + }); | |
272 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | |
222 | 273 | function putpagination(data = json_history["data"]){ |
223 | 274 | var len = Math.ceil(data.length / 20); |
224 | 275 | $(".pagination").empty(); |
... | ... | @@ -242,9 +293,6 @@ |
242 | 293 | .attr('value', '{{ LANGUAGE_CODE }}') |
243 | 294 | .appendTo('#period-form'); |
244 | 295 | }); |
245 | - function altertitle(value) { | |
246 | - $("#title-table").text(value); | |
247 | - } | |
248 | 296 | function add(element,local, first = false){ |
249 | 297 | if (first) $(local).prepend(element); |
250 | 298 | else $(local).append(element); |
... | ... | @@ -255,74 +303,60 @@ |
255 | 303 | function length(element) { |
256 | 304 | return $(element).length; |
257 | 305 | } |
258 | - function backhistory(){ | |
259 | - drawTable(column_history,json_history["data"],true,3); | |
260 | - $("#title-table").text("{{history_table}}"); | |
261 | - $("#link-history").remove(); | |
262 | - search = []; | |
263 | - for (var i in json_history["data"]){ | |
264 | - search.push([json_history["data"][i][0],json_history["data"][i][1], | |
265 | - json_history["data"][i][2],json_history["data"][i][3]]); | |
266 | - } | |
267 | - putpagination(json_history["data"]); | |
268 | - } | |
269 | - // $("#search-input").on("keyup",function(){ | |
270 | - // console.log($("#search-input").val()); | |
271 | - // }); | |
306 | + | |
272 | 307 | $("#search-input").on("keyup",function(){ |
273 | 308 | search = []; |
274 | 309 | var text = $("#search-input").val(); |
310 | + searcher(text,tabela_atual); | |
311 | + }); | |
312 | + | |
313 | + function searcher(text, load_histoty = false,apaga=false){ | |
314 | + if(apaga){ | |
315 | + $("#search-input").val(""); | |
316 | + } | |
275 | 317 | var data = []; |
276 | - if ($("#title-table").text() == "{{n_did_table}}"){ | |
318 | + if (!load_histoty){ | |
277 | 319 | data = $.map(json_n_did["data"], function (obj) { |
278 | 320 | return $.extend(true, {}, obj); |
279 | 321 | }); |
280 | - } else if ($("#title-table").text() == "{{did_table}}") { | |
281 | - data = $.map(json_did["data"], function (obj) { | |
282 | - return $.extend(true, {}, obj); | |
283 | - }); | |
284 | 322 | } else { |
285 | 323 | data = $.map(json_history["data"], function (obj) { |
286 | 324 | return $.extend(true, {}, obj); |
287 | 325 | }); |
288 | 326 | } |
289 | - if ($("#title-table").text() != "{{n_did_table}}"){ | |
327 | + if (load_histoty){ | |
290 | 328 | for (var i in data){ |
291 | 329 | data[i][3] = moment(data[i][3]).format("DD/MM/YYYY HH:mm"); |
292 | 330 | } |
293 | 331 | } |
294 | - if ($("#title-table").text() != "{{n_did_table}}"){ | |
332 | + if (load_histoty){ | |
295 | 333 | for (var i in data){ |
296 | 334 | if (data[i][0].toLowerCase().includes(text.toLowerCase()) |
297 | 335 | || data[i][1].toLowerCase().includes(text.toLowerCase()) |
298 | 336 | || data[i][2].toLowerCase().includes(text.toLowerCase()) |
299 | 337 | || 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 | - } | |
338 | + search.push(json_history["data"][i]); | |
305 | 339 | } |
306 | 340 | } |
307 | 341 | } |
308 | 342 | else { |
309 | 343 | for (var i in data){ |
310 | - if (data[i][0].toLowerCase().includes(text.toLowerCase()) | |
311 | - || data[i][1].toLowerCase().includes(text.toLowerCase())){ | |
344 | + if (data[i][1].toLowerCase().includes(text.toLowerCase()) | |
345 | + || data[i][2].toLowerCase().includes(text.toLowerCase()) | |
346 | + || data[i][3].toLowerCase().includes(text.toLowerCase())){ | |
312 | 347 | search.push(json_n_did["data"][i]); |
313 | 348 | } |
314 | 349 | } |
315 | 350 | } |
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}}")){ | |
351 | + console.log(search); | |
352 | + if (!load_histoty){ | |
320 | 353 | drawTable(column_n_did,pagination(search,1),false); |
321 | 354 | } else { |
322 | 355 | drawTable(column_history,pagination(search,1),true,3); |
323 | 356 | } |
357 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | |
324 | 358 | putpagination(search); |
325 | - }); | |
359 | + } | |
326 | 360 | |
327 | 361 | function pagination(data,pag){ |
328 | 362 | var len = data.length; |
... | ... | @@ -330,16 +364,13 @@ |
330 | 364 | var end = (pag * 20 < len) ? pag * 20:len; |
331 | 365 | var search = data.slice(first,end); |
332 | 366 | return search; |
333 | - // $(".pagination > .disabled").css("color","red"); | |
334 | 367 | } |
335 | - function clickPagination(pag){ | |
368 | + | |
369 | + function clickPagination(pag, load_histoty = false){ | |
336 | 370 | $(".pagination > li").last().remove(); |
337 | 371 | $(".pagination > li").first().remove(); |
338 | 372 | |
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}}")){ | |
373 | + if (!load_histoty){ | |
343 | 374 | drawTable(column_n_did,pagination(search,pag),false); |
344 | 375 | } else { |
345 | 376 | drawTable(column_history,pagination(search,pag),true,3); |
... | ... | @@ -354,5 +385,26 @@ |
354 | 385 | $(".active").removeClass("active"); |
355 | 386 | $("#" + pag).addClass("active"); |
356 | 387 | } |
388 | + function sendMessage(){ | |
389 | + $("#send-message-modal").modal("hide"); | |
390 | + var checked = $("#google-chart-checkbox").serializeArray(); | |
391 | + var email = []; | |
392 | + for (var i in checked){ | |
393 | + email.push(checkbox[checked[i]["name"]]); | |
394 | + } | |
395 | + var message = $("#text_chat_form").serializeArray()[0]["value"]; | |
396 | + $.ajax({ | |
397 | + type: "GET", | |
398 | + data: {"message":message,"users[]":email}, | |
399 | + url: "{% url 'webpages:send_message' subject.slug %}", | |
400 | + success: function(msg){ | |
401 | + console.log(msg); | |
402 | + $('#message').summernote("reset"); | |
403 | + } | |
404 | + }); | |
405 | + } | |
406 | + function openmodal(){ | |
407 | + $("#send-message-modal").modal("show"); | |
408 | + } | |
357 | 409 | </script> |
358 | 410 | {% endblock %} | ... | ... |
webpage/urls.py
... | ... | @@ -10,4 +10,5 @@ urlpatterns = [ |
10 | 10 | url(r'^window_view/(?P<slug>[\w_-]+)/$', views.NewWindowView.as_view(), name = 'window_view'), |
11 | 11 | url(r'^view/(?P<slug>[\w_-]+)/$', views.InsideView.as_view(), name = 'view'), |
12 | 12 | url(r'^chart/(?P<slug>[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), |
13 | + url(r'^send-message/(?P<slug>[\w_-]+)/$', views.sendMessage, name = 'send_message'), | |
13 | 14 | ] | ... | ... |
webpage/views.py
... | ... | @@ -469,33 +469,20 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
469 | 469 | else : |
470 | 470 | start_date = datetime.datetime.strptime(self.request.GET.get('init_date',''),date_format) |
471 | 471 | end_date = datetime.datetime.strptime(self.request.GET.get('end_date',''),date_format) |
472 | - print (start_date," depois") | |
473 | 472 | context["init_date"] = start_date |
474 | 473 | context["end_date"] = end_date |
475 | 474 | alunos = webpage.students.all() |
476 | 475 | |
477 | 476 | 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")) | |
477 | + did,n_did,history = str(_("Realized")),str(_("Unrealized")),str(_("Historic")) | |
479 | 478 | 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"]) | |
479 | + data_n_did,data_history = [],[] | |
480 | + json_n_did, json_history = {},{} | |
485 | 481 | |
486 | 482 | from django.db.models import Count, Max |
487 | 483 | views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) |
488 | 484 | 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"]) | |
485 | + | |
499 | 486 | for log_al in vis_ou.order_by("datetime"): |
500 | 487 | data_history.append([str(alunos.get(email=log_al.user_email)), |
501 | 488 | ", ".join([str(x) for x in webpage.topic.subject.group_subject.filter(participants__email=log_al.user_email)]), |
... | ... | @@ -503,12 +490,13 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
503 | 490 | json_history["data"] = data_history |
504 | 491 | |
505 | 492 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) |
493 | + index = 0 | |
506 | 494 | 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)])]) | |
495 | + 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)]) | |
496 | + index += 1 | |
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() |
... | ... | @@ -517,10 +505,27 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
517 | 505 | context['topic'] = webpage.topic |
518 | 506 | context['subject'] = webpage.topic.subject |
519 | 507 | context['db_data'] = re |
520 | - context['title_chart'] = _('Students viewing the webpage') | |
508 | + context['title_chart'] = _('Actions about resource') | |
521 | 509 | context['title_vAxis'] = _('Quantity') |
522 | 510 | |
523 | 511 | context["n_did_table"] = n_did |
524 | 512 | context["did_table"] = did |
525 | 513 | context["history_table"] = history |
526 | 514 | return context |
515 | + | |
516 | + | |
517 | +from chat.models import Conversation, TalkMessages | |
518 | +from users.models import User | |
519 | +from subjects.models import Subject | |
520 | +def sendMessage(request, slug): | |
521 | + message = request.GET.get('message','') | |
522 | + users = request.GET.getlist('users[]','') | |
523 | + user = request.user | |
524 | + subject = get_object_or_404(Subject,slug = slug) | |
525 | + | |
526 | + for u in users: | |
527 | + to_user = User.objects.get(email=u) | |
528 | + talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) | |
529 | + created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject) | |
530 | + | |
531 | + return JsonResponse({"message":"ok"}) | ... | ... |