Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | <template> <div> <div class="flex justify-between items-center mb-6"> <h3 class="text-lg font-semibold text-gray-900">Playoffs Management</h3> <div class="flex space-x-3"> <!-- League selector --> <select v-model="selectedLeague" @change="onLeagueChange" class="px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" > <option value="">Select League</option> <option v-for="league in leagues" :key="league.id" :value="league.id"> {{ league.name }} </option> </select> <!-- Season selector --> <select v-model="selectedSeason" @change="fetchBracket" class="px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" > <option value="">Select Season</option> <option v-for="season in seasons" :key="season.id" :value="season.id"> {{ season.name }} </option> </select> <!-- Age Group selector --> <select v-model="selectedAgeGroup" @change="fetchBracket" class="px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" > <option value="">Select Age Group</option> <option v-for="ag in ageGroups" :key="ag.id" :value="ag.id"> {{ ag.name }} </option> </select> </div> </div> <!-- Loading --> <div v-if="loading" class="flex justify-center py-8"> <div class="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600" ></div> </div> <!-- Error --> <div v-if="error" class="mb-4 p-3 bg-red-50 border border-red-200 text-red-700 rounded-md text-sm" > {{ error }} </div> <!-- Success message --> <div v-if="successMessage" class="mb-4 p-3 bg-green-50 border border-green-200 text-green-700 rounded-md text-sm" > {{ successMessage }} </div> <!-- No selections yet --> <div v-if=" !loading && (!selectedLeague || !selectedSeason || !selectedAgeGroup) " class="text-center py-12 text-gray-500" > Select a league, season, and age group to manage playoffs. </div> <!-- Bracket content --> <div v-if="!loading && selectedLeague && selectedSeason && selectedAgeGroup" > <!-- No bracket exists - show configuration form --> <div v-if="bracket.length === 0" class="py-8"> <p class="text-gray-500 mb-6 text-center"> No playoff bracket exists for this selection. </p> <div v-if="divisions.length >= 2" class="max-w-lg mx-auto space-y-5"> <h4 class="text-sm font-semibold text-gray-700 mb-3"> Bracket Configuration </h4> <!-- Bracket Type Selection --> <div> <label class="block text-sm text-gray-600 mb-1">Bracket Type</label> <select v-model="configBracketType" class="w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" > <option v-for="bt in bracketTypes" :key="bt.key" :value="bt.key"> {{ bt.name }} </option> </select> <p class="mt-1 text-xs text-gray-500"> {{ selectedBracketType?.description }} </p> </div> <!-- Division Selection --> <div class="grid grid-cols-2 gap-4"> <div> <label class="block text-sm text-gray-600 mb-1">Division A</label> <select v-model="configDivisionA" class="w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" > <option value="">Select...</option> <option v-for="d in divisions" :key="d.id" :value="d.id" :disabled="d.id === configDivisionB" > {{ d.name }} </option> </select> </div> <div> <label class="block text-sm text-gray-600 mb-1">Division B</label> <select v-model="configDivisionB" class="w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" > <option value="">Select...</option> <option v-for="d in divisions" :key="d.id" :value="d.id" :disabled="d.id === configDivisionA" > {{ d.name }} </option> </select> </div> </div> <!-- Start Date --> <div> <label class="block text-sm text-gray-600 mb-1" >First Round Date (Quarterfinals)</label > <input type="date" v-model="configStartDate" class="w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" /> </div> <!-- Tier Names --> <div class="grid grid-cols-2 gap-4"> <div> <label class="block text-sm text-gray-600 mb-1" >Upper Bracket Name (Positions 1-4)</label > <input type="text" v-model="configTier1Name" placeholder="Gold Cup" class="w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" /> </div> <div> <label class="block text-sm text-gray-600 mb-1" >Lower Bracket Name (Positions 5-8)</label > <input type="text" v-model="configTier2Name" placeholder="Silver Cup" class="w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" /> </div> </div> <div class="pt-2"> <button @click="showGenerateConfirm" :disabled="actionLoading || !canGenerate" class="w-full px-6 py-3 bg-blue-600 text-white rounded-md hover:bg-blue-700 disabled:opacity-50 font-medium" > {{ actionLoading ? 'Generating...' : 'Generate Playoff Bracket' }} </button> </div> </div> <div v-else class="text-sm text-red-600 mt-2 text-center"> This league needs at least 2 divisions to generate a playoff bracket. </div> </div> <!-- Bracket exists --> <div v-if="bracket.length > 0"> <!-- Action bar --> <div class="flex justify-end mb-4"> <button @click="resetBracket" :disabled="actionLoading" class="px-4 py-2 bg-red-600 text-white rounded-md hover:bg-red-700 disabled:opacity-50 text-sm" > {{ actionLoading ? 'Deleting...' : 'Reset Bracket' }} </button> </div> <!-- Bracket tiers --> <div v-for="tier in bracketTiers" :key="tier.key" class="mb-8"> <h4 class="text-md font-semibold text-gray-700 mb-3 border-b pb-1"> {{ tier.label }} </h4> <div class="bracket-grid"> <!-- Quarterfinals --> <div class="bracket-round"> <h4 class="text-sm font-semibold text-gray-500 uppercase mb-3 text-center" > Quarterfinals </h4> <div class="space-y-4"> <BracketSlotCard v-for="s in getSlotsByRound(tier.key, 'quarterfinal')" :key="s.id" :bracketSlot="s" @advance="advanceWinner" @updated="fetchBracket" :actionLoading="actionLoading" /> </div> </div> <!-- Semifinals --> <div class="bracket-round"> <h4 class="text-sm font-semibold text-gray-500 uppercase mb-3 text-center" > Semifinals </h4> <div class="space-y-4 mt-12"> <BracketSlotCard v-for="s in getSlotsByRound(tier.key, 'semifinal')" :key="s.id" :bracketSlot="s" @advance="advanceWinner" @updated="fetchBracket" :actionLoading="actionLoading" /> </div> </div> <!-- Final --> <div class="bracket-round"> <h4 class="text-sm font-semibold text-gray-500 uppercase mb-3 text-center" > Final </h4> <div class="mt-32"> <BracketSlotCard v-for="s in getSlotsByRound(tier.key, 'final')" :key="s.id" :bracketSlot="s" @advance="advanceWinner" @updated="fetchBracket" :actionLoading="actionLoading" /> </div> </div> </div> </div> </div> </div> <!-- Generate Bracket Confirmation Modal --> <ConfirmModal :show="showConfirmModal" title="Generate Playoff Bracket" confirmText="Generate Bracket" :loading="actionLoading" loadingText="Generating..." variant="info" @confirm="generateBracket" @cancel="showConfirmModal = false" > <!-- Bracket Type Header --> <div class="mb-4 p-3 bg-blue-50 border border-blue-200 rounded-md text-center" > <div class="text-lg font-semibold text-blue-900"> {{ selectedBracketType?.name }} </div> <div class="text-xs text-blue-700 mt-1"> {{ selectedBracketType?.description }} </div> </div> <!-- Configuration Details --> <div class="bg-gray-50 rounded-md p-4 text-sm space-y-2"> <div class="grid grid-cols-2 gap-x-4"> <div class="text-gray-500">Division A:</div> <div class="font-medium">{{ getDivisionName(configDivisionA) }}</div> </div> <div class="grid grid-cols-2 gap-x-4"> <div class="text-gray-500">Division B:</div> <div class="font-medium">{{ getDivisionName(configDivisionB) }}</div> </div> <div class="grid grid-cols-2 gap-x-4"> <div class="text-gray-500">First Round Date:</div> <div class="font-medium">{{ configStartDate }}</div> </div> <div class="border-t border-gray-200 my-2"></div> <div class="grid grid-cols-2 gap-x-4"> <div class="text-gray-500">Upper Bracket (1-4):</div> <div class="font-medium">{{ configTier1Name || 'Gold Cup' }}</div> </div> <div class="grid grid-cols-2 gap-x-4"> <div class="text-gray-500">Lower Bracket (5-8):</div> <div class="font-medium">{{ configTier2Name || 'Silver Cup' }}</div> </div> </div> </ConfirmModal> </div> </template> <script> import { ref, computed, onMounted } from 'vue'; import { useAuthStore } from '@/stores/auth'; import { getApiBaseUrl } from '../../config/api'; import BracketSlotCard from './BracketSlotCard.vue'; import ConfirmModal from '../ConfirmModal.vue'; export default { name: 'AdminPlayoffs', components: { BracketSlotCard, ConfirmModal }, setup() { const authStore = useAuthStore(); // Reference data const leagues = ref([]); const seasons = ref([]); const ageGroups = ref([]); const divisions = ref([]); // Selections const selectedLeague = ref(''); const selectedSeason = ref(''); const selectedAgeGroup = ref(''); // State const bracket = ref([]); const loading = ref(false); const actionLoading = ref(false); const error = ref(null); const successMessage = ref(null); // Bracket types (expandable in the future) const bracketTypes = [ { key: 'dual_tier_16', name: '16-Team Dual Bracket', description: 'All 16 teams compete in two parallel single-elimination brackets: positions 1-4 in upper bracket, positions 5-8 in lower bracket.', tiers: [ { start: 1, end: 4 }, { start: 5, end: 8 }, ], }, // Future bracket types can be added here: // { key: 'single_8', name: '8-Team Single Elimination', ... }, // { key: 'double_elim', name: 'Double Elimination', ... }, ]; // Bracket generation config const configBracketType = ref('dual_tier_16'); const configDivisionA = ref(''); const configDivisionB = ref(''); const configStartDate = ref(''); const configTier1Name = ref('Gold Cup'); const configTier2Name = ref('Silver Cup'); // Confirm modal state const showConfirmModal = ref(false); // Get selected bracket type details const selectedBracketType = computed(() => bracketTypes.find(bt => bt.key === configBracketType.value) ); // Computed: can generate bracket? const canGenerate = computed( () => configDivisionA.value && configDivisionB.value && configStartDate.value && configDivisionA.value !== configDivisionB.value ); // Computed: derive bracket tiers from bracket data (or show nothing if empty) const bracketTiers = computed(() => { const tierNames = [...new Set(bracket.value.map(s => s.bracket_tier))]; // Sort alphabetically for consistent display tierNames.sort(); return tierNames.map(name => ({ key: name, label: name, })); }); // Get slots filtered by tier and round const getSlotsByRound = (tier, round) => bracket.value .filter(s => s.bracket_tier === tier && s.round === round) .sort((a, b) => a.bracket_position - b.bracket_position); const getDivisionName = divId => { const div = divisions.value.find(d => d.id === divId); return div ? div.name : `Division ${divId}`; }; const fetchReferenceData = async () => { try { const [seasonsData, ageGroupsData, leaguesData] = await Promise.all([ authStore.apiRequest(`${getApiBaseUrl()}/api/seasons`, { method: 'GET', }), authStore.apiRequest(`${getApiBaseUrl()}/api/age-groups`, { method: 'GET', }), authStore.apiRequest(`${getApiBaseUrl()}/api/leagues`, { method: 'GET', }), ]); seasons.value = seasonsData || []; ageGroups.value = ageGroupsData || []; leagues.value = leaguesData || []; } catch (err) { console.error('Error fetching reference data:', err); } }; const onLeagueChange = async () => { // Fetch divisions for the selected league divisions.value = []; bracket.value = []; configDivisionA.value = ''; configDivisionB.value = ''; if (!selectedLeague.value) return; try { const allDivisions = await authStore.apiRequest( `${getApiBaseUrl()}/api/divisions`, { method: 'GET' } ); divisions.value = allDivisions.filter( d => d.league_id === parseInt(selectedLeague.value) ); // Default to first two divisions if available if (divisions.value.length >= 2) { configDivisionA.value = divisions.value[0].id; configDivisionB.value = divisions.value[1].id; } } catch (err) { console.error('Error fetching divisions:', err); } await fetchBracket(); }; const fetchBracket = async () => { error.value = null; successMessage.value = null; if ( !selectedLeague.value || !selectedSeason.value || !selectedAgeGroup.value ) { bracket.value = []; return; } try { loading.value = true; const params = new URLSearchParams({ league_id: selectedLeague.value, season_id: selectedSeason.value, age_group_id: selectedAgeGroup.value, }); const data = await authStore.apiRequest( `${getApiBaseUrl()}/api/playoffs/bracket?${params}`, { method: 'GET' } ); bracket.value = data || []; } catch (err) { error.value = err.message || 'Failed to fetch bracket'; } finally { loading.value = false; } }; const showGenerateConfirm = () => { if (!canGenerate.value) return; showConfirmModal.value = true; }; const generateBracket = async () => { showConfirmModal.value = false; try { actionLoading.value = true; error.value = null; successMessage.value = null; const body = { league_id: parseInt(selectedLeague.value), season_id: parseInt(selectedSeason.value), age_group_id: parseInt(selectedAgeGroup.value), division_a_id: parseInt(configDivisionA.value), division_b_id: parseInt(configDivisionB.value), start_date: configStartDate.value, tiers: [ { name: configTier1Name.value || 'Gold Cup', start_position: 1, end_position: 4, }, { name: configTier2Name.value || 'Silver Cup', start_position: 5, end_position: 8, }, ], }; const data = await authStore.apiRequest( `${getApiBaseUrl()}/api/admin/playoffs/generate`, { method: 'POST', body: JSON.stringify(body), } ); bracket.value = data || []; successMessage.value = 'Playoff bracket generated successfully!'; } catch (err) { error.value = err.message || 'Failed to generate bracket'; } finally { actionLoading.value = false; } }; const advanceWinner = async slotId => { try { actionLoading.value = true; error.value = null; successMessage.value = null; await authStore.apiRequest( `${getApiBaseUrl()}/api/admin/playoffs/advance`, { method: 'POST', body: JSON.stringify({ slot_id: slotId }), } ); successMessage.value = 'Winner advanced successfully!'; await fetchBracket(); } catch (err) { error.value = err.message || 'Failed to advance winner'; } finally { actionLoading.value = false; } }; const resetBracket = async () => { if ( !confirm( 'Delete the entire bracket and all playoff matches? This cannot be undone.' ) ) return; try { actionLoading.value = true; error.value = null; successMessage.value = null; const params = new URLSearchParams({ league_id: selectedLeague.value, season_id: selectedSeason.value, age_group_id: selectedAgeGroup.value, }); await authStore.apiRequest( `${getApiBaseUrl()}/api/admin/playoffs/bracket?${params}`, { method: 'DELETE' } ); bracket.value = []; successMessage.value = 'Bracket deleted successfully.'; } catch (err) { error.value = err.message || 'Failed to delete bracket'; } finally { actionLoading.value = false; } }; onMounted(async () => { await fetchReferenceData(); // Default start date to 7 days from now const defaultDate = new Date(); defaultDate.setDate(defaultDate.getDate() + 7); configStartDate.value = defaultDate.toISOString().split('T')[0]; }); return { leagues, seasons, ageGroups, divisions, selectedLeague, selectedSeason, selectedAgeGroup, bracket, loading, actionLoading, error, successMessage, bracketTiers, bracketTypes, configBracketType, selectedBracketType, configDivisionA, configDivisionB, configStartDate, configTier1Name, configTier2Name, canGenerate, showConfirmModal, getSlotsByRound, getDivisionName, onLeagueChange, fetchBracket, showGenerateConfirm, generateBracket, advanceWinner, resetBracket, }; }, }; </script> <style scoped> .bracket-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 2rem; min-height: 400px; } @media (max-width: 768px) { .bracket-grid { grid-template-columns: 1fr; } } </style> |