Skip to content

Commit

Permalink
Merge pull request #4 from kayanalmeida/master
Browse files Browse the repository at this point in the history
Adicionando animação de loading; Modificando a resposta; Inserindo radio...
  • Loading branch information
vitor-costa committed Dec 9, 2014
2 parents fc65e43 + a99a5b0 commit 0742713
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 16 deletions.
Binary file added public/css/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions public/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#dvLoading {
background:url(loading.gif) no-repeat center center;
height: 100%;
width: 100%;
position: fixed;
left: 0;
top: 0;
margin: 0 0 0 0;
z-index: 2;

}
body {
z-index: 1;
}
22 changes: 18 additions & 4 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.min.css" rel="stylesheet">
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
Expand Down Expand Up @@ -51,7 +52,9 @@
</div><!-- /.container-fluid -->
</nav>

<div class="container">
<div id="dvLoading" ></div>
<div class="container" id="main-container">

<h1> Preencha as informações abaixo</h1>

<form class="form-horizontal" role="form">
Expand Down Expand Up @@ -170,10 +173,21 @@ <h1> Preencha as informações abaixo</h1>
</div>
</div>

<div class="form-group" >
<div class="col-sm-11 col-md-offset-1">
<input type="checkbox" id="dateNow" checked=true> Obter dados em tempo real</div>
<div class="col-md-offset-1" >
<div class="radio-inline">
<label>
<input type="radio" name="dateNow" id="dateNow" checked>
Fazer análise a partir do último dado
</label>
</div>
<div class="radio-inline">
<label>
<input type="radio" name="dateNow" id="optionsRadios2" value="option2">
Fazer análise em um período de tempo
</label>
</div>
</div>

<div class="form-group" >
<label for="initialDate" class="col-sm-2 control-label" data-date-format="DD/MM/YYYY - HH" >Data inicial</label>
<div class="col-sm-4">
Expand Down
53 changes: 41 additions & 12 deletions public/relatorioCodigo.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,23 @@ window.onload = function() {
"emptyLines": averageEmptyLines,
"buses": uniqueLines,
"numberOfJsonsInData": data.length,
"percentual": averageEmptyLinesPercentual
"total": calculateTotalBuses(data)
};
}

var calculatesAverageNumber = function(array, jsonArray) {
return parseInt(array.length / (jsonArray.length));
}

var calculateTotalBuses = function (jsonArray) {
var total = 0;
jsonArray.map(function(data) {
total += data.DATA.length;
});
return parseInt(total);

}

