Commit df417366f6f1ec8646874df32fb9d7611e188e1f

Authored by Jailson Dias
1 parent 0f135ea7

colocando opção para enviar mensagens na webpage

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%}
... ... @@ -22,11 +24,18 @@
22 24 }
23 25  
24 26 var array_n_did = [];
  27 + var checkbox = {};
25 28 {%for data_json in json_n_did.data%}
26   - 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}}"]);
27 36 {% endfor%}
28 37 var json_n_did = {"data":array_n_did};
29   - 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"}];
30 39 </script>
31 40  
32 41  
... ... @@ -58,28 +67,22 @@
58 67 var selectedItem = chart.getSelection()[0];
59 68 if (selectedItem) {
60 69 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}}");
  70 + if (col == "{{n_did_table}}"){
  71 + tabela_atual = false;
69 72 search = [];
70 73 for (var i in json_n_did["data"]){
71   - 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]]);
72 76 }
73   - drawTable(column_n_did,pagination(json_n_did["data"],1),false);
74   - putpagination(json_n_did["data"]);
75   -
76   - } else if (col == "{{did_table}}" && text("#title-table") != "{{did_table}}"){
  77 + searcher(col, tabela_atual,true);
  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([])
... ... @@ -90,6 +93,7 @@
90 93 chart.draw(data, options);
91 94  
92 95 }
  96 + var sortAscending = {0:false,1:false,2:false,3:false};
93 97 function drawTable(columns = column_history,rows = pagination(json_history["data"],1),isdate = true,columndate = 3) {
94 98 var data_table = new google.visualization.DataTable();
95 99 for (var i in columns){
... ... @@ -109,10 +113,34 @@
109 113 // }
110 114 // }
111 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 + }
112 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,24 +176,26 @@
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 " %}{{webpage}}</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   - {# <label class="form-field-report"> {% trans "Initial Date" %} </label> #}
159   - <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 %}">
160   - </div>
161   -
162   - <div class="general-parameters-field">
163   - {# <label class="form-field-report"> {% trans "Final Date" %} </label> #}
164   - <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 %}">
165   - </div>
166   - <input type="submit" value="{% trans 'Search' %}" style="margin-left: 15px;" class="btn btn-success btn-raised">
167   - </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>
168 197 </div>
  198 + <ul>
169 199 </div>
170 200 </div>
171 201 <div class="row">
... ... @@ -191,8 +221,9 @@
191 221 </li>
192 222 </ul>
193 223 </div>
194   -
195   - <div id="table_div"></div>
  224 + <form id="google-chart-checkbox" action="" method="get">
  225 + <div id="table_div"></div>
  226 + </form>
