Initial commit

This commit is contained in:
nemunaire 2018-06-06 19:14:27 +02:00
commit 69a5fa5a8a
3 changed files with 215 additions and 0 deletions

140
app.js Normal file
View File

@ -0,0 +1,140 @@
const BASE_API = "/api";
$("#lines").hide();
$("#line").attr("disabled", true);
$("#destinations").attr("disabled", true);
$("#stations").attr("disabled", true);
$("#traffic").hide();
$("#schedule").hide();
$("#loading").hide();
var nextSchedule = null;
var uri = window.location.pathname.split("/").filter(function(v) {
return v.length > 0;
});
$("#linesFilter").change(function() {
if ($("#linesFilter").val().length != 0) {
findLines($("#linesFilter").val());
}
});
$("#line").change(function() {
if ($("#line").val().length != 0) {
findDestinations($("#linesFilter").val(), $("#line").val());
findStations($("#linesFilter").val(), $("#line").val());
getTraffic($("#linesFilter").val(), $("#line").val());
}
});
$("#stations").change(function() {
if ($("#stations").val().length != 0) {
$("#lines button").removeAttr("disabled");
} else {
$("#lines button").attr("disabled", true);
}
});
$("#lines").submit(function(event) {
event.preventDefault();
window.location.pathname = ["", $("#linesFilter").val(), $("#line").val(), $("#stations").val(), $("#destinations").val().length != 0?$("#destinations").val():""].join("/")
});
function findLines(type) {
$.getJSON( BASE_API + "/lines/" + type, function( data ) {
$("#line").empty();
$("#line").append("<option/>");
$.each( data["result"][type], function( key, val ) {
$( "<option/>", { text: val["name"] + " (" + val["directions"] + ")", value: val["code"]} ).appendTo("#line");
});
$("#line").removeAttr("disabled");
if (uri.length == 2) {
$("#line").val(uri[1]);
$("#line").change();
}
});
}
function findDestinations(type, code) {
$.getJSON( BASE_API + "/destinations/" + type + "/" + code, function( data ) {
$("#destinations").empty();
$("#destinations").append("<option/>");
$.each( data["result"]["destinations"], function( key, val ) {
$( "<option/>", { text: val["name"], value: val["way"]} ).appendTo("#destinations");
});
$("#destinations").removeAttr("disabled");
});
}
function findStations(type, code) {
$.getJSON( BASE_API + "/stations/" + type + "/" + code, function( data ) {
$("#stations").empty();
$("#stations").append("<option/>");
$.each( data["result"]["stations"], function( key, val ) {
$( "<option/>", { text: val["name"], value: val["slug"]} ).appendTo("#stations");
});
$("#stations").removeAttr("disabled");
});
}
function getTraffic(type, code) {
$("#traffic").hide();
$.getJSON( BASE_API + "/traffic/" + type + "/" + code, function( data ) {
$("#traffic h3").text(data["result"]["line"] + " : " + data["result"]["title"]);
$("#traffic p").text(data["result"]["message"]);
$("#traffic").show();
});
}
function getSchedule(type, code, station, way) {
if (nextSchedule != null) {
clearTimeout(nextSchedule);
nextSchedule = null;
}
$("#schedule").hide();
$.getJSON( BASE_API + "/schedules/" + type + "/" + code + "/" + station + "/" + way, function( data ) {
$("#schedule dl").empty();
$.each( data["result"]["schedules"], function( key, val ) {
$("<dt/>", { text: val["destination"] }).appendTo("#schedule dl");
$("<dd/>", { text: val["message"] }).appendTo("#schedule dl");
});
$("#schedule").show();
$("#update").text(data["_metadata"]["date"]);
nextSchedule = setTimeout(function() {
getSchedule(type, code, station, way);
}, 15000);
});
}
function main(uri) {
if (uri.length == 4 || uri.length == 3) {
if (uri.length == 3)
uri.push("A+R");
getSchedule(uri[0], uri[1], uri[2], uri[3]);
getTraffic(uri[0], uri[1]);
} else if (uri.length == 1 || uri.length == 2) {
switch(uri[0]) {
case "metros":
case "rers":
case "bus":
case "tramways":
case "noctiliens":
$("#lines").show();
$("#linesFilter").val(uri[0]);
$("#linesFilter").change();
break;
default:
window.location.pathname = window.location.pathname + "/..";
}
} else if (uri.length == 0) {
if ($("#linesFilter").val().length != 0)
main([ $("#linesFilter").val() ]);
else
$("#lines").show();
}
}
main(uri);

BIN
favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

75
index.html Normal file
View File

@ -0,0 +1,75 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>ratp</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
</head>
<body class="container">
<h1 id="loading">Chargement en cours &hellip;</h1>
<form id="lines" style="display: none">
<div class="form-group row">
<label for="linesFilter" class="col-sm-2 col-form-label">Type de ligne</label>
<div class="col-sm-10">
<select class="form-control" id="linesFilter">
<option></option>
<option value="metros">Métro</option>
<option value="rers">RER</option>
<option value="bus">Bus</option>
<option value="tramways">Tram</option>
<option value="noctiliens">Noctilien</option>
</select>
</div>
</div>
<div class="form-group row">
<label for="line" class="col-sm-2 col-form-label">Numéro de ligne</label>
<div class="col-sm-10">
<select class="form-control" id="line" disabled>
<option></option>
</select>
</div>
</div>
<div class="form-group row">
<label for="destinations" class="col-sm-2 col-form-label">Destination</label>
<div class="col-sm-10">
<select class="form-control" id="destinations" disabled>
<option></option>
</select>
</div>
</div>
<div class="form-group row">
<label for="stations" class="col-sm-2 col-form-label">Station</label>
<div class="col-sm-10">
<select class="form-control" id="stations" disabled>
<option></option>
</select>
</div>
</div>
<button type="submit" class="btn btn-primary" disabled>Go !</button>
</form>
<div id="schedule">
<h3></h3>
<dl></dl>
</div>
<div id="traffic">
<h3></h3>
<p></p>
</div>
<small id="update"></small>
<script src="https://cdn.nemunai.re/js/jquery-3.3.1.min.js" crossorigin="anonymous"></script>
<!--script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script-->
<!--script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script-->
<script src="/app.js"></script>
</body>
</html>