Skip to content
This repository has been archived by the owner on Apr 22, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljeffreys committed Oct 23, 2015
2 parents e89ba25 + 73ab81b commit 71483fb
Show file tree
Hide file tree
Showing 24 changed files with 425 additions and 37 deletions.
4 changes: 3 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"angular-resource": "~1.4",
"angular-animate": "~1.4",
"angular-mocks": "~1.4",
"angular-bootstrap": "~0.13",
"angular-ui-utils": "~0.2",
"angular-ui-router": "~0.2.15"
"angular-ui-router": "~0.2.15",
"angularjs-geolocation": "~0.1.1"
}
}
1 change: 1 addition & 0 deletions lib/api/events/createEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = function () {};
29 changes: 29 additions & 0 deletions lib/api/events/getById.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';
var HoekBoom = require('hoek-boom'),
config = require('../../config');

module.exports = function getById(request, reply) {
var id,
response = {};

HoekBoom.assertBoom(request.params.id, 'ID is required', 'badRequest');

id = request.params.id;
this.els.get({index: config.elsEventsIndex, type: config.elsEventsType, id: id}, function(error, resp) {

if (error && !resp.found) {
return reply({status: 404, message: 'Not found'});
}
else if (error) {
console.error(error);
return reply({status: 400});
}
response.doc = resp._source.event_details;
response.id = id;

reply({
status: 200,
resp: response
});
});
};
9 changes: 9 additions & 0 deletions lib/api/events/getByLocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

var HoekBoom = require('hoek-boom');

module.exports = function getByLocation(request, reply) {

HoekBoom.assertBoom(request.query.lat && request.query.lng, 'lat/lng combo is required', 'badRequest');
return reply('hello');
};
6 changes: 6 additions & 0 deletions lib/api/events/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
getById: require('./getById'),
getByLocation: require('./getByLocation'),
createEvent: require('./createEvent'),
signUp: require('./signup')
};
1 change: 1 addition & 0 deletions lib/api/events/signup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = function () {};
23 changes: 7 additions & 16 deletions lib/api/report/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
'use strict';
var HoekBoom = require('hoek-boom'),
Boom = HoekBoom.boom;
Boom = HoekBoom.boom,
elasticsearch = require('elasticsearch'),
config = require('../../config'),
elsClient;

//setup ELS client
elsClient = new elasticsearch.Client(config.elsClient);

