Commit e244411c authored by Eduardo L. Buratti's avatar Eduardo L. Buratti

web: Add last contacted date above network chart

Signed-off-by: Eduardo L. Buratti's avatarEduardo L. Buratti <elb09@c3sl.ufpr.br>
parent 36eeee39
......@@ -2,6 +2,8 @@ package models;
import java.util.ArrayList;
import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import play.db.*;
import play.libs.Json;
......@@ -21,6 +23,31 @@ public class School implements java.io.Serializable {
return Machine.getMachinesBySchoolId(this.id);
}
public String getLastContactDate() throws SQLException {
Connection conn = DB.getConnection();
String date = "";
try {
PreparedStatement st = conn.prepareStatement(
"SELECT max(dat_id) FROM fact_contact WHERE sch_id=?;");
st.setLong(1, this.id);
ResultSet res = st.executeQuery();
if (res.next()) {
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
date = df.format(res.getDate(1));
}
else
date = "nunca";
}
finally {
conn.close();
}
return date;
}
public static School getById(Long id) throws SQLException {
Connection conn = DB.getConnection();
School school = null;
......
......@@ -71,7 +71,15 @@
</div>
<div class="tab-pane fade" id="network">
<div class="row-fluid">
<div class="span12 text-right">
<strong>Último contato: @school.getLastContactDate()</strong>
</div>
</div>
<div class="row-fluid">
<div class="span12" id="network-chart"></div>
</div>
</div>
</div>
}
......@@ -40,7 +40,7 @@ $.fn.loadContent = function() {
jsRoutes.controllers.Data.netUsage(School.id).ajax({
success: function(data) {
if (data.download.length == 0) {
$('#'+id).html('<br/><br/><div class="alert alert-info text-center span8 offset2">' +
$('#network-chart').html('<br/><br/><div class="alert alert-info text-center span8 offset2">' +
'Não há dados a serem visualizados.</div>');
return;
}
......@@ -54,7 +54,7 @@ $.fn.loadContent = function() {
School.networkChart = new Highcharts.StockChart({
chart: {
renderTo: id,
renderTo: 'network-chart',
height: 550,
},
rangeSelector : {
......@@ -156,7 +156,7 @@ $.fn.loadContent = function() {
});
setTimeout(function(){
$('input.highcharts-range-selector', $('#'+id)).datepicker();
$('input.highcharts-range-selector', $('#network-chart')).datepicker();
}, 1);
$.datepicker.setDefaults({
......@@ -180,7 +180,7 @@ $.fn.loadContent = function() {
});
},
error: function(err) {
$('#'+id).html('<br/><br/><div class="alert alert-error alert-block text-center span8 offset2"><h4>Oops!</h4>' +
$('#network-chart').html('<br/><br/><div class="alert alert-error alert-block text-center span8 offset2"><h4>Oops!</h4>' +
'Ocorreu um erro no carregamento dos dados!</div>');
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment