KI-AGENT: Share-Upload an FEDEO-Design und Listenfilter angleichen

This commit is contained in:
2026-08-08 22:36:09 +02:00
parent ec4469e21f
commit ca91de2284
5 changed files with 166 additions and 130 deletions

View File

@@ -0,0 +1,63 @@
import { Customer, Plant, Project } from './api';
function searchTerms(search: string): string[] {
return search.trim().toLocaleLowerCase('de').split(/\s+/).filter(Boolean);
}
function matchesTerms(values: unknown[], terms: string[]): boolean {
if (terms.length === 0) return true;
const haystack = values
.map((value) => String(value || '').toLocaleLowerCase('de'))
.join(' ');
return terms.every((term) => haystack.includes(term));
}
export function getActiveProjectPhase(project: Project): string {
const explicit = String(project.active_phase || '').trim();
if (explicit) return explicit;
const phases = Array.isArray(project.phases) ? project.phases : [];
const active = phases.find((phase: any) => phase?.active);
return String(active?.label || '').trim();
}
export function isProjectCompleted(project: Project): boolean {
return getActiveProjectPhase(project).toLocaleLowerCase('de') === 'abgeschlossen';
}
export function filterProjects(projects: Project[], search: string, showCompleted = false): Project[] {
const terms = searchTerms(search);
return projects.filter((project) => {
if (!showCompleted && isProjectCompleted(project)) return false;
return matchesTerms([
project.name,
project.projectNumber,
project.notes,
project.customerRef,
project.active_phase,
getActiveProjectPhase(project),
], terms);
});
}
export function filterCustomers(customers: Customer[], search: string, showArchived = false): Customer[] {
const terms = searchTerms(search);
return customers.filter((customer) => {
if (!showArchived && customer.archived) return false;
return matchesTerms([customer.name, customer.customerNumber, customer.notes], terms);
});
}
export function getPlantCustomerName(raw: Plant['customer']): string | null {
if (!raw) return null;
if (typeof raw === 'object') return raw.name ? String(raw.name) : null;
return String(raw);
}
export function filterPlants(plants: Plant[], search: string, showArchived = false): Plant[] {
const terms = searchTerms(search);
return plants.filter((plant) => {
if (!showArchived && plant.archived) return false;
return matchesTerms([plant.name, plant.description, getPlantCustomerName(plant.customer)], terms);
});
}