Fix map areas functionality

This commit is contained in:
Eugene Burmakin 2024-07-27 14:30:46 +02:00
parent 4da8313b51
commit 1e3d9f358d
4 changed files with 18 additions and 9 deletions

View file

@ -1 +1 @@
0.9.5 0.9.6

View file

@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.9.6] — 2024-07-27
### Fixed
- Map areas functionality
---
## [0.9.5] — 2024-07-27 ## [0.9.5] — 2024-07-27
### Added ### Added

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class Api::V1::AreasController < ApplicationController class Api::V1::AreasController < ApplicationController
skip_forgery_protection
before_action :authenticate_api_key before_action :authenticate_api_key
before_action :set_area, only: %i[update destroy] before_action :set_area, only: %i[update destroy]

View file

@ -57,7 +57,7 @@ export default class extends Controller {
L.control.layers(this.baseMaps(), controlsLayer).addTo(this.map); L.control.layers(this.baseMaps(), controlsLayer).addTo(this.map);
// Fetch and draw areas when the map is loaded // Fetch and draw areas when the map is loaded
this.fetchAndDrawAreas(); this.fetchAndDrawAreas(this.apiKey);
let fogEnabled = false; let fogEnabled = false;
@ -431,7 +431,7 @@ export default class extends Controller {
const form = document.getElementById('circle-form'); const form = document.getElementById('circle-form');
form.addEventListener('submit', (e) => { form.addEventListener('submit', (e) => {
e.preventDefault(); e.preventDefault();
this.saveCircle(new FormData(form), layer); this.saveCircle(new FormData(form), layer, this.apiKey);
}); });
}); });
@ -451,7 +451,7 @@ export default class extends Controller {
} }
}); });
fetch(`"/api/v1/areas?api_key=${apiKey}"`, { fetch(`/api/v1/areas?api_key=${apiKey}`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json'}, headers: { 'Content-Type': 'application/json'},
body: JSON.stringify(data) body: JSON.stringify(data)
@ -483,8 +483,8 @@ export default class extends Controller {
}); });
} }
deleteArea(id, layer) { deleteArea(id, layer, apiKey) {
fetch(`/api/v1/areas/${id}`, { fetch(`/api/v1/areas/${id}?api_key=${apiKey}`, {
method: 'DELETE', method: 'DELETE',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -506,8 +506,8 @@ export default class extends Controller {
}); });
} }
fetchAndDrawAreas() { fetchAndDrawAreas(apiKey) {
fetch('/api/v1/areas', { fetch(`/api/v1/areas?api_key=${apiKey}`, {
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
@ -547,7 +547,7 @@ export default class extends Controller {
document.querySelector('.delete-area').addEventListener('click', (e) => { document.querySelector('.delete-area').addEventListener('click', (e) => {
e.preventDefault(); e.preventDefault();
if (confirm('Are you sure you want to delete this area?')) { if (confirm('Are you sure you want to delete this area?')) {
this.deleteArea(area.id, layer); this.deleteArea(area.id, layer, this.apiKey);
} }
}); });
}); });