Skip to content

Commit

Permalink
Merge pull request #29 from teeeg/master
Browse files Browse the repository at this point in the history
closes #20 #21
  • Loading branch information
jimgong92 committed Dec 31, 2014
2 parents 9562f9a + 2b13107 commit e1e8677
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 92 deletions.
2 changes: 1 addition & 1 deletion client/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
'ui.router',
'core',
'core:ComposeController',
'core:DriverController',
'core:PassengerController',
'core:DriverController',
'ngFx'
])

Expand Down
39 changes: 20 additions & 19 deletions client/app/core/controllers/Compose.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@
.module('core:ComposeController',[])
.controller('ComposeController', ComposeController);

function ComposeController($scope, $http, $q, $state){ // removed $state because of testing errors

function ComposeController($scope, $http, $q, $state, $rootScope){ // removed $state because of testing errors
var vm = this;

vm.user = {};

vm.findCoordinates = findCoordinates;
vm.createUser = createUser;
vm.find = createUser;
vm.getUser = getUser;

// gets all form data from compose.html
function createUser (user) {
vm.user = angular.copy(user);
}

// once user has hit submit, its a chain of events that get user info and populates lat/long before posting data to server
function getUser (user) {
//start animation
Expand All @@ -31,38 +24,46 @@
});
}


// gets all form data from compose.html
var createUser = function (user) {
vm.user = angular.copy(user);
}

// returns an object with latitude and longitude
function findCoordinates (place, waypoint, callback) {
var baseURL = "http://nominatim.openstreetmap.org/search?format=json&limit=3&q=";
return $http({
method: "GET",
url: baseURL+place,
url: baseURL+place
}).success(function(data) {
var place = data[0]; // returns multiple places. first object is the most accurate
vm.user[waypoint] = { 'lat': place.lat, 'lon': place.lon };

vm.user[waypoint] = [place.lat,place.lon];
callback();
})
}

// create user, then get origin, then get destination, then save lat,lon to user
// create usfer, then get origin, then get destination, then save lat,lon to user
function postData (user) {
vm.user = angular.copy(user);
$rootScope.origin = vm.user.originCoordinates;
console.log($rootScope.origin,$rootScope.origin[0]);
$rootScope.destination = vm.user.destinationCoordinates;

var redirect = vm.user.title;

$http({
method: 'POST',
url: 'localhost/' + redirect ,
url: '/' + redirect ,
data: JSON.stringify({
name: vm.user.name,
id: vm.user.id,
origin: vm.user.originCoordinates,
destination: vm.user.destinationCoordinates
destination: vm.user.destinationCoordinates,
type: 'create'
})
}).success(function (data) {
//stop animation
$state.go(redirect); // redirect to either driver or passenger
$state.go(redirect)
}).error(function(data, status){
console.log(status);
$state.go(redirect);
});
};
Expand Down
52 changes: 28 additions & 24 deletions client/app/core/controllers/Passenger.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
.module('core:PassengerController',['ngFx'])
.controller('PassengerController', PassengerController);

