updated relative rank
This commit is contained in:
@@ -1,13 +1,86 @@
|
||||
.item {
|
||||
border: 1px solid black;
|
||||
width: fit-content;
|
||||
list-style: none;
|
||||
padding: 5px;
|
||||
margin: 5px 0;
|
||||
border: 1px solid lightgrey;
|
||||
min-width: 6em;
|
||||
width: fit-content;
|
||||
list-style: none;
|
||||
padding: 5px;
|
||||
margin: 5px 0;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.rank {
|
||||
list-style: none;
|
||||
margin-top: 10px;
|
||||
min-width: 6em;
|
||||
width: 120px;
|
||||
height: 10px;
|
||||
background: red;
|
||||
position: relative;
|
||||
border-radius: 10px;
|
||||
}
|
||||
.rank::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
right: 0%;
|
||||
top: -7.5px;
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
border-radius: 50%;
|
||||
background: red;
|
||||
}
|
||||
|
||||
.flex-container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-around;
|
||||
}
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.unranked-items {
|
||||
flex-grow: 1;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ranked-items {
|
||||
flex-grow: 1;
|
||||
text-align: center;
|
||||
}
|
||||
#unranked-items {
|
||||
display: inline-block;
|
||||
min-height: 7rem;
|
||||
min-width: 7em;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
#ranked-items {
|
||||
display: inline-block;
|
||||
min-height: 7rem;
|
||||
min-width: 12em;
|
||||
}
|
||||
|
||||
#add-btn {
|
||||
background: #03df4d;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
#clear-btn {
|
||||
background: #e62d2d;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.delete {
|
||||
border: none;
|
||||
background: none;
|
||||
}
|
||||
|
||||
.delete:hover {
|
||||
border: none;
|
||||
background: darkgray;
|
||||
}
|
||||
|
||||
.rank-btns {
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
background: #03df4d;
|
||||
}
|
||||
|
||||
@@ -59,14 +59,7 @@ main {
|
||||
}
|
||||
/* styles.css */
|
||||
|
||||
#add-rank-btn, #save-btn {
|
||||
background-color: #7A288A; /* This is a deep purple color */
|
||||
border-color: #7A288A;
|
||||
}
|
||||
|
||||
#add-rank-btn:hover, #save-btn:hover {
|
||||
background-color: #55107B; /* This is a darker shade of purple for hover effect */
|
||||
}
|
||||
|
||||
li .nav {
|
||||
list-style: none;
|
||||
|
||||
@@ -1,3 +1,109 @@
|
||||
const unranked = document.getElementById("unranked-items");
|
||||
const ranked = document.getElementById("ranked-items");
|
||||
const ranks = document.getElementById("ranks");
|
||||
const addItemButton = document.getElementById("add-btn");
|
||||
const clearButton = document.getElementById("clear-btn");
|
||||
const lockButton = document.getElementById("lock-rank-btn");
|
||||
const addRankButton = document.getElementById("add-rank-btn");
|
||||
const saveButton = document.getElementById("save-rank-btn");
|
||||
let locked = false;
|
||||
const unrankedPool = new Sortable(unranked, {
|
||||
group: 'items',
|
||||
animation: 100,
|
||||
sort: false
|
||||
})
|
||||
|
||||
const rankedPool = new Sortable(ranked, {
|
||||
group: 'items',
|
||||
animation: 100
|
||||
})
|
||||
|
||||
const ranksPool = new Sortable(ranks, {
|
||||
group: {
|
||||
name: 'items-sorted',
|
||||
},
|
||||
animation: 100,
|
||||
|
||||
sort: false
|
||||
})
|
||||
|
||||
addItemButton.addEventListener("click", () => {
|
||||
const newItem = prompt("Name of new item: ");
|
||||
if (newItem) {
|
||||
let total = Array.from(unranked.children).length + Array.from(ranked.children).length;
|
||||
const li = document.createElement("li");
|
||||
li.className = "item";
|
||||
li.textContent = newItem;
|
||||
li.draggable = true;
|
||||
li.id = String(total) + "-item";
|
||||
const btn = document.createElement("button");
|
||||
btn.className = "delete";
|
||||
btn.textContent = "X";
|
||||
btn.id = String(total) + "-delete";
|
||||
btn.setAttribute("onClick", "deleteItem(id);");
|
||||
li.appendChild(btn);
|
||||
unranked.appendChild(li);
|
||||
}
|
||||
})
|
||||
|
||||
clearButton.addEventListener("click", () => {
|
||||
const userConsent = confirm("Are you sure you want to clear all items from Unranked List?");
|
||||
if (userConsent) {
|
||||
Array.from(unranked.children).forEach((value) => {
|
||||
document.getElementById(value.id).remove()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
lockButton.addEventListener("click", () => {
|
||||
if (locked) {
|
||||
rankedPool.options.group.name = "items";
|
||||
rankedPool.options.filter = ".rank";
|
||||
lockButton.innerText = "Lock Ranks";
|
||||
Array.from(ranked.children).forEach((value) => {
|
||||
if (value.className === "item") {
|
||||
value.children[0].hidden = false;
|
||||
}
|
||||
})
|
||||
locked = false;
|
||||
} else {
|
||||
rankedPool.options.group.name = "items-sorted";
|
||||
rankedPool.options.filter = ".item";
|
||||
lockButton.innerText = "Unlock Ranks";
|
||||
Array.from(ranked.children).forEach((value) => {
|
||||
if (value.className === "item") {
|
||||
value.children[0].hidden = true;
|
||||
}
|
||||
})
|
||||
locked = true;
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
function deleteItem(id) {
|
||||
//console.log("kill me ("+ id + ")")
|
||||
const userConsent = confirm("Are you sure?");
|
||||
if (userConsent) {
|
||||
let liId = id.split("-")[0] + "-item";
|
||||
document.getElementById(liId).remove()
|
||||
//need to handle the id's naming
|
||||
let index = 0;
|
||||
Array.from(unranked.children).forEach((value) => {
|
||||
value.id = index + "-item";
|
||||
value.children[0].id = index + "-delete";
|
||||
index++;
|
||||
})
|
||||
Array.from(ranked.children).forEach((value) => {
|
||||
if(value.className === "item"){
|
||||
value.id = index + "-item";
|
||||
value.children[0].id = index + "-delete";
|
||||
index++;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/* Basic dragging list options
|
||||
function dragstart_handler(ev) {
|
||||
console.log("dragStart");
|
||||
// Change the source element's background color to signify drag has started
|
||||
@@ -22,7 +128,7 @@ function drop_handler(ev) {
|
||||
// payload by the dragstart event handler)
|
||||
var id = ev.dataTransfer.getData("text");
|
||||
// Only Move the element if the source and destination ids are both "move"
|
||||
if (id == "src_move" && ev.target.id == "drop-target"){
|
||||
if (id.includes("src_move") && ev.target.id == "drop-target"){
|
||||
ev.target.appendChild(document.getElementById(id));
|
||||
ev.target.style.background = "white";
|
||||
}
|
||||
@@ -38,4 +144,4 @@ function dragend_handler(ev) {
|
||||
// Restore source's border
|
||||
//ev.target.style.border = "solid black";
|
||||
ev.target.style.background = "white";
|
||||
}
|
||||
} */
|
||||
@@ -58,6 +58,11 @@ addRankBtn.addEventListener("click", () => {
|
||||
document.getElementById("save-btn").addEventListener("click", () => {
|
||||
// Get ranked items
|
||||
const rankedItems = Array.from(rankingArea.children).map((item) => item.textContent.trim());
|
||||
const ranks = Array.from(ranksPool.children).map((item) => parseInt(item.lastElementChild.value || "0"));
|
||||
Array.from(ranks).forEach((item, index) => {
|
||||
console.log([item, index])
|
||||
|
||||
});
|
||||
const sTierEnd = parseInt(document.getElementById("s-tier-end").value || "0");
|
||||
const aTierEnd = parseInt(document.getElementById("a-tier-end").value || "0");
|
||||
|
||||
@@ -92,6 +97,6 @@ document.getElementById("save-btn").addEventListener("click", () => {
|
||||
},
|
||||
body: JSON.stringify({ rankedItems, tiers }),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.catch((error) => console.error("Error:", error));
|
||||
.then((response) => response.json())
|
||||
.catch((error) => console.error("Error:", error));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user