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,13 +7,14 @@ | ||
7 | {{ block.super }} | 7 | {{ block.super }} |
8 | <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> | 8 | <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> |
9 | <script type="text/javascript"> | 9 | <script type="text/javascript"> |
10 | + var tabela_atual = true; | ||
10 | 11 | ||
11 | var array_history = []; | 12 | var array_history = []; |
12 | {%for data_json in json_history.data%} | 13 | {%for data_json in json_history.data%} |
13 | array_history.push(["{{data_json.0}}","{{data_json.1}}","{{data_json.2}}",{% if data_json.3 is not None %}new Date('{{data_json.3.isoformat}}'){% else%}null{% endif %}]); | 14 | array_history.push(["{{data_json.0}}","{{data_json.1}}","{{data_json.2}}",{% if data_json.3 is not None %}new Date('{{data_json.3.isoformat}}'){% else%}null{% endif %}]); |
14 | {% endfor%} | 15 | {% endfor%} |
15 | var json_history = {"data":array_history}; | 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 | var search = []; | 19 | var search = []; |
19 | for (var i in json_history["data"]){ | 20 | for (var i in json_history["data"]){ |
@@ -21,20 +22,19 @@ | @@ -21,20 +22,19 @@ | ||
21 | json_history["data"][i][2],json_history["data"][i][3]]); | 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 | var array_n_did = []; | 25 | var array_n_did = []; |
26 | + var checkbox = {}; | ||
33 | {%for data_json in json_n_did.data%} | 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 | {% endfor%} | 35 | {% endfor%} |
36 | var json_n_did = {"data":array_n_did}; | 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 | </script> | 38 | </script> |
39 | 39 | ||
40 | 40 | ||
@@ -66,43 +66,35 @@ | @@ -66,43 +66,35 @@ | ||
66 | var selectedItem = chart.getSelection()[0]; | 66 | var selectedItem = chart.getSelection()[0]; |
67 | if (selectedItem) { | 67 | if (selectedItem) { |
68 | var col = data.getColumnLabel(selectedItem.column); | 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 | search = []; | 71 | search = []; |
78 | for (var i in json_n_did["data"]){ | 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 | search = []; | 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 | chart.setSelection([]) | 88 | chart.setSelection([]) |
99 | - } | 89 | + } |
100 | 90 | ||
101 | var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); | 91 | var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); |
102 | google.visualization.events.addListener(chart, 'select', selectHandler); | 92 | google.visualization.events.addListener(chart, 'select', selectHandler); |
103 | chart.draw(data, options); | 93 | chart.draw(data, options); |
104 | 94 | ||
105 | } | 95 | } |
96 | + | ||
97 | + var sortAscending = {0:false,1:false,2:false,3:false}; | ||
106 | function drawTable(columns = column_history,rows = pagination(json_history["data"],1),isdate = true,columndate = 3) { | 98 | function drawTable(columns = column_history,rows = pagination(json_history["data"],1),isdate = true,columndate = 3) { |
107 | var data_table = new google.visualization.DataTable(); | 99 | var data_table = new google.visualization.DataTable(); |
108 | for (var i in columns){ | 100 | for (var i in columns){ |
@@ -122,10 +114,33 @@ | @@ -122,10 +114,33 @@ | ||
122 | // } | 114 | // } |
123 | // } | 115 | // } |
124 | // console.log(methods.join(",")); | 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 | var table = new google.visualization.Table(document.getElementById('table_div')); | 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 | </script> | 145 | </script> |
131 | {% endblock%} | 146 | {% endblock%} |
@@ -161,25 +176,29 @@ | @@ -161,25 +176,29 @@ | ||
161 | <div class="col-md-12 text-center"> | 176 | <div class="col-md-12 text-center"> |
162 | <h4 style="margin-top: 15px; margin-bottom: 10px" ><strong>{% trans "Report of the resource " %}{{pdf_file}}</strong></h4> | 177 | <h4 style="margin-top: 15px; margin-bottom: 10px" ><strong>{% trans "Report of the resource " %}{{pdf_file}}</strong></h4> |
163 | </div> | 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 | <div id="general-parameters-div"> | 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 | <form id="period-form" action="" method="get"> | 188 | <form id="period-form" action="" method="get"> |
170 | <div class="general-parameters-field"> | 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 | </div> | 197 | </div> |
198 | + <ul> | ||
181 | </div> | 199 | </div> |
182 | </div> | 200 | </div> |
201 | + | ||
183 | <div class="row"> | 202 | <div class="row"> |
184 | <div class="col-md-10 col-md-offset-1"> | 203 | <div class="col-md-10 col-md-offset-1"> |
185 | <div id="chart_div" style="height: 500px; margin-top: -50px;"></div> | 204 | <div id="chart_div" style="height: 500px; margin-top: -50px;"></div> |
@@ -212,12 +231,45 @@ | @@ -212,12 +231,45 @@ | ||
212 | </div> | 231 | </div> |
213 | </div> | 232 | </div> |
214 | </div> | 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 | <div class="row"> | 256 | <div class="row"> |
216 | <br><br> | 257 | <br><br> |
217 | </div> | 258 | </div> |
218 | </div> | 259 | </div> |
219 | 260 | ||
220 | <script type="text/javascript"> | 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 | function putpagination(data = json_history["data"]){ | 273 | function putpagination(data = json_history["data"]){ |
222 | var len = Math.ceil(data.length / 20); | 274 | var len = Math.ceil(data.length / 20); |
223 | $(".pagination").empty(); | 275 | $(".pagination").empty(); |
@@ -241,9 +293,6 @@ | @@ -241,9 +293,6 @@ | ||
241 | .attr('value', '{{ LANGUAGE_CODE }}') | 293 | .attr('value', '{{ LANGUAGE_CODE }}') |
242 | .appendTo('#period-form'); | 294 | .appendTo('#period-form'); |
243 | }); | 295 | }); |
244 | - function altertitle(value) { | ||
245 | - $("#title-table").text(value); | ||
246 | - } | ||
247 | function add(element,local, first = false){ | 296 | function add(element,local, first = false){ |
248 | if (first) $(local).prepend(element); | 297 | if (first) $(local).prepend(element); |
249 | else $(local).append(element); | 298 | else $(local).append(element); |
@@ -254,74 +303,60 @@ | @@ -254,74 +303,60 @@ | ||
254 | function length(element) { | 303 | function length(element) { |
255 | return $(element).length; | 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 | $("#search-input").on("keyup",function(){ | 307 | $("#search-input").on("keyup",function(){ |
272 | search = []; | 308 | search = []; |
273 | var text = $("#search-input").val(); | 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 | var data = []; | 317 | var data = []; |
275 | - if ($("#title-table").text() == "{{n_did_table}}"){ | 318 | + if (!load_histoty){ |
276 | data = $.map(json_n_did["data"], function (obj) { | 319 | data = $.map(json_n_did["data"], function (obj) { |
277 | return $.extend(true, {}, obj); | 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 | } else { | 322 | } else { |
284 | data = $.map(json_history["data"], function (obj) { | 323 | data = $.map(json_history["data"], function (obj) { |
285 | return $.extend(true, {}, obj); | 324 | return $.extend(true, {}, obj); |
286 | }); | 325 | }); |
287 | } | 326 | } |
288 | - if ($("#title-table").text() != "{{n_did_table}}"){ | 327 | + if (load_histoty){ |
289 | for (var i in data){ | 328 | for (var i in data){ |
290 | data[i][3] = moment(data[i][3]).format("DD/MM/YYYY HH:mm"); | 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 | for (var i in data){ | 333 | for (var i in data){ |
295 | if (data[i][0].toLowerCase().includes(text.toLowerCase()) | 334 | if (data[i][0].toLowerCase().includes(text.toLowerCase()) |
296 | || data[i][1].toLowerCase().includes(text.toLowerCase()) | 335 | || data[i][1].toLowerCase().includes(text.toLowerCase()) |
297 | || data[i][2].toLowerCase().includes(text.toLowerCase()) | 336 | || data[i][2].toLowerCase().includes(text.toLowerCase()) |
298 | || data[i][3].toLowerCase().includes(text.toLowerCase())){ | 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 | else { | 342 | else { |
308 | for (var i in data){ | 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 | search.push(json_n_did["data"][i]); | 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 | drawTable(column_n_did,pagination(search,1),false); | 353 | drawTable(column_n_did,pagination(search,1),false); |
320 | } else { | 354 | } else { |
321 | drawTable(column_history,pagination(search,1),true,3); | 355 | drawTable(column_history,pagination(search,1),true,3); |
322 | } | 356 | } |
357 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | ||
323 | putpagination(search); | 358 | putpagination(search); |
324 | - }); | 359 | + } |
325 | 360 | ||
326 | function pagination(data,pag){ | 361 | function pagination(data,pag){ |
327 | var len = data.length; | 362 | var len = data.length; |
@@ -329,16 +364,12 @@ | @@ -329,16 +364,12 @@ | ||
329 | var end = (pag * 20 < len) ? pag * 20:len; | 364 | var end = (pag * 20 < len) ? pag * 20:len; |
330 | var search = data.slice(first,end); | 365 | var search = data.slice(first,end); |
331 | return search; | 366 | return search; |
332 | - // $(".pagination > .disabled").css("color","red"); | ||
333 | } | 367 | } |
334 | - function clickPagination(pag){ | 368 | + function clickPagination(pag, load_histoty = false){ |
335 | $(".pagination > li").last().remove(); | 369 | $(".pagination > li").last().remove(); |
336 | $(".pagination > li").first().remove(); | 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 | drawTable(column_n_did,pagination(search,pag),false); | 373 | drawTable(column_n_did,pagination(search,pag),false); |
343 | } else { | 374 | } else { |
344 | drawTable(column_history,pagination(search,pag),true,3); | 375 | drawTable(column_history,pagination(search,pag),true,3); |
@@ -353,5 +384,26 @@ | @@ -353,5 +384,26 @@ | ||
353 | $(".active").removeClass("active"); | 384 | $(".active").removeClass("active"); |
354 | $("#" + pag).addClass("active"); | 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 | </script> | 408 | </script> |
357 | {% endblock %} | 409 | {% endblock %} |
pdf_file/urls.py
@@ -9,4 +9,5 @@ urlpatterns = [ | @@ -9,4 +9,5 @@ urlpatterns = [ | ||
9 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteView.as_view(), name = 'delete'), | 9 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteView.as_view(), name = 'delete'), |
10 | url(r'^view/(?P<slug>[\w_-]+)/$', views.ViewPDFFile.as_view(), name = 'view'), | 10 | url(r'^view/(?P<slug>[\w_-]+)/$', views.ViewPDFFile.as_view(), name = 'view'), |
11 | url(r'^chart/(?P<slug>[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), | 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,27 +405,21 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
405 | else : | 405 | else : |
406 | start_date = datetime.datetime.strptime(self.request.GET.get('init_date',''),date_format) | 406 | start_date = datetime.datetime.strptime(self.request.GET.get('init_date',''),date_format) |
407 | end_date = datetime.datetime.strptime(self.request.GET.get('end_date',''),date_format) | 407 | end_date = datetime.datetime.strptime(self.request.GET.get('end_date',''),date_format) |
408 | - # print (start_date," depois") | 408 | + |
409 | context["init_date"] = start_date | 409 | context["init_date"] = start_date |
410 | context["end_date"] = end_date | 410 | context["end_date"] = end_date |
411 | alunos = pdf_file.students.all() | 411 | alunos = pdf_file.students.all() |
412 | 412 | ||
413 | vis_ou = Log.objects.filter(context__contains={'pdffile_id':pdf_file.id},resource="pdffile",action="view",user_email__in=(aluno.email for aluno in alunos), datetime__range=(start_date,end_date + datetime.timedelta(minutes = 1))) | 413 | vis_ou = Log.objects.filter(context__contains={'pdffile_id':pdf_file.id},resource="pdffile",action="view",user_email__in=(aluno.email for aluno in alunos), datetime__range=(start_date,end_date + datetime.timedelta(minutes = 1))) |
414 | - did,n_did,history = str(_("Users who viewed")),str(_("Users who did not viewed")),str(_("Historic")) | 414 | + did,n_did,history = str(_("Realized")),str(_("Unrealized")),str(_("Historic")) |
415 | re = [] | 415 | re = [] |
416 | - data_did, data_n_did,data_history = [],[],[] | ||
417 | - json_did, json_n_did, json_history = {},{},{} | 416 | + data_n_did,data_history = [],[] |
417 | + json_n_did, json_history = {},{} | ||
418 | 418 | ||
419 | from django.db.models import Count, Max | 419 | from django.db.models import Count, Max |
420 | views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) | 420 | views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) |
421 | date_last = vis_ou.values("user_email").annotate(last=Max("datetime")) | 421 | date_last = vis_ou.values("user_email").annotate(last=Max("datetime")) |
422 | 422 | ||
423 | - for i in range(0,len(views_user)): | ||
424 | - data_did.append([str(alunos.get(email=views_user[i].get("user_email"))), | ||
425 | - ", ".join([str(x) for x in pdf_file.topic.subject.group_subject.filter(participants__email=views_user[i].get("user_email"))]), | ||
426 | - views_user[i].get("views"),date_last.get(user_email=views_user[i].get("user_email")).get("last")]) | ||
427 | - json_did["data"] = data_did | ||
428 | - | ||
429 | 423 | ||
430 | for log_al in vis_ou.order_by("datetime"): | 424 | for log_al in vis_ou.order_by("datetime"): |
431 | data_history.append([str(alunos.get(email=log_al.user_email)), | 425 | data_history.append([str(alunos.get(email=log_al.user_email)), |
@@ -434,12 +428,13 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | @@ -434,12 +428,13 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
434 | json_history["data"] = data_history | 428 | json_history["data"] = data_history |
435 | 429 | ||
436 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) | 430 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) |
431 | + index = 0 | ||
437 | for alun in not_view: | 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 | json_n_did["data"] = data_n_did | 435 | json_n_did["data"] = data_n_did |
440 | 436 | ||
441 | 437 | ||
442 | - context["json_did"] = json_did | ||
443 | context["json_n_did"] = json_n_did | 438 | context["json_n_did"] = json_n_did |
444 | context["json_history"] = json_history | 439 | context["json_history"] = json_history |
445 | c_visualizou = vis_ou.distinct("user_email").count() | 440 | c_visualizou = vis_ou.distinct("user_email").count() |
@@ -448,10 +443,27 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | @@ -448,10 +443,27 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
448 | context['topic'] = pdf_file.topic | 443 | context['topic'] = pdf_file.topic |
449 | context['subject'] = pdf_file.topic.subject | 444 | context['subject'] = pdf_file.topic.subject |
450 | context['db_data'] = re | 445 | context['db_data'] = re |
451 | - context['title_chart'] = _('Students viewing the PDF File') | 446 | + context['title_chart'] = _('Actions about resource') |
452 | context['title_vAxis'] = _('Quantity') | 447 | context['title_vAxis'] = _('Quantity') |
453 | 448 | ||
454 | context["n_did_table"] = n_did | 449 | context["n_did_table"] = n_did |
455 | context["did_table"] = did | 450 | context["did_table"] = did |
456 | context["history_table"] = history | 451 | context["history_table"] = history |
457 | return context | 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,6 +7,8 @@ | ||
7 | {{ block.super }} | 7 | {{ block.super }} |
8 | <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> | 8 | <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> |
9 | <script type="text/javascript"> | 9 | <script type="text/javascript"> |
10 | + var tabela_atual = true; | ||
11 | + | ||
10 | 12 | ||
11 | var array_history = []; | 13 | var array_history = []; |
12 | {%for data_json in json_history.data%} | 14 | {%for data_json in json_history.data%} |
@@ -21,20 +23,19 @@ | @@ -21,20 +23,19 @@ | ||
21 | json_history["data"][i][2],json_history["data"][i][3]]); | 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 | var array_n_did = []; | 26 | var array_n_did = []; |
27 | + var checkbox = {}; | ||
33 | {%for data_json in json_n_did.data%} | 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 | {% endfor%} | 36 | {% endfor%} |
36 | var json_n_did = {"data":array_n_did}; | 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 | </script> | 39 | </script> |
39 | 40 | ||
40 | 41 | ||
@@ -66,33 +67,22 @@ | @@ -66,33 +67,22 @@ | ||
66 | var selectedItem = chart.getSelection()[0]; | 67 | var selectedItem = chart.getSelection()[0]; |
67 | if (selectedItem) { | 68 | if (selectedItem) { |
68 | var col = data.getColumnLabel(selectedItem.column); | 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 | search = []; | 72 | search = []; |
78 | for (var i in json_n_did["data"]){ | 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 | search = []; | 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 | chart.setSelection([]) | 88 | chart.setSelection([]) |
@@ -103,6 +93,7 @@ | @@ -103,6 +93,7 @@ | ||
103 | chart.draw(data, options); | 93 | chart.draw(data, options); |
104 | 94 | ||
105 | } | 95 | } |
96 | + var sortAscending = {0:false,1:false,2:false,3:false}; | ||
106 | function drawTable(columns = column_history,rows = pagination(json_history["data"],1),isdate = true,columndate = 3) { | 97 | function drawTable(columns = column_history,rows = pagination(json_history["data"],1),isdate = true,columndate = 3) { |
107 | var data_table = new google.visualization.DataTable(); | 98 | var data_table = new google.visualization.DataTable(); |
108 | for (var i in columns){ | 99 | for (var i in columns){ |
@@ -122,10 +113,34 @@ | @@ -122,10 +113,34 @@ | ||
122 | // } | 113 | // } |
123 | // } | 114 | // } |
124 | // console.log(methods.join(",")); | 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 | var table = new google.visualization.Table(document.getElementById('table_div')); | 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 | </script> | 145 | </script> |
131 | {% endblock%} | 146 | {% endblock%} |
@@ -161,24 +176,26 @@ | @@ -161,24 +176,26 @@ | ||
161 | <div class="col-md-12 text-center"> | 176 | <div class="col-md-12 text-center"> |
162 | <h4 style="margin-top: 15px; margin-bottom: 10px" ><strong>{% trans "Report of the resource " %}{{webpage}}</strong></h4> | 177 | <h4 style="margin-top: 15px; margin-bottom: 10px" ><strong>{% trans "Report of the resource " %}{{webpage}}</strong></h4> |
163 | </div> | 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 | <div id="general-parameters-div"> | 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 | <form id="period-form" action="" method="get"> | 188 | <form id="period-form" action="" method="get"> |
170 | <div class="general-parameters-field"> | 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 | </div> | 197 | </div> |
198 | + <ul> | ||
182 | </div> | 199 | </div> |
183 | </div> | 200 | </div> |
184 | <div class="row"> | 201 | <div class="row"> |
@@ -193,7 +210,7 @@ | @@ -193,7 +210,7 @@ | ||
193 | <ul class="list-inline nav-justified"> | 210 | <ul class="list-inline nav-justified"> |
194 | <li> | 211 | <li> |
195 | <ul id="view-table" class="list-inline text-right"> | 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 | </ul> | 214 | </ul> |
198 | </li> | 215 | </li> |
199 | <li> | 216 | <li> |
@@ -204,8 +221,9 @@ | @@ -204,8 +221,9 @@ | ||
204 | </li> | 221 | </li> |
205 | </ul> | 222 | </ul> |
206 | </div> | 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 | <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12 text-center"> | 227 | <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12 text-center"> |
210 | <ul class="pagination"> | 228 | <ul class="pagination"> |
211 | 229 | ||
@@ -213,12 +231,45 @@ | @@ -213,12 +231,45 @@ | ||
213 | </div> | 231 | </div> |
214 | </div> | 232 | </div> |
215 | </div> | 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 | <div class="row"> | 256 | <div class="row"> |
217 | <br><br> | 257 | <br><br> |
218 | </div> | 258 | </div> |
219 | </div> | 259 | </div> |
220 | 260 | ||
221 | <script type="text/javascript"> | 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 | function putpagination(data = json_history["data"]){ | 273 | function putpagination(data = json_history["data"]){ |
223 | var len = Math.ceil(data.length / 20); | 274 | var len = Math.ceil(data.length / 20); |
224 | $(".pagination").empty(); | 275 | $(".pagination").empty(); |
@@ -242,9 +293,6 @@ | @@ -242,9 +293,6 @@ | ||
242 | .attr('value', '{{ LANGUAGE_CODE }}') | 293 | .attr('value', '{{ LANGUAGE_CODE }}') |
243 | .appendTo('#period-form'); | 294 | .appendTo('#period-form'); |
244 | }); | 295 | }); |
245 | - function altertitle(value) { | ||
246 | - $("#title-table").text(value); | ||
247 | - } | ||
248 | function add(element,local, first = false){ | 296 | function add(element,local, first = false){ |
249 | if (first) $(local).prepend(element); | 297 | if (first) $(local).prepend(element); |
250 | else $(local).append(element); | 298 | else $(local).append(element); |
@@ -255,74 +303,60 @@ | @@ -255,74 +303,60 @@ | ||
255 | function length(element) { | 303 | function length(element) { |
256 | return $(element).length; | 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 | $("#search-input").on("keyup",function(){ | 307 | $("#search-input").on("keyup",function(){ |
273 | search = []; | 308 | search = []; |
274 | var text = $("#search-input").val(); | 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 | var data = []; | 317 | var data = []; |
276 | - if ($("#title-table").text() == "{{n_did_table}}"){ | 318 | + if (!load_histoty){ |
277 | data = $.map(json_n_did["data"], function (obj) { | 319 | data = $.map(json_n_did["data"], function (obj) { |
278 | return $.extend(true, {}, obj); | 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 | } else { | 322 | } else { |
285 | data = $.map(json_history["data"], function (obj) { | 323 | data = $.map(json_history["data"], function (obj) { |
286 | return $.extend(true, {}, obj); | 324 | return $.extend(true, {}, obj); |
287 | }); | 325 | }); |
288 | } | 326 | } |
289 | - if ($("#title-table").text() != "{{n_did_table}}"){ | 327 | + if (load_histoty){ |
290 | for (var i in data){ | 328 | for (var i in data){ |
291 | data[i][3] = moment(data[i][3]).format("DD/MM/YYYY HH:mm"); | 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 | for (var i in data){ | 333 | for (var i in data){ |
296 | if (data[i][0].toLowerCase().includes(text.toLowerCase()) | 334 | if (data[i][0].toLowerCase().includes(text.toLowerCase()) |
297 | || data[i][1].toLowerCase().includes(text.toLowerCase()) | 335 | || data[i][1].toLowerCase().includes(text.toLowerCase()) |
298 | || data[i][2].toLowerCase().includes(text.toLowerCase()) | 336 | || data[i][2].toLowerCase().includes(text.toLowerCase()) |
299 | || data[i][3].toLowerCase().includes(text.toLowerCase())){ | 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 | else { | 342 | else { |
309 | for (var i in data){ | 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 | search.push(json_n_did["data"][i]); | 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 | drawTable(column_n_did,pagination(search,1),false); | 353 | drawTable(column_n_did,pagination(search,1),false); |
321 | } else { | 354 | } else { |
322 | drawTable(column_history,pagination(search,1),true,3); | 355 | drawTable(column_history,pagination(search,1),true,3); |
323 | } | 356 | } |
357 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | ||
324 | putpagination(search); | 358 | putpagination(search); |
325 | - }); | 359 | + } |
326 | 360 | ||
327 | function pagination(data,pag){ | 361 | function pagination(data,pag){ |
328 | var len = data.length; | 362 | var len = data.length; |
@@ -330,16 +364,13 @@ | @@ -330,16 +364,13 @@ | ||
330 | var end = (pag * 20 < len) ? pag * 20:len; | 364 | var end = (pag * 20 < len) ? pag * 20:len; |
331 | var search = data.slice(first,end); | 365 | var search = data.slice(first,end); |
332 | return search; | 366 | return search; |
333 | - // $(".pagination > .disabled").css("color","red"); | ||
334 | } | 367 | } |
335 | - function clickPagination(pag){ | 368 | + |
369 | + function clickPagination(pag, load_histoty = false){ | ||
336 | $(".pagination > li").last().remove(); | 370 | $(".pagination > li").last().remove(); |
337 | $(".pagination > li").first().remove(); | 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 | drawTable(column_n_did,pagination(search,pag),false); | 374 | drawTable(column_n_did,pagination(search,pag),false); |
344 | } else { | 375 | } else { |
345 | drawTable(column_history,pagination(search,pag),true,3); | 376 | drawTable(column_history,pagination(search,pag),true,3); |
@@ -354,5 +385,26 @@ | @@ -354,5 +385,26 @@ | ||
354 | $(".active").removeClass("active"); | 385 | $(".active").removeClass("active"); |
355 | $("#" + pag).addClass("active"); | 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 | </script> | 409 | </script> |
358 | {% endblock %} | 410 | {% endblock %} |
webpage/urls.py
@@ -10,4 +10,5 @@ urlpatterns = [ | @@ -10,4 +10,5 @@ urlpatterns = [ | ||
10 | url(r'^window_view/(?P<slug>[\w_-]+)/$', views.NewWindowView.as_view(), name = 'window_view'), | 10 | url(r'^window_view/(?P<slug>[\w_-]+)/$', views.NewWindowView.as_view(), name = 'window_view'), |
11 | url(r'^view/(?P<slug>[\w_-]+)/$', views.InsideView.as_view(), name = 'view'), | 11 | url(r'^view/(?P<slug>[\w_-]+)/$', views.InsideView.as_view(), name = 'view'), |
12 | url(r'^chart/(?P<slug>[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), | 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,33 +469,20 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
469 | else : | 469 | else : |
470 | start_date = datetime.datetime.strptime(self.request.GET.get('init_date',''),date_format) | 470 | start_date = datetime.datetime.strptime(self.request.GET.get('init_date',''),date_format) |
471 | end_date = datetime.datetime.strptime(self.request.GET.get('end_date',''),date_format) | 471 | end_date = datetime.datetime.strptime(self.request.GET.get('end_date',''),date_format) |
472 | - print (start_date," depois") | ||
473 | context["init_date"] = start_date | 472 | context["init_date"] = start_date |
474 | context["end_date"] = end_date | 473 | context["end_date"] = end_date |
475 | alunos = webpage.students.all() | 474 | alunos = webpage.students.all() |
476 | 475 | ||
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))) | 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 | re = [] | 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 | from django.db.models import Count, Max | 482 | from django.db.models import Count, Max |
487 | views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) | 483 | views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) |
488 | date_last = vis_ou.values("user_email").annotate(last=Max("datetime")) | 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 | for log_al in vis_ou.order_by("datetime"): | 486 | for log_al in vis_ou.order_by("datetime"): |
500 | data_history.append([str(alunos.get(email=log_al.user_email)), | 487 | data_history.append([str(alunos.get(email=log_al.user_email)), |
501 | ", ".join([str(x) for x in webpage.topic.subject.group_subject.filter(participants__email=log_al.user_email)]), | 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,12 +490,13 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
503 | json_history["data"] = data_history | 490 | json_history["data"] = data_history |
504 | 491 | ||
505 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) | 492 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) |
493 | + index = 0 | ||
506 | for alun in not_view: | 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 | json_n_did["data"] = data_n_did | 497 | json_n_did["data"] = data_n_did |
509 | 498 | ||
510 | 499 | ||
511 | - context["json_did"] = json_did | ||
512 | context["json_n_did"] = json_n_did | 500 | context["json_n_did"] = json_n_did |
513 | context["json_history"] = json_history | 501 | context["json_history"] = json_history |
514 | c_visualizou = vis_ou.distinct("user_email").count() | 502 | c_visualizou = vis_ou.distinct("user_email").count() |
@@ -517,10 +505,27 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | @@ -517,10 +505,27 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
517 | context['topic'] = webpage.topic | 505 | context['topic'] = webpage.topic |
518 | context['subject'] = webpage.topic.subject | 506 | context['subject'] = webpage.topic.subject |
519 | context['db_data'] = re | 507 | context['db_data'] = re |
520 | - context['title_chart'] = _('Students viewing the webpage') | 508 | + context['title_chart'] = _('Actions about resource') |
521 | context['title_vAxis'] = _('Quantity') | 509 | context['title_vAxis'] = _('Quantity') |
522 | 510 | ||
523 | context["n_did_table"] = n_did | 511 | context["n_did_table"] = n_did |
524 | context["did_table"] = did | 512 | context["did_table"] = did |
525 | context["history_table"] = history | 513 | context["history_table"] = history |
526 | return context | 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"}) |