Update
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
--title-text: #00ff00;
|
||||
--input-bg: #111111;
|
||||
--status-bg: #1b1b1b;
|
||||
--board-bg: #0a2c14;
|
||||
--board-bg: #0b2f16;
|
||||
--card-bg: #171717;
|
||||
--card-text: #00ff66;
|
||||
}
|
||||
@@ -107,41 +107,12 @@ body {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.config-window {
|
||||
width: 100%;
|
||||
max-width: 980px;
|
||||
}
|
||||
|
||||
.intro-copy {
|
||||
font-size: 1.3rem;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.room-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.config-layout {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 320px;
|
||||
gap: 12px;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.config-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.field-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.field-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -155,6 +126,7 @@ legend {
|
||||
|
||||
input[type="text"],
|
||||
input[type="number"],
|
||||
input[type="password"],
|
||||
select {
|
||||
background: var(--input-bg);
|
||||
color: var(--window-text);
|
||||
@@ -166,8 +138,7 @@ select {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
input[type="text"]:focus,
|
||||
input[type="number"]:focus,
|
||||
input:focus,
|
||||
select:focus {
|
||||
box-shadow: inset 0 0 0 1px var(--title-bg);
|
||||
}
|
||||
@@ -211,6 +182,76 @@ input[type="number"]::-webkit-inner-spin-button {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.btn {
|
||||
background: var(--window-bg);
|
||||
color: var(--window-text);
|
||||
border: 2px solid;
|
||||
border-color: var(--border-light) var(--border-dark) var(--border-dark) var(--border-light);
|
||||
box-shadow: inset 1px 1px var(--border-mid-light), inset -1px -1px var(--border-mid-dark);
|
||||
padding: 4px 12px;
|
||||
font-size: 1.2rem;
|
||||
cursor: pointer;
|
||||
margin-left: 6px;
|
||||
}
|
||||
|
||||
.btn:active {
|
||||
border-color: var(--border-dark) var(--border-light) var(--border-light) var(--border-dark);
|
||||
box-shadow: inset 1px 1px var(--border-mid-dark), inset -1px -1px var(--border-mid-light);
|
||||
padding: 5px 11px 3px 13px;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.actions-row {
|
||||
text-align: right;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.status-line {
|
||||
background: var(--status-bg);
|
||||
border: 2px solid;
|
||||
border-color: var(--border-dark) var(--border-light) var(--border-light) var(--border-dark);
|
||||
padding: 5px 8px;
|
||||
font-size: 1.1rem;
|
||||
min-height: 30px;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Config page */
|
||||
.config-window {
|
||||
width: 100%;
|
||||
max-width: 980px;
|
||||
}
|
||||
|
||||
.intro-copy {
|
||||
font-size: 1.3rem;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.config-layout {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 320px;
|
||||
gap: 12px;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.config-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.field-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.options-box {
|
||||
padding: 8px;
|
||||
}
|
||||
@@ -284,8 +325,12 @@ input[type="number"]::-webkit-inner-spin-button {
|
||||
font-weight: bold;
|
||||
box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5);
|
||||
user-select: none;
|
||||
transition: transform 180ms ease, opacity 180ms ease;
|
||||
cursor: default;
|
||||
transition: transform 180ms ease;
|
||||
cursor: grab;
|
||||
}
|
||||
|
||||
.preview-card.dragging {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.preview-card-remove {
|
||||
@@ -315,8 +360,22 @@ input[type="number"]::-webkit-inner-spin-button {
|
||||
}
|
||||
|
||||
.preview-card.is-removing {
|
||||
opacity: 0;
|
||||
transform: scale(0.55) rotate(-8deg);
|
||||
animation: card-pop-out 190ms ease forwards;
|
||||
}
|
||||
|
||||
@keyframes card-pop-out {
|
||||
from {
|
||||
opacity: 1;
|
||||
transform: scale(1) rotate(0deg);
|
||||
}
|
||||
to {
|
||||
opacity: 0;
|
||||
transform: scale(0.58) rotate(-10deg);
|
||||
}
|
||||
}
|
||||
|
||||
.hint-text {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.card-editor {
|
||||
@@ -335,73 +394,145 @@ input[type="number"]::-webkit-inner-spin-button {
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.status-line {
|
||||
background: var(--status-bg);
|
||||
border: 2px solid;
|
||||
border-color: var(--border-dark) var(--border-light) var(--border-light) var(--border-dark);
|
||||
padding: 5px 8px;
|
||||
font-size: 1.1rem;
|
||||
min-height: 30px;
|
||||
/* Room page */
|
||||
.room-desktop {
|
||||
align-items: stretch;
|
||||
justify-content: center;
|
||||
padding-top: 60px;
|
||||
}
|
||||
|
||||
.actions-row {
|
||||
text-align: right;
|
||||
margin-top: 4px;
|
||||
.room-grid {
|
||||
width: min(1180px, 100%);
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
grid-template-columns: 2fr 1fr;
|
||||
grid-template-rows: auto auto;
|
||||
grid-template-areas:
|
||||
"main participants"
|
||||
"controls participants";
|
||||
}
|
||||
|
||||
.btn {
|
||||
background: var(--window-bg);
|
||||
color: var(--window-text);
|
||||
border: 2px solid;
|
||||
border-color: var(--border-light) var(--border-dark) var(--border-dark) var(--border-light);
|
||||
box-shadow: inset 1px 1px var(--border-mid-light), inset -1px -1px var(--border-mid-dark);
|
||||
padding: 4px 12px;
|
||||
font-size: 1.2rem;
|
||||
cursor: pointer;
|
||||
margin-left: 6px;
|
||||
.room-main-window {
|
||||
grid-area: main;
|
||||
}
|
||||
|
||||
.btn:active {
|
||||
border-color: var(--border-dark) var(--border-light) var(--border-light) var(--border-dark);
|
||||
box-shadow: inset 1px 1px var(--border-mid-dark), inset -1px -1px var(--border-mid-light);
|
||||
padding: 5px 11px 3px 13px;
|
||||
.participants-window {
|
||||
grid-area: participants;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
font-weight: bold;
|
||||
.control-window {
|
||||
grid-area: controls;
|
||||
}
|
||||
|
||||
.taskbar {
|
||||
height: 30px;
|
||||
background: var(--window-bg);
|
||||
border-top: 2px solid var(--border-light);
|
||||
box-shadow: inset 0 1px var(--border-mid-light);
|
||||
.room-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 3px 6px;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 10px;
|
||||
font-size: 1.15rem;
|
||||
}
|
||||
|
||||
.taskbar-start,
|
||||
.taskbar-status {
|
||||
.voting-board {
|
||||
background: var(--board-bg);
|
||||
border: 2px solid;
|
||||
border-color: var(--border-light) var(--border-dark) var(--border-dark) var(--border-light);
|
||||
box-shadow: inset 1px 1px var(--border-mid-light), inset -1px -1px var(--border-mid-dark);
|
||||
padding: 0 8px;
|
||||
font-size: 1.1rem;
|
||||
height: 20px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
border-color: var(--border-dark) var(--border-light) var(--border-light) var(--border-dark);
|
||||
min-height: 260px;
|
||||
padding: 12px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
align-content: flex-start;
|
||||
}
|
||||
|
||||
.taskbar-status {
|
||||
min-width: 180px;
|
||||
.vote-card {
|
||||
width: 72px;
|
||||
height: 100px;
|
||||
border-radius: 6px;
|
||||
border: 2px solid #000;
|
||||
background: var(--card-bg);
|
||||
color: var(--card-text);
|
||||
font-size: 2rem;
|
||||
box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.45);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.vote-card:hover {
|
||||
transform: translateY(-3px);
|
||||
}
|
||||
|
||||
.vote-card.is-selected {
|
||||
outline: 3px solid #ffd200;
|
||||
}
|
||||
|
||||
.participants-content {
|
||||
max-height: 520px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.participant-list {
|
||||
list-style: none;
|
||||
background: var(--input-bg);
|
||||
border: 2px solid;
|
||||
border-color: var(--border-dark) var(--border-light) var(--border-light) var(--border-dark);
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.participant-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 5px;
|
||||
border-bottom: 1px dashed var(--border-mid-dark);
|
||||
font-size: 1.15rem;
|
||||
}
|
||||
|
||||
.participant-item:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.control-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.links-block {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.links-block input {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.admin-controls {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.join-window {
|
||||
position: fixed;
|
||||
z-index: 30;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
width: min(420px, 92vw);
|
||||
}
|
||||
|
||||
#join-error {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.config-layout {
|
||||
.config-layout,
|
||||
.room-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.room-grid {
|
||||
grid-template-areas:
|
||||
"main"
|
||||
"participants"
|
||||
"controls";
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
|
||||
184
static/js/app.js
184
static/js/app.js
@@ -1,184 +0,0 @@
|
||||
const themeToggleBtn = document.getElementById('theme-toggle');
|
||||
const roomConfigForm = document.getElementById('room-config-form');
|
||||
const statusLine = document.getElementById('config-status');
|
||||
const scaleSelect = document.getElementById('estimation-scale');
|
||||
const maxPeopleInput = document.getElementById('max-people');
|
||||
const previewScale = document.getElementById('preview-scale');
|
||||
const previewMaxPeople = document.getElementById('preview-max-people');
|
||||
const previewCards = document.getElementById('preview-cards');
|
||||
const customCardInput = document.getElementById('custom-card');
|
||||
const addCardButton = document.getElementById('add-card');
|
||||
|
||||
const SCALE_PRESETS = {
|
||||
fibonacci: ['0', '1', '2', '3', '5', '8', '13', '21', '?'],
|
||||
tshirt: ['XS', 'S', 'M', 'L', 'XL', '?'],
|
||||
'powers-of-two': ['1', '2', '4', '8', '16', '32', '?'],
|
||||
};
|
||||
|
||||
let isDarkMode = false;
|
||||
let nextCardID = 1;
|
||||
let currentCards = [];
|
||||
|
||||
themeToggleBtn.addEventListener('click', () => {
|
||||
isDarkMode = !isDarkMode;
|
||||
if (isDarkMode) {
|
||||
document.documentElement.setAttribute('data-theme', 'dark');
|
||||
themeToggleBtn.textContent = 'Light Mode';
|
||||
return;
|
||||
}
|
||||
|
||||
document.documentElement.removeAttribute('data-theme');
|
||||
themeToggleBtn.textContent = 'Dark Mode';
|
||||
});
|
||||
|
||||
function createCard(value) {
|
||||
return { id: nextCardID++, value: value.toString() };
|
||||
}
|
||||
|
||||
function getCardsForScale(scale) {
|
||||
return (SCALE_PRESETS[scale] || SCALE_PRESETS.fibonacci).map(createCard);
|
||||
}
|
||||
|
||||
function captureCardPositions() {
|
||||
const positions = new Map();
|
||||
previewCards.querySelectorAll('.preview-card').forEach((el) => {
|
||||
positions.set(el.dataset.cardId, el.getBoundingClientRect());
|
||||
});
|
||||
return positions;
|
||||
}
|
||||
|
||||
function animateCardReflow(previousPositions) {
|
||||
previewCards.querySelectorAll('.preview-card').forEach((el) => {
|
||||
const oldRect = previousPositions.get(el.dataset.cardId);
|
||||
if (!oldRect) {
|
||||
el.style.opacity = '0';
|
||||
el.style.transform = 'scale(0.85)';
|
||||
requestAnimationFrame(() => {
|
||||
el.style.opacity = '1';
|
||||
el.style.transform = 'translate(0, 0) scale(1)';
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const newRect = el.getBoundingClientRect();
|
||||
const deltaX = oldRect.left - newRect.left;
|
||||
const deltaY = oldRect.top - newRect.top;
|
||||
|
||||
if (deltaX === 0 && deltaY === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
el.style.transform = `translate(${deltaX}px, ${deltaY}px)`;
|
||||
requestAnimationFrame(() => {
|
||||
el.style.transform = 'translate(0, 0)';
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function renderCards(previousPositions = new Map()) {
|
||||
previewCards.innerHTML = '';
|
||||
|
||||
currentCards.forEach((card) => {
|
||||
const cardEl = document.createElement('div');
|
||||
cardEl.className = 'preview-card';
|
||||
cardEl.dataset.cardId = String(card.id);
|
||||
cardEl.textContent = card.value;
|
||||
|
||||
const removeBtn = document.createElement('button');
|
||||
removeBtn.type = 'button';
|
||||
removeBtn.className = 'preview-card-remove';
|
||||
removeBtn.textContent = 'X';
|
||||
removeBtn.setAttribute('aria-label', `Remove card ${card.value}`);
|
||||
removeBtn.addEventListener('click', (event) => {
|
||||
event.stopPropagation();
|
||||
removeCard(card.id);
|
||||
});
|
||||
|
||||
cardEl.appendChild(removeBtn);
|
||||
previewCards.appendChild(cardEl);
|
||||
});
|
||||
|
||||
animateCardReflow(previousPositions);
|
||||
}
|
||||
|
||||
function removeCard(cardID) {
|
||||
const cardEl = previewCards.querySelector(`[data-card-id="${cardID}"]`);
|
||||
if (!cardEl) {
|
||||
return;
|
||||
}
|
||||
|
||||
cardEl.classList.add('is-removing');
|
||||
|
||||
window.setTimeout(() => {
|
||||
const previousPositions = captureCardPositions();
|
||||
currentCards = currentCards.filter((card) => card.id !== cardID);
|
||||
renderCards(previousPositions);
|
||||
}, 160);
|
||||
}
|
||||
|
||||
function resetCardsForCurrentScale() {
|
||||
const previousPositions = captureCardPositions();
|
||||
currentCards = getCardsForScale(scaleSelect.value);
|
||||
renderCards(previousPositions);
|
||||
}
|
||||
|
||||
function updatePreviewMeta() {
|
||||
previewScale.textContent = `Scale: ${scaleSelect.value}`;
|
||||
previewMaxPeople.textContent = `Max: ${maxPeopleInput.value || 0}`;
|
||||
}
|
||||
|
||||
addCardButton.addEventListener('click', () => {
|
||||
const value = customCardInput.value.trim();
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
|
||||
const previousPositions = captureCardPositions();
|
||||
currentCards.push(createCard(value.slice(0, 8)));
|
||||
renderCards(previousPositions);
|
||||
customCardInput.value = '';
|
||||
customCardInput.focus();
|
||||
});
|
||||
|
||||
customCardInput.addEventListener('keydown', (event) => {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
addCardButton.click();
|
||||
}
|
||||
});
|
||||
|
||||
scaleSelect.addEventListener('change', () => {
|
||||
resetCardsForCurrentScale();
|
||||
updatePreviewMeta();
|
||||
statusLine.textContent = 'Card deck reset to selected estimation scale.';
|
||||
});
|
||||
|
||||
maxPeopleInput.addEventListener('input', () => {
|
||||
updatePreviewMeta();
|
||||
});
|
||||
|
||||
roomConfigForm.addEventListener('submit', (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
const formData = new FormData(roomConfigForm);
|
||||
const roomName = (formData.get('roomName') || '').toString().trim();
|
||||
const username = (formData.get('username') || '').toString().trim();
|
||||
|
||||
if (!roomName || !username) {
|
||||
statusLine.textContent = 'Please fill in both room name and username.';
|
||||
return;
|
||||
}
|
||||
|
||||
statusLine.textContent = `Room "${roomName}" prepared by ${username} with ${currentCards.length} cards.`;
|
||||
});
|
||||
|
||||
roomConfigForm.addEventListener('reset', () => {
|
||||
window.setTimeout(() => {
|
||||
updatePreviewMeta();
|
||||
resetCardsForCurrentScale();
|
||||
statusLine.textContent = 'Room settings reset to defaults.';
|
||||
}, 0);
|
||||
});
|
||||
|
||||
updatePreviewMeta();
|
||||
resetCardsForCurrentScale();
|
||||
260
static/js/config.js
Normal file
260
static/js/config.js
Normal file
@@ -0,0 +1,260 @@
|
||||
const USERNAME_KEY = 'scrumPoker.username';
|
||||
|
||||
const SCALE_PRESETS = {
|
||||
fibonacci: ['0', '1', '2', '3', '5', '8', '13', '21', '?'],
|
||||
tshirt: ['XS', 'S', 'M', 'L', 'XL', '?'],
|
||||
'powers-of-two': ['1', '2', '4', '8', '16', '32', '?'],
|
||||
};
|
||||
|
||||
const themeToggleBtn = document.getElementById('theme-toggle');
|
||||
const roomConfigForm = document.getElementById('room-config-form');
|
||||
const statusLine = document.getElementById('config-status');
|
||||
const scaleSelect = document.getElementById('estimation-scale');
|
||||
const maxPeopleInput = document.getElementById('max-people');
|
||||
const previewScale = document.getElementById('preview-scale');
|
||||
const previewMaxPeople = document.getElementById('preview-max-people');
|
||||
const previewCards = document.getElementById('preview-cards');
|
||||
const customCardInput = document.getElementById('custom-card');
|
||||
const addCardButton = document.getElementById('add-card');
|
||||
const usernameInput = document.getElementById('username');
|
||||
|
||||
let isDarkMode = false;
|
||||
let nextCardID = 1;
|
||||
let currentCards = [];
|
||||
let draggingCardID = '';
|
||||
|
||||
const savedUsername = localStorage.getItem(USERNAME_KEY);
|
||||
if (savedUsername && !usernameInput.value) {
|
||||
usernameInput.value = savedUsername;
|
||||
}
|
||||
|
||||
themeToggleBtn.addEventListener('click', () => {
|
||||
isDarkMode = !isDarkMode;
|
||||
if (isDarkMode) {
|
||||
document.documentElement.setAttribute('data-theme', 'dark');
|
||||
themeToggleBtn.textContent = 'Light Mode';
|
||||
return;
|
||||
}
|
||||
|
||||
document.documentElement.removeAttribute('data-theme');
|
||||
themeToggleBtn.textContent = 'Dark Mode';
|
||||
});
|
||||
|
||||
function createCard(value) {
|
||||
return { id: String(nextCardID++), value: value.toString() };
|
||||
}
|
||||
|
||||
function getCardsForScale(scale) {
|
||||
return (SCALE_PRESETS[scale] || SCALE_PRESETS.fibonacci).map(createCard);
|
||||
}
|
||||
|
||||
function captureCardPositions() {
|
||||
const positions = new Map();
|
||||
previewCards.querySelectorAll('.preview-card').forEach((el) => {
|
||||
positions.set(el.dataset.cardId, el.getBoundingClientRect());
|
||||
});
|
||||
return positions;
|
||||
}
|
||||
|
||||
function animateReflow(previousPositions) {
|
||||
previewCards.querySelectorAll('.preview-card').forEach((el) => {
|
||||
const previousRect = previousPositions.get(el.dataset.cardId);
|
||||
if (!previousRect) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nextRect = el.getBoundingClientRect();
|
||||
const deltaX = previousRect.left - nextRect.left;
|
||||
const deltaY = previousRect.top - nextRect.top;
|
||||
if (!deltaX && !deltaY) {
|
||||
return;
|
||||
}
|
||||
|
||||
el.style.transform = `translate(${deltaX}px, ${deltaY}px)`;
|
||||
requestAnimationFrame(() => {
|
||||
el.style.transform = 'translate(0, 0)';
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function removeCard(cardID) {
|
||||
const cardEl = previewCards.querySelector(`[data-card-id="${cardID}"]`);
|
||||
if (!cardEl) {
|
||||
return;
|
||||
}
|
||||
|
||||
cardEl.classList.add('is-removing');
|
||||
cardEl.addEventListener('animationend', () => {
|
||||
const previousPositions = captureCardPositions();
|
||||
currentCards = currentCards.filter((card) => card.id !== cardID);
|
||||
renderCards(previousPositions);
|
||||
}, { once: true });
|
||||
}
|
||||
|
||||
function reorderCard(fromID, toID) {
|
||||
if (fromID === toID) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fromIndex = currentCards.findIndex((card) => card.id === fromID);
|
||||
const toIndex = currentCards.findIndex((card) => card.id === toID);
|
||||
if (fromIndex < 0 || toIndex < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const previousPositions = captureCardPositions();
|
||||
const [moved] = currentCards.splice(fromIndex, 1);
|
||||
currentCards.splice(toIndex, 0, moved);
|
||||
renderCards(previousPositions);
|
||||
}
|
||||
|
||||
function buildCardElement(card) {
|
||||
const cardEl = document.createElement('div');
|
||||
cardEl.className = 'preview-card';
|
||||
cardEl.dataset.cardId = card.id;
|
||||
cardEl.textContent = card.value;
|
||||
cardEl.draggable = true;
|
||||
|
||||
const removeBtn = document.createElement('button');
|
||||
removeBtn.type = 'button';
|
||||
removeBtn.className = 'preview-card-remove';
|
||||
removeBtn.textContent = 'X';
|
||||
removeBtn.setAttribute('aria-label', `Remove ${card.value}`);
|
||||
removeBtn.addEventListener('click', (event) => {
|
||||
event.stopPropagation();
|
||||
removeCard(card.id);
|
||||
});
|
||||
|
||||
cardEl.addEventListener('dragstart', () => {
|
||||
draggingCardID = card.id;
|
||||
cardEl.classList.add('dragging');
|
||||
});
|
||||
|
||||
cardEl.addEventListener('dragend', () => {
|
||||
draggingCardID = '';
|
||||
cardEl.classList.remove('dragging');
|
||||
});
|
||||
|
||||
cardEl.addEventListener('dragover', (event) => {
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
cardEl.addEventListener('drop', (event) => {
|
||||
event.preventDefault();
|
||||
if (!draggingCardID) {
|
||||
return;
|
||||
}
|
||||
reorderCard(draggingCardID, card.id);
|
||||
});
|
||||
|
||||
cardEl.appendChild(removeBtn);
|
||||
return cardEl;
|
||||
}
|
||||
|
||||
function renderCards(previousPositions = new Map()) {
|
||||
previewCards.innerHTML = '';
|
||||
currentCards.forEach((card) => {
|
||||
previewCards.appendChild(buildCardElement(card));
|
||||
});
|
||||
|
||||
animateReflow(previousPositions);
|
||||
}
|
||||
|
||||
function resetCardsForScale() {
|
||||
const previousPositions = captureCardPositions();
|
||||
currentCards = getCardsForScale(scaleSelect.value);
|
||||
renderCards(previousPositions);
|
||||
}
|
||||
|
||||
function updatePreviewMeta() {
|
||||
previewScale.textContent = `Scale: ${scaleSelect.value}`;
|
||||
previewMaxPeople.textContent = `Max: ${maxPeopleInput.value || 0}`;
|
||||
}
|
||||
|
||||
addCardButton.addEventListener('click', () => {
|
||||
const value = customCardInput.value.trim();
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
|
||||
const previousPositions = captureCardPositions();
|
||||
currentCards.push(createCard(value.slice(0, 8)));
|
||||
renderCards(previousPositions);
|
||||
customCardInput.value = '';
|
||||
customCardInput.focus();
|
||||
});
|
||||
|
||||
customCardInput.addEventListener('keydown', (event) => {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
addCardButton.click();
|
||||
}
|
||||
});
|
||||
|
||||
scaleSelect.addEventListener('change', () => {
|
||||
resetCardsForScale();
|
||||
updatePreviewMeta();
|
||||
statusLine.textContent = 'Card deck reset to selected estimation scale.';
|
||||
});
|
||||
|
||||
maxPeopleInput.addEventListener('input', updatePreviewMeta);
|
||||
|
||||
roomConfigForm.addEventListener('submit', async (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
const formData = new FormData(roomConfigForm);
|
||||
const username = (formData.get('username') || '').toString().trim();
|
||||
const roomName = (formData.get('roomName') || '').toString().trim();
|
||||
|
||||
if (!username || !roomName) {
|
||||
statusLine.textContent = 'Room name and username are required.';
|
||||
return;
|
||||
}
|
||||
|
||||
localStorage.setItem(USERNAME_KEY, username);
|
||||
|
||||
const payload = {
|
||||
roomName,
|
||||
creatorUsername: username,
|
||||
maxPeople: Number(formData.get('maxPeople') || 50),
|
||||
cards: currentCards.map((card) => card.value),
|
||||
allowSpectators: Boolean(formData.get('allowSpectators')),
|
||||
anonymousVoting: Boolean(formData.get('anonymousVoting')),
|
||||
autoReset: Boolean(formData.get('autoReset')),
|
||||
revealMode: (formData.get('revealMode') || 'manual').toString(),
|
||||
votingTimeoutSec: Number(formData.get('votingTimeoutSec') || 0),
|
||||
password: (formData.get('password') || '').toString(),
|
||||
};
|
||||
|
||||
statusLine.textContent = 'Creating room...';
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/rooms', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
statusLine.textContent = data.error || 'Failed to create room.';
|
||||
return;
|
||||
}
|
||||
|
||||
const target = `/room/${encodeURIComponent(data.roomId)}?participantId=${encodeURIComponent(data.creatorParticipantId)}&adminToken=${encodeURIComponent(data.adminToken)}`;
|
||||
window.location.assign(target);
|
||||
} catch (err) {
|
||||
statusLine.textContent = 'Network error while creating room.';
|
||||
}
|
||||
});
|
||||
|
||||
roomConfigForm.addEventListener('reset', () => {
|
||||
window.setTimeout(() => {
|
||||
updatePreviewMeta();
|
||||
resetCardsForScale();
|
||||
statusLine.textContent = 'Room settings reset to defaults.';
|
||||
}, 0);
|
||||
});
|
||||
|
||||
updatePreviewMeta();
|
||||
resetCardsForScale();
|
||||
306
static/js/room.js
Normal file
306
static/js/room.js
Normal file
@@ -0,0 +1,306 @@
|
||||
const USERNAME_KEY = 'scrumPoker.username';
|
||||
|
||||
const roomID = document.body.dataset.roomId;
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
|
||||
const themeToggleBtn = document.getElementById('theme-toggle');
|
||||
const roomTitle = document.getElementById('room-title');
|
||||
const revealModeLabel = document.getElementById('reveal-mode-label');
|
||||
const roundStateLabel = document.getElementById('round-state-label');
|
||||
const votingBoard = document.getElementById('voting-board');
|
||||
const participantList = document.getElementById('participant-list');
|
||||
const adminControls = document.getElementById('admin-controls');
|
||||
const revealBtn = document.getElementById('reveal-btn');
|
||||
const resetBtn = document.getElementById('reset-btn');
|
||||
const participantLinkInput = document.getElementById('participant-link');
|
||||
const adminLinkInput = document.getElementById('admin-link');
|
||||
const roomStatus = document.getElementById('room-status');
|
||||
|
||||
const joinPanel = document.getElementById('join-panel');
|
||||
const joinForm = document.getElementById('join-form');
|
||||
const joinUsernameInput = document.getElementById('join-username');
|
||||
const joinRoleInput = document.getElementById('join-role');
|
||||
const joinPasswordInput = document.getElementById('join-password');
|
||||
const joinAdminTokenInput = document.getElementById('join-admin-token');
|
||||
const joinError = document.getElementById('join-error');
|
||||
|
||||
let isDarkMode = false;
|
||||
let participantID = params.get('participantId') || '';
|
||||
let adminToken = params.get('adminToken') || '';
|
||||
let eventSource = null;
|
||||
let latestState = null;
|
||||
|
||||
themeToggleBtn.addEventListener('click', () => {
|
||||
isDarkMode = !isDarkMode;
|
||||
if (isDarkMode) {
|
||||
document.documentElement.setAttribute('data-theme', 'dark');
|
||||
themeToggleBtn.textContent = 'Light Mode';
|
||||
return;
|
||||
}
|
||||
|
||||
document.documentElement.removeAttribute('data-theme');
|
||||
themeToggleBtn.textContent = 'Dark Mode';
|
||||
});
|
||||
|
||||
const savedUsername = localStorage.getItem(USERNAME_KEY) || '';
|
||||
joinUsernameInput.value = savedUsername;
|
||||
joinAdminTokenInput.value = adminToken;
|
||||
|
||||
function setJoinError(message) {
|
||||
if (!message) {
|
||||
joinError.classList.add('hidden');
|
||||
joinError.textContent = '';
|
||||
return;
|
||||
}
|
||||
|
||||
joinError.classList.remove('hidden');
|
||||
joinError.textContent = message;
|
||||
}
|
||||
|
||||
function updateURL() {
|
||||
const next = new URL(window.location.href);
|
||||
if (participantID) {
|
||||
next.searchParams.set('participantId', participantID);
|
||||
} else {
|
||||
next.searchParams.delete('participantId');
|
||||
}
|
||||
if (adminToken) {
|
||||
next.searchParams.set('adminToken', adminToken);
|
||||
} else {
|
||||
next.searchParams.delete('adminToken');
|
||||
}
|
||||
window.history.replaceState({}, '', next.toString());
|
||||
}
|
||||
|
||||
async function joinRoom({ username, role, password, participantIdOverride }) {
|
||||
const response = await fetch(`/api/rooms/${encodeURIComponent(roomID)}/join`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
participantId: participantIdOverride || participantID,
|
||||
username,
|
||||
role,
|
||||
password,
|
||||
adminToken,
|
||||
}),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error || 'Unable to join room.');
|
||||
}
|
||||
|
||||
participantID = data.participantId;
|
||||
if (data.isAdmin && !adminToken) {
|
||||
adminToken = joinAdminTokenInput.value.trim();
|
||||
}
|
||||
|
||||
localStorage.setItem(USERNAME_KEY, data.username);
|
||||
updateURL();
|
||||
joinPanel.classList.add('hidden');
|
||||
setJoinError('');
|
||||
}
|
||||
|
||||
function renderParticipants(participants, isRevealed) {
|
||||
participantList.innerHTML = '';
|
||||
participants.forEach((participant) => {
|
||||
const item = document.createElement('li');
|
||||
item.className = 'participant-item';
|
||||
|
||||
const name = document.createElement('span');
|
||||
let label = participant.username;
|
||||
if (participant.id === participantID) {
|
||||
label += ' (You)';
|
||||
}
|
||||
if (participant.isAdmin) {
|
||||
label += ' [Admin]';
|
||||
}
|
||||
name.textContent = label;
|
||||
|
||||
const status = document.createElement('span');
|
||||
if (participant.role === 'viewer') {
|
||||
status.textContent = 'Viewer';
|
||||
} else if (!participant.hasVoted) {
|
||||
status.textContent = 'Voting...';
|
||||
} else if (isRevealed) {
|
||||
status.textContent = participant.voteValue || '-';
|
||||
} else {
|
||||
status.textContent = participant.voteValue ? `Voted (${participant.voteValue})` : 'Voted';
|
||||
}
|
||||
|
||||
item.appendChild(name);
|
||||
item.appendChild(status);
|
||||
participantList.appendChild(item);
|
||||
});
|
||||
}
|
||||
|
||||
function renderCards(cards, participants, isRevealed) {
|
||||
const self = participants.find((participant) => participant.id === participantID);
|
||||
const canVote = self && self.role === 'participant';
|
||||
const selfVote = self ? self.voteValue : '';
|
||||
|
||||
votingBoard.innerHTML = '';
|
||||
cards.forEach((value) => {
|
||||
const card = document.createElement('button');
|
||||
card.type = 'button';
|
||||
card.className = 'vote-card';
|
||||
card.textContent = value;
|
||||
|
||||
if (selfVote === value && !isRevealed) {
|
||||
card.classList.add('is-selected');
|
||||
}
|
||||
|
||||
card.disabled = !canVote;
|
||||
card.addEventListener('click', () => castVote(value));
|
||||
votingBoard.appendChild(card);
|
||||
});
|
||||
}
|
||||
|
||||
function renderState(state) {
|
||||
latestState = state;
|
||||
roomTitle.textContent = `${state.roomName} (${state.roomId})`;
|
||||
revealModeLabel.textContent = `Reveal mode: ${state.revealMode}`;
|
||||
roundStateLabel.textContent = state.revealed ? 'Cards revealed' : 'Cards hidden';
|
||||
|
||||
renderParticipants(state.participants, state.revealed);
|
||||
renderCards(state.cards, state.participants, state.revealed);
|
||||
|
||||
participantLinkInput.value = `${window.location.origin}${state.links.participantLink}`;
|
||||
adminLinkInput.value = state.links.adminLink ? `${window.location.origin}${state.links.adminLink}` : '';
|
||||
|
||||
if (state.viewerIsAdmin) {
|
||||
adminControls.classList.remove('hidden');
|
||||
} else {
|
||||
adminControls.classList.add('hidden');
|
||||
}
|
||||
|
||||
const votedCount = state.participants.filter((p) => p.role === 'participant' && p.hasVoted).length;
|
||||
const totalParticipants = state.participants.filter((p) => p.role === 'participant').length;
|
||||
roomStatus.textContent = `Votes: ${votedCount}/${totalParticipants}`;
|
||||
}
|
||||
|
||||
function connectSSE() {
|
||||
if (eventSource) {
|
||||
eventSource.close();
|
||||
}
|
||||
|
||||
eventSource = new EventSource(`/api/rooms/${encodeURIComponent(roomID)}/events?participantId=${encodeURIComponent(participantID)}`);
|
||||
eventSource.addEventListener('state', (event) => {
|
||||
try {
|
||||
const payload = JSON.parse(event.data);
|
||||
renderState(payload);
|
||||
} catch (_err) {
|
||||
roomStatus.textContent = 'Failed to parse room update.';
|
||||
}
|
||||
});
|
||||
|
||||
eventSource.onerror = () => {
|
||||
roomStatus.textContent = 'Connection interrupted. Retrying...';
|
||||
};
|
||||
}
|
||||
|
||||
async function castVote(card) {
|
||||
if (!participantID) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/rooms/${encodeURIComponent(roomID)}/vote`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ participantId: participantID, card }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const data = await response.json();
|
||||
roomStatus.textContent = data.error || 'Vote rejected.';
|
||||
}
|
||||
} catch (_err) {
|
||||
roomStatus.textContent = 'Network error while casting vote.';
|
||||
}
|
||||
}
|
||||
|
||||
async function adminAction(action) {
|
||||
if (!participantID) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/rooms/${encodeURIComponent(roomID)}/${action}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ participantId: participantID }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const data = await response.json();
|
||||
roomStatus.textContent = data.error || `Unable to ${action}.`;
|
||||
}
|
||||
} catch (_err) {
|
||||
roomStatus.textContent = 'Network error while sending admin action.';
|
||||
}
|
||||
}
|
||||
|
||||
revealBtn.addEventListener('click', () => adminAction('reveal'));
|
||||
resetBtn.addEventListener('click', () => adminAction('reset'));
|
||||
|
||||
joinForm.addEventListener('submit', async (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
const username = joinUsernameInput.value.trim();
|
||||
if (!username) {
|
||||
setJoinError('Username is required.');
|
||||
return;
|
||||
}
|
||||
|
||||
adminToken = joinAdminTokenInput.value.trim();
|
||||
|
||||
try {
|
||||
await joinRoom({
|
||||
username,
|
||||
role: joinRoleInput.value,
|
||||
password: joinPasswordInput.value,
|
||||
});
|
||||
connectSSE();
|
||||
} catch (err) {
|
||||
setJoinError(err.message);
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('pagehide', () => {
|
||||
if (!participantID) {
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = JSON.stringify({ participantId: participantID });
|
||||
navigator.sendBeacon(`/api/rooms/${encodeURIComponent(roomID)}/leave`, new Blob([payload], { type: 'application/json' }));
|
||||
});
|
||||
|
||||
async function bootstrap() {
|
||||
if (!participantID) {
|
||||
joinPanel.classList.remove('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!savedUsername) {
|
||||
joinPanel.classList.remove('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await joinRoom({
|
||||
username: savedUsername,
|
||||
role: 'participant',
|
||||
password: '',
|
||||
participantIdOverride: participantID,
|
||||
});
|
||||
connectSSE();
|
||||
} catch (_err) {
|
||||
participantID = '';
|
||||
updateURL();
|
||||
joinPanel.classList.remove('hidden');
|
||||
setJoinError('Please join this room to continue.');
|
||||
}
|
||||
}
|
||||
|
||||
bootstrap();
|
||||
Reference in New Issue
Block a user