Skip to content

Commit

Permalink
feat: implement history of queries
Browse files Browse the repository at this point in the history
Signed-off-by: WoodenMaiden <yann.pomie@laposte.net>
  • Loading branch information
WoodenMaiden committed Jun 14, 2024
1 parent 3994a17 commit 11b9b67
Showing 3 changed files with 550 additions and 481 deletions.
71 changes: 62 additions & 9 deletions agrold-javaweb/src/main/webapp/localStoreConsent.html
Original file line number Diff line number Diff line change
@@ -7,18 +7,18 @@
we treat your data with the utmost care and are transparent about how we handle it.
You can add accept the treatment of your data by clicking on the Accept button, reject it or learn more about it.
</p>
<button onclick="acceptAllData()" type="button" class="btn btn-outline-success">Accept</button>
<button onclick="acceptLocalStorage(false)" type="button" class="btn btn-outline-danger">Reject</button>
<button type="button" class="btn btn-outline-secondary" data-toggle="modal" data-target="#labelstoreModal">Learn more</button>
<button onclick="acceptAllData()" type="button" class="btn btn-success">Accept</button>
<button onclick="acceptLocalStorage(false)" type="button" class="btn btn-danger">Reject</button>
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#labelstoreModal">Learn more</button>
</div>
</div>
<div class="modal fade" id="labelstoreModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form id="labelstore-form">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
<button id="close-storage-modal" type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Modal title</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body text-center">
To improve your experience on our site, we would like to store certain data in your
@@ -33,12 +33,65 @@ <h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-outline-secondary">Accept Selected</button>
<button onclick="acceptAllData()" data-dismiss="modal" type="button" class="btn btn-outline-success">Accept All</button>
<button onclick="acceptLocalStorage(false)" data-dismiss="modal" type="button" class="btn btn-outline-danger">Reject All</button>
<button type="submit" class="btn btn-info">Accept Selected</button>
<button onclick="acceptAllData()" data-dismiss="modal" type="button" class="btn btn-success">Accept All</button>
<button onclick="acceptLocalStorage(false)" data-dismiss="modal" type="button" class="btn btn-danger">Reject All</button>
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript" src="scripts/localStorage.js"></script>
<script type="text/javascript" src="scripts/localStorage.js">
const acceptFromSelection = (e) => {
e.preventDefault()

acceptData(
Object.entries(
Object.fromEntries(new FormData(e.target)) // retireve the form data
).filter(([_, value]) => value === "on").map(([key, _]) => key) // only keep ticked checkboxes
)

$("#labelstoreModal").modal('hide')
return false
}

/// popup setup
const popup = document.getElementById("localStorage-ask")
document.getElementById("labelstore-form")?.addEventListener("submit", acceptFromSelection)

// v question unanswered
if(isLocalStorageAvailable() && sessionStorage.getItem("acceptLocalStorage") === null){
if (popup) popup.style.visibility = "visible";

const consentList = document.getElementById('consent-inputs')

Object.entries(LocalStorageDataConsent).forEach(([key, value]) => {
consentList.appendChild(
document.createElement("hr")
)
const input = document.createElement("input");
Object.entries({
class: "form-check-input",
type: "checkbox",
role: "switch",
style: "margin: 5px;",
id: key,
name: key,
checked: "true",
}).forEach(([key, value]) => input.setAttribute(key, value))

consentList.appendChild(input)

const label = document.createElement("label")
Object.entries({
class: "form-check-label",
for: key,
}).forEach(([key, value]) => input.setAttribute(key, value))

label.textContent = value
consentList.appendChild(label)
})
} else {
if (popup) popup.style.display = "none";
}
</script>
54 changes: 0 additions & 54 deletions agrold-javaweb/src/main/webapp/scripts/localStorage.js
Original file line number Diff line number Diff line change
@@ -58,57 +58,3 @@ const acceptAllData = () => {
acceptData(defaultLocalStorageData)
}

const acceptFromSelection = (e) => {
e.preventDefault()

acceptData(
Object.entries(
Object.fromEntries(new FormData(e.target)) // retireve the form data
).filter(([_, value]) => value === "on").map(([key, _]) => key) // only keep ticked checkboxes
)

// ugly but hey that works!
// we cannot acutally close the modal from the form in bootstrap
document.getElementById("close-storage-modal")?.click()
return false
}

/// popup setup
const popup = document.getElementById("localStorage-ask")
document.getElementById("labelstore-form")?.addEventListener("submit", acceptFromSelection)

// v question unanswered
if(isLocalStorageAvailable() && sessionStorage.getItem("acceptLocalStorage") === null){
if (popup) popup.style.visibility = "visible";

const consentList = document.getElementById('consent-inputs')

Object.entries(LocalStorageDataConsent).forEach(([key, value]) => {
consentList.appendChild(
document.createElement("hr")
)
const input = document.createElement("input");
Object.entries({
class: "form-check-input",
type: "checkbox",
role: "switch",
style: "margin: 5px;",
id: key,
name: key,
checked: "true",
}).forEach(([key, value]) => input.setAttribute(key, value))

consentList.appendChild(input)

const label = document.createElement("label")
Object.entries({
class: "form-check-label",
for: key,
}).forEach(([key, value]) => input.setAttribute(key, value))

label.textContent = value
consentList.appendChild(label)
})
} else {
if (popup) popup.style.display = "none";
}
Loading
Oops, something went wrong.

0 comments on commit 11b9b67

Please sign in to comment.