Refactor match and predefined activity services for improved functionality and user experience

Removed unnecessary logging from the MatchService to streamline performance. Enhanced the PredefinedActivityService by implementing a more intelligent search feature that splits queries into individual terms, allowing for more precise filtering of activities. Updated the frontend PredefinedActivities.vue to include a search input with real-time results and a clear search button, improving user interaction and accessibility.
This commit is contained in:
Torsten Schulz (local)
2025-10-24 16:35:03 +02:00
parent c18b70c6f6
commit d16f250f80
3 changed files with 120 additions and 17 deletions

View File

@@ -291,8 +291,6 @@ class MatchService {
}
const clubName = club.name;
devLog(`Filtering matches for club: ${clubName}`);
// Find all club teams in this league
const clubTeams = await ClubTeam.findAll({
where: {
@@ -302,8 +300,6 @@ class MatchService {
attributes: ['id', 'name']
});
devLog(`Club teams in league ${leagueId}: ${clubTeams.map(ct => ct.name).join(', ')}`);
// Find all Team entries that contain our club name
const ownTeams = await Team.findAll({
where: {
@@ -316,7 +312,6 @@ class MatchService {
});
const ownTeamIds = ownTeams.map(t => t.id);
devLog(`Own team IDs in this league: ${ownTeamIds.join(', ')} (${ownTeams.map(t => t.name).join(', ')})`);
// Load matches
let matches;
@@ -331,10 +326,8 @@ class MatchService {
]
}
});
devLog(`Found ${matches.length} matches for our teams`);
} else {
// No own teams found - show nothing
devLog('No own teams found in this league, showing no matches');
matches = [];
}

View File

@@ -58,20 +58,40 @@ class PredefinedActivityService {
if (!q || q.length < 2) {
return [];
}
return await PredefinedActivity.findAll({
// Intelligente Suche: Teile den Query in einzelne Begriffe auf
const searchTerms = q.split(/\s+/).filter(term => term.length > 0);
if (searchTerms.length === 0) {
return [];
}
// Hole alle Aktivitäten mit Kürzeln
const allActivities = await PredefinedActivity.findAll({
where: {
[Op.or]: [
{ name: { [Op.like]: `%${q}%` } },
{ code: { [Op.like]: `%${q}%` } },
],
code: { [Op.ne]: null } // Nur Aktivitäten mit Kürzel
},
order: [
[sequelize.literal('code IS NULL'), 'ASC'],
['code', 'ASC'],
['name', 'ASC'],
],
limit: Math.min(parseInt(limit || 20, 10), 50),
limit: 1000 // Höhere Grenze für Filterung
});
// Filtere die Ergebnisse, um nur die zu finden, die ALLE Begriffe enthalten
const filteredResults = allActivities.filter(activity => {
const code = (activity.code || '').toLowerCase();
// Prüfe, ob alle Suchbegriffe im Kürzel enthalten sind
return searchTerms.every(term => {
const normalizedTerm = term.toLowerCase();
return code.includes(normalizedTerm);
});
});
// Begrenze die Ergebnisse
return filteredResults.slice(0, Math.min(parseInt(limit || 20, 10), 50));
}
async mergeActivities(sourceId, targetId) {

View File

@@ -6,10 +6,20 @@
<div class="toolbar">
<button @click="startCreate" class="btn-primary">Neu</button>
<button @click="reload" class="btn-secondary">Neu laden</button>
<div>
</div>
<div class="search-section">
<input
type="text"
v-model="searchQuery"
@input="onSearchInput"
placeholder="Kürzel suchen (z.B. 'as vh us' oder 'vh as us')..."
class="search-input"
/>
<button v-if="searchQuery" @click="clearSearch" class="btn-clear-search"></button>
</div>
<div>
<button @click="deduplicate" class="btn-secondary">Doppelungen zusammenführen</button>
</div
</div>
<div class="merge-tools">
<select v-model="mergeSourceId">
<option disabled value="">Quelle wählen</option>
@@ -22,7 +32,6 @@
</select>
<button class="btn-secondary" :disabled="!canMerge" @click="mergeSelected">Zusammenführen</button>
</div>
</div>
<ul class="items">
<li v-for="a in sortedActivities" :key="a.id" :class="{ active: selectedActivity && selectedActivity.id === a.id }" @click="select(a)">
<div class="title">
@@ -167,11 +176,17 @@ export default {
selectedDrawingData: null,
mergeSourceId: '',
mergeTargetId: '',
searchQuery: '',
searchResults: [],
isSearching: false,
};
},
computed: {
sortedActivities() {
return [...(this.activities || [])].sort((a, b) => {
// Wenn gesucht wird, zeige Suchergebnisse, sonst alle Aktivitäten
const activitiesToSort = this.searchQuery.trim() ? this.searchResults : this.activities;
return [...(activitiesToSort || [])].sort((a, b) => {
const ac = (a.code || '').toLocaleLowerCase('de-DE');
const bc = (b.code || '').toLocaleLowerCase('de-DE');
const aEmpty = ac === '';
@@ -221,6 +236,34 @@ export default {
this.confirmDialog.isOpen = false;
},
// Suchfunktionen
async onSearchInput() {
const query = this.searchQuery.trim();
if (!query || query.length < 2) {
this.searchResults = [];
return;
}
this.isSearching = true;
try {
const response = await apiClient.get('/predefined-activities/search/query', {
params: { q: query, limit: 50 }
});
this.searchResults = response.data || [];
} catch (error) {
console.error('Error searching activities:', error);
this.searchResults = [];
} finally {
this.isSearching = false;
}
},
clearSearch() {
this.searchQuery = '';
this.searchResults = [];
},
parseDrawingData(value) {
if (!value) return null;
if (typeof value === 'object') return value;
@@ -556,5 +599,52 @@ input[type="text"], input[type="number"], textarea { width: 100%; }
color: #333;
font-size: 1rem;
}
/* Suchfeld Styles */
.search-section {
position: relative;
margin: 1rem 0;
}
.search-input {
width: 100%;
padding: 0.75rem 2.5rem 0.75rem 1rem;
border: 2px solid #ddd;
border-radius: var(--border-radius);
font-size: 1rem;
background: white;
transition: border-color 0.3s ease;
}
.search-input:focus {
outline: none;
border-color: #007bff;
box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}
.btn-clear-search {
position: absolute;
right: 0.75rem;
top: 50%;
transform: translateY(-50%);
background: none;
border: none;
color: #666;
font-size: 1.2rem;
cursor: pointer;
padding: 0.25rem;
border-radius: 50%;
width: 2rem;
height: 2rem;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
}
.btn-clear-search:hover {
background: #f8f9fa;
color: #333;
}
</style>