From 99bf2635f2f4b64e57870bc32042d916ea801667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gw=C3=A9na=C3=ABl=20Rault?= Date: Wed, 23 Jul 2025 10:27:38 +0200 Subject: [PATCH 1/2] Add router-demo submodule --- .github/workflows/main.yml | 4 + .gitignore | 6 ++ .gitmodules | 3 + README.md | 37 +++++++++ config/router-demo.vite.patch | 18 +++++ docker-compose.yml | 17 +++++ public/js/route.js | 137 ---------------------------------- public/route.html.erb | 41 ---------- router-demo | 1 + 9 files changed, 86 insertions(+), 178 deletions(-) create mode 100644 .gitmodules create mode 100644 config/router-demo.vite.patch delete mode 100644 public/js/route.js delete mode 100644 public/route.html.erb create mode 160000 router-demo 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( - $('