diff --git a/quasar-app/src/api/segments.js b/quasar-app/src/api/segments.js index fffd65f..b322a0e 100644 --- a/quasar-app/src/api/segments.js +++ b/quasar-app/src/api/segments.js @@ -48,3 +48,16 @@ export function removeSegment(rs, segmentId) { .catch(error => reject(error)); }); } + +export function toggleOccupied(rs, segmentId) { + return new Promise((resolve, reject) => { + axios.patch(`${API_URL}/rs/${rs.id}/s/${segmentId}/occupied`) + .then(response => { + const updatedSegment = response.data; + const segment = rs.segments.find(s => s.id === updatedSegment.id); + segment.occupied = updatedSegment.occupied; + resolve(); + }) + .catch(reject); + }) +} diff --git a/quasar-app/src/components/rs/MapView.vue b/quasar-app/src/components/rs/MapView.vue index 1e5e9a9..d343e16 100644 --- a/quasar-app/src/components/rs/MapView.vue +++ b/quasar-app/src/components/rs/MapView.vue @@ -5,176 +5,18 @@ Your browser doesn't support canvas. - +
-
+
- - - - Add Signal - - - - Add Segment Boundary - - - - Add Switch - - - - Add Label - - + - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/quasar-app/src/components/rs/SegmentsView.vue b/quasar-app/src/components/rs/SegmentsView.vue index f862a00..daca296 100644 --- a/quasar-app/src/components/rs/SegmentsView.vue +++ b/quasar-app/src/components/rs/SegmentsView.vue @@ -13,9 +13,15 @@ {{segment.name}} Id: {{segment.id}} + + + + + Toggle Occupied + Delete @@ -68,7 +74,7 @@ import { useRailSystemsStore } from "stores/railSystemsStore"; import { RailSystem } from "src/api/railSystems"; import { useQuasar } from "quasar"; -import { createSegment, removeSegment } from "src/api/segments"; +import { createSegment, removeSegment, toggleOccupied } from "src/api/segments"; import { ref } from "vue"; export default { @@ -115,6 +121,9 @@ export default { onReset() { this.segmentName = ""; }, + toggleOccupiedInline(segment) { + toggleOccupied(this.rsStore.selectedRailSystem, segment.id) + }, remove(segment) { this.quasar.dialog({ title: "Confirm", diff --git a/quasar-app/src/components/rs/add_component/AddComponentForm.vue b/quasar-app/src/components/rs/add_component/AddComponentForm.vue new file mode 100644 index 0000000..a76d93b --- /dev/null +++ b/quasar-app/src/components/rs/add_component/AddComponentForm.vue @@ -0,0 +1,293 @@ + + + + + diff --git a/quasar-app/src/components/rs/component_views/SegmentBoundaryComponentView.vue b/quasar-app/src/components/rs/component_views/SegmentBoundaryComponentView.vue index 316497d..021bcd8 100644 --- a/quasar-app/src/components/rs/component_views/SegmentBoundaryComponentView.vue +++ b/quasar-app/src/components/rs/component_views/SegmentBoundaryComponentView.vue @@ -10,6 +10,38 @@ ID: {{segment.id}} + + + + + + +
Edit Segments
+

+ Update the segments that this boundary joins. +

+
+ + + + + + + +
+
+
+
@@ -18,6 +50,9 @@ diff --git a/quasar-app/src/render/mapRenderer.js b/quasar-app/src/render/mapRenderer.js index f6b5d4e..b79fd31 100644 --- a/quasar-app/src/render/mapRenderer.js +++ b/quasar-app/src/render/mapRenderer.js @@ -23,7 +23,7 @@ const hoveredElements = []; export function initMap(rs) { railSystem = rs; console.log("Initializing map for rail system: " + rs.name); - hoveredElements.length = 0; + resetView(); mapCanvas = document.getElementById("railSystemMapCanvas"); mapContainerDiv = document.getElementById("railSystemMapCanvasContainer"); mapCanvas.removeEventListener("wheel", onMouseWheel); @@ -39,6 +39,16 @@ export function initMap(rs) { draw(); } +function resetView() { + mapTranslation.x = 0; + mapTranslation.y = 0; + mapDragOrigin = null; + mapDragTranslation = null; + lastMousePoint = new DOMPoint(0, 0, 0, 0); + hoveredElements.length = 0; + mapScaleIndex = SCALE_INDEX_NORMAL; +} + export function draw() { if (!(mapCanvas && railSystem && railSystem.components)) { console.warn("Attempted to draw map without canvas or railSystem."); diff --git a/src/main/java/nl/andrewl/railsignalapi/rest/SegmentsApiController.java b/src/main/java/nl/andrewl/railsignalapi/rest/SegmentsApiController.java index 46f7c40..3d9cef8 100644 --- a/src/main/java/nl/andrewl/railsignalapi/rest/SegmentsApiController.java +++ b/src/main/java/nl/andrewl/railsignalapi/rest/SegmentsApiController.java @@ -36,4 +36,9 @@ public class SegmentsApiController { segmentService.remove(rsId, sId); return ResponseEntity.noContent().build(); } + + @PatchMapping(path = "/{sId}/occupied") + public FullSegmentResponse toggleOccupied(@PathVariable long rsId, @PathVariable long sId) { + return segmentService.toggleOccupied(rsId, sId); + } } diff --git a/src/main/java/nl/andrewl/railsignalapi/service/SegmentService.java b/src/main/java/nl/andrewl/railsignalapi/service/SegmentService.java index 47be561..1ec8b7a 100644 --- a/src/main/java/nl/andrewl/railsignalapi/service/SegmentService.java +++ b/src/main/java/nl/andrewl/railsignalapi/service/SegmentService.java @@ -76,6 +76,16 @@ public class SegmentService { } } + @Transactional + public FullSegmentResponse toggleOccupied(long rsId, long sId) { + var segment = segmentRepository.findByIdAndRailSystemId(sId, rsId) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND)); + segment.setOccupied(!segment.isOccupied()); + segmentRepository.save(segment); + sendSegmentOccupiedStatus(segment); + return new FullSegmentResponse(segment); + } + /** * Handles updates from segment boundary components. * @param msg The update message.