var calculatesAveragePercentual = function(array, jsonArray) {
var totalCounter = 0;
jsonArray.map(function(data) {
Expand Down Expand Up @@ -92,7 +101,7 @@ window.onload = function() {
"totalStoped": average,
"buses": uniqueStopped,
"numberOfJsonsInData": data.length,
"percentual": averagePercentual
"total": calculateTotalBuses(data)
};
}

Expand Down Expand Up @@ -122,7 +131,7 @@ window.onload = function() {
"totalOutDated": average,
"buses": uniqueOutDated,
"numberOfJsonsInData": data.length,
"percentual": averagePercentual
"total": calculateTotalBuses(data)
};
}

Expand Down Expand Up @@ -192,7 +201,7 @@ window.onload = function() {
"numberOfLines": calculatesAverageNumber(output_list, data),
"lines": uniqueLines,
"numberOfJsonsInData": data.length,
"percentual": percentual
"total": calculateTotalBuses(data)
};

return output;
Expand Down Expand Up @@ -229,7 +238,7 @@ window.onload = function() {
"numberOfBuses": calculatesAverageNumber(in_range_buses, data),
"buses": removeDuplicatedFromArray(in_range_buses),
"numberOfJsonsInData": data.length,
"percentual": calculatesAveragePercentual(in_range_buses, data)
"total": calculateTotalBuses(data)
};

return output;
Expand All @@ -238,6 +247,7 @@ window.onload = function() {
var result;

$(document).on('click', '#button', function() {
startLoadingAnimation();
var selected = $('input[name="report"]:checked').val();
var dateNow = $("#dateNow");
var initialDate = $("#initialDate").val();
Expand Down Expand Up @@ -334,6 +344,7 @@ window.onload = function() {


$(function(){
endLoadingAnimation();
$('.checkbox').hide();

$('ul[role=menu] a').click(function(event) {
Expand All @@ -356,13 +367,30 @@ $(function(){
});
// when the page loads, the initial and final date must be disabled
$('[id*=Date]').prop('disabled', true);
var dateInputDisabled = true;

$('#dateNow').on('change',function(event) {
$('input[name=dateNow]').on('change',function(event) {
event.preventDefault();
//when the dateNow checkbox changes, the fields become available or no
$('[id*=Date]').prop('disabled', $(this).prop('checked') );
dateInputDisabled = !dateInputDisabled;
$('[id*=Date]').prop('disabled', dateInputDisabled);
});
})

function startLoadingAnimation(){
// Starts the loading animation
$('#main-container').fadeTo("fast",0.1,function(){
$('#dvLoading').fadeIn("fast");
});
}

function endLoadingAnimation(){
// Finishes the loading animation
$('#dvLoading').fadeOut("fast", function() {
$('#main-container').fadeTo("fast",1);
});
}

function showForm(form){
//Making fade transition to hide previous report and show the other
var formTitle = $('a[data-input-id='+form+']').html();
Expand All @@ -381,6 +409,7 @@ function showForm(form){

function generateTable(answerArray,report){
//placing server's answer on a better format for the user...
endLoadingAnimation();
if (answerArray.length > 1){}
$('#dados-analisados').html('');
$('#dados-analisados').append('Levamos em consideração ' + answerArray.numberOfJsonsInData + ' captura(s) de dado(s) distinta(s).');
Expand All @@ -394,7 +423,7 @@ function generateTable(answerArray,report){
$('#resposta > h2').append('Nenhum resultado encontrado');
}
else {
$('#resposta > h2').append('Total de ônibus sem linha - ' + answerArray.emptyLines + ' (' + answerArray.percentual + '% do total)');
$('#resposta > h2').append('Total de ônibus sem linha - ' + answerArray.emptyLines + ' do total de ' + answerArray.total + ' (' + parseFloat(answerArray.emptyLines/answerArray.total*100).toFixed(2) + '% do total)');
$('#resposta > table > thead').append('<th> Hora </th>');
$('#resposta > table > thead').append('<th> Código do ônibus </th>');
for (var i in answerArray.buses){
Expand All @@ -415,7 +444,7 @@ function generateTable(answerArray,report){
$('#resposta > h2').append('Nenhum resultado encontrado');
}
else {
$('#resposta > h2').append('Total de ônibus sem linha - ' + answerArray.totalStoped + ' (' + answerArray.percentual + '% do total)');
$('#resposta > h2').append('Total de ônibus sem linha - ' + answerArray.totalStoped + ' do total de ' + answerArray.total + ' (' + parseFloat(answerArray.totalStoped/answerArray.total*100).toFixed(2) + '% do total)');
$('#resposta > table > thead').append('<th> Hora </th>');
$('#resposta > table > thead').append('<th> Código do ônibus </th>');
for (var i in answerArray.buses){
Expand All @@ -436,7 +465,7 @@ function generateTable(answerArray,report){
$('#resposta > h2').append('Nenhum resultado encontrado');
}
else {
$('#resposta > h2').append('Total de ônibus atrasados - ' + answerArray.totalOutDated + ' (' + answerArray.percentual + '% do total)');
$('#resposta > h2').append('Total de ônibus atrasados - ' + answerArray.totalOutDated + ' do total de ' + answerArray.total + ' (' + parseFloat(answerArray.totalOutDated/answerArray.total*100).toFixed(2) + '% do total)');
$('#resposta > table > thead').append('<th> Hora </th>');
$('#resposta > table > thead').append('<th> Código do ônibus </th>');
for (var i in answerArray.buses){
Expand All @@ -458,7 +487,7 @@ function generateTable(answerArray,report){
$('#resposta > h2').append('Nenhum resultado encontrado');
}
else {
$('#resposta > h2').append('Total de linhas - ' + answerArray['numberOfLines'] + ' (' + answerArray.percentual + '% do total)');
$('#resposta > h2').append('Total de linhas - ' + answerArray.numberOfLines + ' do total de ' + answerArray.total + ' (' + parseFloat(answerArray.numberOfLines/answerArray.total*100).toFixed(2) + '% do total)');
$('#resposta > table ').css('width','40%');
$('#resposta > table > thead').append('<th> Número da Linha </th>');
for (var i in answerArray.lines){
Expand All @@ -478,7 +507,7 @@ function generateTable(answerArray,report){
$('#resposta > h2').append('Nenhum resultado encontrado');
}
else {
$('#resposta > h2').append('Total de ônibus dentro da faixa de velocidade - ' + answerArray['numberOfBuses'] + ' (' + answerArray.percentual + '% do total)');
$('#resposta > h2').append('Total de ônibus dentro da faixa de velocidade - ' + answerArray.numberOfBuses + ' do total de ' + answerArray.total + ' (' + parseFloat(answerArray.numberOfBuses/answerArray.total*100).toFixed(2) + '% do total)');
$('#resposta > table > thead').append('<th> Hora </th>');
$('#resposta > table > thead').append('<th> Código do ônibus </th>');
$('#resposta > table > thead').append('<th> Velocidade Instantânea </th>');
Expand Down

0 comments on commit 0742713

Please sign in to comment.