Skip to content

Commit

Permalink
countryapp
Browse files Browse the repository at this point in the history
  • Loading branch information
sakhtar committed Jun 20, 2013
0 parents commit ef64cff
Show file tree
Hide file tree
Showing 255 changed files with 238 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Empty file added README.md
Empty file.
36 changes: 36 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

/**
* Module dependencies.
*/

var express = require('express')
, routes = require('./routes')
// , user = require('./routes/user')
, http = require('http')
, path = require('path');

var app = express();

app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});

app.configure('development', function(){
app.use(express.errorHandler());
});

// app.get('/', routes.index);
// app.get('/users', user.list);
require('./routes')(app);

http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
6 changes: 6 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var config = {
countryserverurl : 'http://localhost:4000/?country=',
countryserverport : 4000
};

module.exports = config;
29 changes: 29 additions & 0 deletions dummycontryserver.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "Country Info App",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app"
},
"dependencies": {
"express": "3.0.5",
"jade": "*",
"request": "*"
}
}
Binary file added public/images/AD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AF.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AG.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AL.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AO.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AP.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AQ.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AR.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AS.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AU.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AW.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/AZ.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/BA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/BB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/BD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/BE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/BF.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/BG.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/BH.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/BI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/BJ.png
Binary file added public/images/BL.png
Binary file added public/images/BM.png
Binary file added public/images/BN.png
Binary file added public/images/BO.png
Binary file added public/images/BR.png
Binary file added public/images/BS.png
Binary file added public/images/BT.png
Binary file added public/images/BV.png
Binary file added public/images/BW.png
Binary file added public/images/BY.png
Binary file added public/images/BZ.png
Binary file added public/images/CA.png
Binary file added public/images/CC.png
Binary file added public/images/CD.png
Binary file added public/images/CF.png
Binary file added public/images/CG.png
Binary file added public/images/CH.png
Binary file added public/images/CI.png
Binary file added public/images/CK.png
Binary file added public/images/CL.png
Binary file added public/images/CM.png
Binary file added public/images/CN.png
Binary file added public/images/CO.png
Binary file added public/images/CR.png
Binary file added public/images/CU.png
Binary file added public/images/CV.png
Binary file added public/images/CX.png
Binary file added public/images/CY.png
Binary file added public/images/CZ.png
Binary file added public/images/DE.png
Binary file added public/images/DJ.png
Binary file added public/images/DK.png
Binary file added public/images/DM.png
Binary file added public/images/DO.png
Binary file added public/images/DZ.png
Binary file added public/images/EC.png
Binary file added public/images/EE.png
Binary file added public/images/EG.png
Binary file added public/images/EH.png
Binary file added public/images/ER.png
Binary file added public/images/ES.png
Binary file added public/images/ET.png
Binary file added public/images/EU.png
Binary file added public/images/FI.png
Binary file added public/images/FJ.png
Binary file added public/images/FK.png
Binary file added public/images/FM.png
Binary file added public/images/FO.png
Binary file added public/images/FR.png
Binary file added public/images/GA.png
Binary file added public/images/GB.png
Binary file added public/images/GD.png
Binary file added public/images/GE.png
Binary file added public/images/GG.png
Binary file added public/images/GH.png
Binary file added public/images/GI.png
Binary file added public/images/GL.png
Binary file added public/images/GM.png
Binary file added public/images/GN.png
Binary file added public/images/GQ.png
Binary file added public/images/GR.png
Binary file added public/images/GT.png
Binary file added public/images/GU.png
Binary file added public/images/GW.png
Binary file added public/images/GY.png
Binary file added public/images/HK.png
Binary file added public/images/HM.png
Binary file added public/images/HN.png
Binary file added public/images/HR.png
Binary file added public/images/HT.png
Binary file added public/images/HU.png
Binary file added public/images/ID.png
Binary file added public/images/IE.png
Binary file added public/images/IL.png
Binary file added public/images/IM.png
Binary file added public/images/IN.png
Binary file added public/images/IO.png
Binary file added public/images/IQ.png
Binary file added public/images/IR.png
Binary file added public/images/IS.png
Binary file added public/images/IT.png
Binary file added public/images/JE.png
Binary file added public/images/JM.png
Binary file added public/images/JO.png
Binary file added public/images/JP.png
Binary file added public/images/KE.png
Binary file added public/images/KG.png
Binary file added public/images/KH.png
Binary file added public/images/KI.png
Binary file added public/images/KM.png
Binary file added public/images/KN.png
Binary file added public/images/KP.png
Binary file added public/images/KR.png
Binary file added public/images/KW.png
Binary file added public/images/KY.png
Binary file added public/images/KZ.png
Binary file added public/images/LA.png
Binary file added public/images/LB.png
Binary file added public/images/LC.png
Binary file added public/images/LI.png
Binary file added public/images/LK.png
Binary file added public/images/LR.png
Binary file added public/images/LS.png
Binary file added public/images/LT.png
Binary file added public/images/LU.png
Binary file added public/images/LV.png
Binary file added public/images/LY.png
Binary file added public/images/MA.png
Binary file added public/images/MC.png
Binary file added public/images/MD.png
Binary file added public/images/ME.png
Binary file added public/images/MF.png
Binary file added public/images/MG.png
Binary file added public/images/MH.png
Binary file added public/images/MK.png
Binary file added public/images/ML.png
Binary file added public/images/MM.png
Binary file added public/images/MN.png
Binary file added public/images/MO.png
Binary file added public/images/MP.png
Binary file added public/images/MR.png
Binary file added public/images/MS.png
Binary file added public/images/MT.png
Binary file added public/images/MU.png
Binary file added public/images/MV.png
Binary file added public/images/MW.png
Binary file added public/images/MX.png
Binary file added public/images/MY.png
Binary file added public/images/MZ.png
Binary file added public/images/NA.png
Binary file added public/images/NC.png
Binary file added public/images/NE.png
Binary file added public/images/NF.png
Binary file added public/images/NG.png
Binary file added public/images/NI.png
Binary file added public/images/NL.png
Binary file added public/images/NO.png
Binary file added public/images/NP.png
Binary file added public/images/NR.png
Binary file added public/images/NU.png
Binary file added public/images/NZ.png
Binary file added public/images/OM.png
Binary file added public/images/PA.png
Binary file added public/images/PE.png
Binary file added public/images/PF.png
Binary file added public/images/PG.png
Binary file added public/images/PH.png
Binary file added public/images/PK.png
Binary file added public/images/PL.png
Binary file added public/images/PM.png
Binary file added public/images/PN.png
Binary file added public/images/PR.png
Binary file added public/images/PS.png
Binary file added public/images/PT.png
Binary file added public/images/PW.png
Binary file added public/images/PY.png
Binary file added public/images/QA.png
Binary file added public/images/RO.png
Binary file added public/images/RS.png
Binary file added public/images/RU.png
Binary file added public/images/RW.png
Binary file added public/images/SA.png
Binary file added public/images/SB.png
Binary file added public/images/SC.png
Binary file added public/images/SD.png
Binary file added public/images/SE.png
Binary file added public/images/SG.png
Binary file added public/images/SH.png
Binary file added public/images/SI.png
Binary file added public/images/SJ.png
Binary file added public/images/SK.png
Binary file added public/images/SL.png
Binary file added public/images/SM.png
Binary file added public/images/SN.png
Binary file added public/images/SO.png
Binary file added public/images/SR.png
Binary file added public/images/ST.png
Binary file added public/images/SV.png
Binary file added public/images/SY.png
Binary file added public/images/SZ.png
Binary file added public/images/TC.png
Binary file added public/images/TD.png
Binary file added public/images/TF.png
Binary file added public/images/TG.png
Binary file added public/images/TH.png
Binary file added public/images/TJ.png
Binary file added public/images/TK.png
Binary file added public/images/TL.png
Binary file added public/images/TM.png
Binary file added public/images/TN.png
Binary file added public/images/TO.png
Binary file added public/images/TR.png
Binary file added public/images/TT.png
Binary file added public/images/TV.png
Binary file added public/images/TW.png
Binary file added public/images/TZ.png
Binary file added public/images/UA.png
Binary file added public/images/UG.png
Binary file added public/images/US.png
Binary file added public/images/UY.png
Binary file added public/images/UZ.png
Binary file added public/images/VA.png
Binary file added public/images/VC.png
Binary file added public/images/VE.png
Binary file added public/images/VG.png
Binary file added public/images/VI.png
Binary file added public/images/VN.png
Binary file added public/images/VU.png
Binary file added public/images/WF.png
Binary file added public/images/WS.png
Binary file added public/images/YE.png
Binary file added public/images/YT.png
Binary file added public/images/ZA.png
Binary file added public/images/ZM.png
Binary file added public/images/ZW.png
Binary file added public/images/beachflag.png
8 changes: 8 additions & 0 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}

