Skip to content

Commit

Permalink
have steps 1 and 2 complete for adding new rack
Browse files Browse the repository at this point in the history
  • Loading branch information
lao9 committed Aug 1, 2017
1 parent b3215ed commit 08ce663
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 16 deletions.
13 changes: 0 additions & 13 deletions app/assets/javascripts/index.js

This file was deleted.

19 changes: 19 additions & 0 deletions app/assets/javascripts/index.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// define global map variables
var map;
var infoWindows = [];
var brackMarkers = [];
var currentCenter = [];

$(document).ready(function(){
var path = window.location.pathname
if (path === "/" || path === "/bracks") {
geolocator()
expandRackOptions()
} else if (path === "/bracks/new") {
url = '<%="https://maps.googleapis.com/maps/api/js?key=#{ENV['GOOGLE_MAP_KEY']}&libraries=places"%>'
$.getScript(url).done(function() {
var coords = {latitude: 39.7495666290001, longitude: -105.000145148}
BrackMap.drawMapForNewBrack(coords)
})
}
})
85 changes: 85 additions & 0 deletions app/assets/javascripts/new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
BrackMap.drawMapForNewBrack = function(coords) {
// setup map instance vars for a central location
brackMap = new BrackMap(coords)
map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: brackMap.center
})
var input = document.getElementById('pac-input')
var searchBox = new google.maps.places.SearchBox(input);
addNewBrackListener(searchBox)
}

function addNewBrackListener(searchBox) {
searchBox.addListener('places_changed', function(){
var searched = false

clearCurrentMarkers()
// get location from search
var places = searchBox.getPlaces();
if (places.length == 0) { return; }
var place = places[0]
if (!place.geometry) {
console.log("Returned place contains no geometry");
return;
}
// place center marker
var latLng = place.geometry.location
brackMap = new BrackMap({latitude: latLng.lat(), longitude: latLng.lng()})

var userLatLng = new google.maps.LatLng(brackMap.lat, brackMap.lng);

var userMarker = new google.maps.Marker({
position: userLatLng,
map: map,
animation: google.maps.Animation.DROP,
icon: brackMap.image,
draggable: true,
title: "Drag me!"
})

if (!searched) {
moveToStepTwo()
searched = true
}

currentCenter.push(userMarker)

map.panTo(latLng)
map.setZoom(18)
// add marker drag listener
google.maps.event.addListener(userMarker, 'dragend', function(event) {
console.log(currentCenter[0].position.lat())
console.log(currentCenter[0].position.lng())
console.log('final position is '+event.latLng.lat()+' / '+event.latLng.lng());
});

})
}

function moveToStepTwo() {
setTimeout(function(){
$("h5").text("Drag bike rack pin to correct location on map")
$("h5").fadeIn("slow", function() {
$(this).toggleClass("highlight");
});
}, 1000)
setTimeout(function(){
$("#map").animate({
height: "-=100"
}, 700)
$(".new-next").show()
}, 2000)
setTimeout(function () {
$("h5").toggleClass("highlight");
$("h5").toggleClass("unhighlight");
}, 3000);
$(".new-next").on('click', function(){
console.log("Yay!")
debugger
})
}

function moveToStepThree() {

}
20 changes: 20 additions & 0 deletions app/assets/stylesheets/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,23 @@ body {
#pack-input:focus {
border-color: #4d90fe;
}

.new-next {
background-color: black;
border-style: ridge;
color: white;
text-align: center;
padding-top: 3px;
padding-bottom: 5px;
display: none;
}

.unhighlight {
background-color: none;
transition: all 1s ease-in-out;
}

.highlight {
background-color: #fceab8;
transition: all 1s ease-in-out;
}
4 changes: 4 additions & 0 deletions app/controllers/bracks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class BracksController < ApplicationController
before_action :authenticate_user, only: [:new]

def index
end

def new
end

end
11 changes: 11 additions & 0 deletions app/views/bracks/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h1>Add a New Rack</h1>

<div class="map-box">
<h5>Input nearest address to new bike rack:</h5>
<input id="pac-input" class="controls" type="text" placeholder="Search">
<hr>
<div id="map"></div>
<div tabindex="0" class="new-next">
<h3>Save Rack Location</h3>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/layouts/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<li><%= link_to "Sign Up", new_user_path %></li>
<% end %>
<li><%= link_to "Bike Rack Map", bracks_path, method: :get %></li>
<li><a href="#">Add New Bike</a></li>
<li><%= link_to "Add New Bike", new_brack_path %></li>
<% if current_user %>
<li><%= link_to logout_path, method: :delete do %>
Log Out</a>
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
get '/login', to: 'sessions#new'
post '/login', to: 'sessions#create'
delete '/logout', to: 'sessions#destroy'
resources :bracks, only: [:index]

resources :bracks, only: [:index, :new]
resources :users, only: [:new, :create]

namespace :api do
Expand Down

0 comments on commit 08ce663

Please sign in to comment.