feat: implement table assignment and distribution for tournament matches
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 44s
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 44s
This commit is contained in:
@@ -247,6 +247,35 @@ export const getTournamentMatches = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Setze Tischnummer für ein Spiel
|
||||
export const setMatchTable = async (req, res) => {
|
||||
const { authcode: token } = req.headers;
|
||||
const { clubId, tournamentId, matchId } = req.params;
|
||||
const { tableNumber } = req.body;
|
||||
try {
|
||||
const updated = await tournamentService.setMatchTable(token, clubId, tournamentId, matchId, tableNumber);
|
||||
emitTournamentChanged(clubId, tournamentId);
|
||||
res.status(200).json(updated);
|
||||
} catch (error) {
|
||||
console.error('[setMatchTable] Error:', error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
// Freie Tische verteilen (Batch)
|
||||
export const distributeTables = async (req, res) => {
|
||||
const { authcode: token } = req.headers;
|
||||
const { clubId, tournamentId } = req.body;
|
||||
try {
|
||||
const updated = await tournamentService.distributeTables(token, clubId, tournamentId);
|
||||
emitTournamentChanged(clubId, tournamentId);
|
||||
res.status(200).json({ updated, message: 'Tische wurden verteilt.' });
|
||||
} catch (error) {
|
||||
console.error('[distributeTables] Error:', error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
// 11. Satz-Ergebnis speichern
|
||||
export const addMatchResult = async (req, res) => {
|
||||
const { authcode: token } = req.headers;
|
||||
|
||||
@@ -201,7 +201,7 @@ const Member = sequelize.define('Member', {
|
||||
}
|
||||
});
|
||||
|
||||
Member.belongsTo(Club, { as: 'club' });
|
||||
Club.hasMany(Member, { as: 'members' });
|
||||
Member.belongsTo(Club, { as: 'club', foreignKey: 'clubId', constraints: false });
|
||||
Club.hasMany(Member, { as: 'members', foreignKey: 'clubId', constraints: false });
|
||||
|
||||
export default Member;
|
||||
|
||||
@@ -59,6 +59,11 @@ const TournamentMatch = sequelize.define('TournamentMatch', {
|
||||
allowNull: false,
|
||||
defaultValue: false,
|
||||
},
|
||||
tableNumber: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
field: 'table_number',
|
||||
},
|
||||
result: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
getTournamentMatches,
|
||||
addMatchResult,
|
||||
finishMatch,
|
||||
setMatchTable,
|
||||
startKnockout,
|
||||
manualAssignGroups,
|
||||
resetGroups,
|
||||
@@ -39,6 +40,7 @@ import {
|
||||
createPairing,
|
||||
updatePairing,
|
||||
deletePairing,
|
||||
distributeTables,
|
||||
} from '../controllers/tournamentController.js';
|
||||
import {
|
||||
getStages,
|
||||
@@ -65,11 +67,13 @@ router.post('/match/result', authenticate, addMatchResult);
|
||||
router.delete('/match/result', authenticate, deleteMatchResult);
|
||||
router.post("/match/reopen", authenticate, reopenMatch);
|
||||
router.post('/match/finish', authenticate, finishMatch);
|
||||
router.put('/match/:clubId/:tournamentId/:matchId/table', authenticate, setMatchTable);
|
||||
router.put('/match/:clubId/:tournamentId/:matchId/active', authenticate, setMatchActive);
|
||||
router.get('/matches/:clubId/:tournamentId', authenticate, getTournamentMatches);
|
||||
router.post('/knockout', authenticate, startKnockout);
|
||||
router.delete("/matches/knockout", authenticate, deleteKnockoutMatches);
|
||||
router.post('/groups/manual', authenticate, manualAssignGroups);
|
||||
router.post('/matches/distribute', authenticate, distributeTables);
|
||||
router.put('/participant/group', authenticate, assignParticipantToGroup); // Muss VOR /:clubId/:tournamentId stehen!
|
||||
router.put('/:clubId/:tournamentId', authenticate, updateTournament);
|
||||
router.get('/:clubId/:tournamentId', authenticate, getTournament);
|
||||
|
||||
@@ -44,7 +44,7 @@ async function run() {
|
||||
|
||||
console.log('[api-test] Using token for tournament', targetTournament.id, 'club', targetTournament.clubId);
|
||||
|
||||
const url = `http://localhost:3005/tournament/${targetTournament.clubId}/${targetTournament.id}`;
|
||||
const url = `http://localhost:3005/api/tournament/${targetTournament.clubId}/${targetTournament.id}`;
|
||||
const payload = {
|
||||
name: targetTournament.name || 'Test Tournament',
|
||||
date: targetTournament.date,
|
||||
|
||||
29
backend/scripts/create_token_for_user.js
Normal file
29
backend/scripts/create_token_for_user.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import '../config.js';
|
||||
import sequelize from '../database.js';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import User from '../models/User.js';
|
||||
import UserToken from '../models/UserToken.js';
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('[create-token] DB connected');
|
||||
const email = process.env.TEST_TOKEN_EMAIL || 'tournamentmanager@test.de';
|
||||
const user = await User.findOne({ where: { email } });
|
||||
if (!user) {
|
||||
console.error('[create-token] User not found:', email);
|
||||
process.exit(2);
|
||||
}
|
||||
const payload = { userId: user.id };
|
||||
const token = jwt.sign(payload, process.env.JWT_SECRET, { expiresIn: '7d' });
|
||||
const expiresAt = new Date(Date.now() + 7 * 24 * 3600 * 1000);
|
||||
await UserToken.create({ userId: user.id, token, expiresAt });
|
||||
console.log('[create-token] TOKEN_START');
|
||||
console.log(token);
|
||||
console.log('[create-token] TOKEN_END');
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
console.error('[create-token] Error:', err);
|
||||
process.exit(3);
|
||||
}
|
||||
})();
|
||||
51
backend/scripts/inspect_and_fix_active_matches.js
Normal file
51
backend/scripts/inspect_and_fix_active_matches.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import '../config.js';
|
||||
import sequelize from '../database.js';
|
||||
import TournamentMatch from '../models/TournamentMatch.js';
|
||||
|
||||
const argv = process.argv.slice(2);
|
||||
if (argv.length === 0) {
|
||||
console.error('Usage: node inspect_and_fix_active_matches.js <tournamentId> [--fix-all]');
|
||||
process.exit(2);
|
||||
}
|
||||
const tournamentId = Number(argv[0]);
|
||||
const fixAll = argv.includes('--fix-all') || argv.includes('--fix');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('[inspect] DB connected');
|
||||
|
||||
const active = await TournamentMatch.findAll({
|
||||
where: { tournamentId, isActive: true },
|
||||
order: [['id', 'ASC']]
|
||||
});
|
||||
|
||||
console.log(`[inspect] active matches for tournament ${tournamentId}: ${active.length}`);
|
||||
for (const m of active) {
|
||||
console.log(` id=${m.id} p1=${m.player1Id} p2=${m.player2Id} isFinished=${m.isFinished} table=${m.tableNumber}`);
|
||||
}
|
||||
|
||||
const candidates = await TournamentMatch.findAll({
|
||||
where: { tournamentId, isFinished: false, tableNumber: null },
|
||||
order: [['id', 'ASC']]
|
||||
});
|
||||
console.log(`[inspect] candidate matches (not finished, no table): ${candidates.length}`);
|
||||
for (const m of candidates) {
|
||||
console.log(` id=${m.id} p1=${m.player1Id} p2=${m.player2Id} isActive=${m.isActive}`);
|
||||
}
|
||||
|
||||
if (fixAll) {
|
||||
console.log('[inspect] Fix mode: resetting isActive=false for all matches in tournament');
|
||||
const [upd] = await sequelize.query('UPDATE tournament_match SET is_active = 0 WHERE tournament_id = :t', { replacements: { t: tournamentId } });
|
||||
console.log('[inspect] Raw update result:', upd);
|
||||
|
||||
const nowActive = await TournamentMatch.count({ where: { tournamentId, isActive: true } });
|
||||
console.log('[inspect] Remaining active matches:', nowActive);
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
console.error('[inspect] Error:', err);
|
||||
process.exit(3);
|
||||
}
|
||||
})();
|
||||
@@ -2066,7 +2066,10 @@ class TournamentService {
|
||||
}
|
||||
match.isFinished = true;
|
||||
match.result = `${win}:${lose}`;
|
||||
// Wenn ein Match abgeschlossen wird, darf es nicht mehr als aktiv gelten
|
||||
match.isActive = false;
|
||||
await match.save();
|
||||
console.log(`[finishMatch] match ${matchId} finished, result=${match.result}, isActive set to false`);
|
||||
|
||||
// Platz-3-Spiel (Legacy-KO ohne Stages): erst erzeugen, wenn beide Halbfinals fertig sind.
|
||||
// Keine Placeholders beim KO-Start.
|
||||
@@ -2894,6 +2897,80 @@ class TournamentService {
|
||||
await match.save();
|
||||
}
|
||||
|
||||
async setMatchTable(userToken, clubId, tournamentId, matchId, tableNumber) {
|
||||
await checkAccess(userToken, clubId);
|
||||
|
||||
const match = await TournamentMatch.findOne({ where: { id: matchId, tournamentId } });
|
||||
if (!match) throw new Error('Match nicht gefunden');
|
||||
|
||||
match.tableNumber = (tableNumber == null) ? null : Number(tableNumber);
|
||||
await match.save();
|
||||
return match.toJSON ? match.toJSON() : match;
|
||||
}
|
||||
|
||||
async distributeTables(userToken, clubId, tournamentId) {
|
||||
await checkAccess(userToken, clubId);
|
||||
|
||||
const tournament = await Tournament.findByPk(tournamentId);
|
||||
if (!tournament || tournament.clubId != clubId) throw new Error('Turnier nicht gefunden');
|
||||
|
||||
const numTables = tournament.numberOfTables ? Number(tournament.numberOfTables) : 0;
|
||||
if (!numTables || numTables < 1) throw new Error('Anzahl der Tische nicht gesetzt');
|
||||
|
||||
console.log(`[distributeTables] clubId=${clubId}, tournamentId=${tournamentId}, numberOfTables=${numTables}`);
|
||||
|
||||
// Ermittle aktuell laufende Matches, damit wir nur Spiele verteilen, bei denen beide Spieler frei sind
|
||||
const activeMatches = await TournamentMatch.findAll({ where: { tournamentId, isActive: true, isFinished: false } });
|
||||
const activePlayerIds = new Set();
|
||||
activeMatches.forEach(am => {
|
||||
if (am.player1Id) activePlayerIds.add(Number(am.player1Id));
|
||||
if (am.player2Id) activePlayerIds.add(Number(am.player2Id));
|
||||
});
|
||||
|
||||
console.log(`[distributeTables] activeMatches=${activeMatches.length} activePlayers=${[...activePlayerIds].slice(0,10).join(',')}`);
|
||||
|
||||
// Lade nur noch die nicht abgeschlossenen, noch nicht zugewiesenen Matches
|
||||
const matches = await TournamentMatch.findAll({
|
||||
where: { tournamentId, isFinished: false, tableNumber: null },
|
||||
order: [ ['group_round', 'ASC'], ['id', 'ASC'] ]
|
||||
});
|
||||
|
||||
console.log(`[distributeTables] candidateMatches=${matches.length}`);
|
||||
|
||||
let idx = 0;
|
||||
const updated = [];
|
||||
for (const m of matches) {
|
||||
// Spiele mit BYE (fehlendem Spieler) überspringen
|
||||
if (!m.player1Id || !m.player2Id) {
|
||||
console.log(`[distributeTables] skipping match ${m.id} (BYE or missing player) p1=${m.player1Id} p2=${m.player2Id}`);
|
||||
continue;
|
||||
}
|
||||
// Nur vergeben, wenn beide Spieler aktuell nicht in einem aktiven Match sind
|
||||
if (activePlayerIds.has(Number(m.player1Id)) || activePlayerIds.has(Number(m.player2Id))) {
|
||||
console.log(`[distributeTables] skipping match ${m.id} because player active p1=${m.player1Id} p2=${m.player2Id}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const assign = (idx % numTables) + 1;
|
||||
m.tableNumber = assign;
|
||||
// Markiere das Spiel als gestartet (läuft)
|
||||
m.isActive = true;
|
||||
await m.save();
|
||||
updated.push(m.toJSON ? m.toJSON() : m);
|
||||
|
||||
console.log(`[distributeTables] assigned match ${m.id} -> table ${assign}`);
|
||||
|
||||
// Spieler gelten nun als aktiv - damit kein weiteres Spiel für sie zugewiesen wird
|
||||
activePlayerIds.add(Number(m.player1Id));
|
||||
activePlayerIds.add(Number(m.player2Id));
|
||||
idx++;
|
||||
}
|
||||
|
||||
console.log(`[distributeTables] finished: assignedCount=${updated.length}`);
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
async resetKnockout(userToken, clubId, tournamentId, classId = null) {
|
||||
await checkAccess(userToken, clubId);
|
||||
// lösche alle Matches außer Gruppenphase
|
||||
|
||||
@@ -204,7 +204,9 @@
|
||||
v-model="infoDialog.isOpen"
|
||||
:title="infoDialog.title"
|
||||
:message="infoDialog.message"
|
||||
:details="infoDialog.details"
|
||||
:details="infoDialog.details"
|
||||
:detailsHtml="infoDialog.detailsHtml"
|
||||
:size="infoDialog.size"
|
||||
:type="infoDialog.type"
|
||||
/>
|
||||
|
||||
@@ -345,7 +347,15 @@ export default {
|
||||
},
|
||||
// Dialog Helper Methods
|
||||
async showInfo(title, message, details = '', type = 'info') {
|
||||
this.infoDialog = buildInfoConfig({ title, message, details, type });
|
||||
// If details looks like HTML (e.g., a table), pass it as detailsHtml so InfoDialog renders it
|
||||
const looksLikeHtml = typeof details === 'string' && /<\s*\w+[^>]*>/.test(details);
|
||||
console.debug('[App.showInfo] looksLikeHtml=', looksLikeHtml, 'title=', title, 'message=', message, 'detailsLength=', typeof details === 'string' ? details.length : 0);
|
||||
if (looksLikeHtml) {
|
||||
// For HTML details (tables), use a wider dialog
|
||||
this.infoDialog = buildInfoConfig({ title, message, details: '', detailsHtml: details, type, size: 'medium' });
|
||||
} else {
|
||||
this.infoDialog = buildInfoConfig({ title, message, details, type });
|
||||
}
|
||||
},
|
||||
|
||||
async showConfirm(title, message, details = '', type = 'info', options = {}) {
|
||||
|
||||
@@ -180,12 +180,25 @@ export default {
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.info-details :deep(table) {
|
||||
.info-details ::v-deep table {
|
||||
color: #000;
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.info-details ::v-deep table thead th {
|
||||
padding: 6px 8px;
|
||||
border-bottom: 1px solid #e9ecef;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.info-details :deep(tr:nth-child(even)) {
|
||||
.info-details ::v-deep table tbody td {
|
||||
padding: 6px 8px;
|
||||
border-bottom: 1px solid #f1f3f5;
|
||||
}
|
||||
|
||||
.info-details ::v-deep table tbody tr:nth-child(even) {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
{{ $t('tournaments.numberOfTables') }}:
|
||||
<input type="number" :value="numberOfTables" @input="$emit('update:numberOfTables', $event.target.value ? parseInt($event.target.value, 10) : null)" min="1" />
|
||||
</label>
|
||||
<button @click="$emit('generate-pdf')" class="btn-primary" style="margin-top: 1rem;">{{ $t('tournaments.exportPDF') }}</button>
|
||||
<button @click="$emit('generate-pdf')" class="btn-primary" style="margin-top: 1rem;">{{ $t('tournaments.exportPDF') }}</button>
|
||||
<!-- 'Freie Tische verteilen' removed from Konfiguration tab -->
|
||||
</div>
|
||||
<label class="checkbox-item">
|
||||
<input type="checkbox" :checked="isGroupTournament" @change="$emit('update:isGroupTournament', $event.target.checked)" />
|
||||
@@ -203,6 +204,16 @@ export default {
|
||||
components: {
|
||||
TournamentClassList
|
||||
},
|
||||
methods: {
|
||||
async onDistributeTables() {
|
||||
try {
|
||||
await apiClient.post('/tournament/matches/distribute', { clubId: this.clubId, tournamentId: this.tournamentId });
|
||||
this.stageConfig.success = this.$t('tournaments.tablesDistributed') || 'Tische wurden verteilt.';
|
||||
} catch (err) {
|
||||
this.stageConfig.error = err?.response?.data?.error || err.message || String(err);
|
||||
}
|
||||
},
|
||||
},
|
||||
props: {
|
||||
clubId: {
|
||||
type: [Number, String],
|
||||
|
||||
@@ -8,13 +8,19 @@
|
||||
@update:modelValue="$emit('update:selectedViewClass', $event)"
|
||||
/>
|
||||
<section v-if="filteredGroupMatches.length" class="group-matches">
|
||||
<h4>{{ $t('tournaments.groupMatches') }}</h4>
|
||||
<div style="display:flex; align-items:center; justify-content:space-between;">
|
||||
<h4>{{ $t('tournaments.groupMatches') }}</h4>
|
||||
<div>
|
||||
<button v-if="numberOfTables" @click="onDistributeTables" class="btn-secondary">{{ $t('tournaments.distributeTables') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $t('tournaments.round') }}</th>
|
||||
<th>{{ $t('tournaments.group') }}</th>
|
||||
<th>{{ $t('tournaments.encounter') }}</th>
|
||||
<th>Tisch</th>
|
||||
<th>{{ $t('tournaments.result') }}</th>
|
||||
<th>{{ $t('tournaments.sets') }}</th>
|
||||
<th>{{ $t('tournaments.action') }}</th>
|
||||
@@ -44,6 +50,17 @@
|
||||
{{ getMatchPlayerNames(m).name1 }} – {{ getMatchPlayerNames(m).name2 }}
|
||||
</template>
|
||||
</td>
|
||||
<td>
|
||||
<template v-if="numberOfTables">
|
||||
<select @click.stop @change.stop="onSetMatchTable(m, $event.target.value)" :value="m.tableNumber || ''">
|
||||
<option value="">-</option>
|
||||
<option v-for="n in numberOfTables" :key="n" :value="n">{{ n }}</option>
|
||||
</select>
|
||||
</template>
|
||||
<template v-else>
|
||||
-
|
||||
</template>
|
||||
</td>
|
||||
<td>
|
||||
<template v-if="m.result === 'BYE'">
|
||||
BYE
|
||||
@@ -124,6 +141,7 @@
|
||||
<th>{{ $t('tournaments.class') }}</th>
|
||||
<th>{{ $t('tournaments.round') }}</th>
|
||||
<th>{{ $t('tournaments.encounter') }}</th>
|
||||
<th>Tisch</th>
|
||||
<th>{{ $t('tournaments.result') }}</th>
|
||||
<th>{{ $t('tournaments.sets') }}</th>
|
||||
<th>{{ $t('tournaments.action') }}</th>
|
||||
@@ -146,6 +164,17 @@
|
||||
{{ getMatchPlayerNames(m).name1 }} – {{ getMatchPlayerNames(m).name2 }}
|
||||
</template>
|
||||
</td>
|
||||
<td>
|
||||
<template v-if="numberOfTables">
|
||||
<select @click.stop @change.stop="onSetMatchTable(m, $event.target.value)" :value="m.tableNumber || ''">
|
||||
<option value="">-</option>
|
||||
<option v-for="n in numberOfTables" :key="n" :value="n">{{ n }}</option>
|
||||
</select>
|
||||
</template>
|
||||
<template v-else>
|
||||
-
|
||||
</template>
|
||||
</td>
|
||||
<td>
|
||||
<template v-if="!m.isFinished">
|
||||
<template v-for="r in m.tournamentResults" :key="r.set">
|
||||
@@ -248,10 +277,17 @@
|
||||
stroke: currentColor;
|
||||
}
|
||||
.inline-delete:focus{ outline: none; box-shadow: 0 0 0 3px rgba(211,47,47,0.12); border-radius:3px; }
|
||||
|
||||
/* Highlight for running matches (ensure high specificity) */
|
||||
.match-live:not(.match-finished) td {
|
||||
background: #fff3cd !important;
|
||||
color: #5a3500 !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
import TournamentClassSelector from './TournamentClassSelector.vue';
|
||||
import apiClient from '../../apiClient';
|
||||
|
||||
export default {
|
||||
name: 'TournamentResultsTab',
|
||||
@@ -315,6 +351,15 @@ export default {
|
||||
type: Array,
|
||||
required: true
|
||||
},
|
||||
clubId: {
|
||||
type: [Number, String],
|
||||
required: false,
|
||||
default: null,
|
||||
},
|
||||
numberOfTables: {
|
||||
type: [Number, null],
|
||||
default: null,
|
||||
},
|
||||
pairings: {
|
||||
type: Array,
|
||||
required: true
|
||||
@@ -400,8 +445,72 @@ export default {
|
||||
'start-matches',
|
||||
'start-knockout',
|
||||
'reset-knockout'
|
||||
,'tables-distributed'
|
||||
],
|
||||
methods: {
|
||||
// Simple HTML escape to avoid injecting unsafe markup into the dialog
|
||||
// We keep it minimal and safe for names/numbers
|
||||
|
||||
escapeHtml(str) {
|
||||
if (str == null) return '';
|
||||
return String(str)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
},
|
||||
|
||||
async onDistributeTables() {
|
||||
if (!this.clubId || !this.selectedDate) return;
|
||||
try {
|
||||
const resp = await apiClient.post('/tournament/matches/distribute', { clubId: this.clubId, tournamentId: this.selectedDate });
|
||||
const updated = resp?.data?.updated || [];
|
||||
|
||||
if (updated.length === 0) {
|
||||
// Keine passenden Spiele gefunden
|
||||
const msg = resp?.data?.message || (this.$t ? this.$t('tournaments.noAssignableMatches') : 'Keine Spiele verfügbar, bei denen beide Spieler frei sind.');
|
||||
if (this.$root && this.$root.showInfo) this.$root.showInfo(this.$t('tournaments.distributeTablesResult') || 'Tischverteilung', msg);
|
||||
} else {
|
||||
// Baue eine lesbare Liste der zugewiesenen Paarungen
|
||||
// Generate an HTML table for better readability
|
||||
const rows = updated.map(m => {
|
||||
const local = (this.groupMatches || []).concat(this.knockoutMatches || []).find(x => x.id === m.id) || m;
|
||||
const names = this.getMatchPlayerNames(local);
|
||||
const tbl = m.tableNumber || (local.tableNumber || '-');
|
||||
return `<tr><td>${this.escapeHtml(names.name1)}</td><td>–</td><td>${this.escapeHtml(names.name2)}</td><td style="text-align:right">${this.escapeHtml(String(tbl))}</td></tr>`;
|
||||
}).join('');
|
||||
const tableHtml = `
|
||||
<table style="width:100%;border-collapse:collapse;">
|
||||
<thead><tr><th style="text-align:left">Spieler A</th><th></th><th style="text-align:left">Spieler B</th><th style="text-align:right">Tisch</th></tr></thead>
|
||||
<tbody>${rows}</tbody>
|
||||
</table>
|
||||
`;
|
||||
if (this.$root && this.$root.showInfo) this.$root.showInfo(this.$t('tournaments.distributeTablesResult') || 'Tischverteilung', this.$t('tournaments.tablesDistributed') || 'Tische wurden verteilt.', tableHtml);
|
||||
}
|
||||
// Debug log and emit updated matches so parent can update UI immediately
|
||||
console.debug('[TournamentResultsTab.onDistributeTables] updatedCount=', Array.isArray(updated) ? updated.length : 0, 'updatedIds=', (updated || []).map(u => u.id));
|
||||
this.$emit('tables-distributed', updated);
|
||||
} catch (err) {
|
||||
const msg = err?.response?.data?.error || err.message || String(err);
|
||||
if (this.$root && this.$root.showInfo) {
|
||||
this.$root.showInfo(this.$t('messages.error') || 'Fehler', msg, '', 'error');
|
||||
}
|
||||
}
|
||||
},
|
||||
async onSetMatchTable(match, value) {
|
||||
if (!this.clubId || !this.selectedDate || !match) return;
|
||||
const tableNumber = value === '' ? null : Number(value);
|
||||
try {
|
||||
await apiClient.put(`/tournament/match/${this.clubId}/${this.selectedDate}/${match.id}/table`, { tableNumber });
|
||||
this.$emit('tables-distributed');
|
||||
} catch (err) {
|
||||
const msg = err?.response?.data?.error || err.message || String(err);
|
||||
if (this.$root && this.$root.showInfo) {
|
||||
this.$root.showInfo(this.$t('messages.error') || 'Fehler', msg, '', 'error');
|
||||
}
|
||||
}
|
||||
},
|
||||
async onDeleteSet(match, set) {
|
||||
const title = this.$t ? this.$t('tournaments.confirmDeleteSetTitle') : null;
|
||||
const message = this.$t ? this.$t('tournaments.confirmDeleteSet') : 'Satz wirklich löschen?';
|
||||
|
||||
@@ -35,6 +35,7 @@ export function buildInfoConfig({
|
||||
title = 'Information',
|
||||
message = '',
|
||||
details = '',
|
||||
detailsHtml = '',
|
||||
type = 'info',
|
||||
size = 'small',
|
||||
closeOnOverlay = true,
|
||||
@@ -53,6 +54,8 @@ export function buildInfoConfig({
|
||||
title: sanitizeText(title, defaultTitle, 120),
|
||||
message: sanitizeText(message, '', 600),
|
||||
details: sanitizeText(details, '', 1200),
|
||||
// detailsHtml is intentionally not sanitized here to allow HTML tables; callers must ensure safety.
|
||||
detailsHtml: typeof detailsHtml === 'string' ? detailsHtml : '',
|
||||
type: safeType,
|
||||
size,
|
||||
closeOnOverlay,
|
||||
|
||||
@@ -182,9 +182,11 @@
|
||||
/>
|
||||
|
||||
<!-- Tab: Ergebnisse -->
|
||||
<TournamentResultsTab
|
||||
<TournamentResultsTab
|
||||
v-if="activeTab === 'results'"
|
||||
:selected-date="selectedDate"
|
||||
:club-id="currentClub"
|
||||
:number-of-tables="currentNumberOfTables"
|
||||
:selected-view-class="selectedViewClass"
|
||||
:tournament-classes="tournamentClasses"
|
||||
:group-matches="groupMatches"
|
||||
@@ -213,6 +215,7 @@
|
||||
@start-matches="startMatches"
|
||||
@start-knockout="startKnockout"
|
||||
@reset-knockout="resetKnockout"
|
||||
@tables-distributed="handleTablesDistributed"
|
||||
/>
|
||||
|
||||
<!-- Tab: Platzierungen -->
|
||||
@@ -240,6 +243,7 @@
|
||||
:title="infoDialog.title"
|
||||
:message="infoDialog.message"
|
||||
:details="infoDialog.details"
|
||||
:detailsHtml="infoDialog.detailsHtml"
|
||||
:type="infoDialog.type"
|
||||
/>
|
||||
|
||||
@@ -1398,6 +1402,30 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
async handleTablesDistributed(updated) {
|
||||
console.debug('[TournamentTab.handleTablesDistributed] updatedCount=', Array.isArray(updated) ? updated.length : 0);
|
||||
try {
|
||||
// Wenn updated mitgegeben wurde, aktualisiere lokale Matches sofort (tableNumber + isActive)
|
||||
if (Array.isArray(updated) && updated.length > 0) {
|
||||
const map = new Map(updated.map(u => [Number(u.id), u]));
|
||||
this.matches = this.matches.map(m => {
|
||||
const found = map.get(Number(m.id));
|
||||
if (found) {
|
||||
console.debug('[TournamentTab] apply update to match', m.id, '-> tableNumber=', found.tableNumber || found.table_number);
|
||||
return { ...m, tableNumber: found.tableNumber || found.table_number || m.tableNumber, isActive: true };
|
||||
}
|
||||
return m;
|
||||
});
|
||||
// Force re-render so CSS highlight applies
|
||||
this.$forceUpdate();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[handleTablesDistributed] Error updating local matches:', err);
|
||||
}
|
||||
// Lade die Turnierdaten zur endgültigen Synchronisation
|
||||
try { await this.loadTournamentData(); } catch (e) { /* ignore */ }
|
||||
},
|
||||
|
||||
getPlayerName(p) {
|
||||
// Unterstütze sowohl interne (mit member) als auch externe Teilnehmer
|
||||
if (p.member) {
|
||||
@@ -1712,12 +1740,27 @@ export default {
|
||||
},
|
||||
|
||||
async finishMatch(match) {
|
||||
await apiClient.post('/tournament/match/finish', {
|
||||
clubId: this.currentClub,
|
||||
tournamentId: this.selectedDate,
|
||||
matchId: match.id
|
||||
});
|
||||
await this.loadTournamentData();
|
||||
try {
|
||||
await apiClient.post('/tournament/match/finish', {
|
||||
clubId: this.currentClub,
|
||||
tournamentId: this.selectedDate,
|
||||
matchId: match.id
|
||||
});
|
||||
await this.loadTournamentData();
|
||||
|
||||
// Nach dem Neuladen die aktualisierte Match‑Info holen und anzeigen (inkl. Tisch)
|
||||
const updated = (this.matches || []).find(m => m.id === match.id) || match;
|
||||
const names = this.getMatchPlayerNames(updated);
|
||||
const table = (updated && updated.tableNumber != null) ? updated.tableNumber : (match.tableNumber != null ? match.tableNumber : '-');
|
||||
const title = this.$t ? this.$t('messages.info') : 'Info';
|
||||
const body = `${names.name1} – ${names.name2}\n${this.$t ? this.$t('tournaments.numberOfTables') : 'Tisch'}: ${table}`;
|
||||
if (this.$root && this.$root.showInfo) {
|
||||
this.$root.showInfo(title, body);
|
||||
}
|
||||
} catch (err) {
|
||||
const message = safeErrorMessage(err, 'Fehler beim Abschließen des Matches.');
|
||||
await this.showInfo('Fehler', message, '', 'error');
|
||||
}
|
||||
},
|
||||
|
||||
async setMatchActive(match, isActive) {
|
||||
@@ -4044,14 +4087,14 @@ tbody tr:hover:not(.active-match) {
|
||||
color: #828a91 !important;
|
||||
}
|
||||
|
||||
/* Laufende Spiele farblich hervorheben - nur wenn nicht abgeschlossen */
|
||||
/* Laufende Spiele farblich hervorheben - nur wenn nicht abgeschlossen (orange wie vorher) */
|
||||
.match-live:not(.match-finished) {
|
||||
background-color: #d4edda !important;
|
||||
border-left: 4px solid #28a745 !important;
|
||||
background-color: #fff3cd !important; /* helles Orange/Gelb */
|
||||
border-left: 4px solid #ff9800 !important; /* oranger Rand */
|
||||
}
|
||||
|
||||
.match-live:not(.match-finished) td {
|
||||
color: #155724;
|
||||
color: #8a4f28; /* dunkles Orange/Braun für Lesbarkeit */
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
|
||||
@@ -135,8 +135,22 @@ internal fun TournamentEditorClassesTab(
|
||||
)
|
||||
}
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
Button(onClick = { showAdd = true }, modifier = Modifier.fillMaxWidth()) {
|
||||
Text(tr("tournaments.addClass", "Klasse anlegen"))
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth()) {
|
||||
Button(onClick = { showAdd = true }, modifier = Modifier.weight(1f)) {
|
||||
Text(tr("tournaments.addClass", "Klasse anlegen"))
|
||||
}
|
||||
OutlinedButton(onClick = {
|
||||
scope.launch {
|
||||
runCatching {
|
||||
withContext(Dispatchers.IO) {
|
||||
api.distributeTables(de.tsschulz.tt_tagebuch.shared.api.models.TournamentClubTournamentBody(clubId, tournamentId))
|
||||
}
|
||||
}.onFailure { onError(it.message) }
|
||||
onReload()
|
||||
}
|
||||
}, modifier = Modifier.weight(1f)) {
|
||||
Text(tr("tournaments.distributeTables", "Freie Tische verteilen"))
|
||||
}
|
||||
}
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.padding(top = 12.dp)) {
|
||||
classes.forEach { c ->
|
||||
|
||||
@@ -156,6 +156,12 @@ class TournamentsApi(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun distributeTables(body: TournamentClubTournamentBody) {
|
||||
client.http.post("/api/tournament/matches/distribute") {
|
||||
setBody(body)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getGroups(clubId: Int, tournamentId: Int): JsonElement {
|
||||
return client.http.get("/api/tournament/groups") {
|
||||
parameter("clubId", clubId)
|
||||
|
||||
Reference in New Issue
Block a user