-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/delivery' into paypal
Conflicts: app/controllers/users_controller.rb app/models/user.rb config/routes.rb db/schema.rb
- Loading branch information
Showing
14 changed files
with
228 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
class Location < ActiveRecord::Base | ||
def self.distance loc1, loc2 | ||
rad_per_deg = Math::PI/180 # PI / 180 | ||
rkm = 6371 # Earth radius in kilometers | ||
rm = rkm * 1000 # Radius in meters | ||
|
||
dlat_rad = (loc2.latitude-loc1.latitude) * rad_per_deg # Delta, converted to rad | ||
dlon_rad = (loc2.longitude-loc1.longitude) * rad_per_deg | ||
|
||
lat1_rad, lon1_rad = [loc1.latitude, loc1.longitude].map {|i| i * rad_per_deg } | ||
lat2_rad, lon2_rad = [loc2.latitude, loc2.longitude] .map {|i| i * rad_per_deg } | ||
|
||
a = Math.sin(dlat_rad/2)**2 + Math.cos(lat1_rad) * Math.cos(lat2_rad) * Math.sin(dlon_rad/2)**2 | ||
c = 2 * Math::atan2(Math::sqrt(a), Math::sqrt(1-a)) | ||
|
||
rm * c # Delta in meters | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
class Order < ActiveRecord::Base | ||
has_many :items | ||
belongs_to :user | ||
belongs_to :deliverer, class_name: 'User', foreign_key: 'deliverer_id' | ||
has_one :trip | ||
|
||
scope :unassigned, -> { where(status: 'unassigned')} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
class Trip < ActiveRecord::Base | ||
belongs_to :order | ||
belongs_to :user | ||
|
||
def distance(trip) | ||
start_loc1 = Location.find(start_location_id) | ||
end_loc1 = Location.find(end_location_id) | ||
|
||
start_loc2 = Location.find(trip.start_location_id) | ||
end_loc2 = Location.find(trip.end_location_id) | ||
|
||
Location.distance(start_loc1, start_loc2) + Location.distance(end_loc1, end_loc2) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
class User < ActiveRecord::Base | ||
has_one :order | ||
has_one :account | ||
# Include default devise modules. Others available are: | ||
# :confirmable, :lockable, :timeoutable and :omniauthable | ||
devise :database_authenticatable, :registerable, | ||
:recoverable, :rememberable, :trackable, :validatable | ||
|
||
|
||
has_one :order | ||
has_one :account | ||
has_many :deliveries, class_name: 'Order', foreign_key: 'deliverer_id' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
h1 Available Orders | ||
br | ||
= form_tag search_orders_path | ||
div.form-group | ||
= label :location, :address, "Travelling From" | ||
= text_field :location, :address, class:"form-control purchase-addr", required:true | ||
div.form-group.hidden | ||
= label :location, :longitude, class: "col-sm-1" | ||
div.col-sm-3 | ||
= text_field :location, :longitude, class: "form-control purchase-lon", required:true | ||
= label :location, :latitude, class: "col-sm-1" | ||
div.col-sm-3 | ||
= text_field :location, :latitude, class: "form-control purchase-lat", required:true | ||
|
||
div.form-group | ||
= label :location, :address_to, "Destination" | ||
= text_field :location, :address_to, class:"form-control deliver-addr", required:true | ||
div.form-group.hidden | ||
= label :location, :longitude_to, class: "col-sm-1" | ||
div.col-sm-3 | ||
= text_field :location, :longitude_to, class: "form-control deliver-lon", required:true | ||
= label :location, :latitude_to, class: "col-sm-1" | ||
div.col-sm-3 | ||
= text_field :location, :latitude_to, class: "form-control deliver-lat", required:true | ||
|
||
= submit_tag 'Find My Customised Orders', class: "btn btn-default" | ||
|
||
div.hidden id="purchase" style="width: 500px; height: 400px;" | ||
div.hidden id="deliver" style="width: 500px; height: 400px;" | ||
|
||
br | ||
br | ||
|
||
- @orders.each do |order| | ||
div.panel.panel-default | ||
div.panel-heading | ||
h3 = order.user.name | ||
div.panel-body | ||
- item = order.items.first | ||
p | ||
| wants to buy | ||
= item.name + ' ' | ||
| with quantity of | ||
= item.quantity | ||
- purchase_loc = Location.find(order.trip.start_location_id) | ||
p | ||
| Purchase From: | ||
= purchase_loc.address | ||
- delivery_loc = Location.find(order.trip.end_location_id) | ||
p | ||
| Delivery To: | ||
= delivery_loc.address | ||
p | ||
| Tips: $ | ||
= order.tips.to_s + ' ' | ||
| Estimated Price: $ | ||
= item.estimated_price | ||
div.panel-footer | ||
= link_to "I'll Deliver", deliver_order_path(order), class: "btn btn-default" | ||
|
||
|
||
javascript: | ||
$('#purchase').locationpicker({ | ||
location: {latitude: -37.8239402221389, longitude: 144.9911028355707}, | ||
radius: 3, | ||
inputBinding: { | ||
latitudeInput: $('.purchase-lat'), | ||
longitudeInput: $('.purchase-lon'), | ||
locationNameInput: $('.purchase-addr') | ||
}, | ||
enableAutocomplete: true, | ||
}); | ||
$('#deliver').locationpicker({ | ||
location: {latitude: -37.8239402221389, longitude: 144.9911028355707}, | ||
radius: 3, | ||
inputBinding: { | ||
latitudeInput: $('.deliver-lat'), | ||
longitudeInput: $('.deliver-lon'), | ||
locationNameInput: $('.deliver-addr') | ||
}, | ||
enableAutocomplete: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
h1 My Assigned Deliveries | ||
- @orders.each do |order| | ||
div.panel.panel-default | ||
div.panel-heading | ||
h3 = order.user.name | ||
div.panel-body | ||
- item = order.items.first | ||
p | ||
| wants to buy | ||
= item.name + ' ' | ||
| with quantity of | ||
= item.quantity | ||
- purchase_loc = Location.find(order.trip.start_location_id) | ||
p | ||
| Purchase From: | ||
= purchase_loc.address | ||
- delivery_loc = Location.find(order.trip.end_location_id) | ||
p | ||
| Delivery To: | ||
= delivery_loc.address | ||
p | ||
| Tips: $ | ||
= order.tips.to_s + ' ' | ||
| Estimated Price: $ | ||
= item.estimated_price | ||
div.panel-footer | ||
= link_to "Cancel Delivery", '#', class: "btn btn-default" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<div class="container"> | ||
<div class="row"> | ||
<h3>I want to ...</h3> | ||
<button type="button" class="btn btn-default btn-lg"><%= link_to "Order", new_order_path %></button> | ||
<%= link_to "Order", new_order_path, class: 'btn btn-default btn-lg' %> | ||
<a><button type="button" class="btn btn-default btn-lg">Deliver</button></a> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
Rails.application.routes.draw do | ||
root to: 'users#index' | ||
get 'users/account' => 'users#account' | ||
devise_for :users | ||
resources :users | ||
get 'users/account' => 'users#account' | ||
get 'users/index', to: 'users#index' | ||
get 'users/show', to: 'users#show' | ||
get 'users/deliveries', to: 'users#deliveries', as: 'user_deliveries' | ||
|
||
resources :orders | ||
resources :orders do | ||
member do | ||
get 'deliver' | ||
end | ||
collection do | ||
post 'search' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddDelivererIdToOrder < ActiveRecord::Migration | ||
def change | ||
add_column :orders, :deliverer_id, :integer | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters