Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add phone number in client and correct date bug

  • Loading branch information...
commit 1620c93353925165d6987e4c00f9757cc07b79c7 1 parent e05ef56
@johanbrook authored
View
4 build/app.js
@@ -8,7 +8,7 @@
express = require('express');
- routes = require('./routes/routes');
+ routes = require('./routes');
require("date-utils");
@@ -38,8 +38,6 @@
app.get('/stores', routes.stores);
- app.get("/test", routes.db);
-
app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
View
3  build/public/javascripts/client.js
@@ -38,7 +38,7 @@
console.log(obj);
opens = new Date(Date.parse(obj.opening_hours.opens));
closes = new Date(Date.parse(obj.opening_hours.closes));
- is_open = Date.today().between(opens, closes);
+ is_open = new Date().between(opens, closes);
data = {
opens: opens.toFormat("HH24:MI"),
closes: closes.toFormat("HH24:MI"),
@@ -46,6 +46,7 @@
postal_code: obj.postal_code,
locality: capitalize(obj.locality),
is_open: is_open ? "Ja" : "Nej",
+ phone: obj.phone,
query_url: encodeURIComponent("" + obj.address + " " + obj.postal_code + " " + obj.locality)
};
text = render($("#closest-store-template").html(), data);
View
86 build/routes/routes.js
@@ -1,86 +0,0 @@
-(function() {
- var coll, db, db_name, error, get_stores_from_coordinates, host, mongo, mongo_url, nconf, port, success, url;
-
- mongo = require("mongodb");
-
- url = require("url");
-
- nconf = require("nconf");
-
- nconf.argv().env().file({
- file: "./config.json"
- });
-
- db_name = nconf.get("database:name");
-
- host = nconf.get("database:host");
-
- port = nconf.get("database:port");
-
- coll = nconf.get("database:collection");
-
- mongo_url = "mongodb://" + host + ":" + port + "/" + db_name;
-
- console.log("Connecting to Mongo database '" + db_name + "' at " + host + " on port " + port + " ...");
-
- db = new mongo.Db(db_name, new mongo.Server(host, port, {}));
-
- db.open(function() {});
-
- get_stores_from_coordinates = function(coords, limit, callback) {
- return db.collection(coll, function(err, collection) {
- var q;
- q = {
- loc: {
- $near: [parseFloat(coords[0]), parseFloat(coords[1])]
- }
- };
- return collection.find(q).limit(limit).toArray(callback);
- });
- };
-
- success = function(results, res) {
- var responseText;
- console.log("Found " + results.length + " results");
- responseText = JSON.stringify(results);
- res.writeHead(200, {
- "Content-Type": "application/json",
- "Content-Length": Buffer.byteLength(responseText)
- });
- return res.end(responseText);
- };
-
- error = function(code, msg, res) {
- var json;
- console.err(msg);
- json = "{\"code\": " + code + ", \"message\": \"" + msg + "\"}";
- res.writeHead(code, {
- "Content-Type": "application/json",
- "Content-Length": Buffer.byteLength(json)
- });
- return res.end(json);
- };
-
- exports.index = function(req, res) {
- return res.render("index");
- };
-
- exports.stores = function(req, res) {
- var latitude, longitude, query;
- query = url.parse(req.url, true).query;
- latitude = query.lat;
- longitude = query.lon;
- if (!latitude || !longitude) {
- return error(400, "Please provide lat and lon query parameters", res);
- }
- console.log("Incoming request to /stores with coordinates " + latitude + ", " + longitude);
- return get_stores_from_coordinates([latitude, longitude], 1, function(err, results) {
- if (!err) {
- return success(results, res);
- } else {
- return error(err, res);
- }
- });
- };
-
-}).call(this);
View
3  src/app.coffee
@@ -3,7 +3,7 @@
###
express = require 'express'
-routes = require './routes/routes'
+routes = require './routes'
require "date-utils"
app = module.exports = express.createServer()
@@ -28,7 +28,6 @@ app.configure 'production', ->
app.get '/', routes.index
app.get '/stores', routes.stores
-app.get "/test", routes.db
app.listen 3000
console.log "Express server listening on port %d in %s mode", app.address().port, app.settings.env
View
3  src/public/javascripts/client.coffee
@@ -29,7 +29,7 @@ getClosestStore = (json) ->
opens = new Date(Date.parse obj.opening_hours.opens)
closes = new Date(Date.parse obj.opening_hours.closes)
- is_open = Date.today().between opens, closes
+ is_open = new Date().between opens, closes
data =
opens: opens.toFormat "HH24:MI"
@@ -38,6 +38,7 @@ getClosestStore = (json) ->
postal_code: obj.postal_code
locality: capitalize obj.locality
is_open: if is_open then "Ja" else "Nej"
+ phone: obj.phone
query_url: encodeURIComponent("#{obj.address} #{obj.postal_code} #{obj.locality}")
text = render $("#closest-store-template").html(), data
View
64 src/routes/routes.coffee
@@ -1,64 +0,0 @@
-mongo = require "mongodb"
-url = require "url"
-nconf = require "nconf"
-
-nconf.argv().env().file(file: "./config.json")
-
-db_name = nconf.get "database:name"
-host = nconf.get "database:host"
-port = nconf.get "database:port"
-coll = nconf.get "database:collection"
-
-mongo_url = "mongodb://#{host}:#{port}/#{db_name}"
-
-console.log "Connecting to Mongo database '#{db_name}' at #{host} on port #{port} ..."
-db = new mongo.Db(db_name, new mongo.Server(host, port, {}))
-db.open () ->
-
-
-# Helpers
-
-get_stores_from_coordinates = (coords, limit, callback) ->
- db.collection coll, (err, collection) ->
- q =
- loc :
- # No idea why I have to call parseFloat on the coords ..
- $near : [parseFloat(coords[0]), parseFloat(coords[1])]
-
- collection.find(q).limit(limit).toArray(callback)
-
-
-
-success = (results, res) ->
- console.log "Found #{results.length} results"
- responseText = JSON.stringify results
- res.writeHead 200, "Content-Type": "application/json", "Content-Length": Buffer.byteLength(responseText)
- res.end responseText
-
-
-error = (code, msg, res) ->
- console.err msg
- json = "{\"code\": #{code}, \"message\": \"#{msg}\"}"
- res.writeHead code, "Content-Type": "application/json", "Content-Length": Buffer.byteLength(json)
- res.end json
-
-
-# Routes
-
-exports.index = (req, res) ->
- res.render "index"
-
-exports.stores = (req, res) ->
-
- query = url.parse(req.url, true).query
- latitude = query.lat
- longitude = query.lon
-
- if not latitude or not longitude
- return error 400, "Please provide lat and lon query parameters", res
-
- console.log "Incoming request to /stores with coordinates #{latitude}, #{longitude}"
-
- get_stores_from_coordinates [latitude, longitude], 1, (err, results) ->
- if not err then success(results, res)
- else error(err, res)
Please sign in to comment.
Something went wrong with that request. Please try again.