Virtual collection: digital version
In this previous post, I suggest an analog means of developing a prospective collection. Today, let's go digital with some basic code!...
Step 1: copy and paste the code below into a text editor (such as Notepad on the PC or Textedit on the Mac). Save as a plain text file (no rich text formatting - on the Mac this means changing the settings in Textedit and restarting the app before you begin) with the file extension '.html'.
Step 2: open the html file in a new tab in your browser. If things have worked properly, you should see a simple app which allows you upload jpg pictures of watches you like into the left hand column and then drag and drop them into the right hand column.
I am not a software developer - I just did this by prompting ChatGPT to generate the code by the way.
Enjoy! 😎
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Watch Kanban</title>
<style>
/* General styles */
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
display: flex;
justify-content: center;
align-items: flex-start;
height: 100vh;
margin: 0;
color: #333;
padding: 20px;
}
.kanban-container {
display: flex;
justify-content: space-between;
width: 80%;
max-width: 1200px;
}
.kanban-column {
width: 45%;
min-height: 400px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
overflow-y: auto;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
.kanban-column h2 {
text-align: center;
font-size: 24px;
margin-bottom: 20px;
color: #4CAF50;
}
.upload-btn {
margin-bottom: 20px;
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
.upload-btn:hover {
background-color: #45a049;
}
.image-container {
width: 100%;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 10px;
margin-top: 20px;
padding: 10px;
}
.image-item {
display: flex;
justify-content: center;
align-items: center;
cursor: grab;
transition: transform 0.2s;
position: relative;
max-width: 100%;
max-height: 300px;
padding: 10px;
box-sizing: border-box;
}
.image-item img {
width: auto;
height: auto;
max-width: 100%;
max-height: 100%;
object-fit: contain;
border-radius: 8px;
}
.kanban-column.droppable {
border: 2px dashed #4CAF50;
}
/* Drag and drop styles */
.image-item.dragging {
opacity: 0.5;
}
.kanban-column.droppable .image-item {
opacity: 1;
}
</style>
</head>
<body>
<div class="kanban-container">
<!-- Possibles Column -->
<div class="kanban-column" id="possibles" ondrop="drop(event)" ondragover="allowDrop(event)">
<h2>Possibles</h2>
<input type="file" id="upload" class="upload-btn" accept="image/*" onchange="handleFileUpload(event)">
<div class="image-container" id="possibles-images"></div>
</div>
<!-- Collection Column -->
<div class="kanban-column" id="collection" ondrop="drop(event)" ondragover="allowDrop(event)">
<h2>Collection</h2>
<div class="image-container" id="collection-images"></div>
</div>
</div>
<script>
// Handle file upload
function handleFileUpload(event) {
const files = event.target.files;
const possiblesContainer = document.getElementById("possibles-images");
for (let i = 0; i < files.length; i++) {
const file = files[i];
const reader = new FileReader();
reader.onload = function(e) {
const imgElement = document.createElement("img");
imgElement.src = e.target.result;
imgElement.setAttribute("draggable", "true");
imgElement.classList.add("image-item");
imgElement.id = "image_" + Date.now(); // Create unique ID for each image
imgElement.addEventListener("dragstart", function(ev) {
ev.dataTransfer.setData("imageId", imgElement.id); // Store image ID in dataTransfer
ev.target.classList.add("dragging");
});
imgElement.addEventListener("dragend", function(ev) {
ev.target.classList.remove("dragging");
});
possiblesContainer.appendChild(imgElement);
}
reader.readAsDataURL(file);
}
}
// Allow drop function
function allowDrop(event) {
event.preventDefault();
}
// Handle drop function
function drop(event) {
event.preventDefault();
const imageId = event.dataTransfer.getData("imageId");
const draggedImage = document.getElementById(imageId);
const targetColumn = event.target.closest(".kanban-column");
if (!targetColumn) return;
const possiblesContainer = document.getElementById("possibles-images");
const collectionContainer = document.getElementById("collection-images");
// If dragged to the Collection column
if (targetColumn.id === "collection") {
collectionContainer.appendChild(draggedImage);
}
// If dragged to the Possibles column
else if (targetColumn.id === "possibles") {
possiblesContainer.appendChild(draggedImage);
}
}
</script>
</body>
</html>
This is the prompt I used with ChatGPT. I needed to iterate a few times by getting the AI to fix things:
Create a two column kanban application for watch enthusiasts to upload watch photos and move them between a left hand column labelled ‘Possibles’ and a right hand column labelled ‘Collection’. Use only Javascript, CSS and HTML. The user should be able to drag and drop uploaded photos onto a snap-to grid. Keep the size and aspect ratio of the photos the same in both columns. Make the UI attractively styled. Consolidate the code into a single file.
RABBIT HOLE!!!
Is this like the fantasy watch collector idea I have seen pop up? We need to get watch charts involved with this.
Is this like the fantasy watch collector idea I have seen pop up? We need to get watch charts involved with this.
You could use it for that certainly. I was thinking more testing the ones you own against ones you might own, but users are free to decide!...