File size: 37,155 Bytes
e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 8a37466 e1551f7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Coach Dashboard</title>
<style>
body {
font-family: 'Roboto', Arial, sans-serif;
margin: 0;
padding: 0;
background: linear-gradient(135deg, #f0f2f5 0%, #e9ecef 100%);
color: #2d3748;
line-height: 1.6;
}
.header {
background: linear-gradient(to right, #1a3c7a, #2957a4);
padding: 15px 25px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
position: sticky;
top: 0;
z-index: 100;
}
.header-title {
color: #fff;
margin: 0;
font-size: 26px;
font-weight: 700;
text-align: center;
padding-bottom: 10px;
}
.header-actions {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
}
.avatar {
width: 42px;
height: 42px;
background: linear-gradient(to right, #f6ad55, #ed8936);
color: #fff;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
font-weight: 600;
cursor: pointer;
position: relative;
transition: transform 0.2s ease;
}
.avatar:hover {
transform: scale(1.05);
background: linear-gradient(to right, #ed8936, #dd6b20);
}
.dropdown {
display: none;
position: absolute;
top: 50px;
right: 0;
background-color: #fff;
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
border-radius: 10px;
min-width: 160px;
z-index: 101;
overflow: hidden;
}
.dropdown.active {
display: block;
}
.dropdown a {
display: block;
padding: 12px 20px;
color: #2d3748;
text-decoration: none;
font-size: 15px;
transition: background 0.3s ease;
}
.dropdown a:hover {
background-color: #f7fafc;
}
.search-container {
position: relative;
flex: 1;
max-width: 500px;
}
.search-bar {
width: 100%;
padding: 12px 45px 12px 20px;
border: 2px solid #e2e8f0;
border-radius: 25px;
font-size: 15px;
box-sizing: border-box;
transition: border-color 0.3s ease, box-shadow 0.3s ease;
background-color: #fff;
}
.search-bar:focus {
border-color: #ed8936;
outline: none;
box-shadow: 0 0 8px rgba(237, 137, 54, 0.3);
}
.mic-icon {
position: absolute;
right: 15px;
top: 50%;
transform: translateY(-50%);
width: 22px;
height: 22px;
background: url('https://img.icons8.com/ios-filled/50/000000/microphone.png') no-repeat center;
background-size: contain;
cursor: pointer;
opacity: 0.6;
transition: opacity 0.3s ease;
}
.mic-icon:hover {
opacity: 1;
}
.search-results {
position: absolute;
top: 50px;
left: 0;
right: 0;
background-color: #fff;
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
border-radius: 10px;
max-height: 220px;
overflow-y: auto;
z-index: 100;
display: none;
}
.search-results.active {
display: block;
}
.search-results p {
padding: 10px 15px;
margin: 0;
font-size: 14px;
color: #4a5568;
border-bottom: 1px solid #edf2f7;
transition: background 0.2s ease;
}
.search-results p:hover {
background-color: #f7fafc;
}
.search-results p:last-child {
border-bottom: none;
}
.action-bar {
background-color: #fff;
padding: 15px 25px;
display: flex;
justify-content: center;
gap: 20px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
position: sticky;
top: 90px;
z-index: 99;
}
.container {
max-width: 1200px;
margin: 40px auto;
padding: 0 25px;
}
.content-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 30px;
margin-bottom: 40px;
}
.section {
padding: 25px;
background-color: #fff;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
border-left: 5px solid #ed8936;
transition: transform 0.2s ease, box-shadow 0.3s ease;
}
.section:hover {
transform: translateY(-5px);
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
}
.section.full-width {
grid-column: span 2;
}
h3 {
margin: 0 0 20px 0;
color: #1a3c7a;
font-size: 22px;
font-weight: 600;
display: flex;
align-items: center;
gap: 10px;
}
h3 i {
font-size: 20px;
color: #ed8936;
}
/* Daily Checklist Section */
.checklist-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.progress-circle {
width: 50px;
height: 50px;
background: conic-gradient(#ed8936 var(--progress), #e2e8f0 0);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
font-weight: 600;
color: #2d3748;
position: relative;
}
.progress-circle::before {
content: '';
position: absolute;
width: 40px;
height: 40px;
background-color: #fff;
border-radius: 50%;
}
.progress-circle span {
position: relative;
z-index: 1;
}
.checklist-item {
display: flex;
align-items: center;
margin-bottom: 15px;
font-size: 16px;
padding: 10px;
border-radius: 8px;
transition: background 0.2s ease;
}
.checklist-item:hover {
background-color: #f7fafc;
}
.checklist-item input {
width: 20px;
height: 20px;
margin-right: 15px;
accent-color: #ed8936;
cursor: pointer;
}
.checklist-item label {
flex: 1;
color: #4a5568;
cursor: pointer;
}
.checklist-item.completed label {
text-decoration: line-through;
color: #a0aec0;
}
/* Focus Tips Section */
.tip-card {
background: linear-gradient(145deg, #e6f0fa, #d1e3ff);
padding: 20px;
border-radius: 10px;
margin-bottom: 15px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
transition: transform 0.2s ease;
}
.tip-card:hover {
transform: translateY(-3px);
}
.tip-card h4 {
margin: 0 0 15px 0;
color: #1a3c7a;
font-size: 18px;
font-weight: 600;
}
.tip-card ul {
padding-left: 20px;
margin: 0;
list-style-type: disc;
}
.tip-card li {
margin-bottom: 10px;
font-size: 15px;
color: #4a5568;
}
/* Supervisor Data Section */
pre {
background-color: #f7fafc;
padding: 15px;
border: 1px solid #e2e8f0;
border-radius: 8px;
white-space: pre-wrap;
font-size: 15px;
max-height: 250px;
overflow-y: auto;
color: #4a5568;
}
/* Reflection Journal Section */
.reflection-journal {
display: flex;
flex-direction: column;
gap: 20px;
}
.reflection-input-area {
display: flex;
flex-direction: column;
gap: 15px;
}
.reflection-journal textarea {
width: 100%;
height: 120px;
padding: 15px;
border: 2px solid #e2e8f0;
border-radius: 10px;
resize: none;
font-size: 15px;
box-sizing: border-box;
transition: border-color 0.3s ease, box-shadow 0.3s ease;
background-color: #f7fafc;
}
.reflection-journal textarea:focus {
border-color: #ed8936;
outline: none;
box-shadow: 0 0 8px rgba(237, 137, 54, 0.3);
}
.reflection-history {
max-height: 200px;
overflow-y: auto;
padding: 15px;
background-color: #f7fafc;
border-radius: 10px;
border: 1px solid #e2e8f0;
}
.reflection-entry {
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 1px solid #e2e8f0;
font-size: 14px;
color: #4a5568;
}
.reflection-entry:last-child {
border-bottom: none;
margin-bottom: 0;
}
.reflection-entry span {
font-weight: 600;
color: #2d3748;
}
/* KPI Summary Dashboard Section */
.kpi-dashboard {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
padding: 20px;
background: linear-gradient(145deg, #fff, #f7fafc);
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}
.kpi-card {
padding: 20px;
border-radius: 10px;
background-color: #fff;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
text-align: center;
transition: transform 0.2s ease;
}
.kpi-card:hover {
transform: translateY(-3px);
}
.kpi-card h4 {
margin: 0 0 10px 0;
font-size: 16px;
color: #1a3c7a;
font-weight: 600;
}
.kpi-value {
font-size: 24px;
font-weight: 700;
color: #ed8936;
margin-bottom: 10px;
}
.progress-bar {
width: 100%;
height: 8px;
background-color: #e2e8f0;
border-radius: 4px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: linear-gradient(to right, #ed8936, #f6ad55);
transition: width 0.5s ease;
}
.kpi-trend {
font-size: 13px;
color: #718096;
margin-top: 8px;
}
.kpi-flag {
display: inline-block;
padding: 5px 10px;
border-radius: 5px;
font-size: 12px;
font-weight: 600;
margin-top: 8px;
}
.kpi-flag.active {
background-color: #48bb78;
color: #fff;
}
.kpi-flag.inactive {
background-color: #f56565;
color: #fff;
}
/* Buttons */
button {
padding: 12px 25px;
background: linear-gradient(to right, #f6ad55, #ed8936);
color: #fff;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 15px;
font-weight: 600;
transition: transform 0.1s ease, background 0.3s ease;
}
button:hover {
background: linear-gradient(to right, #ed8936, #dd6b20);
transform: scale(1.02);
}
.download-btn {
background: linear-gradient(to right, #38a169, #48bb78);
}
.download-btn:hover {
background: linear-gradient(to right, #2f855a, #38a169);
}
/* Toast Notifications */
.toast {
position: fixed;
top: 20px;
right: 20px;
padding: 15px 25px;
border-radius: 8px;
z-index: 102;
display: none;
font-size: 15px;
font-weight: 500;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.toast.error {
background-color: #f56565;
color: #fff;
}
.toast.success {
background-color: #48bb78;
color: #fff;
}
.toast.visible {
display: block;
}
/* Responsive Design */
@media (max-width: 900px) {
.content-grid {
grid-template-columns: 1fr;
}
.section.full-width {
grid-column: span 1;
}
.kpi-dashboard {
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
}
@media (max-width: 700px) {
body {
padding: 0;
}
.header {
padding: 10px 15px;
}
.header-title {
font-size: 22px;
padding-bottom: 8px;
}
.header-actions {
flex-wrap: wrap;
gap: 10px;
}
.search-container {
flex: 100%;
max-width: 100%;
}
.avatar {
width: 38px;
height: 38px;
font-size: 18px;
}
.dropdown {
top: 48px;
min-width: 140px;
}
.action-bar {
top: 70px;
flex-direction: column;
gap: 10px;
padding: 10px 15px;
}
.container {
padding: 20px 15px;
margin: 15px 0;
}
h3 {
font-size: 20px;
}
.section {
padding: 20px;
}
.progress-circle {
width: 40px;
height: 40px;
font-size: 12px;
}
.progress-circle::before {
width: 32px;
height: 32px;
}
.checklist-item, .tip-card li, .reflection-journal textarea, pre {
font-size: 14px;
}
.kpi-value {
font-size: 20px;
}
.kpi-card h4 {
font-size: 14px;
}
button {
width: 100%;
padding: 10px;
font-size: 14px;
}
.toast {
top: 10px;
right: 10px;
padding: 10px 15px;
font-size: 14px;
}
}
</style>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
</head>
<body>
<div class="header">
<h2 class="header-title">AI Coach Dashboard</h2>
<div class="header-actions">
<div class="search-container">
<input type="text" class="search-bar" id="search-bar" placeholder="Search checklists, tips, reflections...">
<div class="mic-icon" onclick="simulateVoiceSearch()"></div>
<div class="search-results" id="search-results"></div>
</div>
<div class="avatar" id="avatar" onclick="toggleDropdown()">?</div>
<div class="dropdown" id="dropdown">
<a href="#" onclick="viewProfile()">View Profile</a>
<a href="#" onclick="logout()">Logout</a>
</div>
</div>
</div>
<div class="action-bar">
<button onclick="generateCoaching()">Generate Coaching Output</button>
<button class="download-btn" onclick="downloadPDF()" id="download-btn">Download PDF Summary</button>
</div>
<div class="container">
<div class="content-grid">
<!-- Daily Checklist Section -->
<div class="section checklist-section">
<div class="checklist-header">
<h3><i>📋</i> Daily Checklist</h3>
<div class="progress-circle" id="checklist-progress"><span>0%</span></div>
</div>
<div id="checklist-items"></div>
</div>
<!-- Focus Tips Section -->
<div class="section tips-section">
<h3><i>💡</i> Today's Top 3 Focus Areas</h3>
<div id="focus-tips"></div>
</div>
<!-- Supervisor Data Section -->
<div class="section full-width">
<h3><i>📊</i> Supervisor Data</h3>
<pre id="supervisor-data">Loading supervisor data...</pre>
</div>
<!-- Reflection Journal Section -->
<div class="section full-width reflection-journal">
<h3><i>📝</i> Reflection Journal</h3>
<div class="reflection-input-area">
<textarea id="reflection-input" placeholder="Log your reflections for today..."></textarea>
<button onclick="submitReflection()">Submit Reflection</button>
</div>
<div class="reflection-history" id="reflection-history">
<p>No reflections yet. Start logging your thoughts!</p>
</div>
</div>
<!-- KPI Summary Dashboard Section -->
<div class="section full-width kpi-section">
<h3><i>📈</i> KPI Summary Dashboard</h3>
<div class="kpi-dashboard" id="kpi-dashboard">
<!-- KPIs will be populated dynamically -->
</div>
</div>
</div>
</div>
<!-- Toast Notifications -->
<div id="error" class="toast error"></div>
<div id="success" class="toast success"></div>
<script>
let supervisorData = null;
let coachingOutput = null;
let reflectionHistory = [];
let checklistProgress = 0;
let totalChecklistItems = 0;
// Toast Notification Function
function showToast(id, message) {
const toast = document.getElementById(id);
toast.textContent = message;
toast.classList.add('visible');
setTimeout(() => {
toast.classList.remove('visible');
}, 3000);
}
// Set Avatar Initial
async function setAvatar() {
const avatar = document.getElementById('avatar');
try {
const response = await fetch('/get_supervisor_data');
const result = await response.json();
if (result.status === 'success' && result.data.supervisor_id !== 'GUEST') {
const username = result.data.supervisor_id.split('_')[1] || 'User';
avatar.textContent = username.charAt(0).toUpperCase();
} else {
avatar.textContent = 'G';
}
} catch (error) {
avatar.textContent = 'U';
}
}
// Dropdown Toggle
function toggleDropdown() {
const dropdown = document.getElementById('dropdown');
dropdown.classList.toggle('active');
}
function viewProfile() {
showToast('error', 'Profile view not implemented yet.');
}
async function logout() {
try {
const response = await fetch('/logout', {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
});
const result = await response.json();
if (result.status === 'success') {
window.location.href = '/login';
} else {
showToast('error', result.message);
}
} catch (error) {
showToast('error', 'Error during logout: ' + error.message);
}
}
// Search Functionality
function searchData() {
const query = document.getElementById('search-bar').value.toLowerCase().trim();
const resultsDiv = document.getElementById('search-results');
resultsDiv.innerHTML = '';
resultsDiv.classList.remove('active');
if (!query) return;
const searchableContent = [];
if (coachingOutput && coachingOutput.checklist) {
coachingOutput.checklist.forEach(item => searchableContent.push(`Checklist: ${item}`));
}
if (coachingOutput && coachingOutput.tips) {
coachingOutput.tips.forEach(tip => searchableContent.push(`Tip: ${tip}`));
}
if (supervisorData && supervisorData.reflection_log) {
searchableContent.push(`Reflection: ${supervisorData.reflection_log}`);
}
if (reflectionHistory.length > 0) {
reflectionHistory.forEach(ref => searchableContent.push(`Past Reflection: ${ref.text}`));
}
const results = searchableContent.filter(item => item.toLowerCase().includes(query));
if (results.length > 0) {
results.forEach(result => {
const p = document.createElement('p');
p.textContent = result;
resultsDiv.appendChild(p);
});
resultsDiv.classList.add('active');
} else {
const p = document.createElement('p');
p.textContent = 'No results found.';
resultsDiv.appendChild(p);
resultsDiv.classList.add('active');
}
}
function simulateVoiceSearch() {
showToast('error', 'Voice search not implemented yet.');
}
// Update Checklist Progress
function updateChecklistProgress() {
const completedItems = document.querySelectorAll('.checklist-item.completed').length;
checklistProgress = totalChecklistItems > 0 ? (completedItems / totalChecklistItems) * 100 : 0;
const progressCircle = document.getElementById('checklist-progress');
progressCircle.style.setProperty('--progress', `${checklistProgress}%`);
progressCircle.querySelector('span').textContent = `${Math.round(checklistProgress)}%`;
}
async function fetchSupervisorData() {
try {
const response = await fetch('/get_supervisor_data');
const result = await response.json();
if (result.status === 'success') {
supervisorData = result.data;
document.getElementById('supervisor-data').textContent = JSON.stringify(supervisorData, null, 2);
// Populate Daily Checklist from Salesforce
const checklistDiv = document.getElementById('checklist-items');
if (supervisorData.daily_checklist) {
const checklistItems = supervisorData.daily_checklist.split('\n').filter(item => item.trim());
totalChecklistItems = checklistItems.length;
checklistDiv.innerHTML = '';
checklistItems.forEach((item, index) => {
const itemDiv = document.createElement('div');
itemDiv.className = 'checklist-item';
itemDiv.innerHTML = `
<input type="checkbox" id="checklist-${index}" onchange="markComplete(${index}, this)">
<label for="checklist-${index}">${item}</label>
`;
checklistDiv.appendChild(itemDiv);
});
updateChecklistProgress();
} else {
checklistDiv.innerHTML = '<p>No checklist items available.</p>';
}
// Populate Focus Tips from Salesforce
const tipsDiv = document.getElementById('focus-tips');
if (supervisorData.suggested_tips) {
const tips = supervisorData.suggested_tips.split('\n').filter(tip => tip.trim());
tipsDiv.innerHTML = '';
const tipCard = document.createElement('div');
tipCard.className = 'tip-card';
tipCard.innerHTML = `
<h4>Today's Top 3 Focus Areas</h4>
<ul>
${tips.map(tip => `<li>${tip}</li>`).join('')}
</ul>
`;
tipsDiv.appendChild(tipCard);
} else {
tipsDiv.innerHTML = '<p>No focus tips available.</p>';
}
// Populate Reflection History
if (supervisorData.reflection_log) {
reflectionHistory.push({
date: new Date().toLocaleString(),
text: supervisorData.reflection_log
});
updateReflectionHistory();
}
// Update Download Link
const downloadBtn = document.getElementById('download-btn');
if (supervisorData.download_link) {
downloadBtn.onclick = () => window.open(supervisorData.download_link, '_blank');
downloadBtn.textContent = 'Download Report';
} else {
downloadBtn.onclick = downloadPDF;
downloadBtn.textContent = 'Download PDF Summary';
}
updateKPIDashboard();
} else {
showToast('error', result.message);
document.getElementById('supervisor-data').textContent = 'Failed to load supervisor data.';
}
} catch (error) {
showToast('error', 'Error fetching supervisor data: ' + error.message);
document.getElementById('supervisor-data').textContent = 'Failed to load supervisor data.';
}
}
async function generateCoaching() {
if (!supervisorData) {
showToast('error', 'Supervisor data not loaded. Please refresh the page.');
return;
}
try {
const response = await fetch('/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(supervisorData)
});
const result = await response.json();
if (result.status === 'success') {
coachingOutput = result.output;
showToast('success', 'Coaching output generated successfully!');
// Populate Daily Checklist
const checklistDiv = document.getElementById('checklist-items');
checklistDiv.innerHTML = '';
if (coachingOutput.checklist && coachingOutput.checklist.length > 0) {
totalChecklistItems = coachingOutput.checklist.length;
coachingOutput.checklist.forEach((item, index) => {
const itemDiv = document.createElement('div');
itemDiv.className = 'checklist-item';
itemDiv.innerHTML = `
<input type="checkbox" id="checklist-${index}" onchange="markComplete(${index}, this)">
<label for="checklist-${index}">${item}</label>
`;
checklistDiv.appendChild(itemDiv);
});
updateChecklistProgress();
} else {
checklistDiv.innerHTML = '<p>No checklist items available.</p>';
}
// Populate Focus Tips
const tipsDiv = document.getElementById('focus-tips');
tipsDiv.innerHTML = '';
if (coachingOutput.tips && coachingOutput.tips.length > 0) {
const tipCard = document.createElement('div');
tipCard.className = 'tip-card';
tipCard.innerHTML = `
<h4>Today's Top 3 Focus Areas</h4>
<ul>
${coachingOutput.tips.map(tip => `<li>${tip}</li>`).join('')}
</ul>
`;
tipsDiv.appendChild(tipCard);
} else {
tipsDiv.innerHTML = '<p>No focus tips available.</p>';
}
updateKPIDashboard();
} else {
showToast('error', result.message);
document.getElementById('checklist-items').innerHTML = '<p>Failed to generate checklist.</p>';
document.getElementById('focus-tips').innerHTML = '<p>Failed to generate focus tips.</p>';
}
} catch (error) {
showToast('error', 'Error generating coaching output: ' + error.message);
document.getElementById('checklist-items').innerHTML = '<p>Failed to generate checklist.</p>';
document.getElementById('focus-tips').innerHTML = '<p>Failed to generate focus tips.</p>';
}
}
function markComplete(index, checkbox) {
const itemDiv = checkbox.parentElement;
if (checkbox.checked) {
itemDiv.classList.add('completed');
} else {
itemDiv.classList.remove('completed');
}
updateChecklistProgress();
showToast('success', `Checklist item ${index + 1} marked as ${checkbox.checked ? 'complete' : 'incomplete'} (simulated).`);
}
function updateReflectionHistory() {
const historyDiv = document.getElementById('reflection-history');
historyDiv.innerHTML = '';
if (reflectionHistory.length > 0) {
reflectionHistory.forEach(ref => {
const entryDiv = document.createElement('div');
entryDiv.className = 'reflection-entry';
entryDiv.innerHTML = `<span>${ref.date}:</span> ${ref.text}`;
historyDiv.appendChild(entryDiv);
});
} else {
historyDiv.innerHTML = '<p>No reflections yet. Start logging your thoughts!</p>';
}
}
async function submitReflection() {
const reflectionInput = document.getElementById('reflection-input').value.trim();
if (!reflectionInput) {
showToast('error', 'Please enter a reflection before submitting.');
return;
}
if (!supervisorData) {
showToast('error', 'Supervisor data not loaded. Please refresh the page.');
return;
}
try {
const response = await fetch('/submit_reflection', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ reflection: reflectionInput })
});
const result = await response.json();
if (result.status === 'success') {
supervisorData.reflection_log = reflectionInput;
document.getElementById('supervisor-data').textContent = JSON.stringify(supervisorData, null, 2);
reflectionHistory.push({
date: new Date().toLocaleString(),
text: reflectionInput
});
updateReflectionHistory();
document.getElementById('reflection-input').value = '';
showToast('success', result.message);
generateCoaching();
} else {
showToast('error', result.message);
}
} catch (error) {
showToast('error', 'Error submitting reflection: ' + error.message);
}
}
function updateKPIDashboard() {
const kpiDashboard = document.getElementById('kpi-dashboard');
kpiDashboard.innerHTML = '';
// KPI 1: Engagement Score
const engagementScore = supervisorData && supervisorData.engagement_score ? supervisorData.engagement_score : 85;
const engagementCard = document.createElement('div');
engagementCard.className = 'kpi-card';
engagementCard.innerHTML = `
<h4>Engagement Score</h4>
<div class="kpi-value">${engagementScore}%</div>
<div class="progress-bar">
<div class="progress-fill" style="width: ${engagementScore}%"></div>
</div>
<p class="kpi-trend">Target: 90%</p>
`;
kpiDashboard.appendChild(engagementCard);
// KPI 2: Task Completion Rate
const taskCompletionRate = checklistProgress;
const taskCard = document.createElement('div');
taskCard.className = 'kpi-card';
taskCard.innerHTML = `
<h4>Task Completion Rate</h4>
<div class="kpi-value">${Math.round(taskCompletionRate)}%</div>
<div class="progress-bar">
<div class="progress-fill" style="width: ${taskCompletionRate}%"></div>
</div>
<p class="kpi-trend">Based on Daily Checklist</p>
`;
kpiDashboard.appendChild(taskCard);
// KPI 3: Reflection Frequency
const reflectionFrequency = reflectionHistory.length;
const reflectionCard = document.createElement('div');
reflectionCard.className = 'kpi-card';
reflectionCard.innerHTML = `
<h4>Reflection Frequency</h4>
<div class="kpi-value">${reflectionFrequency}</div>
<div class="progress-bar">
<div class="progress-fill" style="width: ${(reflectionFrequency / 5) * 100}%"></div>
</div>
<p class="kpi-trend">Goal: 5 per week</p>
`;
kpiDashboard.appendChild(reflectionCard);
// KPI 4: KPI Flag
const kpiFlag = supervisorData && supervisorData.kpi_flag !== undefined ? supervisorData.kpi_flag : false;
const flagCard = document.createElement('div');
flagCard.className = 'kpi-card';
flagCard.innerHTML = `
<h4>KPI Flag Status</h4>
<div class="kpi-value">
<span class="kpi-flag ${kpiFlag ? 'active' : 'inactive'}">${kpiFlag ? 'Active' : 'Inactive'}</span>
</div>
<p class="kpi-trend">Performance Indicator</p>
`;
kpiDashboard.appendChild(flagCard);
}
function downloadPDF() {
if (!supervisorData || !supervisorData.download_link) {
showToast('error', 'No download link available.');
return;
}
window.open(supervisorData.download_link, '_blank');
}
// Event Listeners
document.getElementById('search-bar').addEventListener('input', searchData);
window.onload = () => {
fetchSupervisorData();
setAvatar();
};
</script>
</body>
</html> |