generated from firstmoversadvantage/fma-ruby-on-rails-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70623e0
commit 65fa5f5
Showing
9 changed files
with
119 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class MapController < ApplicationController | ||
def index | ||
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,2 @@ | ||
module MapHelper | ||
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,14 @@ | ||
import Vue from 'vue/dist/vue.esm' | ||
import TurbolinksAdapter from 'vue-turbolinks'; | ||
import MapComponent from './map_component.vue'; | ||
|
||
Vue.use(TurbolinksAdapter); | ||
|
||
document.addEventListener('turbolinks:load', () => { | ||
new Vue({ | ||
el: '#data-center-map-component', | ||
render(createElement) { | ||
return createElement(MapComponent) | ||
} | ||
}) | ||
}) |
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,73 @@ | ||
<template> | ||
<div id="map"></div> | ||
</template> | ||
|
||
<script> | ||
import axios from 'axios'; | ||
import { mapGetters } from 'vuex'; | ||
axios.defaults.headers.get["Authorization"] = window.api_authorization; | ||
(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({ | ||
key: "AIzaSyDgZS-lkCg_dKPRU-oRTSM6ZY0mXwiznEk", | ||
v: "weekly", | ||
}); | ||
export default { | ||
data() { | ||
return { | ||
data_centers: [], | ||
map: null | ||
} | ||
}, | ||
created() { | ||
this.initMap(); | ||
this.add_markers(); | ||
}, | ||
computed: mapGetters([ | ||
'network' | ||
]), | ||
methods: { | ||
initMap: async function() { | ||
// The location of Uluru | ||
const position = { lat: -25.344, lng: 131.031 }; | ||
const { Map } = await google.maps.importLibrary("maps") | ||
// The map, centered at Uluru | ||
this.map = new Map(document.getElementById("map"), { | ||
zoom: 4, | ||
center: position, | ||
mapId: "DEMO_MAP_ID", | ||
}); | ||
}, | ||
add_markers: async function() { | ||
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker"); | ||
const infoWindow = new google.maps.InfoWindow(); | ||
axios.get('/api/v1/data-centers-for-map') | ||
.then(response => { | ||
this.data_centers = response.data['data_centers']; | ||
this.data_centers.forEach(data_center => { | ||
let position = { lat: parseFloat(data_center.location_latitude), lng: parseFloat(data_center.location_longitude) }; | ||
let marker = new google.maps.Marker({ | ||
position: position, | ||
map: this.map, | ||
title: data_center.data_center_key, | ||
optimized: false | ||
}); | ||
marker.addListener("click", () => { | ||
infoWindow.close(); | ||
infoWindow.setContent(marker.getTitle()); | ||
infoWindow.open(marker.getMap(), marker); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
</script> |
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,3 @@ | ||
<%= javascript_pack_tag "data_centers/map_component.js" %> | ||
|
||
<div id="data-center-map-component"></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
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,8 @@ | ||
require "test_helper" | ||
|
||
class MapControllerTest < ActionDispatch::IntegrationTest | ||
test "should get index" do | ||
get map_index_url | ||
assert_response :success | ||
end | ||
end |