function PassengerController ($scope, $http, $state, $q, $timeout) {
function PassengerController ($scope, $http, $state, $q, $timeout, $rootScope) {


var passenger = this;
passenger.drivers = [];
var drivers = [];
passenger.findDrivers = findDrivers;

//set some timeout to push to passenger.drivers array
var push = function (data, array) {
Expand All @@ -16,33 +20,33 @@
}
}

// dummy data
var drivers = [
{ name: 'Thomas ', start: 'Berkeley, CA', end: 'Palo Alto, CA', deviation: '10 min', img: 'https://avatars1.githubusercontent.com/u/1794233?v=3&s=100'},
{ name: 'Jimmy ', start: 'Oakland, CA', end: 'San Jose, CA', deviation: '8 min', img: 'https://avatars2.githubusercontent.com/u/7923322?v=3&s=100'},
{ name: 'Beth ', start: 'Richmond, CA', end: 'Fremon, CA', deviation: '12 min', img: 'https://avatars1.githubusercontent.com/u/7968370?v=3&s=100'},
{ name: 'Thomas ', start: 'Berkeley, CA', end: 'Palo Alto, CA', deviation: '10 min', img: 'https://avatars1.githubusercontent.com/u/1794233?v=3&s=100'},
{ name: 'Jimmy ', start: 'Oakland, CA', end: 'San Jose, CA', deviation: '8 min', img: 'https://avatars2.githubusercontent.com/u/7923322?v=3&s=100'},
{ name: 'Beth ', start: 'Richmond, CA', end: 'Fremon, CA', deviation: '12 min', img: 'https://avatars1.githubusercontent.com/u/7968370?v=3&s=100'},
{ name: 'Thomas ', start: 'Berkeley, CA', end: 'Palo Alto, CA', deviation: '10 min', img: 'https://avatars1.githubusercontent.com/u/1794233?v=3&s=100'},
{ name: 'Jimmy ', start: 'Oakland, CA', end: 'San Jose, CA', deviation: '8 min', img: 'https://avatars2.githubusercontent.com/u/7923322?v=3&s=100'},
{ name: 'Beth ', start: 'Richmond, CA', end: 'Fremon, CA', deviation: '12 min', img: 'https://avatars1.githubusercontent.com/u/7968370?v=3&s=100'},
{ name: 'Thomas ', start: 'Berkeley, CA', end: 'Palo Alto, CA', deviation: '10 min', img: 'https://avatars1.githubusercontent.com/u/1794233?v=3&s=100'},
{ name: 'Jimmy ', start: 'Oakland, CA', end: 'San Jose, CA', deviation: '8 min', img: 'https://avatars2.githubusercontent.com/u/7923322?v=3&s=100'},
{ name: 'Beth ', start: 'Richmond, CA', end: 'Fremon, CA', deviation: '12 min', img: 'https://avatars1.githubusercontent.com/u/7968370?v=3&s=100'},
{ name: 'Thomas ', start: 'Berkeley, CA', end: 'Palo Alto, CA', deviation: '10 min', img: 'https://avatars1.githubusercontent.com/u/1794233?v=3&s=100'},
{ name: 'Jimmy ', start: 'Oakland, CA', end: 'San Jose, CA', deviation: '8 min', img: 'https://avatars2.githubusercontent.com/u/7923322?v=3&s=100'},
{ name: 'Beth ', start: 'Richmond, CA', end: 'Fremon, CA', deviation: '12 min', img: 'https://avatars1.githubusercontent.com/u/7968370?v=3&s=100'},


];

(passenger.getDrivers = function (array) {

// http://127.0.0.1:5000/driver?oLat=39.52927&oLong=-119.8136744&dLat=37.7792768&dLong=-122.4192704
// returns an object with latitude and longitude
var findDrivers = function() {
$http({
method: 'GET',
url: '/driver',
params: {
oLat: $rootScope.origin[0],
oLong: $rootScope.origin[1],
dLat: $rootScope.destination[0],
dLong: $rootScope.destination[1]
}
}).success(function(data) {
passenger.drivers = data.matches;
}).error(function(data) {
console.log("Data corrupts");
})
}

findDrivers();
passenger.getDrivers = function (array) {
array.forEach(function (item, index) {
$timeout(push(item,passenger.drivers), index * 50);
})
return passenger.drivers;
})(drivers);
};

}
}).call(this);
121 changes: 121 additions & 0 deletions client/app/core/controllers/temp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
@function grey($opacity){
@return rgba(136, 207, 48,$opacity);
}

.passenger {
h1 {
@include fontlight;
text-align: center;
}
}

.passenger-block {
vertical-align: middle;
text-align: center;
padding: 5% 0;
margin: 2% 0;
width: 100%;
border: 1px solid lightgrey;
}

///////////////////////////////////

.passenger-role {
@include fontlight;
padding: 2% 0;
webkit-user-select: none;

.passenger-drivers {
user-select: none;
cursor: pointer;
padding: 1%;
border-bottom-style: solid;
border-bottom-width: thin;
border-bottom-color: $green;
transition: all 200ms ease;
}

.expanded {
// background-color: grey(0.3);
margin-left: -16px;
margin-right: -16px;
transition: all 100ms ease;
box-shadow: 0px 2px 5px lightgrey;
}

.path {
height: 100%;
display: table;
width: 50%;
padding-left: 2%;
margin: 2% 0;
font-size: 1.5rem;
}

.deviation {
height: 100%;
display: table;
width: 50%;
padding-left: 2%;
margin: 2% 0;
font-size: 2rem;
}

.box {
display: table-cell;
text-align: center;
vertical-align: middle;
}

.sidebar {
width: 100px;
font-size: 1.2rem;
}

.details {
width: 100%;
.route {
img {width: 50%;}
text-align: right;
display: inline-block;
width: 60%;
}
.info {
text-align: right;
display: inline-block;
width: 39%;
text-align: left;
}
}
}


