diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 743bd80..05e3c60 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,6 +42,10 @@ jobs: id-token: write steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Docker Build and Push uses: cartoway/docker-compose-build-push-action@main with: diff --git a/.gitignore b/.gitignore index 98b3f61..161e8f4 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ build/ /docker/osrm/landuses /docker/osrm/profiles /docker/otp/data +/docker/access.rb /docker/production.rb ## Environment normalisation: @@ -52,3 +53,8 @@ local.env # Redis *.aof + +## Submodules build +public/assets/ +public/*.svg +public/route.html diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d8afb65 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "router-demo"] + path = router-demo + url = https://github.com/cartoway/router-demo.git diff --git a/README.md b/README.md index b904079..097d371 100644 --- a/README.md +++ b/README.md @@ -205,3 +205,40 @@ docker compose -f docker-compose-tools.yml down redis-build ``` docker compose run --rm gh-car-iceland gh-build.sh ``` + +## Local router-demo submodule + +To work on with the router-demo locally, you must load the front-end submodule `router-demo` (web interface). + +### 1. Initialize the submodule + +Before using Docker or building, run: + +```bash +git submodule update --init --recursive +``` + +### 2. Build the docker image + +You can use the following script to automate everything: + +```bash +docker-compose up --build +``` + +The build of the `router-demo` submodule is automatically handled by the `router-demo-build` service in `docker-compose.yml`. The generated files are copied into the `public/` folder and served by the API. + +### 4. Access the web interface + +After launching, access the front-end at: +- [http://localhost:8082/route.html](http://localhost:8082/route.html) + +JS/CSS assets are served automatically. + +### 5. Update the submodule + +To update the front-end: + +```bash +git submodule update --remote --merge +``` diff --git a/config/router-demo.vite.patch b/config/router-demo.vite.patch new file mode 100644 index 0000000..7f90e4e --- /dev/null +++ b/config/router-demo.vite.patch @@ -0,0 +1,18 @@ +diff --git a/vite.config.ts b/vite.config.ts +index 0cc309f..a2d3e55 100644 +--- a/vite.config.ts ++++ b/vite.config.ts +@@ -28,4 +28,13 @@ export default defineConfig({ + host: '0.0.0.0', + port: 5173, + }, ++ build: { ++ rollupOptions: { ++ output: { ++ entryFileNames: 'assets/route-[hash].js', ++ chunkFileNames: 'assets/route-[hash].js', ++ assetFileNames: 'assets/route-[hash][extname]' ++ } ++ } ++ } + }); diff --git a/docker-compose.yml b/docker-compose.yml index 875e74b..ca7be84 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,12 +7,14 @@ services: - "8082:80" # HOST:CONTAINER, edit only HOST part volumes: - .:/srv/app + - ./router-demo/dist:/srv/app/public - ./docker/access.rb:/srv/app/config/access.rb - ./docker/production.rb:/srv/app/config/environments/production.rb - ./docker/production.rb:/srv/app/config/environments/development.rb - ./docker/poly:/srv/app/poly depends_on: - redis-cache + - router-demo-build environment: REDIS_HOST: redis-cache APP_ENV: ${APP_ENV:-development} @@ -21,6 +23,21 @@ services: command: bundle exec puma -v -p 80 --pidfile 'tmp/server.pid' restart: unless-stopped + router-demo-build: + image: node:20 + working_dir: /srv/app/router-demo + volumes: + - .:/srv/app + command: > + sh -c "\ + patch vite.config.ts < ../config/router-demo.vite.patch && \ + npm install && \ + npm run build && \ + mv dist/index.html dist/route.html && \ + cp -r dist/* ../public/ && \ + patch -R vite.config.ts < ../config/router-demo.vite.patch\ + " + redis-cache: image: redis:${REDIS_VERSION:-7-alpine} command: redis-server --save "" diff --git a/public/js/route.js b/public/js/route.js deleted file mode 100644 index b08324d..0000000 --- a/public/js/route.js +++ /dev/null @@ -1,137 +0,0 @@ -function init(data) { - var routing; - var waypoints = []; - - function capitalizeFirstLetter(string) { - return string.charAt(0).toUpperCase() + string.slice(1); - } - - function getMode() { - return $('#router-mode').val(); - } - - function getDimension() { - return $('#router-dimension').val(); - } - - function getMotorway() { - return $('#motorway').is(':checked'); - } - - function getToll() { - return $('#toll').is(':checked'); - } - - function getLowEmissionZone() { - return $('#low_emission_zone').is(':checked'); - } - - function resetMap() { - map.removeControl(routing); - } - - function initMap() { - routing = L.Routing.control({ - router: L.Routing.mt($.extend(options, { - mode: getMode(), - dimension: getDimension(), - motorway: getMotorway(), - toll: getToll(), - low_emission_zone: getLowEmissionZone(), - })), - waypoints: waypoints, - routeWhileDragging: true - }).addTo(map); - - var search = new URLSearchParams(window.location.search); - (search.get('waypoints') || "").split(';').forEach(function(waypoint, i) { - var latlng = waypoint.split(',').reverse(); - routing.spliceWaypoints(i, 1, latlng); - }); - waypoints = routing.getPlan()._waypoints; - - routing.on('routingstart', function(e) { - updateUrl(waypoints); - }); - } - - function initDimensions(mode) { - var select = $('#router-dimension'); - select.find('option').remove(); - $.each(data.route, function(i, item) { - if (item.mode == mode) { - $.each(item.dimensions, function(k, v) { - select.append( - $('').val(v).html(capitalizeFirstLetter(v)) - ) - }); - } - }); - if(!routing) { - initMap(); - } - } - - function updateUrl(waypoints) { - var url = new URL(window.location.href); - url.searchParams.set('waypoints', waypoints - .filter((waypoint) => waypoint.latLng) - .map((waypoint) => waypoint.latLng.lng + ',' + waypoint.latLng.lat) - .join(';') - ); - history.replaceState({}, '', url); - } - - function createButton(label, container) { - var btn = L.DomUtil.create('button', '', container); - btn.setAttribute('type', 'button'); - btn.innerHTML = label; - return btn; - } - - $.each(data.route, function(i, item) { - $('#router-mode').append( - $('').val(item.mode).html(item.name) - ) - }); - - $('#router-mode').change(function(e) { - initDimensions(getMode()); - }); - - initDimensions(getMode()); - - $('select').select2({ minimumResultsForSearch: -1 }); - $('select, input').change(function(e) { - resetMap(); - initMap(); - }); - - routing.getPlan().on('waypointschanged', function(e) { - waypoints = e.waypoints; - }); - - routing.getPlan().on('waypointdragend', function(e) { - waypoints = routing.getPlan()._waypoints; - }); - - map.on('click', function(e) { - var container = L.DomUtil.create('div'); - startBtn = createButton('Start from this location', container), - destBtn = createButton('Go to this location', container); - - L.popup().setContent(container).setLatLng(e.latlng).openOn(map); - - L.DomEvent.on(startBtn, 'click', function() { - routing.spliceWaypoints(0, 1, e.latlng); - waypoints = routing.getPlan()._waypoints; - map.closePopup(); - }); - - L.DomEvent.on(destBtn, 'click', function() { - routing.spliceWaypoints(routing.getWaypoints().length - 1, 1, e.latlng); - waypoints = routing.getPlan()._waypoints; - map.closePopup(); - }); - }); -} diff --git a/public/route.html.erb b/public/route.html.erb deleted file mode 100644 index 5eefbed..0000000 --- a/public/route.html.erb +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - Motorways - Tolls - Low Emission Zone - - - - - - - Geocode - - - - Locate - - - - - - - - - - - - - - diff --git a/router-demo b/router-demo new file mode 160000 index 0000000..9e01328 --- /dev/null +++ b/router-demo @@ -0,0 +1 @@ +Subproject commit 9e01328f6ff2359b391c770a3cd9cca6b7a7d9eb