diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js deleted file mode 100644 index cb0ddec..0000000 --- a/app/assets/javascripts/index.js +++ /dev/null @@ -1,13 +0,0 @@ -// 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() - } -}) diff --git a/app/assets/javascripts/index.js.erb b/app/assets/javascripts/index.js.erb new file mode 100644 index 0000000..284a6e8 --- /dev/null +++ b/app/assets/javascripts/index.js.erb @@ -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) + }) + } +}) diff --git a/app/assets/javascripts/new.js b/app/assets/javascripts/new.js new file mode 100644 index 0000000..1a2752e --- /dev/null +++ b/app/assets/javascripts/new.js @@ -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() { + +} diff --git a/app/assets/stylesheets/custom.css b/app/assets/stylesheets/custom.css index 5abe2c3..27e1a69 100644 --- a/app/assets/stylesheets/custom.css +++ b/app/assets/stylesheets/custom.css @@ -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; +} diff --git a/app/controllers/bracks_controller.rb b/app/controllers/bracks_controller.rb index 12d4aca..15f3ce6 100644 --- a/app/controllers/bracks_controller.rb +++ b/app/controllers/bracks_controller.rb @@ -1,6 +1,10 @@ class BracksController < ApplicationController + before_action :authenticate_user, only: [:new] def index end + def new + end + end diff --git a/app/views/bracks/new.html.erb b/app/views/bracks/new.html.erb new file mode 100644 index 0000000..7c82764 --- /dev/null +++ b/app/views/bracks/new.html.erb @@ -0,0 +1,11 @@ +