-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring/tobias 117 convert leaflet to js (#137)
Refactor leaflet ruby gem to plain js. This merge will remove the map on the location show page, as communicated with team @hpi-swt2/apmw21. We moved functionality from server to client. Coverage will be restored with Issue #149. * Start working on refactoring to js * Refactor map elements to js * Remove style from head * removed brackets as suggested * Fix variable erroneously dumped to page fixes Places::DESTINATIONS variable being dumped into HTML (introduced in #102) * Restore package-lock.json and other feedback * First steps on new js conversion Co-authored-by: TheGrayStone <[email protected]> Co-authored-by: Julian Schmidt <[email protected]> * Refactor routing display * Add Route to its own layer * Trying to fix tests with js * Comment on old magic constant * Adapt tests for routing * linting stuff * Remove test for targets, minor fixes * [CodeFactor] Apply fixes * Remove old map from locations, needs more fixing * Extra js file for leaflet Map * prepare locations show * Remove map from location page * add debugging help to routing tests * add waiting time for routing * remove unnecessary code * adding wait_for_ajax to route tests * Remove old unused code (Commented for target) * tag tests and improve backend routes * improved tagging to new syntax * exclude tests with the tag "local_only" * add jQuery as requested * code cleanup for jQuery * enable indoor rooms from hg * add target marker functionality * remove old variable on index * [CodeFactor] Apply fixes * a try on fixing tests * [CodeFactor] Apply fixes * fix CodeFactor issue * improve tests with find and waiting time * edit tags for tests * remove parallel execution in js * remove wait_for_ajax * run route tests only local * restore yarn.lock * add newline to yarn.lock * Code improvements * [CodeFactor] Apply fixes * Fix magic string * possible fix for routing tests * Parallelize ajax requests Co-authored-by: Julian Schmidt * reverse changes for parallel ajax * add comment about race condition * Paralize ajax requests WITH tests * remove tests for routing (race condition) Co-authored-by: Lukas Rost <[email protected]> Co-authored-by: TheGrayStone <[email protected]> Co-authored-by: Julian Schmidt <[email protected]> Co-authored-by: codefactor-io <[email protected]>
- Loading branch information
Showing
18 changed files
with
333 additions
and
203 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
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,11 +1,12 @@ | ||
module Locations | ||
def self.transform_leaflet_position(position, name) | ||
{ | ||
latlng: position, | ||
div_icon: { | ||
html: name, | ||
class_name: "building-icon" | ||
} | ||
} | ||
end | ||
# Only needed for creating a leaflet marker | ||
# def self.transform_leaflet_position(position, name) | ||
# { | ||
# latlng: position, | ||
# div_icon: { | ||
# html: name, | ||
# class_name: "location-icon" | ||
# } | ||
# } | ||
# 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
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,11 +1,38 @@ | ||
class BuildingMapController < ApplicationController | ||
YOUR_LOCATION_MAGIC_STRING = "Your location".freeze | ||
YOUR_LOCATION_MAGIC_STRING = "Your location".freeze # TODO: This is currenty hard coded in the building_map.js file | ||
|
||
def index | ||
@start = RoutingHelper.resolve_coordinates(params[:start]) | ||
@destination = RoutingHelper.resolve_coordinates(params[:dest]) | ||
@route = RoutingHelper.calculate_route(@start, @destination) if @start.present? && @destination.present? | ||
def index; end | ||
|
||
@target = params[:target] | ||
def buildings | ||
polygons = BuildingMapHelper.leaflet_polygons | ||
respond_to do |format| | ||
format.json { render json: polygons } | ||
end | ||
end | ||
|
||
def view | ||
view = BuildingMapHelper.leaflet_center | ||
respond_to do |format| | ||
format.json { render json: view } | ||
end | ||
end | ||
|
||
def markers | ||
markers = Buildings.transform_leaflet_letters(Buildings::HPI_LETTERS) | ||
respond_to do |format| | ||
format.json { render json: markers } | ||
end | ||
end | ||
|
||
def route | ||
start = RoutingHelper.resolve_coordinates(params[:start]) | ||
dest = RoutingHelper.resolve_coordinates(params[:dest]) | ||
route = RoutingHelper.calculate_route(start, dest) if start.present? && dest.present? | ||
|
||
result = { polyline: RoutingHelper.transform_route_to_polyline(route), | ||
marker: RoutingHelper.transform_route_to_time_marker(route) } | ||
respond_to do |format| | ||
format.json { render json: result } | ||
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
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,73 @@ | ||
import { displayRoute, setupMap } from './leafletMap.js'; | ||
|
||
let currentLocation; | ||
const YOUR_LOCATION_MAGIC_STRING = "Your location" // This will be changed when the page supports multiple languages | ||
|
||
setupMap(); | ||
|
||
const start_input_field = $("#start_input")[0]; | ||
start_input_field.addEventListener("change", () => { | ||
request_location(); | ||
if (validate_place_input("start_input", "startOptions")) { | ||
start_input_field.setCustomValidity(""); | ||
} else { | ||
start_input_field.setCustomValidity( | ||
"Please select a valid starting place." | ||
); | ||
} | ||
}); | ||
start_input_field.dispatchEvent(new Event("change")); | ||
|
||
const dest_input_field = $("#dest_input")[0]; | ||
dest_input_field.addEventListener("change", () => { | ||
if (validate_place_input("dest_input", "destOptions")) { | ||
dest_input_field.setCustomValidity(""); | ||
} else { | ||
dest_input_field.setCustomValidity( | ||
"Please select a valid destination place." | ||
); | ||
} | ||
}); | ||
dest_input_field.dispatchEvent(new Event("change")); | ||
|
||
$("#navigation_form")[0] | ||
.addEventListener("submit", (event) => { | ||
event.preventDefault(); | ||
if (start_input_field.value === YOUR_LOCATION_MAGIC_STRING) { | ||
start_input_field.value = currentLocation; | ||
} | ||
const start = start_input_field.value; | ||
const dest = dest_input_field.value; | ||
displayRoute(start, dest); | ||
}); | ||
|
||
function validate_place_input(inputId, optionsId) { | ||
const input = $(`#${inputId}`)[0]; | ||
const options = $(`#${optionsId}`)[0].options; | ||
return Array.from(options).some((o) => o.value === input.value); | ||
} | ||
|
||
function request_location() { | ||
if (start_input_field.value !== YOUR_LOCATION_MAGIC_STRING) return; | ||
navigator.geolocation.getCurrentPosition( | ||
(pos) => { | ||
currentLocation = | ||
String(pos.coords.latitude) + | ||
"," + | ||
String(pos.coords.longitude); | ||
start_input_field.setCustomValidity(""); | ||
}, | ||
(error) => { | ||
console.warn(`ERROR(${error.code}): ${error.message}`); | ||
if (error.code === GeolocationPositionError.PERMISSION_DENIED) { | ||
start_input_field.setCustomValidity( | ||
"You have to grant your browser the permission to access your location if you want to use this feature." | ||
); | ||
} else { | ||
start_input_field.setCustomValidity( | ||
"Your browser could not determine your position. Please choose a different starting place." | ||
); | ||
} | ||
} | ||
); | ||
} |
Oops, something went wrong.