Update
This commit is contained in:
41
static/js/cards.js
Normal file
41
static/js/cards.js
Normal file
@@ -0,0 +1,41 @@
|
||||
(() => {
|
||||
const CARD_ICONS = ['★', '◆', '✦', '☀', '☘', '⚙', '♣', '♠', '♥', '♦', '✚', '⚡', '☾', '✿'];
|
||||
|
||||
function iconForValue(value) {
|
||||
const normalized = String(value || '');
|
||||
if (normalized === '?') return '❓';
|
||||
if (normalized === '☕') return '☕';
|
||||
if (normalized === '∞') return '∞';
|
||||
|
||||
let hash = 0;
|
||||
for (let i = 0; i < normalized.length; i += 1) {
|
||||
hash = (hash * 31 + normalized.charCodeAt(i)) >>> 0;
|
||||
}
|
||||
return CARD_ICONS[hash % CARD_ICONS.length];
|
||||
}
|
||||
|
||||
function appendFace(el, value) {
|
||||
const normalized = String(value || '');
|
||||
|
||||
const topLeft = document.createElement('span');
|
||||
topLeft.className = 'card-corner top-left';
|
||||
topLeft.textContent = normalized;
|
||||
|
||||
const center = document.createElement('span');
|
||||
center.className = 'card-center-icon';
|
||||
center.textContent = iconForValue(normalized);
|
||||
|
||||
const bottomRight = document.createElement('span');
|
||||
bottomRight.className = 'card-corner bottom-right';
|
||||
bottomRight.textContent = normalized;
|
||||
|
||||
el.appendChild(topLeft);
|
||||
el.appendChild(center);
|
||||
el.appendChild(bottomRight);
|
||||
}
|
||||
|
||||
window.CardUI = {
|
||||
iconForValue,
|
||||
appendFace,
|
||||
};
|
||||
})();
|
||||
@@ -13,8 +13,6 @@ const SPECIAL_CARD_ORDER = {
|
||||
'☕': 3,
|
||||
};
|
||||
|
||||
const CARD_ICONS = ['★', '◆', '✦', '☀', '☘', '⚙', '♣', '♠', '♥', '♦', '✚', '⚡', '☾', '✿'];
|
||||
|
||||
const roomConfigForm = document.getElementById('room-config-form');
|
||||
const statusLine = document.getElementById('config-status');
|
||||
const scaleSelect = document.getElementById('estimation-scale');
|
||||
@@ -49,6 +47,10 @@ if (savedUsername && !usernameInput.value) {
|
||||
usernameInput.value = savedUsername;
|
||||
}
|
||||
|
||||
if (!window.CardUI || typeof window.CardUI.appendFace !== 'function') {
|
||||
throw new Error('CardUI is not loaded. Ensure /static/js/cards.js is included before config.js.');
|
||||
}
|
||||
|
||||
|
||||
function parseNumericCard(value) {
|
||||
if (!/^-?\d+(\.\d+)?$/.test(value)) {
|
||||
@@ -84,36 +86,6 @@ function createCard(value) {
|
||||
return { id: String(nextCardID++), value: value.toString() };
|
||||
}
|
||||
|
||||
function iconForCard(value) {
|
||||
if (value === '?') return '❓';
|
||||
if (value === '☕') return '☕';
|
||||
if (value === '∞') return '∞';
|
||||
|
||||
let hash = 0;
|
||||
for (let i = 0; i < value.length; i += 1) {
|
||||
hash = (hash * 31 + value.charCodeAt(i)) >>> 0;
|
||||
}
|
||||
return CARD_ICONS[hash % CARD_ICONS.length];
|
||||
}
|
||||
|
||||
function appendCardFace(el, value) {
|
||||
const topLeft = document.createElement('span');
|
||||
topLeft.className = 'card-corner top-left';
|
||||
topLeft.textContent = value;
|
||||
|
||||
const center = document.createElement('span');
|
||||
center.className = 'card-center-icon';
|
||||
center.textContent = iconForCard(value);
|
||||
|
||||
const bottomRight = document.createElement('span');
|
||||
bottomRight.className = 'card-corner bottom-right';
|
||||
bottomRight.textContent = value;
|
||||
|
||||
el.appendChild(topLeft);
|
||||
el.appendChild(center);
|
||||
el.appendChild(bottomRight);
|
||||
}
|
||||
|
||||
function getCardsForScale(scale) {
|
||||
return (SCALE_PRESETS[scale] || SCALE_PRESETS.fibonacci).map(createCard);
|
||||
}
|
||||
@@ -190,7 +162,7 @@ function buildCardElement(card) {
|
||||
cardEl.className = 'preview-card';
|
||||
cardEl.dataset.cardId = card.id;
|
||||
cardEl.draggable = true;
|
||||
appendCardFace(cardEl, card.value);
|
||||
window.CardUI.appendFace(cardEl, card.value);
|
||||
|
||||
const removeBtn = document.createElement('button');
|
||||
removeBtn.type = 'button';
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const USERNAME_KEY = 'scrumPoker.username';
|
||||
const CARD_ICONS = ['★', '◆', '✦', '☀', '☘', '⚙', '♣', '♠', '♥', '♦', '✚', '⚡', '☾', '✿'];
|
||||
|
||||
const roomID = document.body.dataset.roomId;
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
@@ -37,6 +36,10 @@ const savedUsername = localStorage.getItem(USERNAME_KEY) || '';
|
||||
joinUsernameInput.value = savedUsername;
|
||||
joinAdminTokenInput.value = adminToken;
|
||||
|
||||
if (!window.CardUI || typeof window.CardUI.appendFace !== 'function') {
|
||||
throw new Error('CardUI is not loaded. Ensure /static/js/cards.js is included before room.js.');
|
||||
}
|
||||
|
||||
|
||||
function setJoinError(message) {
|
||||
if (!message) {
|
||||
@@ -100,7 +103,8 @@ async function joinRoom({ username, role, password, participantIdOverride }) {
|
||||
function renderParticipants(participants, isRevealed) {
|
||||
participantList.innerHTML = '';
|
||||
|
||||
participants.forEach((participant) => {
|
||||
const visibleParticipants = participants.filter((participant) => participant.connected);
|
||||
visibleParticipants.forEach((participant) => {
|
||||
const item = document.createElement('li');
|
||||
item.className = 'participant-item';
|
||||
|
||||
@@ -138,41 +142,15 @@ function parseNumericVote(value) {
|
||||
return Number(value);
|
||||
}
|
||||
|
||||
function iconForCard(value) {
|
||||
if (value === '?') return '❓';
|
||||
if (value === '☕') return '☕';
|
||||
if (value === '∞') return '∞';
|
||||
|
||||
let hash = 0;
|
||||
for (let i = 0; i < value.length; i += 1) {
|
||||
hash = (hash * 31 + value.charCodeAt(i)) >>> 0;
|
||||
}
|
||||
return CARD_ICONS[hash % CARD_ICONS.length];
|
||||
}
|
||||
|
||||
function appendCardFace(el, value) {
|
||||
const topLeft = document.createElement('span');
|
||||
topLeft.className = 'card-corner top-left';
|
||||
topLeft.textContent = value;
|
||||
|
||||
const center = document.createElement('span');
|
||||
center.className = 'card-center-icon';
|
||||
center.textContent = iconForCard(value);
|
||||
|
||||
const bottomRight = document.createElement('span');
|
||||
bottomRight.className = 'card-corner bottom-right';
|
||||
bottomRight.textContent = value;
|
||||
|
||||
el.appendChild(topLeft);
|
||||
el.appendChild(center);
|
||||
el.appendChild(bottomRight);
|
||||
}
|
||||
|
||||
function calculateSummary(state) {
|
||||
const rows = new Map();
|
||||
const numericVotes = [];
|
||||
|
||||
state.participants.forEach((participant) => {
|
||||
if (!participant.connected) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (participant.role !== 'participant' || !participant.hasVoted || !participant.voteValue) {
|
||||
return;
|
||||
}
|
||||
@@ -242,7 +220,7 @@ function renderSummary(state) {
|
||||
}
|
||||
|
||||
function renderCards(cards, participants, isRevealed) {
|
||||
const self = participants.find((participant) => participant.id === participantID);
|
||||
const self = participants.find((participant) => participant.id === participantID && participant.connected);
|
||||
const canVote = self && self.role === 'participant';
|
||||
const selfVote = self ? self.voteValue : '';
|
||||
|
||||
@@ -253,7 +231,7 @@ function renderCards(cards, participants, isRevealed) {
|
||||
card.type = 'button';
|
||||
card.className = 'vote-card';
|
||||
card.setAttribute('aria-label', `Vote ${value}`);
|
||||
appendCardFace(card, value);
|
||||
window.CardUI.appendFace(card, value);
|
||||
|
||||
if (selfVote === value && !isRevealed) {
|
||||
card.classList.add('is-selected');
|
||||
@@ -289,8 +267,8 @@ function renderState(state) {
|
||||
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;
|
||||
const votedCount = state.participants.filter((p) => p.connected && p.role === 'participant' && p.hasVoted).length;
|
||||
const totalParticipants = state.participants.filter((p) => p.connected && p.role === 'participant').length;
|
||||
roomStatus.textContent = `Votes: ${votedCount}/${totalParticipants}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user