Skip to content

Commit

Permalink
Fix map areas functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Freika committed Jul 27, 2024
1 parent 4da8313 commit 1e3d9f3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .app_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.5
0.9.6
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).


## [0.9.6] — 2024-07-27

### Fixed

- Map areas functionality

---

## [0.9.5] — 2024-07-27

### Added
Expand Down
1 change: 1 addition & 0 deletions app/controllers/api/v1/areas_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

class Api::V1::AreasController < ApplicationController
skip_forgery_protection
before_action :authenticate_api_key
before_action :set_area, only: %i[update destroy]

Expand Down
16 changes: 8 additions & 8 deletions app/javascript/controllers/maps_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class extends Controller {
L.control.layers(this.baseMaps(), controlsLayer).addTo(this.map);

// Fetch and draw areas when the map is loaded
this.fetchAndDrawAreas();
this.fetchAndDrawAreas(this.apiKey);

let fogEnabled = false;

Expand Down Expand Up @@ -431,7 +431,7 @@ export default class extends Controller {
const form = document.getElementById('circle-form');
form.addEventListener('submit', (e) => {
e.preventDefault();
this.saveCircle(new FormData(form), layer);
this.saveCircle(new FormData(form), layer, this.apiKey);
});
});

Expand All @@ -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',
headers: { 'Content-Type': 'application/json'},
body: JSON.stringify(data)
Expand Down Expand Up @@ -483,8 +483,8 @@ export default class extends Controller {
});
}

deleteArea(id, layer) {
fetch(`/api/v1/areas/${id}`, {
deleteArea(id, layer, apiKey) {
fetch(`/api/v1/areas/${id}?api_key=${apiKey}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
Expand All @@ -506,8 +506,8 @@ export default class extends Controller {
});
}

fetchAndDrawAreas() {
fetch('/api/v1/areas', {
fetchAndDrawAreas(apiKey) {
fetch(`/api/v1/areas?api_key=${apiKey}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
Expand Down Expand Up @@ -547,7 +547,7 @@ export default class extends Controller {
document.querySelector('.delete-area').addEventListener('click', (e) => {
e.preventDefault();
if (confirm('Are you sure you want to delete this area?')) {
this.deleteArea(area.id, layer);
this.deleteArea(area.id, layer, this.apiKey);
}
});
});
Expand Down

0 comments on commit 1e3d9f3

Please sign in to comment.