mirror of
https://gitlab.silvrtree.co.uk/martind2000/old-silvrgit.git
synced 2025-02-10 20:19:16 +00:00
added train times
This commit is contained in:
parent
8091e72308
commit
b08983e7f7
52
app/app.js
52
app/app.js
@ -295,6 +295,50 @@
|
||||
elm.prop('class', status);
|
||||
};
|
||||
|
||||
var getTrainsCB = function (results) {
|
||||
var dest$ = $('#trainResults');
|
||||
var html = new EJS({url: '/template/trains.ejs'}).render(results);
|
||||
|
||||
console.log(html);
|
||||
dest$.empty();
|
||||
dest$.append(html);
|
||||
dest$.toggle();
|
||||
|
||||
};
|
||||
|
||||
var getTrains = function(from, to) {
|
||||
var url = '/gettrains?from=' + from + "&to=" + to;
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
|
||||
timeout: 10000,
|
||||
|
||||
//contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
|
||||
},
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
|
||||
// updateTrain('glqdbe',data);
|
||||
getTrainsCB(data);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
tick();
|
||||
get_weather();
|
||||
@ -317,6 +361,14 @@
|
||||
get_weather();
|
||||
}, (60000 * 15));
|
||||
|
||||
$('#dbeglq').on('click',function(){
|
||||
getTrains('dbe','glq');
|
||||
});
|
||||
|
||||
$('#glqdbe').on('click',function(){
|
||||
getTrains('glq','dbe');
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
var popitout = function (url) {
|
||||
|
@ -261,6 +261,7 @@
|
||||
<div class="mui-text-title mui-text-black">Travel <span id="fx"></div>
|
||||
<!-- Travel -->
|
||||
<span>DBEGLQ: <span id="dbeglq">---</span></span> <span>GLQDBE: <span id="glqdbe">---</span></span>
|
||||
<div id='trainResults' style='display:none'></div>
|
||||
<ul>
|
||||
<li>
|
||||
<a href='http://www.journeycheck.com/firstscotrail'>Journey Check</a>
|
||||
@ -397,5 +398,6 @@
|
||||
|
||||
|
||||
</body>
|
||||
<script src="libs/ejs.js"></script>
|
||||
<script src="app.js"></script>
|
||||
</html>
|
||||
|
17
app/template/trains.ejs
Normal file
17
app/template/trains.ejs
Normal file
@ -0,0 +1,17 @@
|
||||
<div>To: <%=filterLocationName%></div>
|
||||
<table class="mui-table mui-table-bordered">
|
||||
<tr><th>Destination</th>
|
||||
<th>Time</th>
|
||||
<th>Status</th>
|
||||
<th>Platform</th></tr>
|
||||
|
||||
<% trainServices.forEach(function (item) { %>
|
||||
<tr>
|
||||
<td><%=item.destination[0].locationName%></td>
|
||||
<td><%=item.sta%></td>
|
||||
<td><%=item.eta%></td>
|
||||
<td><%=item.platform%></td>
|
||||
</tr>
|
||||
<% }) %>
|
||||
|
||||
</table>
|
21
lib/train.js
21
lib/train.js
@ -63,8 +63,27 @@ module.exports = {
|
||||
}, res, 'huxley.apphb.com', '/next/glq/to/dbe/1?accessToken=215b99fe-b237-4a01-aadc-cf315d6756d8');
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
getTrainTimes: function(req, res) {
|
||||
console.log(req);
|
||||
console.log('---------');
|
||||
console.log(req.query);
|
||||
if (req.query.hasOwnProperty('from') && req.query.hasOwnProperty('from'))
|
||||
{
|
||||
|
||||
var url = '/all/' + req.query.from + '/to/' + req.query.to + '/10?accessToken=215b99fe-b237-4a01-aadc-cf315d6756d8';
|
||||
|
||||
Query(function (a, b) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(a));
|
||||
}, res, 'huxley.apphb.com', url);
|
||||
}
|
||||
else{
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify({}));
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
function toSeconds(inval) {
|
||||
|
@ -32,6 +32,7 @@ app.configure(function () {
|
||||
app.use('/dbeglq', train.dbe_glq);
|
||||
|
||||
app.use('/glqdbe', train.glq_dbe);
|
||||
app.use('/gettrains', train.getTrainTimes);
|
||||
|
||||
app.use('/lot', function (req, res) {
|
||||
var pg = require('pg');
|
||||
|
Loading…
Reference in New Issue
Block a user