196 227 <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12 text-center">
197 228 <ul class="pagination">
198 229  
... ... @@ -200,12 +231,44 @@
200 231 </div>
201 232 </div>
202 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>
203 256 <div class="row">
204 257 <br><br>
205 258 </div>
206 259 </div>
207 260  
208 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 + });
209 272 $("#title-table").text(search.length + " {% trans 'record(s)' %}");
210 273 function putpagination(data = json_history["data"]){
211 274 var len = Math.ceil(data.length / 20);
... ... @@ -230,9 +293,6 @@
230 293 .attr('value', '{{ LANGUAGE_CODE }}')
231 294 .appendTo('#period-form');
232 295 });
233   - function altertitle(value) {
234   - $("#title-table").text(value);
235   - }
236 296 function add(element,local, first = false){
237 297 if (first) $(local).prepend(element);
238 298 else $(local).append(element);
... ... @@ -243,31 +303,19 @@
243 303 function length(element) {
244 304 return $(element).length;
245 305 }
246   - function backhistory(){
247   - drawTable(column_history,json_history["data"],true,3);
248   - $("#link-history").remove();
249   - search = [];
250   - for (var i in json_history["data"]){
251   - search.push([json_history["data"][i][0],json_history["data"][i][1],
252   - json_history["data"][i][2],json_history["data"][i][3]]);
253   - }
254   - $("#title-table").text(search.length + " {% trans 'record(s)' %}");
255   - putpagination(json_history["data"]);
256   - }
257   -
258 306  
259 307 $("#search-input").on("keyup",function(){
260 308 search = [];
261 309 var text = $("#search-input").val();
262   - searcher(text);
  310 + searcher(text,tabela_atual);
263 311 });
264 312  
265   - function searcher(text, load_histoty = false){
266   - if (load_histoty){
267   - $("#link-history").remove();
  313 + function searcher(text, load_histoty = false,apaga=false){
  314 + if(apaga){
  315 + $("#search-input").val("");
268 316 }
269 317 var data = [];
270   - if ($("#title-table").text() == "{{n_did_table}}" && !load_histoty){
  318 + if (!load_histoty){
271 319 data = $.map(json_n_did["data"], function (obj) {
272 320 return $.extend(true, {}, obj);
273 321 });
... ... @@ -276,12 +324,12 @@
276 324 return $.extend(true, {}, obj);
277 325 });
278 326 }
279   - if (load_histoty || $("#title-table").text() != "{{n_did_table}}"){
  327 + if (load_histoty){
280 328 for (var i in data){
281 329 data[i][3] = moment(data[i][3]).format("DD/MM/YYYY HH:mm");
282 330 }
283 331 }
284   - if (load_histoty || $("#title-table").text() != "{{n_did_table}}"){
  332 + if (load_histoty){
285 333 for (var i in data){
286 334 if (data[i][0].toLowerCase().includes(text.toLowerCase())
287 335 || data[i][1].toLowerCase().includes(text.toLowerCase())
... ... @@ -293,20 +341,20 @@
293 341 }
294 342 else {
295 343 for (var i in data){
296   - if (data[i][0].toLowerCase().includes(text.toLowerCase())
297   - || 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())){
298 347 search.push(json_n_did["data"][i]);
299 348 }
300 349 }
301 350 }
302   - if (!load_histoty && ($("#title-table").text() == "{{n_did_table}}")){
  351 + console.log(search);
  352 + if (!load_histoty){
303 353 drawTable(column_n_did,pagination(search,1),false);
304 354 } else {
305 355 drawTable(column_history,pagination(search,1),true,3);
306 356 }
307   - if (load_histoty || ($("#title-table").text() != "{{n_did_table}}")){
308   - $("#title-table").text(search.length + " {% trans 'record(s)' %}");
309   - }
  357 + $("#title-table").text(search.length + " {% trans 'record(s)' %}");
310 358 putpagination(search);
311 359 }
312 360  
... ... @@ -317,11 +365,12 @@
317 365 var search = data.slice(first,end);
318 366 return search;
319 367 }
320   - function clickPagination(pag){
  368 +
  369 + function clickPagination(pag, load_histoty = false){
321 370 $(".pagination > li").last().remove();
322 371 $(".pagination > li").first().remove();
323 372  
324   - if (($("#title-table").text() == "{{n_did_table}}")){
  373 + if (!load_histoty){
325 374 drawTable(column_n_did,pagination(search,pag),false);
326 375 } else {
327 376 drawTable(column_history,pagination(search,pag),true,3);
... ... @@ -336,5 +385,26 @@
336 385 $(".active").removeClass("active");
337 386 $("#" + pag).addClass("active");
338 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 + }
339 409 </script>
340 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,7 +469,6 @@ 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()
... ... @@ -491,9 +490,10 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView):
491 490 json_history["data"] = data_history
492 491  
493 492 not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")])
494   -
  493 + index = 0
495 494 for alun in not_view:
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'))])
  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
497 497 json_n_did["data"] = data_n_did
498 498  
499 499  
... ... @@ -505,10 +505,27 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView):
505 505 context['topic'] = webpage.topic
506 506 context['subject'] = webpage.topic.subject
507 507 context['db_data'] = re
508   - context['title_chart'] = _('Students viewing the webpage')
  508 + context['title_chart'] = _('Actions about resource')
509 509 context['title_vAxis'] = _('Quantity')
510 510  
511 511 context["n_did_table"] = n_did
512 512 context["did_table"] = did
513 513 context["history_table"] = history
514 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"})
... ...