<div class="passenger" ng-controller="PassengerController">
<h1>Available Drivers</h1>

<div class="passenger-role">
<div class="passenger-drivers"
ng-class="{ 'expanded' : isSelected}"
ng-repeat='driver in passenger.drivers'>
<div class="header" ng-init="isSelected = false"
ng-click="isSelected = !isSelected">
<div class="box sidebar">
<img src = "{{ driver.img }}"/>
{{ driver.name }}
</div>
<div class="box path">
début: <b>{{ driver.start }}</b> <br>
fin: <b>{{ driver.end }}</b>
</div>
<div class="box deviation">
{{ driver.deviation }}
</div>
</div>
<div class="details" ng-show="isSelected">
<div class="route"><img src="/map.png"></div>
<div class="info">
<button ng-click="pingDriver()">Contact Driver</button>
</div>
</div>
</div>

18 changes: 18 additions & 0 deletions client/app/core/services/User.factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
;(function () {
'use strict';

angular
.module('core','app')
.factory('UserFactory', UserFactory);

function UserFactory($scope, $http, $q, $state){
var user = this;

// gets all form data from compose.html
function createUser (user) {
user = angular.copy(user);
return user;
}
}).call(this);


54 changes: 27 additions & 27 deletions client/app/core/tests/composeControllerTest.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
describe('Controller: testController', function () {
beforeEach(module('core:ComposeController'))
// describe('Controller: testController', function () {
// beforeEach(module('core:ComposeController'))

var scope, controller, httpBackend, authRequestHandler;
// var scope, controller, httpBackend, authRequestHandler;


beforeEach(inject(function ($controller, $rootScope, _$httpBackend_) {
scope = $rootScope.$new();
httpBackend = _$httpBackend_;
// beforeEach(inject(function ($controller, $rootScope, _$httpBackend_) {
// scope = $rootScope.$new();
// httpBackend = _$httpBackend_;

controller = $controller('ComposeController as vm', {
$scope: scope,
});
// controller = $controller('ComposeController as vm', {
// $scope: scope,
// });

scope.vm.user = {};
// scope.vm.user = {};

spyOn(controller, 'findCoordinates').and.callFake(function () {
console.log('hi');
});
// spyOn(controller, 'findCoordinates').and.callFake(function () {
// console.log('hi');
// });

}));
// }));

afterEach(function () {
httpBackend.verifyNoOutstandingExpectation();
httpBackend.verifyNoOutstandingRequest();
})
// afterEach(function () {
// httpBackend.verifyNoOutstandingExpectation();
// httpBackend.verifyNoOutstandingRequest();
// })

it('should return copy user', function () {
scope.vm.user.name = 'Jon'
scope.vm.createUser( scope.vm.user.name );
// it('should return copy user', function () {
// scope.vm.user.name = 'Jon'
// scope.vm.createUser( scope.vm.user.name );

expect(scope.vm.user).toEqual( { name: 'Jon' } );
});
// expect(scope.vm.user).toEqual( { name: 'Jon' } );
// });

// it('when called returns the requested value', function () {
// expect(scope.vm.user).toEqual(10);
// });
// // it('when called returns the requested value', function () {
// // expect(scope.vm.user).toEqual(10);
// // });

});
// });
2 changes: 1 addition & 1 deletion client/app/core/views/compose.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1>Create</h1>

<div class="compose-id">
<span>Email</span>
<input type="text" ng-model="user.name" placeholder="[email protected]">
<input type="text" ng-model="user.id" placeholder="[email protected]">
</div>

<div class="compose-submit">
Expand Down
2 changes: 1 addition & 1 deletion client/app/core/views/driver.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ <h1>Available Passengers</h1>

<div class="driver-role">
<div class="driver-passengers fx-fade-up fx-easing-sine" ng-repeat='passenger in driver.passengers'>
name: {{ passenger.name }}
name: {{ passenger }}
start: {{ passenger.start }}
end: {{ passenger.end }}
</div>
Expand Down
Loading

0 comments on commit e1e8677

Please sign in to comment.