a {
color: #00B7FF;
}
69 changes: 69 additions & 0 deletions routes/countries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
var request = require('request');
var config = require('../config');

var countries = {

codes : {"BD":"Bangladesh","BE":"Belgium","BF":"Burkina Faso","BG":"Bulgaria",
"BA":"Bosnia and Herzegovina","BB":"Barbados","WF":"Wallis and Futuna",
"BL":"Saint Barthelemy","BM":"Bermuda","BN":"Brunei","BO":"Bolivia","BH":"Bahrain",
"BI":"Burundi","BJ":"Benin","BT":"Bhutan","JM":"Jamaica","BV":"Bouvet Island","BW":"Botswana",
"WS":"Samoa","BR":"Brazil","BS":"Bahamas","JE":"Jersey","BY":"Belarus","BZ":"Belize","RU":"Russia",
"RW":"Rwanda","RS":"Serbia","TL":"Timor-Leste","TM":"Turkmenistan","TJ":"Tajikistan","RO":"Romania",
"TK":"Tokelau","GW":"Guinea-Bissau","GU":"Guam","GT":"Guatemala","GR":"Greece","GQ":"Equatorial Guinea",
"JP":"Japan","GY":"Guyana","GG":"Guernsey","GE":"Georgia","GD":"Grenada","GB":"United Kingdom","GA":"Gabon",
"SV":"El Salvador","GN":"Guinea","GM":"Gambia","GL":"Greenland","GI":"Gibraltar","GH":"Ghana","OM":"Oman",
"TN":"Tunisia","JO":"Jordan","HR":"Croatia","HT":"Haiti","HU":"Hungary","HK":"Hong Kong","HN":"Honduras",
"HM":"Heard Island and McDonald Islands","VE":"Venezuela","PR":"Puerto Rico","PS":"Palestinian Territory",
"PW":"Palau","PT":"Portugal","SJ":"Svalbard","PY":"Paraguay","IQ":"Iraq","PA":"Panama","PF":"French Polynesia",
"PG":"Papua New Guinea","PE":"Peru","PK":"Pakistan","PH":"Philippines","PN":"Pitcairn","PL":"Poland",
"PM":"Saint Pierre and Miquelon","ZM":"Zambia","EH":"Western Sahara","EE":"Estonia","EG":"Egypt","ZA":"South Africa",
"EC":"Ecuador","IT":"Italy","VN":"Vietnam","SB":"Solomon Islands","EU":"European Union","ET":"Ethiopia","SO":"Somalia",
"ZW":"Zimbabwe","SA":"Saudi Arabia","ES":"Spain","ER":"Eritrea","ME":"Montenegro","MD":"Moldova","MG":"Madagascar",
"MF":"Saint Martin","MA":"Morocco","MC":"Monaco","UZ":"Uzbekistan","MM":"Myanmar","ML":"Mali","MO":"Macao",
"MN":"Mongolia","MH":"Marshall Islands","MK":"Macedonia","MU":"Mauritius","MT":"Malta","MW":"Malawi","MV":"Maldives",
"MP":"Northern Mariana Islands","MS":"Montserrat","MR":"Mauritania","IM":"Isle of Man","UG":"Uganda","MY":"Malaysia",
"MX":"Mexico","IL":"Israel","FR":"France","IO":"British Indian Ocean Territory",
"SH":"Saint Helena Ascension and Tristan da Cunha","FI":"Finland","FJ":"Fiji","FK":"Falkland Islands",
"FM":"Micronesia","FO":"Faroe Islands","NI":"Nicaragua","NL":"Netherlands","NO":"Norway","NA":"Namibia",
"VU":"Vanuatu","NC":"New Caledonia","NE":"Niger","NF":"Norfolk Island","NG":"Nigeria",
"NZ":"New Zealand","NP":"Nepal","NR":"Nauru","NU":"Niue","CK":"Cook Islands","CI":"Ivory Coast",
"CH":"Switzerland","CO":"Colombia","CN":"China","CM":"Cameroon","CL":"Chile","CC":"Cocos Islands",
"CA":"Canada","CG":"Congo Republic","CF":"Central African Republic","CD":"Congo Democratic Republic",
"CZ":"Czech Republic","CY":"Cyprus","CX":"Christmas Island","CR":"Costa Rica","CV":"Cape Verde","CU":"Cuba",
"SZ":"Swaziland","SY":"Syria","KG":"Kyrgyzstan","KE":"Kenya","SR":"Suriname","KI":"Kiribati","KH":"Cambodia",
"KN":"Saint Kitts and Nevis","KM":"Comoros","ST":"Sao Tome and Principe","SK":"Slovakia","KR":"Korea South",
"SI":"Slovenia","KP":"Korea North","KW":"Kuwait","SN":"Senegal","SM":"San Marino","SL":"Sierra Leone",
"SC":"Seychelles","KZ":"Kazakhstan","KY":"Cayman Islands","SG":"Singapore","SE":"Sweden","SD":"Sudan",
"DO":"Dominican Republic","DM":"Dominica","DJ":"Djibouti","DK":"Denmark","VG":"British Virgin Islands",
"DE":"Germany","YE":"Yemen","DZ":"Algeria","US":"United States","UY":"Uruguay","YT":"Mayotte","LB":"Lebanon",
"LC":"Saint Lucia","LA":"Laos","TV":"Tuvalu","TW":"Taiwan","TT":"Trinidad and Tobago","TR":"Turkey","LK":"Sri Lanka",
"LI":"Liechtenstein","LV":"Latvia","TO":"Tonga","LT":"Lithuania","LU":"Luxembourg","LR":"Liberia","LS":"Lesotho",
"TH":"Thailand","TF":"French Southern Territories","TG":"Togo","TD":"Chad","TC":"Turks and Caicos Islands",
"LY":"Libya","VA":"Holy See","VC":"Saint Vincent and the Grenadines","AE":"United Arab Emirates","AD":"Andorra",
"AG":"Antigua and Barbuda","AF":"Afghanistan","AI":"Anguilla","VI":"Virgin Islands","IS":"Iceland","IR":"Iran",
"AM":"Armenia","AL":"Albania","AO":"Angola","AN":"Netherlands Antilles","AQ":"Antarctica","AP":"Asia & Pacific",
"AS":"American Samoa","AR":"Argentina","AU":"Australia","AT":"Austria","AW":"Aruba","IN":"India","TZ":"Tanzania",
"AZ":"Azerbaijan","IE":"Ireland","ID":"Indonesia","UA":"Ukraine","QA":"Qatar","MZ":"Mozambique"},

getcountires: function(req, res) {
res.render('index', { title: 'All Countries' , codes:countries.codes});
},

getcountry:function(req, res) {
var name = req.param('name');
request.get(config.countryserverurl+name, function(err, r, data){
if (!err) {
data = JSON.parse(data);
if (Object.keys(data).length == 0) {
res.render('404', { title: 'Oops no data!!'});
} else {
res.render('country', { title: data.Name +'\'s Information' , data:data, code:name});
}
} else {
res.render('404', { title: 'Oops no data!!'});
}
});
}
};

