Commit 0f135ea72625338c18f7aa52da8e8802926b5150
1 parent
aaba2230
Exists in
master
and in
2 other branches
colocando opção para enviar mensagens no pdf file
Showing
3 changed files
with
154 additions
and
63 deletions
Show diff stats
pdf_file/templates/pdf_file/relatorios.html
... | ... | @@ -7,6 +7,7 @@ |
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%} |
... | ... | @@ -22,11 +23,18 @@ |
22 | 23 | } |
23 | 24 | |
24 | 25 | var array_n_did = []; |
26 | + var checkbox = {}; | |
25 | 27 | {%for data_json in json_n_did.data%} |
26 | - array_n_did.push(['<input type="checkbox" value="">',"{{data_json.0}}","{{data_json.1}}", "{{data_json.2}}"]); | |
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}}"]); | |
27 | 35 | {% endfor%} |
28 | 36 | var json_n_did = {"data":array_n_did}; |
29 | - var column_n_did = [{"string":'{% trans "Enviar mensagem" %}'},{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":"Action don't realized"}]; | |
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"}]; | |
30 | 38 | </script> |
31 | 39 | |
32 | 40 | |
... | ... | @@ -58,38 +66,35 @@ |
58 | 66 | var selectedItem = chart.getSelection()[0]; |
59 | 67 | if (selectedItem) { |
60 | 68 | var col = data.getColumnLabel(selectedItem.column); |
61 | - var element = '<li id="link-history">\ | |
62 | - <a id="call-history" href="javascript:void(0);" onclick="return backhistory();"> <i class="fa fa-arrow-left ta-fw"> </i> {{history_table}}</a>\ | |
63 | - </li>'; | |
64 | - if (col == "{{n_did_table}}" && text("#title-table") != "{{n_did_table}}"){ | |
65 | - if (length("#link-history") <= 0){ | |
66 | - add(element,"#view-table",true); | |
67 | - } | |
68 | - altertitle("{{n_did_table}}"); | |
69 | + if (col == "{{n_did_table}}"){ | |
70 | + tabela_atual = false; | |
69 | 71 | search = []; |
70 | 72 | for (var i in json_n_did["data"]){ |
71 | - 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]]); | |
72 | 75 | } |
73 | - drawTable(column_n_did,pagination(json_n_did["data"],1),false); | |
74 | - putpagination(json_n_did["data"]); | |
76 | + searcher(col, tabela_atual,true); | |
75 | 77 | |
76 | - } else if (col == "{{did_table}}" && text("#title-table") != "{{did_table}}"){ | |
78 | + } else if (col == "{{did_table}}"){ | |
79 | + tabela_atual = true; | |
77 | 80 | search = []; |
78 | 81 | for (var i in json_history["data"]){ |
79 | 82 | search.push([json_history["data"][i][0],json_history["data"][i][1], |
80 | 83 | json_history["data"][i][2],json_history["data"][i][3]]); |
81 | 84 | } |
82 | - searcher(col, true); | |
85 | + searcher(col, tabela_atual,true); | |
83 | 86 | } |
84 | 87 | } |
85 | 88 | chart.setSelection([]) |
86 | - } | |
89 | + } | |
87 | 90 | |
88 | 91 | var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); |
89 | 92 | google.visualization.events.addListener(chart, 'select', selectHandler); |
90 | 93 | chart.draw(data, options); |
91 | 94 | |
92 | 95 | } |
96 | + | |
97 | + var sortAscending = {0:false,1:false,2:false,3:false}; | |
93 | 98 | function drawTable(columns = column_history,rows = pagination(json_history["data"],1),isdate = true,columndate = 3) { |
94 | 99 | var data_table = new google.visualization.DataTable(); |
95 | 100 | for (var i in columns){ |
... | ... | @@ -109,10 +114,33 @@ |
109 | 114 | // } |
110 | 115 | // } |
111 | 116 | // console.log(methods.join(",")); |
112 | - | |
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 | + } | |
113 | 141 | var table = new google.visualization.Table(document.getElementById('table_div')); |
114 | - | |
115 | - table.draw(data_table, {allowHtml: true, cssClassNames : {tableRow: 'text-center',tableCell: 'text-center', headerCell: 'text-center'},showRowNumber: true, width: '100%', height: '100%'}); | |
142 | + google.visualization.events.addListener(table, 'sort', function(e) {ordenar(e)}); | |
143 | + table.draw(data_table, options); | |
116 | 144 | } |
117 | 145 | </script> |
118 | 146 | {% endblock%} |
... | ... | @@ -148,25 +176,29 @@ |
148 | 176 | <div class="col-md-12 text-center"> |
149 | 177 | <h4 style="margin-top: 15px; margin-bottom: 10px" ><strong>{% trans "Report of the resource " %}{{pdf_file}}</strong></h4> |
150 | 178 | </div> |
151 | - <div class="col-md-2 text-right"> | |
152 | - <h4>{% trans "Select the period: " %}</h4> | |
153 | - </div> | |
154 | - <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"> | |
155 | 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> | |
156 | 188 | <form id="period-form" action="" method="get"> |
157 | 189 | <div class="general-parameters-field"> |
158 | - <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 %}"> | |
159 | - </div> | |
160 | - | |
161 | - <div class="general-parameters-field"> | |
162 | - {# <label class="form-field-report"> {% trans "Final Date" %} </label> #} | |
163 | - <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 %}"> | |
164 | - </div> | |
165 | - <input type="submit" value="{% trans 'Search' %}" style="margin-left: 15px;" class="btn btn-success btn-raised"> | |
166 | - </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> | |
167 | 197 | </div> |
198 | + <ul> | |
168 | 199 | </div> |
169 | 200 | </div> |
201 | + | |
170 | 202 | <div class="row"> |
171 | 203 | <div class="col-md-10 col-md-offset-1"> |
172 | 204 | <div id="chart_div" style="height: 500px; margin-top: -50px;"></div> |
... | ... | @@ -199,12 +231,44 @@ |
199 | 231 | </div> |
200 | 232 | </div> |
201 | 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 | + | |
202 | 256 | <div class="row"> |
203 | 257 | <br><br> |
204 | 258 | </div> |
205 | 259 | </div> |
206 | 260 | |
207 | 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 | + }); | |
208 | 272 | $("#title-table").text(search.length + " {% trans 'record(s)' %}"); |
209 | 273 | function putpagination(data = json_history["data"]){ |
210 | 274 | var len = Math.ceil(data.length / 20); |
... | ... | @@ -229,9 +293,6 @@ |
229 | 293 | .attr('value', '{{ LANGUAGE_CODE }}') |
230 | 294 | .appendTo('#period-form'); |
231 | 295 | }); |
232 | - function altertitle(value) { | |
233 | - $("#title-table").text(value); | |
234 | - } | |
235 | 296 | function add(element,local, first = false){ |
236 | 297 | if (first) $(local).prepend(element); |
237 | 298 | else $(local).append(element); |
... | ... | @@ -242,30 +303,19 @@ |
242 | 303 | function length(element) { |
243 | 304 | return $(element).length; |
244 | 305 | } |
245 | - function backhistory(){ | |
246 | - drawTable(column_history,json_history["data"],true,3); | |
247 | - $("#link-history").remove(); | |
248 | - search = []; | |
249 | - for (var i in json_history["data"]){ | |
250 | - search.push([json_history["data"][i][0],json_history["data"][i][1], | |
251 | - json_history["data"][i][2],json_history["data"][i][3]]); | |
252 | - } | |
253 | - $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | |
254 | - putpagination(json_history["data"]); | |
255 | - } | |
256 | 306 | |
257 | 307 | $("#search-input").on("keyup",function(){ |
258 | 308 | search = []; |
259 | 309 | var text = $("#search-input").val(); |
260 | - searcher(text); | |
310 | + searcher(text,tabela_atual); | |
261 | 311 | }); |
262 | 312 | |
263 | - function searcher(text, load_histoty = false){ | |
264 | - if (load_histoty){ | |
265 | - $("#link-history").remove(); | |
313 | + function searcher(text, load_histoty = false,apaga=false){ | |
314 | + if(apaga){ | |
315 | + $("#search-input").val(""); | |
266 | 316 | } |
267 | 317 | var data = []; |
268 | - if ($("#title-table").text() == "{{n_did_table}}" && !load_histoty){ | |
318 | + if (!load_histoty){ | |
269 | 319 | data = $.map(json_n_did["data"], function (obj) { |
270 | 320 | return $.extend(true, {}, obj); |
271 | 321 | }); |
... | ... | @@ -274,12 +324,12 @@ |
274 | 324 | return $.extend(true, {}, obj); |
275 | 325 | }); |
276 | 326 | } |
277 | - if (load_histoty || $("#title-table").text() != "{{n_did_table}}"){ | |
327 | + if (load_histoty){ | |
278 | 328 | for (var i in data){ |
279 | 329 | data[i][3] = moment(data[i][3]).format("DD/MM/YYYY HH:mm"); |
280 | 330 | } |
281 | 331 | } |
282 | - if (load_histoty || $("#title-table").text() != "{{n_did_table}}"){ | |
332 | + if (load_histoty){ | |
283 | 333 | for (var i in data){ |
284 | 334 | if (data[i][0].toLowerCase().includes(text.toLowerCase()) |
285 | 335 | || data[i][1].toLowerCase().includes(text.toLowerCase()) |
... | ... | @@ -291,20 +341,20 @@ |
291 | 341 | } |
292 | 342 | else { |
293 | 343 | for (var i in data){ |
294 | - if (data[i][0].toLowerCase().includes(text.toLowerCase()) | |
295 | - || 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())){ | |
296 | 347 | search.push(json_n_did["data"][i]); |
297 | 348 | } |
298 | 349 | } |
299 | 350 | } |
300 | - if (!load_histoty && ($("#title-table").text() == "{{n_did_table}}")){ | |
351 | + console.log(search); | |
352 | + if (!load_histoty){ | |
301 | 353 | drawTable(column_n_did,pagination(search,1),false); |
302 | 354 | } else { |
303 | 355 | drawTable(column_history,pagination(search,1),true,3); |
304 | 356 | } |
305 | - if (load_histoty || ($("#title-table").text() != "{{n_did_table}}")){ | |
306 | - $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | |
307 | - } | |
357 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | |
308 | 358 | putpagination(search); |
309 | 359 | } |
310 | 360 | |
... | ... | @@ -315,11 +365,11 @@ |
315 | 365 | var search = data.slice(first,end); |
316 | 366 | return search; |
317 | 367 | } |
318 | - function clickPagination(pag){ | |
368 | + function clickPagination(pag, load_histoty = false){ | |
319 | 369 | $(".pagination > li").last().remove(); |
320 | 370 | $(".pagination > li").first().remove(); |
321 | 371 | |
322 | - if (($("#title-table").text() == "{{n_did_table}}")){ | |
372 | + if (!load_histoty){ | |
323 | 373 | drawTable(column_n_did,pagination(search,pag),false); |
324 | 374 | } else { |
325 | 375 | drawTable(column_history,pagination(search,pag),true,3); |
... | ... | @@ -334,5 +384,26 @@ |
334 | 384 | $(".active").removeClass("active"); |
335 | 385 | $("#" + pag).addClass("active"); |
336 | 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 | + } | |
337 | 408 | </script> |
338 | 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
... | ... | @@ -428,8 +428,10 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
428 | 428 | json_history["data"] = data_history |
429 | 429 | |
430 | 430 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) |
431 | + index = 0 | |
431 | 432 | for alun in not_view: |
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'))]) | |
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 | |
433 | 435 | json_n_did["data"] = data_n_did |
434 | 436 | |
435 | 437 | |
... | ... | @@ -441,10 +443,27 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
441 | 443 | context['topic'] = pdf_file.topic |
442 | 444 | context['subject'] = pdf_file.topic.subject |
443 | 445 | context['db_data'] = re |
444 | - context['title_chart'] = _('Students viewing the PDF File') | |
446 | + context['title_chart'] = _('Actions about resource') | |
445 | 447 | context['title_vAxis'] = _('Quantity') |
446 | 448 | |
447 | 449 | context["n_did_table"] = n_did |
448 | 450 | context["did_table"] = did |
449 | 451 | context["history_table"] = history |
450 | 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"}) | ... | ... |