Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add localstorage and reset #4

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions function/LocalStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const resetDiagram = () => {
localStorage.clear();
location.reload();
};

const localStorageSize = () => {
var _lsTotal = 0,
_xLen,
_x;
for (_x in localStorage) {
if (!localStorage.hasOwnProperty(_x)) {
continue;
}
_xLen = (localStorage[_x].length + _x.length) * 2;
_lsTotal += _xLen;
console.log(
_x.substr(0, 50) + " = " + (_xLen / 1024).toFixed(2) + " KB"
);
}
console.log("Total = " + (_lsTotal / 1024).toFixed(2) + " KB");
};
6 changes: 4 additions & 2 deletions function/actors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
let actors = [];
const actorContainer = document.querySelector("#actor-container");
let actors = JSON.parse(localStorage.getItem("actors")) || [];

const updateActorTitles = () => {
const actorTitles = document.querySelectorAll(".actor-title-span");
Expand All @@ -12,12 +11,15 @@ const updateActorTitles = () => {

const createActor = () => {
// Create a new actor object
const actorContainer = document.querySelector("#actor-container");
const actor = {
id: Math.floor(Math.random() * 10000),
name: "",
role: "",
};

console.log(actor);
andredevsantos marked this conversation as resolved.
Show resolved Hide resolved

actors.push(actor);
// Appends new actor input form
actorContainer.innerHTML += createActorElement(actor);
Expand Down
5 changes: 5 additions & 0 deletions function/diagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const createSwimlane = () => {
canvas.innerHTML += createSwimlaneElement(actor);
});
replaceBoxes();
console.log(touchpoints);
console.log(actors);
andredevsantos marked this conversation as resolved.
Show resolved Hide resolved
localStorage.setItem("touchpoints", JSON.stringify(touchpoints));
localStorage.setItem("actors", JSON.stringify(actors));
localStorage.setItem("modal", document.querySelector(".modal").innerHTML);
};

const createSwimlaneElement = (actor) => {
Expand Down
10 changes: 9 additions & 1 deletion function/touchpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ const TouchpointType = {
communication: "communication",
};

let touchpoints = [];
let touchpoints = JSON.parse(localStorage.getItem("touchpoints")) || [];

if (actors.length > 0 || touchpoints.length > 0) {
console.log(1);
console.log(actors);
console.log(touchpoints);
andredevsantos marked this conversation as resolved.
Show resolved Hide resolved
document.querySelector(".modal").innerHTML = localStorage.getItem("modal");
}

let titleNos = [];
const touchpointContainer = document.querySelector("#touchpoint-container");

Expand Down
9 changes: 7 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item ">
<button type="button" class="btn btn-primary" data-bs-toggle="modal"
data-bs-target="#staticBackdrop" id="start"> Start/Edit </button>
data-bs-target="#staticBackdrop" id="start""> Start/Edit </button>
</li>
<li class="nav-item">
<li class=" nav-item ">
<button type=" button" class="btn btn-danger" id="restart" onclick="resetDiagram()">
Reset </button>
</li>
<li class=" nav-item">
<a class="nav-link" id="export-xml" href="#" onclick="exportXML()">Export XML</a>
</li>
<li class="nav-item">
Expand Down Expand Up @@ -191,6 +195,7 @@ <h3>Touchpoints
crossorigin="anonymous"></script>
<script src="https://cdn.bootcss.com/jquery/1.12.1/jquery.min.js"></script>
<script src="function/exportPng.js"></script>
<script src="function/LocalStorage.js"></script>
</body>

</html>