module.exports = countries;
10 changes: 10 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";

var countries = require('./countries');


module.exports = function(app) {
app.get('/', countries.getcountires);
app.get('/country/:name', countries.getcountry);

};
4 changes: 4 additions & 0 deletions views/404.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extends layout

block content
h1= title
45 changes: 45 additions & 0 deletions views/country.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
extends layout
block heads
if(data.Capital)
meta(name="viewport", content="initial-scale=1.0, user-scalable=no")
script(type="text/javascript", src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAZpCJc0YFKmbo2DXkeiDIFLSni2Q5GPy4&sensor=true")
script(type="text/javascript")
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(#{data.Capital.GeoPt}),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
var image = '/images/beachflag.png';
var myLatLng = new google.maps.LatLng(#{data.Capital.GeoPt});
var beachMarker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image
});

}
google.maps.event.addDomListener(window, 'load', initialize);

block content
h1= title
img(src='/images/#{code}.png', title='#{data.Name}')
table
tr
td Country Name
td #{data.Name}
if(data.Capital)
tr
td Capital
td #{data.Capital.Name}
tr
td Capitals Geopoint
td #{data.Capital.GeoPt}
tr
td Country GeoRectangle
td !{JSON.stringify(data.GeoRectangle)}
div(id="map-canvas", style="width:400px;height:400px")


9 changes: 9 additions & 0 deletions views/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extends layout

block content
h1= title
each x,y in codes
div(style='display:inline-block;padding:10px 10px 10px 10px')
a(href='/country/#{y}')
img(src='images/#{y}.png', title='#{x}')

8 changes: 8 additions & 0 deletions views/layout.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
doctype 5
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
block heads
body
block content

0 comments on commit ef64cff

Please sign in to comment.