exports.createReport = function (request, reply) {
reply({
Expand All @@ -9,21 +15,6 @@ exports.createReport = function (request, reply) {
});
};

//get an event by id
exports.getById = function (request, reply) {
var id;

HoekBoom.assertBoom(request.params.id, 'ID is required', 'badRequest');

id = request.params.id;

reply({
status: 200,
id: id
});
//TODO: get event by id
};

//get an event by lat/lng
exports.getByLocation = function (request, reply) {
var lat,
Expand Down
8 changes: 7 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
var constants = {
server: {
port: process.env.PORT || 3000
}
},
elsClient: {
host: 'https://hvjryrh8:[email protected]/',
log: 'trace'
},
elsEventsIndex: 'events',
elsEventsType: 'event'
};

module.exports = Object.freeze(constants);
12 changes: 5 additions & 7 deletions lib/routes.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
'use strict';

var report = require('./api/report');
var events = require('./api/events');

module.exports = [
{ method: 'GET', path: '/', handler: { file: function () { return 'public/views/index.html'; }}},
{ method: 'GET', path: '/views/{file?}', handler: { directory: { path: 'public/views/'}}},
{ method: 'GET', path: '/javascript/{file?}', handler: { directory: { path: 'public/javascript/'}}},
{ method: 'POST', path: '/api/report', handler: report.createReport },

//the money maker...
{ method: 'GET', path: '/api/events/id/{id?}', handler: report.getById },
{ method: 'GET', path: '/api/events/location', handler: report.getByLocation },
{ method: 'GET', path: '/api/events/search', handler: report.getByName },
{ method: 'POST', path: '/api/events/create/{id?}', handler: report.createEvent },
{ method: 'POST', path: '/api/events/signup/{id?}', handler: report.signup }
{ method: 'GET', path: '/api/events/id/{id?}', handler: events.getById },
{ method: 'GET', path: '/api/events/location', handler: events.getByLocation },
{ method: 'POST', path: '/api/events/', handler: events.createEvent },
{ method: 'POST', path: '/api/events/signup/{id?}', handler: events.signUp }
];
10 changes: 9 additions & 1 deletion lib/setup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
'use strict';

var Hapi = require('hapi'),
config = require('./config');
config = require('./config'),
elasticsearch = require('elasticsearch'),
config = require('./config'),
elsClient;

elsClient = new elasticsearch.Client(config.elsClient);

module.exports = function (next) {
var server = new Hapi.Server();

server.connection(config.server);
server.bind({
els: elsClient
});
server.start(function (err) {
if (err) {
return next(err);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"dependencies": {
"hapi": "8.x.x",
"hoek-boom": "1.x.x"
"hoek-boom": "1.x.x",
"elasticsearch": "8.x.x"
},
"engines": {
"node": "0.10.x"
Expand Down
7 changes: 7 additions & 0 deletions public/javascript/angular-ui-router.min.js

Large diffs are not rendered by default.

29 changes: 20 additions & 9 deletions public/javascript/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ var a = 'Hello world';
console.log(a);

var ngModule = angular.module;
ngModule('hrApp', [
var app = ngModule('hrApp', [
'home',
'about',
'globalNav'
'globalNav',
'ui.router'
]);

ngModule('globalNav', [])
Expand All @@ -30,10 +31,20 @@ ngModule('home', [])
}
})
.controller('homePageController', [
'$http',
'$scope',
function ($scope) {
function ($http, $scope) {
var self = this;
self.name = 'Home Page View';

$http({
method: 'GET',
url: 'http://hack4hr2015.herokuapp.com/api/events/'
}).then(function (response) {
console.log(response);
}, function (error) {
console.log(error);
});
}
]);

Expand All @@ -59,12 +70,12 @@ ngModule('about', [])
}
]);
// html 5 mode on
// ngModule.config([
// '$locationProvider',
// function ($locationProvider) {
// $locationProvider.html5Mode(true);
// }
// ]);
app.config([
'$locationProvider',
function () {
//$locationProvider.html5Mode(true);
}
]);
// bootstrapping the application this way avoids clutting up the
// home page with 'ngapp=hrapp'
angular.element(document).ready(function () {
Expand Down
38 changes: 38 additions & 0 deletions public/javascript/lib/angularjs-geolocation/.bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "angularjs-geolocation",
"version": "0.1.1",
"homepage": "https://github.com/arunisrael/angularjs-geolocation",
"authors": [
"Arun Israel <[email protected]>"
],
"description": "An angular.js wrapper around window.navigator.geolocation",
"main": "./src/geolocation.js",
"keywords": [
"geolocation",
"angular.js"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"angular": "~1.x"
},
"devDependencies": {
"angular-mocks": "~1.x"
},
"_release": "0.1.1",
"_resolution": {
"type": "version",
"tag": "0.1.1",
"commit": "4174fca718da6dacc9de1fbc5deb9a9227783956"
},
"_source": "git://github.com/arunisrael/angularjs-geolocation.git",
"_target": "~0.1.1",
"_originalSource": "angularjs-geolocation",
"_direct": true
}
47 changes: 47 additions & 0 deletions public/javascript/lib/angularjs-geolocation/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
options: {
// options here to override JSHint defaults
globalstrict: true,
globals: {
jQuery: true,
console: true,
module: true,
document: true,
expect: true,
it: true,
spyOn: true,
beforeEach: true,
angular: true,
inject: true,
describe: true
}
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
},
dist: {
files: {
'dist/<%= pkg.name %>.min.js': 'src/geolocation.js'
}
}
},
karma: {
unit: {
configFile: 'karma.conf.js'
}
}
});

grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-karma');
grunt.registerTask('default', ['jshint', 'karma','uglify']);
};
20 changes: 20 additions & 0 deletions public/javascript/lib/angularjs-geolocation/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2013 Arun Israel

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
62 changes: 62 additions & 0 deletions public/javascript/lib/angularjs-geolocation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
AngularJS-Geolocation
=========

An angular.js wrapper around window.navigator.geolocation

Bower
--
This module is available as bower package, install it with this command:

```bash
bower install angularjs-geolocation
```
or

```bash
bower install git://github.com/arunisrael/angularjs-geolocation.git
```

Usage
--
- Add the geolocation module as dependency
- Inject the geolocation service (yes, it has the same name)
- Invoke the getLocation method on the geolocation service to retrieve a promise
- The promise will be resolved with the position returned by window.navigator.getCurrentPosition if the user allows the browser to access their location
- The promise will be rejected if the user rejects location access or the browser does not support it

Example
--
```
angular.module('barterApp',['geolocation'])
.controller('geoCtrl', function ($scope,geolocation) {
geolocation.getLocation().then(function(data){
$scope.coords = {lat:data.coords.latitude, long:data.coords.longitude};
});
});
```

Demo
--
See this [plunker](http://embed.plnkr.co/TM71LBh6ttYotOo6t7oX/preview) that displays your latitude/longitude

Error Handling
--
The geolocation module defines a geolocation-msgs constant holding error msgs that are broadcast if the user rejects location access:
```
$rootScope.$broadcast('error',CONSTANTS['errors.location.notFound']);
```

or if the browser does not support geolocation:
```
$rootScope.$broadcast('error',geolocation_msgs['errors.location.unsupportedBrowser']);
```

Testing
--
```
grunt test
```

License
--
MIT
Loading

0 comments on commit 71483fb

Please sign in to comment.