-
-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
247 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<ons-page id="segment-edit-map-page"> | ||
<div id="segment-edit-container"> | ||
<div class="segment-edit-header"> | ||
<ons-back-button>Forbidden Markers</ons-back-button> | ||
<span id="segment-edit-map-page-h1"></span> | ||
</div> | ||
|
||
<ons-progress-bar id="loading-bar-segment-edit" value="0"></ons-progress-bar> | ||
<canvas id="segment-edit-map"></canvas> | ||
</div> | ||
|
||
<div class="map-page-buttons"> | ||
<ons-fab ripple id="segment-edit-add-split-line"> | ||
<ons-icon icon="fa-arrows-h"></ons-icon> | ||
</ons-fab> | ||
<ons-fab ripple id="segment-edit-split"> | ||
<ons-icon icon="fa-cut"></ons-icon> | ||
</ons-fab> | ||
<ons-fab ripple id="segment-edit-join"> | ||
<ons-icon icon="fa-object-group"></ons-icon> | ||
</ons-fab> | ||
</div> | ||
|
||
<script> | ||
{ | ||
let s = document.createElement('script'); | ||
s.src = "segment-edit-map.js"; | ||
s.type = "module"; | ||
s.crossOrigin = "use-credentials"; | ||
ons.getScriptPage().appendChild(s); | ||
s.onreadystatechange = s.onload = () => { window.markerConfigInit(); }; | ||
} | ||
</script> | ||
<style> | ||
#segment-edit-container { | ||
display: grid; | ||
grid-template-columns: 1fr; | ||
grid-template-rows: auto auto 1fr; | ||
|
||
height: 100%; | ||
width: 100%; | ||
} | ||
|
||
#segment-edit-map { | ||
touch-action: none; | ||
height: 100%; | ||
width: 100%; | ||
} | ||
|
||
#segment-edit-map-page-h1 { | ||
flex-grow: 1; | ||
text-align: center; | ||
} | ||
|
||
.segment-edit-header { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.segment-edit-buttons { | ||
position: absolute; | ||
right: 1.5em; | ||
bottom: 1.5em; | ||
display: grid; | ||
grid-template-columns: auto; | ||
grid-template-rows: auto; | ||
grid-gap: 0.5em; | ||
} | ||
</style> | ||
</ons-page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/*global ons, fn*/ | ||
import {VacuumMap} from "./zone/js-modules/vacuum-map.js"; | ||
import {ApiService} from "./services/api.service.js"; | ||
|
||
function markerConfigInit() { | ||
const map = new VacuumMap(document.getElementById("segment-edit-map")); | ||
const loadingBarSegmentEdit = document.getElementById("loading-bar-segment-edit"); | ||
|
||
const topPage = fn.getTopPage(); | ||
const mapData = JSON.parse(JSON.stringify(topPage.data.map)); //cloned for good measure | ||
|
||
mapData.layers.forEach(layer => { | ||
if (layer.type === "segment") { | ||
layer.metaData.active = false; | ||
} | ||
}); | ||
|
||
map.initCanvas(mapData, {metaData: "segments", noGotoPoints: true}); | ||
window.fn.map = map; | ||
|
||
document.getElementById("segment-edit-map-page-h1").innerText = "Editing Segments"; | ||
|
||
document.getElementById("segment-edit-add-split-line").onclick = () => { | ||
if (map.getLocations().virtualWalls.length === 0) { | ||
map.addVirtualWall(null, false, true); | ||
} else { | ||
ons.notification.toast("There can only be one split line.",{buttonLabel: "Dismiss", timeout: window.fn.toastErrorTimeout}); | ||
} | ||
}; | ||
|
||
document.getElementById("segment-edit-split").onclick = async () => { | ||
let locations = map.getLocations(); | ||
|
||
if (locations.selectedSegments.length === 1) { | ||
if (locations.virtualWalls.length === 1) { | ||
loadingBarSegmentEdit.setAttribute("indeterminate", "indeterminate"); | ||
|
||
try { | ||
await ApiService.splitSegment( | ||
{ | ||
x: locations.virtualWalls[0][0], | ||
y: locations.virtualWalls[0][1] | ||
}, | ||
{ | ||
x: locations.virtualWalls[0][2], | ||
y: locations.virtualWalls[0][3] | ||
}, | ||
locations.selectedSegments[0].id | ||
); | ||
await ons.notification.toast( | ||
"Successfully split segment!", | ||
{buttonLabel: "Dismiss", timeout: window.fn.toastOKTimeout}); | ||
fn.popPage(); | ||
} catch (err) { | ||
ons.notification.toast(err.message, {buttonLabel: "Dismiss", timeout: window.fn.toastErrorTimeout}); | ||
} finally { | ||
loadingBarSegmentEdit.removeAttribute("indeterminate"); | ||
} | ||
} else { | ||
ons.notification.toast("You need to have a split line to split",{buttonLabel: "Dismiss", timeout: window.fn.toastErrorTimeout}); | ||
} | ||
} else { | ||
ons.notification.toast("You need to select exactly one segment to execute a split",{buttonLabel: "Dismiss", timeout: window.fn.toastErrorTimeout}); | ||
} | ||
}; | ||
|
||
document.getElementById("segment-edit-join").onclick = async () => { | ||
let locations = map.getLocations(); | ||
|
||
if (locations.selectedSegments.length === 2) { | ||
loadingBarSegmentEdit.setAttribute("indeterminate", "indeterminate"); | ||
|
||
try { | ||
await ApiService.joinSegments( | ||
locations.selectedSegments[0].id, | ||
locations.selectedSegments[1].id | ||
); | ||
await ons.notification.toast( | ||
"Successfully joined segment!", | ||
{buttonLabel: "Dismiss", timeout: window.fn.toastOKTimeout}); | ||
fn.popPage(); | ||
} catch (err) { | ||
ons.notification.toast(err.message, {buttonLabel: "Dismiss", timeout: window.fn.toastErrorTimeout}); | ||
} finally { | ||
loadingBarSegmentEdit.removeAttribute("indeterminate"); | ||
} | ||
} else { | ||
ons.notification.toast("You need to select exactly two segment to execute a join",{buttonLabel: "Dismiss", timeout: window.fn.toastErrorTimeout}); | ||
} | ||
}; | ||
|
||
/* | ||
saveButton.onclick = async () => { | ||
loadingBarSaveMarkers.setAttribute("indeterminate", "indeterminate"); | ||
saveButton.setAttribute("disabled", "disabled"); | ||
try { | ||
await ApiService.setPersistentData( | ||
map.getLocations().virtualWalls, | ||
map.getLocations().forbiddenZones, | ||
map.getLocations().forbiddenMopZones | ||
); | ||
await ons.notification.toast( | ||
"Successfully saved forbidden markers!", | ||
{buttonLabel: "Dismiss", timeout: window.fn.toastOKTimeout}); | ||
fn.popPage(); | ||
} catch (err) { | ||
ons.notification.toast(err.message, {buttonLabel: "Dismiss", timeout: window.fn.toastErrorTimeout}); | ||
} finally { | ||
loadingBarSaveMarkers.removeAttribute("indeterminate"); | ||
saveButton.removeAttribute("disabled"); | ||
} | ||
}; */ | ||
} | ||
|
||
window.markerConfigInit = markerConfigInit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters