Permalink
Browse files

Load airport arrival and departure boards using ajax. Also added sina…

…tra-contrib gem for having multiple yields
  • Loading branch information...
1 parent ae6f1ec commit b847c9b855f4d0eafd26a847b5687641e3a07110 @tdawe committed Jun 16, 2012
Showing with 131 additions and 54 deletions.
  1. +1 −0 Gemfile
  2. +10 −0 Gemfile.lock
  3. +1 −0 flightboard.rb
  4. +71 −0 public/airports.js
  5. +47 −54 views/airport.haml
  6. +1 −0 views/layout.haml
View
@@ -3,6 +3,7 @@ gem 'sinatra'
gem 'vatsim'
gem 'datamapper'
gem 'haml'
+gem 'sinatra-contrib'
group :development do
gem 'sqlite3', :platform => [:ruby, :mswin, :mingw]
View
@@ -2,6 +2,7 @@ GEM
remote: http://rubygems.org/
specs:
addressable (2.2.8)
+ backports (2.6.1)
bcrypt-ruby (3.0.1)
crack (0.3.1)
data_objects (0.10.8)
@@ -58,6 +59,7 @@ GEM
data_objects (= 0.10.8)
do_sqlite3 (0.10.8)
data_objects (= 0.10.8)
+ eventmachine (0.12.10)
fastercsv (1.5.5)
haml (3.1.6)
json (1.6.7)
@@ -86,6 +88,13 @@ GEM
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
+ sinatra-contrib (1.3.1)
+ backports (>= 2.0)
+ eventmachine
+ rack-protection
+ rack-test
+ sinatra (~> 1.3.0)
+ tilt (~> 1.3)
sqlite3 (1.3.6)
stringex (1.3.3)
tilt (1.3.3)
@@ -111,6 +120,7 @@ DEPENDENCIES
rspec
simplecov
sinatra
+ sinatra-contrib
sqlite3
vatsim
webmock
View
@@ -1,4 +1,5 @@
require 'sinatra'
+require 'sinatra/content_for'
require 'haml'
require 'vatsim'
require File.dirname(__FILE__) + '/models.rb'
View
@@ -0,0 +1,71 @@
+$(document).ready(function() {
+ load_boards();
+});
+
+function load_boards()
+{
+ $.getJSON("/airports/"+icao+"/arrivals.json", function(data) { load_arrivals(data) });
+ $.getJSON("/airports/"+icao+"/departures.json", function(data) { load_departures(data) });
+ setTimeout("load_boards()", 60000);
+}
+
+function load_arrivals(data)
+{
+ $("#arrivals > tbody > tr").remove();
+
+ $.each(data, function(index, arrival) {
+
+ row_class = ""
+ if(arrival.arrival_status == "Early")
+ row_class = "early"
+ else if(arrival.arrival_status == "Late")
+ row_class = "late"
+ else if(arrival.arrival_status == "On Time")
+ row_class = "on_time"
+
+ arrival.scheduled_departure_time = arrival.scheduled_departure_time == null ? "" : arrival.scheduled_departure_time
+ arrival.scheduled_arrival_time = arrival.scheduled_arrival_time == null ? "" : arrival.scheduled_arrival_time
+ arrival.estimated_arrival_time = arrival.estimated_arrival_time == null ? "" : arrival.estimated_arrival_time
+
+ $('#arrivals > tbody:last').append('<tr class=\"'+row_class+'\">' +
+ '<td>'+arrival.callsign+'</td>' +
+ '<td>'+arrival.planned_aircraft+'</td>' +
+ '<td>'+arrival.planned_depairport+'</td>' +
+ '<td>'+arrival.scheduled_departure_time+'</td>' +
+ '<td>'+arrival.scheduled_arrival_time+'</td>' +
+ '<td>'+arrival.estimated_arrival_time+'</td>' +
+ '<td>'+arrival.arrival_status+'</td>' +
+ '<td>'+arrival.flight_status+'</td>');
+ });
+}
+
+function load_departures(data)
+{
+ $("#departures > tbody > tr").remove();
+
+ $.each(data, function(index, departure) {
+
+ row_class = ""
+ if(departure.arrival_status == "Early")
+ row_class = "early"
+ else if(departure.arrival_status == "Late")
+ row_class = "late"
+ else if(departure.arrival_status == "On Time")
+ row_class = "on_time"
+
+ departure.scheduled_departure_time = departure.scheduled_departure_time == null ? "" : departure.scheduled_departure_time
+ departure.scheduled_arrival_time = departure.scheduled_arrival_time == null ? "" : departure.scheduled_arrival_time
+ departure.estimated_arrival_time = departure.estimated_arrival_time == null ? "" : departure.estimated_arrival_time
+
+ $('#departures > tbody:last').append('<tr class=\"'+row_class+'\">' +
+ '<td>'+departure.callsign+'</td>' +
+ '<td>'+departure.planned_aircraft+'</td>' +
+ '<td>'+departure.planned_destairport+'</td>' +
+ '<td>'+departure.scheduled_departure_time+'</td>' +
+ '<td>'+departure.scheduled_arrival_time+'</td>' +
+ '<td>'+departure.estimated_arrival_time+'</td>' +
+ '<td>'+departure.arrival_status+'</td>' +
+ '<td>'+departure.flight_status+'</td>');
+ });
+}
+
View
@@ -1,67 +1,60 @@
+- content_for :some_key do
+ %script{:src => "/airports.js", :type => "text/javascript"}
+ %script
+ var icao = "#{params[:icao]}";
+ %style{:type => "text/css"}
+ \tr.on_time { background-color: #00ff00; }
+ \tr.late { background-color: #DB2929; }
+ \tr.early { background-color: #4169E1; }
+
%h3
#{"Current Time: " + Time.now.getgm.to_s}
%h2
Arrivals
-%table{:border => 1, :cellspacing => 0}
+%table{:border => 1, :cellspacing => 0, :id => "arrivals"}
+ %thead
+ %tr
+ %th
+ Ident
+ %th
+ Type
+ %th
+ From
+ %th
+ Scheduled Departure
+ %th
+ Scheduled Arrival
+ %th
+ Estimated Arrival
+ %th
+ Status
+ %th
+ Flight Status
%tbody
- %th
- Ident
- %th
- Type
- %th
- From
- %th
- Scheduled Departure
- %th
- Scheduled Arrival
- %th
- Estimated Arrival
- %th
- Status
- %th
- Flight Status
- - @arrivals.each do |arrival|
- %tr
- %td= arrival.callsign
- %td= arrival.planned_aircraft
- %td= arrival.planned_depairport
- %td{:align => :center}= arrival.scheduled_departure_time.nil? ? "" : Time.parse(arrival.scheduled_departure_time).strftime("%R %Z")
- %td{:align => :center}= arrival.scheduled_arrival_time.nil? ? "" : Time.parse(arrival.scheduled_arrival_time).strftime("%R %Z")
- %td{:align => :center}= arrival.estimated_arrival_time.nil? ? "" : Time.parse(arrival.estimated_arrival_time).strftime("%R %Z")
- %td= arrival.arrival_status
- %td= arrival.flight_status
%h2
Departures
-%table{:border => 1, :cellspacing => 0}
+%table{:border => 1, :cellspacing => 0, :id => "departures"}
+ %thead
+ %tr
+ %th
+ Ident
+ %th
+ Type
+ %th
+ To
+ %th
+ Scheduled Departure
+ %th
+ Scheduled Arrival
+ %th
+ Estimated Arrival
+ %th
+ Status
+ %th
+ Flight Status
%tbody
- %th
- Ident
- %th
- Type
- %th
- To
- %th
- Scheduled Departure
- %th
- Scheduled Arrival
- %th
- Estimated Arrival
- %th
- Status
- %th
- Flight Status
- - @departures.each do |departure|
- %tr
- %td= departure.callsign
- %td= departure.planned_aircraft
- %td= departure.planned_destairport
- %td{:align => :center}= departure.scheduled_departure_time.nil? ? "" : Time.parse(departure.scheduled_departure_time).strftime("%R %Z")
- %td{:align => :center}= departure.scheduled_arrival_time.nil? ? "" : Time.parse(departure.scheduled_arrival_time).strftime("%R %Z")
- %td{:align => :center}= departure.estimated_arrival_time.nil? ? "" : Time.parse(departure.estimated_arrival_time).strftime("%R %Z")
- %td= departure.arrival_status
- %td= departure.flight_status
View
@@ -4,6 +4,7 @@
%title flightboard
%script{:src => "/jquery.js", :type => "text/javascript"}
%script{:src => "/scripts.js", :type => "text/javascript"}
+ = yield_content :some_key
%body
%h1 flightboard
%p

0 comments on commit b847c9b

Please sign in to comment.