Commit 772fbb0a64d5910e93addfa4984f501583a04e47
1 parent
69fad6bc
Exists in
master
and in
2 other branches
criando a página de relatórios para videos do youtube
Showing
4 changed files
with
651 additions
and
1 deletions
Show diff stats
topics/templates/resources/list.html
@@ -29,6 +29,9 @@ | @@ -29,6 +29,9 @@ | ||
29 | </button> | 29 | </button> |
30 | <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="moreResources"> | 30 | <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="moreResources"> |
31 | <li><a href="{% url resource.update_link topic.slug resource.slug %}" class="edit"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | 31 | <li><a href="{% url resource.update_link topic.slug resource.slug %}" class="edit"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> |
32 | + {% if resource|class_name == 'ytvideo' %} | ||
33 | + <li><a href="{% url 'youtube:get_chart' resource.slug %}" class="edit"><i class="fa fa-line-chart fa-fw" aria-hidden="true"></i>{% trans 'Reports' %}</a></li> | ||
34 | + {% endif %} | ||
32 | {% if resource|class_name == 'link' %} | 35 | {% if resource|class_name == 'link' %} |
33 | <li><a href="{% url 'links:get_chart' resource.slug %}" class="edit"><i class="fa fa-line-chart fa-fw" aria-hidden="true"></i>{% trans 'Reports' %}</a></li> | 36 | <li><a href="{% url 'links:get_chart' resource.slug %}" class="edit"><i class="fa fa-line-chart fa-fw" aria-hidden="true"></i>{% trans 'Reports' %}</a></li> |
34 | {% endif %} | 37 | {% endif %} |
@@ -0,0 +1,473 @@ | @@ -0,0 +1,473 @@ | ||
1 | +{% extends "youtube/view.html" %} | ||
2 | + | ||
3 | +{% load static i18n pagination permissions_tags subject_counter %} | ||
4 | +{% load django_bootstrap_breadcrumbs %} | ||
5 | + | ||
6 | +{% block javascript%} | ||
7 | + {{ block.super }} | ||
8 | + <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> | ||
9 | + <script type="text/javascript"> | ||
10 | + var tabela_atual = true; | ||
11 | + | ||
12 | + var array_history = []; | ||
13 | + {%for data_json in json_history.data %} | ||
14 | + array_history.push(["{{data_json.0}}","{{data_json.1}}","{% if data_json.2 == 'view' %} {{view}} {% elif data_json.2 == 'watch' %} {{watch}} {% else %} {{finish}} {% endif %}",{% if data_json.3 is not None %}new Date('{{data_json.3.isoformat}}'){% else%}null{% endif %}]); | ||
15 | + {% endfor%} | ||
16 | + var json_history = {"data":array_history}; | ||
17 | + var column_history = [{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":'{% trans "Action" %}'},{"date":'{% trans "Date of Action" %}'}]; | ||
18 | + | ||
19 | + var search = []; | ||
20 | + for (var i in json_history["data"]){ | ||
21 | + search.push([json_history["data"][i][0],json_history["data"][i][1], | ||
22 | + json_history["data"][i][2],json_history["data"][i][3]]); | ||
23 | + } | ||
24 | + | ||
25 | + var array_n_did = []; | ||
26 | + var checkbox = {}; | ||
27 | + {%for data_json in json_n_did.data%} | ||
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%} | ||
36 | + var json_n_did = {"data":array_n_did}; | ||
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":"{% trans "Action don't realized" %}"}]; | ||
38 | + </script> | ||
39 | + | ||
40 | + | ||
41 | + <script type="text/javascript"> | ||
42 | + google.charts.load('current', {'packages':['corechart',"table"]}); | ||
43 | + google.charts.setOnLoadCallback(drawChart); | ||
44 | + google.charts.setOnLoadCallback(drawTable); | ||
45 | + | ||
46 | + function drawChart() { | ||
47 | + var data = google.visualization.arrayToDataTable({{db_data|safe}}); | ||
48 | + var options = { | ||
49 | + title: '{{title_chart}}', | ||
50 | + // legend: {position: 'right', maxLines: 1}, | ||
51 | + bar: { groupWidth: '50%' }, | ||
52 | + chartArea:{width:"50%"}, | ||
53 | + titlePosition: 'out', | ||
54 | + vAxis: { | ||
55 | + title: '{{title_vAxis}}', | ||
56 | + ticks: [0, .20, .40, .60, .80, 1], | ||
57 | + viewWindow: { | ||
58 | + min: 0, | ||
59 | + max: 1 | ||
60 | + } | ||
61 | + }, | ||
62 | + isStacked: "percent", | ||
63 | + }; | ||
64 | + | ||
65 | + function selectHandler() { | ||
66 | + var selectedItem = chart.getSelection()[0]; | ||
67 | + console.log(selectedItem.row,selectedItem.column); | ||
68 | + if (selectedItem) { | ||
69 | + if (selectedItem.row == 0 && selectedItem.column == 1){ | ||
70 | + tabela_atual = true; | ||
71 | + search = []; | ||
72 | + var text = "{{view}}"; | ||
73 | + for (var i in json_history["data"]){ | ||
74 | + if (json_history["data"][i][2].toLowerCase().includes(text.toLowerCase())){ | ||
75 | + search.push([json_history["data"][i][0],json_history["data"][i][1], | ||
76 | + json_history["data"][i][2],json_history["data"][i][3]]); | ||
77 | + } | ||
78 | + } | ||
79 | + drawTable(column_history,pagination(search,1),true,3); | ||
80 | + alterTitleTable(search.length); | ||
81 | + putpagination(search,tabela_atual); | ||
82 | + } else if(selectedItem.row == 0 && selectedItem.column == 2){ | ||
83 | + tabela_atual = false; | ||
84 | + search = []; | ||
85 | + var text = "{{view}}"; | ||
86 | + for (var i in json_n_did["data"]){ | ||
87 | + if (json_n_did["data"][i][3].toLowerCase().includes(text.toLowerCase())){ | ||
88 | + search.push([json_n_did["data"][i][0],json_n_did["data"][i][1], | ||
89 | + json_n_did["data"][i][2],json_n_did["data"][i][3]]); | ||
90 | + } | ||
91 | + } | ||
92 | + drawTable(column_n_did,pagination(search,1),false); | ||
93 | + alterTitleTable(search.length); | ||
94 | + putpagination(search,tabela_atual); | ||
95 | + } else if (selectedItem.row == 1 && selectedItem.column == 1){ | ||
96 | + tabela_atual = true; | ||
97 | + search = []; | ||
98 | + var text = "{{watch}}"; | ||
99 | + for (var i in json_history["data"]){ | ||
100 | + if (json_history["data"][i][2].toLowerCase().includes(text.toLowerCase())){ | ||
101 | + search.push([json_history["data"][i][0],json_history["data"][i][1], | ||
102 | + json_history["data"][i][2],json_history["data"][i][3]]); | ||
103 | + } | ||
104 | + } | ||
105 | + drawTable(column_history,pagination(search,1),true,3); | ||
106 | + alterTitleTable(search.length); | ||
107 | + putpagination(search,tabela_atual); | ||
108 | + } else if(selectedItem.row == 1 && selectedItem.column == 2){ | ||
109 | + tabela_atual = false; | ||
110 | + search = []; | ||
111 | + var text = "{{watch}}"; | ||
112 | + for (var i in json_n_did["data"]){ | ||
113 | + if (json_n_did["data"][i][3].toLowerCase().includes(text.toLowerCase())){ | ||
114 | + search.push([json_n_did["data"][i][0],json_n_did["data"][i][1], | ||
115 | + json_n_did["data"][i][2],json_n_did["data"][i][3]]); | ||
116 | + } | ||
117 | + } | ||
118 | + drawTable(column_n_did,pagination(search,1),false); | ||
119 | + alterTitleTable(search.length); | ||
120 | + putpagination(search,tabela_atual); | ||
121 | + } else if (selectedItem.row == 2 && selectedItem.column == 1){ | ||
122 | + tabela_atual = true; | ||
123 | + search = []; | ||
124 | + var text = "{{finish}}"; | ||
125 | + for (var i in json_history["data"]){ | ||
126 | + if (json_history["data"][i][2].toLowerCase().includes(text.toLowerCase())){ | ||
127 | + search.push([json_history["data"][i][0],json_history["data"][i][1], | ||
128 | + json_history["data"][i][2],json_history["data"][i][3]]); | ||
129 | + } | ||
130 | + } | ||
131 | + drawTable(column_history,pagination(search,1),true,3); | ||
132 | + alterTitleTable(search.length); | ||
133 | + putpagination(search,tabela_atual); | ||
134 | + } else if(selectedItem.row == 2 && selectedItem.column == 2){ | ||
135 | + tabela_atual = false; | ||
136 | + search = []; | ||
137 | + var text = "{{finish}}"; | ||
138 | + for (var i in json_n_did["data"]){ | ||
139 | + if (json_n_did["data"][i][3].toLowerCase().includes(text.toLowerCase())){ | ||
140 | + search.push([json_n_did["data"][i][0],json_n_did["data"][i][1], | ||
141 | + json_n_did["data"][i][2],json_n_did["data"][i][3]]); | ||
142 | + } | ||
143 | + } | ||
144 | + drawTable(column_n_did,pagination(search,1),false); | ||
145 | + alterTitleTable(search.length); | ||
146 | + putpagination(search,tabela_atual); | ||
147 | + } | ||
148 | + } | ||
149 | + chart.setSelection([]) | ||
150 | + } | ||
151 | + | ||
152 | + var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); | ||
153 | + google.visualization.events.addListener(chart, 'select', selectHandler); | ||
154 | + chart.draw(data, options); | ||
155 | + | ||
156 | + } | ||
157 | + | ||
158 | + var sortAscending = {0:false,1:false,2:false,3:false}; | ||
159 | + function drawTable(columns = column_history,rows = pagination(json_history["data"],1),isdate = true,columndate = 3) { | ||
160 | + var data_table = new google.visualization.DataTable(); | ||
161 | + for (var i in columns){ | ||
162 | + for (var item in columns[i]){ | ||
163 | + data_table.addColumn(item,columns[i][item]); | ||
164 | + } | ||
165 | + } | ||
166 | + | ||
167 | + data_table.addRows(rows); | ||
168 | + var formate_date = new google.visualization.DateFormat({pattern: 'dd/MM/yyyy HH:mm'}); | ||
169 | + if (isdate) formate_date.format(data_table, columndate); | ||
170 | + | ||
171 | + // var methods = []; | ||
172 | + // for (var m in data_table) { | ||
173 | + // if (typeof data_table[m] == "function") { | ||
174 | + // methods.push(m); | ||
175 | + // } | ||
176 | + // } | ||
177 | + // console.log(methods.join(",")); | ||
178 | + var options = { | ||
179 | + sort: "event", | ||
180 | + allowHtml: true, | ||
181 | + cssClassNames : { | ||
182 | + tableRow: 'text-center', | ||
183 | + tableCell: 'text-center', | ||
184 | + headerCell: 'text-center' | ||
185 | + }, | ||
186 | + showRowNumber: true, | ||
187 | + width: '100%', | ||
188 | + height: '100%', | ||
189 | + } | ||
190 | + function ordenar(properties){ | ||
191 | + var columnIndex = properties['column']; | ||
192 | + if (columnIndex > 0) { | ||
193 | + options["sortColumn"] = columnIndex; | ||
194 | + options["sortAscending"] = sortAscending[columnIndex]; | ||
195 | + data_table.sort({column:columnIndex,desc:sortAscending[columnIndex]}); | ||
196 | + sortAscending = {0:false,1:false,2:false,3:false}; | ||
197 | + sortAscending[columnIndex] = !sortAscending[columnIndex]; | ||
198 | + // console.log(sortAscending); | ||
199 | + table.draw(data_table, options); | ||
200 | + } | ||
201 | + } | ||
202 | + | ||
203 | + var table = new google.visualization.Table(document.getElementById('table_div')); | ||
204 | + google.visualization.events.addListener(table, 'sort', function(e) {ordenar(e)}); | ||
205 | + table.draw(data_table, options); | ||
206 | + } | ||
207 | + </script> | ||
208 | +{% endblock%} | ||
209 | + | ||
210 | +{% block breadcrumbs %} | ||
211 | + {{ block.super }} | ||
212 | + {% trans 'Reports' as bread %} | ||
213 | + {% breadcrumb bread ytvideo%} | ||
214 | +{% endblock %} | ||
215 | + | ||
216 | +{% block content %} | ||
217 | + {% if messages %} | ||
218 | + {% for message in messages %} | ||
219 | + <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert"> | ||
220 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
221 | + <span aria-hidden="true">×</span> | ||
222 | + </button> | ||
223 | + <p>{{ message }}</p> | ||
224 | + </div> | ||
225 | + {% endfor %} | ||
226 | + {% endif %} | ||
227 | + <div class="panel panel-info topic-panel"> | ||
228 | + <div class="panel-heading"> | ||
229 | + <div class="row"> | ||
230 | + <div class="col-md-12 category-header"> | ||
231 | + <h4 class="panel-title" style="margin-top: 10px; margin-bottom: 8px"> | ||
232 | + <span>{{ytvideo}} / {% trans "Reports" %}</span> | ||
233 | + </h4> | ||
234 | + </div> | ||
235 | + </div> | ||
236 | + </div> | ||
237 | + <div class="row"> | ||
238 | + <div class="col-md-12 text-center"> | ||
239 | + <h4 style="margin-top: 15px; margin-bottom: 10px" ><strong>{% trans "Report of the resource " %}{{ytvideo}}</strong></h4> | ||
240 | + </div> | ||
241 | + </div> | ||
242 | + <div class="row"> | ||
243 | + <div class="col-md-12"> | ||
244 | + | ||
245 | + <ul class="list-inline nav-justified"> | ||
246 | + <div id="general-parameters-div"> | ||
247 | + <div class="general-parameters-field"> | ||
248 | + <li class="text-right"><h4>{% trans "Select the period: " %}</h4></li> | ||
249 | + </div> | ||
250 | + <form id="period-form" action="" method="get"> | ||
251 | + <div class="general-parameters-field"> | ||
252 | + <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> | ||
253 | + </div> | ||
254 | + <div class="general-parameters-field"> | ||
255 | + <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> | ||
256 | + </div> | ||
257 | + <li><input type="submit" value="{% trans 'Search' %}" style="margin-left: 15px;" class="btn btn-success btn-raised"></li> | ||
258 | + </form> | ||
259 | + </div> | ||
260 | + <ul> | ||
261 | + </div> | ||
262 | + </div> | ||
263 | + | ||
264 | + <div class="row"> | ||
265 | + <div class="col-md-10 col-md-offset-1"> | ||
266 | + <div id="chart_div" style="height: 500px; margin-top: -50px;"></div> | ||
267 | + </div> | ||
268 | + </div> | ||
269 | + | ||
270 | + <div class="row"> | ||
271 | + <div class="col-md-10 col-md-offset-1"> | ||
272 | + <div class="text-center"> | ||
273 | + <ul class="list-inline nav-justified"> | ||
274 | + <li> | ||
275 | + <ul id="view-table" class="list-inline text-right"> | ||
276 | + <li><h3 id="title-table"></h3></li> | ||
277 | + </ul> | ||
278 | + </li> | ||
279 | + <li> | ||
280 | + <ul class="list-inline text-right"> | ||
281 | + <li><p>{% trans "Filter: " %}</p></li> | ||
282 | + <li><input id="search-input" class="form-control" type="text" name="search" value=""></li> | ||
283 | + </ul> | ||
284 | + </li> | ||
285 | + </ul> | ||
286 | + </div> | ||
287 | + <form id="google-chart-checkbox" action="" method="get"> | ||
288 | + <div id="table_div"></div> | ||
289 | + </form> | ||
290 | + <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12 text-center"> | ||
291 | + <ul class="pagination"> | ||
292 | + | ||
293 | + </ul> | ||
294 | + </div> | ||
295 | + </div> | ||
296 | + </div> | ||
297 | + <div id="modal-message"></div> | ||
298 | + <div class="row"> | ||
299 | + <br><br> | ||
300 | + </div> | ||
301 | + </div> | ||
302 | + | ||
303 | + <script type="text/javascript"> | ||
304 | + | ||
305 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | ||
306 | + function putpagination(data = json_history["data"], load_histoty = true){ | ||
307 | + var len = Math.ceil(data.length / 20); | ||
308 | + $(".pagination").empty(); | ||
309 | + $(".pagination").append('<li class="disabled"><span>«</span></li>'); | ||
310 | + $(".pagination").append('<li id="1" class="active">\ | ||
311 | + <a href="javascript:void(0);" onclick="return clickPagination(1, '+ load_histoty +');">1</a>\ | ||
312 | + </li>'); | ||
313 | + for (var i = 2; i <= len;i++){ | ||
314 | + $(".pagination").append('<li id="' + i + '">\ | ||
315 | + <a href="javascript:void(0);" onclick="return clickPagination(' + i +', ' + load_histoty + ');">' + i + '</a>\ | ||
316 | + </li>'); | ||
317 | + } | ||
318 | + if (len > 1) $(".pagination").append('<li><a href="javascript:void(0);" onclick="return clickPagination(2, '+ load_histoty +');"><span>»</span></a></li>'); | ||
319 | + else $(".pagination").append('<li class="disabled"><span>»</span></li>'); | ||
320 | + }; | ||
321 | + putpagination(); | ||
322 | + | ||
323 | + $('#period-form').submit(function(event) { | ||
324 | + $('<input />').attr('type', 'hidden') | ||
325 | + .attr('name', "language") | ||
326 | + .attr('value', '{{ LANGUAGE_CODE }}') | ||
327 | + .appendTo('#period-form'); | ||
328 | + }); | ||
329 | + function add(element,local, first = false){ | ||
330 | + if (first) $(local).prepend(element); | ||
331 | + else $(local).append(element); | ||
332 | + } | ||
333 | + function text(element){ | ||
334 | + return $(element).text(); | ||
335 | + } | ||
336 | + function length(element) { | ||
337 | + return $(element).length; | ||
338 | + } | ||
339 | + | ||
340 | + $("#search-input").on("keyup",function(){ | ||
341 | + search = []; | ||
342 | + var text = $("#search-input").val(); | ||
343 | + searcher(text,tabela_atual); | ||
344 | + }); | ||
345 | + | ||
346 | + function searcher(text, load_histoty = false,apaga=false){ | ||
347 | + if(apaga){ | ||
348 | + $("#search-input").val(""); | ||
349 | + } | ||
350 | + var data = []; | ||
351 | + if (!load_histoty){ | ||
352 | + data = $.map(json_n_did["data"], function (obj) { | ||
353 | + return $.extend(true, {}, obj); | ||
354 | + }); | ||
355 | + } else { | ||
356 | + data = $.map(json_history["data"], function (obj) { | ||
357 | + return $.extend(true, {}, obj); | ||
358 | + }); | ||
359 | + } | ||
360 | + if (load_histoty){ | ||
361 | + for (var i in data){ | ||
362 | + data[i][3] = moment(data[i][3]).format("DD/MM/YYYY HH:mm"); | ||
363 | + } | ||
364 | + } | ||
365 | + if (load_histoty){ | ||
366 | + for (var i in data){ | ||
367 | + if (data[i][0].toLowerCase().includes(text.toLowerCase()) | ||
368 | + || data[i][1].toLowerCase().includes(text.toLowerCase()) | ||
369 | + || data[i][2].toLowerCase().includes(text.toLowerCase()) | ||
370 | + || data[i][3].toLowerCase().includes(text.toLowerCase())){ | ||
371 | + search.push(json_history["data"][i]); | ||
372 | + } | ||
373 | + } | ||
374 | + } | ||
375 | + else { | ||
376 | + for (var i in data){ | ||
377 | + if (data[i][1].toLowerCase().includes(text.toLowerCase()) | ||
378 | + || data[i][2].toLowerCase().includes(text.toLowerCase()) | ||
379 | + || data[i][3].toLowerCase().includes(text.toLowerCase())){ | ||
380 | + search.push(json_n_did["data"][i]); | ||
381 | + } | ||
382 | + } | ||
383 | + } | ||
384 | + console.log(search); | ||
385 | + if (!load_histoty){ | ||
386 | + drawTable(column_n_did,pagination(search,1),false); | ||
387 | + } else { | ||
388 | + drawTable(column_history,pagination(search,1),true,3); | ||
389 | + } | ||
390 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | ||
391 | + putpagination(search,load_histoty); | ||
392 | + } | ||
393 | + | ||
394 | + function pagination(data,pag){ | ||
395 | + var len = data.length; | ||
396 | + var first = (pag * 20 - 20 < len) ? pag * 20 - 20:len; | ||
397 | + var end = (pag * 20 < len) ? pag * 20:len; | ||
398 | + var search = data.slice(first,end); | ||
399 | + return search; | ||
400 | + } | ||
401 | + | ||
402 | + function clickPagination(pag, load_histoty = false){ | ||
403 | + $(".pagination > li").last().remove(); | ||
404 | + $(".pagination > li").first().remove(); | ||
405 | + | ||
406 | + if (!load_histoty){ | ||
407 | + drawTable(column_n_did,pagination(search,pag),false); | ||
408 | + } else { | ||
409 | + drawTable(column_history,pagination(search,pag),true,3); | ||
410 | + } | ||
411 | + | ||
412 | + if (pag < Math.ceil(search.length / 20)) | ||
413 | + $(".pagination").append('<li><a href="javascript:void(0);" onclick="return clickPagination(' + (pag + 1) + ', '+ load_histoty +');"><span>»</span></a></li>'); | ||
414 | + else $(".pagination").append('<li class="disabled"><span>»</span></li>'); | ||
415 | + if (pag > 1) | ||
416 | + $(".pagination").prepend('<li><a href="javascript:void(0);" onclick="return clickPagination(' + (pag - 1) + ', '+ load_histoty +');"><span>«</span></a></li>'); | ||
417 | + else $(".pagination").prepend('<li class="disabled"><span>«</span></li>'); | ||
418 | + $(".active").removeClass("active"); | ||
419 | + $("#" + pag).addClass("active"); | ||
420 | + } | ||
421 | + | ||
422 | + function openmodal(){ | ||
423 | + $( "#modal-message" ).empty(); | ||
424 | + $.get( "{% url 'youtube:send_message' ytvideo.slug %}", function( data ) { | ||
425 | + $( "#modal-message" ).append( data ); | ||
426 | + $("#send-message-modal").modal("show"); | ||
427 | + }); | ||
428 | + } | ||
429 | + | ||
430 | + function sendMessage(){ | ||
431 | + $("#send-message-modal").modal("hide"); | ||
432 | + var checked = $("#google-chart-checkbox").serializeArray(); | ||
433 | + var email = []; | ||
434 | + for (var i in checked){ | ||
435 | + email.push(checkbox[checked[i]["name"]]); | ||
436 | + } | ||
437 | + $('<input />').attr('type', 'hidden') | ||
438 | + .attr('name', "users[]") | ||
439 | + .attr('value', email) | ||
440 | + .appendTo('#text_chat_form'); | ||
441 | + | ||
442 | + var formData = new FormData($('#text_chat_form').get(0)); | ||
443 | + $.ajax({ | ||
444 | + url: "{% url 'youtube:send_message' ytvideo.slug %}", | ||
445 | + type: "POST", | ||
446 | + data: formData, | ||
447 | + cache: false, | ||
448 | + processData: false, | ||
449 | + contentType: false, | ||
450 | + success: function(data) { | ||
451 | + if (data["message"]){ | ||
452 | + console.log("success"); | ||
453 | + $("body").removeClass("modal-open"); | ||
454 | + $( "#modal-message" ).empty(); | ||
455 | + $(".modal-backdrop.fade.in").remove(); | ||
456 | + } else { | ||
457 | + $( "#modal-message" ).empty(); | ||
458 | + $(".modal-backdrop.fade.in").remove(); | ||
459 | + $( "#modal-message" ).append( data ); | ||
460 | + $("#send-message-modal").modal("show"); | ||
461 | + } | ||
462 | + }, | ||
463 | + error: function(data){ | ||
464 | + console.log("erro"); | ||
465 | + } | ||
466 | + }); | ||
467 | + } | ||
468 | + | ||
469 | + function alterTitleTable (quant){ | ||
470 | + $("#title-table").text(quant + " {% trans 'record(s)' %}"); | ||
471 | + } | ||
472 | + </script> | ||
473 | +{% endblock %} |
youtube_video/urls.py
@@ -11,4 +11,6 @@ urlpatterns = [ | @@ -11,4 +11,6 @@ urlpatterns = [ | ||
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'^watch/(?P<ytvideo>[\w_-]+)/$', views.ytvideo_watch_log, name = 'watch'), | 12 | url(r'^watch/(?P<ytvideo>[\w_-]+)/$', views.ytvideo_watch_log, name = 'watch'), |
13 | url(r'^finish/(?P<ytvideo>[\w_-]+)/$', views.ytvideo_finish_log, name = 'finish'), | 13 | url(r'^finish/(?P<ytvideo>[\w_-]+)/$', views.ytvideo_finish_log, name = 'finish'), |
14 | + url(r'^chart/(?P<slug>[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), | ||
15 | + url(r'^send-message/(?P<slug>[\w_-]+)/$', views.SendMessage.as_view(), name = 'send_message'), | ||
14 | ] | 16 | ] |
youtube_video/views.py
@@ -18,6 +18,16 @@ from topics.models import Topic | @@ -18,6 +18,16 @@ from topics.models import Topic | ||
18 | from .forms import YTVideoForm, InlinePendenciesFormset | 18 | from .forms import YTVideoForm, InlinePendenciesFormset |
19 | from .models import YTVideo | 19 | from .models import YTVideo |
20 | 20 | ||
21 | +import datetime | ||
22 | +from log.models import Log | ||
23 | +from chat.models import Conversation, TalkMessages | ||
24 | +from users.models import User | ||
25 | +from subjects.models import Subject | ||
26 | + | ||
27 | +from webpage.forms import FormModalMessage | ||
28 | + | ||
29 | +from django.db.models import Q | ||
30 | + | ||
21 | class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): | 31 | class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): |
22 | log_component = 'resources' | 32 | log_component = 'resources' |
23 | log_action = 'view' | 33 | log_action = 'view' |
@@ -460,4 +470,166 @@ def ytvideo_finish_log(request, ytvideo): | @@ -460,4 +470,166 @@ def ytvideo_finish_log(request, ytvideo): | ||
460 | 470 | ||
461 | request.log_context = log_context | 471 | request.log_context = log_context |
462 | 472 | ||
463 | - return JsonResponse({'message': 'ok'}) | ||
464 | \ No newline at end of file | 473 | \ No newline at end of file |
474 | + return JsonResponse({'message': 'ok'}) | ||
475 | + | ||
476 | + | ||
477 | +class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
478 | + log_component = 'resources' | ||
479 | + log_action = 'view_statistics' | ||
480 | + log_resource = 'ytvideo' | ||
481 | + log_context = {} | ||
482 | + | ||
483 | + login_url = reverse_lazy("users:login") | ||
484 | + redirect_field_name = 'next' | ||
485 | + model = YTVideo | ||
486 | + template_name = 'youtube/relatorios.html' | ||
487 | + | ||
488 | + def dispatch(self, request, *args, **kwargs): | ||
489 | + slug = self.kwargs.get('slug', '') | ||
490 | + ytvideo = get_object_or_404(YTVideo, slug = slug) | ||
491 | + | ||
492 | + if not has_subject_permissions(request.user, ytvideo.topic.subject): | ||
493 | + return redirect(reverse_lazy('subjects:home')) | ||
494 | + | ||
495 | + return super(StatisticsView, self).dispatch(request, *args, **kwargs) | ||
496 | + | ||
497 | + def get_context_data(self, **kwargs): | ||
498 | + context = super(StatisticsView, self).get_context_data(**kwargs) | ||
499 | + | ||
500 | + self.log_context['category_id'] = self.object.topic.subject.category.id | ||
501 | + self.log_context['category_name'] = self.object.topic.subject.category.name | ||
502 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | ||
503 | + self.log_context['subject_id'] = self.object.topic.subject.id | ||
504 | + self.log_context['subject_name'] = self.object.topic.subject.name | ||
505 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | ||
506 | + self.log_context['topic_id'] = self.object.topic.id | ||
507 | + self.log_context['topic_name'] = self.object.topic.name | ||
508 | + self.log_context['topic_slug'] = self.object.topic.slug | ||
509 | + self.log_context['ytvideo_id'] = self.object.id | ||
510 | + self.log_context['ytvideo_name'] = self.object.name | ||
511 | + self.log_context['ytvideo_slug'] = self.object.slug | ||
512 | + | ||
513 | + super(StatisticsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | ||
514 | + | ||
515 | + | ||
516 | + context['title'] = _('Youtube Video Reports') | ||
517 | + | ||
518 | + slug = self.kwargs.get('slug') | ||
519 | + ytvideo = get_object_or_404(YTVideo, slug = slug) | ||
520 | + print (self.request.GET.get('init_date','')) | ||
521 | + date_format = "%d/%m/%Y %H:%M" if self.request.GET.get('language','') == 'pt-br' else "%m/%d/%Y %I:%M %p" | ||
522 | + if self.request.GET.get('language','') == "": | ||
523 | + start_date = datetime.datetime.now() - datetime.timedelta(30) | ||
524 | + end_date = datetime.datetime.now() | ||
525 | + else : | ||
526 | + start_date = datetime.datetime.strptime(self.request.GET.get('init_date',''),date_format) | ||
527 | + end_date = datetime.datetime.strptime(self.request.GET.get('end_date',''),date_format) | ||
528 | + context["init_date"] = start_date | ||
529 | + context["end_date"] = end_date | ||
530 | + alunos = ytvideo.students.all() | ||
531 | + if ytvideo.all_students : | ||
532 | + alunos = ytvideo.topic.subject.students.all() | ||
533 | + | ||
534 | + vis_ou = Log.objects.filter(context__contains={'ytvideo_id':ytvideo.id},resource="ytvideo",user_email__in=(aluno.email for aluno in alunos), datetime__range=(start_date,end_date + datetime.timedelta(minutes = 1))).filter(Q(action="view") | Q(action="watch") | Q(action="finish")) | ||
535 | + did,n_did,history = str(_("Realized")),str(_("Unrealized")),str(_("Historic")) | ||
536 | + re = [] | ||
537 | + data_n_did,data_history = [],[] | ||
538 | + json_n_did, json_history = {},{} | ||
539 | + | ||
540 | + from django.db.models import Count, Max | ||
541 | + views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) | ||
542 | + date_last = vis_ou.values("user_email").annotate(last=Max("datetime")) | ||
543 | + | ||
544 | + for log_al in vis_ou.order_by("datetime"): | ||
545 | + data_history.append([str(alunos.get(email=log_al.user_email)), | ||
546 | + ", ".join([str(x) for x in ytvideo.topic.subject.group_subject.filter(participants__email=log_al.user_email)]), | ||
547 | + log_al.action,log_al.datetime]) | ||
548 | + json_history["data"] = data_history | ||
549 | + | ||
550 | + column_view,column_watch,column_finish = str(_('View')),str(_('Watch')),str(_('Finish')) | ||
551 | + | ||
552 | + not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.filter(action="view").distinct("user_email")]) | ||
553 | + index = 0 | ||
554 | + for alun in not_view: | ||
555 | + data_n_did.append([index,str(alun),", ".join([str(x) for x in ytvideo.topic.subject.group_subject.filter(participants__email=alun.email)]),column_view, str(alun.email)]) | ||
556 | + index += 1 | ||
557 | + | ||
558 | + not_watch = alunos.exclude(email__in=[log.user_email for log in vis_ou.filter(action="watch").distinct("user_email")]) | ||
559 | + for alun in not_watch: | ||
560 | + data_n_did.append([index,str(alun),", ".join([str(x) for x in ytvideo.topic.subject.group_subject.filter(participants__email=alun.email)]),column_watch, str(alun.email)]) | ||
561 | + index += 1 | ||
562 | + | ||
563 | + not_finish = alunos.exclude(email__in=[log.user_email for log in vis_ou.filter(action="finish").distinct("user_email")]) | ||
564 | + for alun in not_finish: | ||
565 | + data_n_did.append([index,str(alun),", ".join([str(x) for x in ytvideo.topic.subject.group_subject.filter(participants__email=alun.email)]),column_finish, str(alun.email)]) | ||
566 | + index += 1 | ||
567 | + | ||
568 | + json_n_did["data"] = data_n_did | ||
569 | + | ||
570 | + | ||
571 | + context["json_n_did"] = json_n_did | ||
572 | + context["json_history"] = json_history | ||
573 | + c_visualizou = vis_ou.filter(action="view").distinct("user_email").count() | ||
574 | + c_watch = vis_ou.filter(action="watch").distinct("user_email").count() | ||
575 | + c_finish = vis_ou.filter(action="finish").distinct("user_email").count() | ||
576 | + re.append([str(_('Youtube Video')),did,n_did]) | ||
577 | + | ||
578 | + re.append([column_view,c_visualizou, alunos.count() - c_visualizou]) | ||
579 | + re.append([column_watch,c_watch, alunos.count() - c_watch]) | ||
580 | + re.append([column_finish,c_finish, alunos.count() - c_finish]) | ||
581 | + | ||
582 | + context['view'] = column_view | ||
583 | + context['watch'] = column_watch | ||
584 | + context['finish'] = column_finish | ||
585 | + context['topic'] = ytvideo.topic | ||
586 | + context['subject'] = ytvideo.topic.subject | ||
587 | + context['db_data'] = re | ||
588 | + context['title_chart'] = _('Actions about resource') | ||
589 | + context['title_vAxis'] = _('Quantity') | ||
590 | + | ||
591 | + context["n_did_table"] = n_did | ||
592 | + context["did_table"] = did | ||
593 | + context["history_table"] = history | ||
594 | + return context | ||
595 | + | ||
596 | + | ||
597 | + | ||
598 | +class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): | ||
599 | + log_component = 'resources' | ||
600 | + log_action = 'send' | ||
601 | + log_resource = 'ytvideo' | ||
602 | + log_context = {} | ||
603 | + | ||
604 | + login_url = reverse_lazy("users:login") | ||
605 | + redirect_field_name = 'next' | ||
606 | + | ||
607 | + template_name = 'youtube/send_message.html' | ||
608 | + form_class = FormModalMessage | ||
609 | + | ||
610 | + def dispatch(self, request, *args, **kwargs): | ||
611 | + slug = self.kwargs.get('slug', '') | ||
612 | + ytvideo = get_object_or_404(YTVideo, slug = slug) | ||
613 | + self.ytvideo = ytvideo | ||
614 | + | ||
615 | + if not has_subject_permissions(request.user, ytvideo.topic.subject): | ||
616 | + return redirect(reverse_lazy('subjects:home')) | ||
617 | + | ||
618 | + return super(SendMessage, self).dispatch(request, *args, **kwargs) | ||
619 | + | ||
620 | + def form_valid(self, form): | ||
621 | + message = form.cleaned_data.get('comment') | ||
622 | + image = form.cleaned_data.get("image") | ||
623 | + users = (self.request.POST.get('users[]','')).split(",") | ||
624 | + user = self.request.user | ||
625 | + subject = self.ytvideo.topic.subject | ||
626 | + for u in users: | ||
627 | + to_user = User.objects.get(email=u) | ||
628 | + talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) | ||
629 | + created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image) | ||
630 | + return JsonResponse({"message":"ok"}) | ||
631 | + | ||
632 | + def get_context_data(self, **kwargs): | ||
633 | + context = super(SendMessage,self).get_context_data() | ||
634 | + context["ytvideo"] = get_object_or_404(YTVideo, slug=self.kwargs.get('slug', '')) | ||
635 | + return context | ||
636 | + |