function renderItems() { if (!items.length) return `
No items found
`; // Apply Icode filter const filteredItems = filterIcode ? items.filter(item => { const board = item.boardObj || {}; return board.Icode && parseInt(board.Icode) > 99; }) : items; // Calculate summary const totalItems = filteredItems.length; const totalProgress = filteredItems.reduce((sum, item) => { const board = item.boardObj || {}; const cupPercent = board.cup_totalRequired && board.cup_answeredRequired ? (board.cup_answeredRequired / board.cup_totalRequired * 100) : 0; const bucketPercent = board.bucket_totalRequired && board.bucket_answeredRequired ? (board.bucket_answeredRequired / board.bucket_totalRequired * 100) : 0; return sum + ((cupPercent + bucketPercent) / 2); }, 0) / (totalItems || 1); const totalDone = filteredItems.filter(item => { const board = item.boardObj || {}; const cupPercent = board.cup_totalRequired && board.cup_answeredRequired ? (board.cup_answeredRequired / board.cup_totalRequired * 100) : 0; const bucketPercent = board.bucket_totalRequired && board.bucket_answeredRequired ? (board.bucket_answeredRequired / board.bucket_totalRequired * 100) : 0; return ((cupPercent + bucketPercent) / 2) >= 100; }).length; const inProgress = filteredItems.filter(item => { const board = item.boardObj || {}; const cupPercent = board.cup_totalRequired && board.cup_answeredRequired ? (board.cup_answeredRequired / board.cup_totalRequired * 100) : 0; const bucketPercent = board.bucket_totalRequired && board.bucket_answeredRequired ? (board.bucket_answeredRequired / board.bucket_totalRequired * 100) : 0; const total = (cupPercent + bucketPercent) / 2; return total > 0 && total < 100; }).length; const notStarted = totalItems - totalDone - inProgress; // Sort filtered items const sortedItems = [...filteredItems].sort((a, b) => { const boardA = a.boardObj || {}; const boardB = b.boardObj || {}; let valueA, valueB; switch (sortField) { case 'id': valueA = a.id || ''; valueB = b.id || ''; break; case 'name': valueA = a.name || ''; valueB = b.name || ''; break; case 'boardUser': valueA = a.boardUser || ''; valueB = b.boardUser || ''; break; case 'username': valueA = boardA.user_name || ''; valueB = boardB.user_name || ''; break; case 'progress': const cupPercentA = boardA.cup_totalRequired && boardA.cup_answeredRequired ? (boardA.cup_answeredRequired / boardA.cup_totalRequired * 100) : 0; const bucketPercentA = boardA.bucket_totalRequired && boardA.bucket_answeredRequired ? (boardA.bucket_answeredRequired / boardA.bucket_totalRequired * 100) : 0; const cupPercentB = boardB.cup_totalRequired && boardB.cup_answeredRequired ? (boardB.cup_answeredRequired / boardB.cup_totalRequired * 100) : 0; const bucketPercentB = boardB.bucket_totalRequired && boardB.bucket_answeredRequired ? (boardB.bucket_answeredRequired / boardB.bucket_totalRequired * 100) : 0; valueA = (cupPercentA + bucketPercentA) / 2; valueB = (cupPercentB + bucketPercentB) / 2; break; } if (sortField !== 'progress') { valueA = valueA.toString().toLowerCase(); valueB = valueB.toString().toLowerCase(); return sortOrder === 'asc' ? valueA.localeCompare(valueB) : valueB.localeCompare(valueA); } else { return sortOrder === 'asc' ? valueA - valueB : valueB - valueA; } }); return `
Summary: Total Items (filtered): ${totalItems} | Total Progress: ${totalProgress.toFixed(1)}% | Done: ${totalDone} | In-Progress: ${inProgress}
${sortedItems.map(item => { const board = item.boardObj || {}; const cupPercent = board.cup_totalRequired && board.cup_answeredRequired ? (board.cup_answeredRequired / board.cup_totalRequired * 100).toFixed(1) : '0'; const bucketPercent = board.bucket_totalRequired && board.bucket_answeredRequired ? (board.bucket_answeredRequired / board.bucket_totalRequired * 100).toFixed(1) : '0'; const totalPercent = ((parseFloat(cupPercent) + parseFloat(bucketPercent)) / 2).toFixed(1); return `
ID: ${item.id}
${item.name || 'N/A'} | ${board.user_name || 'N/A'}
Progress: ${totalPercent}%
Profile: ${cupPercent}%
Assessment: ${bucketPercent}%
First Time: ${board.firstTime || 'N/A'}
`; }).join('')}
`; }