Files
Infraviewer/public/dev.html

520 lines
16 KiB
HTML

<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="/images/icons/favicon.png">
<link rel="apple-touch-icon" href="/images/icons/icon-180x180.png">
<title>Infraviewer - Volltextsuche</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.header {
text-align: center;
color: white;
margin-bottom: 40px;
}
.header h1 {
font-size: 2.5rem;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}
.header p {
font-size: 1.1rem;
opacity: 0.9;
}
.search-card {
background: white;
border-radius: 12px;
padding: 30px;
box-shadow: 0 10px 40px rgba(0,0,0,0.2);
margin-bottom: 30px;
}
.search-box {
display: flex;
gap: 10px;
margin-bottom: 20px;
}
.search-input {
flex: 1;
padding: 15px 20px;
font-size: 16px;
border: 2px solid #e0e0e0;
border-radius: 8px;
outline: none;
transition: border-color 0.3s;
}
.search-input:focus {
border-color: #667eea;
}
.search-button {
padding: 15px 40px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
}
.search-button:hover {
transform: translateY(-2px);
box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}
.search-button:active {
transform: translateY(0);
}
.search-button:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.stats {
display: flex;
gap: 20px;
padding: 15px;
background: #f5f5f5;
border-radius: 8px;
margin-bottom: 20px;
}
.stat-item {
flex: 1;
text-align: center;
}
.stat-value {
font-size: 2rem;
font-weight: 700;
color: #667eea;
}
.stat-label {
font-size: 0.9rem;
color: #666;
margin-top: 5px;
}
.results {
margin-top: 30px;
}
.table-result {
background: white;
border-radius: 8px;
margin-bottom: 20px;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.table-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 15px 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
.table-name {
font-size: 1.2rem;
font-weight: 600;
}
.table-count {
background: rgba(255,255,255,0.2);
padding: 5px 15px;
border-radius: 20px;
font-size: 0.9rem;
}
.records {
padding: 20px;
}
.record {
display: flex;
margin-bottom: 10px;
border-radius: 6px;
overflow: hidden;
background: #f9f9f9;
}
.record-status-bar {
width: 16px;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
padding: 8px 0;
}
.record-status-label {
writing-mode: vertical-rl;
text-orientation: mixed;
transform: rotate(180deg);
color: rgba(255,255,255,0.95);
font-size: 11px;
font-weight: 600;
white-space: nowrap;
letter-spacing: 0.5px;
}
.record-body {
flex: 1;
padding: 15px;
}
/* Status-Farben (siehe status.txt): aktiv=grün, inaktiv/löschbar=rot, prüfbar=orange, pseudoteil=grün */
.record-status-bar.record--aktiv { background: #2e7d32; }
.record-status-bar.record--inaktiv { background: #c62828; }
.record-status-bar.record--loeschbar { background: #c62828; }
.record-status-bar.record--pruefbar { background: #e65100; }
.record-status-bar.record--pseudoteil { background: #2e7d32; }
.record-field {
display: flex;
padding: 5px 0;
}
.field-name {
font-weight: 600;
color: #666;
min-width: 150px;
}
.field-value {
color: #333;
word-break: break-word;
}
.highlight {
background-color: #ffeb3b;
padding: 2px 4px;
border-radius: 3px;
}
.loading {
text-align: center;
padding: 40px;
color: #666;
}
.spinner {
border: 4px solid #f3f3f3;
border-top: 4px solid #667eea;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 0 auto 20px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.error {
background: #ffebee;
color: #c62828;
padding: 15px;
border-radius: 8px;
margin-top: 20px;
}
.no-results {
text-align: center;
padding: 40px;
color: #666;
}
.config-button {
padding: 10px 20px;
background: white;
color: #667eea;
border: 2px solid white;
border-radius: 8px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
margin-left: 10px;
}
.config-button:hover {
background: transparent;
color: white;
}
@media (max-width: 768px) {
.search-box {
flex-direction: column;
}
.stats {
flex-direction: column;
}
.header h1 {
font-size: 1.8rem;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🔍 Infraviewer</h1>
<p>Volltextsuche über MS SQL Server Express Datenbank</p>
</div>
<div class="search-card">
<div class="search-box">
<input
type="text"
id="searchInput"
class="search-input"
placeholder="Suchbegriff eingeben..."
autofocus
>
<button id="searchButton" class="search-button">Suchen</button>
<button id="configButton" class="config-button" style="display: none;">Konfiguration</button>
</div>
<div id="stats" class="stats" style="display: none;">
<div class="stat-item">
<div class="stat-value" id="totalMatches">0</div>
<div class="stat-label">Treffer</div>
</div>
<div class="stat-item">
<div class="stat-value" id="tablesSearched">0</div>
<div class="stat-label">Tabellen durchsucht</div>
</div>
<div class="stat-item">
<div class="stat-value" id="searchTime">0ms</div>
<div class="stat-label">Suchzeit</div>
</div>
</div>
</div>
<div id="results" class="results"></div>
</div>
<script>
const searchInput = document.getElementById('searchInput');
const searchButton = document.getElementById('searchButton');
const resultsDiv = document.getElementById('results');
const statsDiv = document.getElementById('stats');
let currentSearchTerm = '';
// Enter-Taste zum Suchen
searchInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
performSearch();
}
});
searchButton.addEventListener('click', performSearch);
async function performSearch() {
const searchTerm = searchInput.value.trim();
if (!searchTerm) {
alert('Bitte geben Sie einen Suchbegriff ein');
return;
}
currentSearchTerm = searchTerm;
searchButton.disabled = true;
searchButton.textContent = 'Suche läuft...';
resultsDiv.innerHTML = '<div class="loading"><div class="spinner"></div><p>Datenbank wird durchsucht...</p></div>';
const startTime = performance.now();
try {
const response = await fetch(`/api/search?q=${encodeURIComponent(searchTerm)}`);
const data = await response.json();
const endTime = performance.now();
const searchTime = Math.round(endTime - startTime);
if (data.success) {
displayResults(data, searchTime);
} else {
displayError(data.error);
}
} catch (error) {
displayError('Verbindungsfehler: ' + error.message);
} finally {
searchButton.disabled = false;
searchButton.textContent = 'Suchen';
}
}
function displayResults(data, searchTime) {
// Statistiken anzeigen
statsDiv.style.display = 'flex';
document.getElementById('totalMatches').textContent = data.totalMatches;
document.getElementById('tablesSearched').textContent = data.tablesSearched;
document.getElementById('searchTime').textContent = searchTime + 'ms';
// Ergebnisse anzeigen
if (data.totalMatches === 0) {
resultsDiv.innerHTML = `
<div class="no-results">
<h2>Keine Ergebnisse gefunden</h2>
<p>Der Suchbegriff "${escapeHtml(data.searchTerm)}" wurde in keiner Tabelle gefunden.</p>
</div>
`;
return;
}
let html = '';
data.results.forEach(tableResult => {
if (tableResult.matchCount > 0) {
html += `
<div class="table-result">
<div class="table-header">
<span class="table-name">${escapeHtml(tableResult.tableName)}</span>
<span class="table-count">${tableResult.matchCount} Treffer</span>
</div>
<div class="records">
${tableResult.records.map(record => renderRecord(record)).join('')}
</div>
</div>
`;
}
});
resultsDiv.innerHTML = html;
}
// Feste Spaltenreihenfolge und Anzeige-Labels (siehe Spalten.txt)
const DISPLAY_COLUMNS = [
{ key: 'Teil', label: 'Teilenummer' },
{ key: 'Bez', label: 'Bezeichnung' },
{ key: 'Bez2', label: 'Bezeichnung 2' },
{ key: 'Ben7', label: 'Englischer Text' },
{ key: 'Ben8', label: 'Deutscher Text' },
{ key: 'Hersteller', label: 'Hersteller' },
{ key: 'Text', label: 'Zusatztext' },
{ key: 'PrsVK', label: 'Verkaufspreis in €' },
{ key: 'Ersatz', label: 'Ersetzt durch' }
];
function getStatusClass(stat) {
const s = (stat == null ? '' : String(stat).trim());
if (s === 'i') return 'record--inaktiv';
if (s === 'l') return 'record--loeschbar';
if (s === 'L') return 'record--pruefbar';
if (s === 'p') return 'record--pseudoteil';
return 'record--aktiv'; // "" oder leer = aktiv
}
function getStatusLabel(stat) {
const s = (stat == null ? '' : String(stat).trim());
if (s === 'i') return 'Inaktiv';
if (s === 'l') return 'Löschbar';
if (s === 'L') return 'Prüfbar';
if (s === 'p') return 'Pseudoteil';
return 'Aktiv';
}
function renderRecord(record) {
const statusClass = getStatusClass(record.Stat);
const statusLabel = getStatusLabel(record.Stat);
let html = `
<div class="record">
<div class="record-status-bar ${statusClass}">
<span class="record-status-label">${escapeHtml(statusLabel)}</span>
</div>
<div class="record-body">`;
for (const { key, label } of DISPLAY_COLUMNS) {
if (!(key in record)) continue;
const value = record[key];
const displayValue = value === null || value === undefined ? '' : highlightSearchTerm(String(value));
html += `
<div class="record-field">
<span class="field-name">${escapeHtml(label)}:</span>
<span class="field-value">${displayValue}</span>
</div>`;
}
html += `
</div>
</div>`;
return html;
}
function highlightSearchTerm(text) {
if (!currentSearchTerm) return escapeHtml(text);
const words = currentSearchTerm.trim().split(/\s+/).filter(Boolean);
if (words.length === 0) return escapeHtml(text);
const escapedText = escapeHtml(text);
const pattern = words.map(w => escapeRegex(w)).join('|');
const searchRegex = new RegExp(`(${pattern})`, 'gi');
return escapedText.replace(searchRegex, '<span class="highlight">$1</span>');
}
function displayError(errorMessage) {
statsDiv.style.display = 'none';
resultsDiv.innerHTML = `
<div class="error">
<strong>Fehler:</strong> ${escapeHtml(errorMessage)}
</div>
`;
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
function escapeRegex(text) {
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
// Health Check beim Laden
window.addEventListener('load', async () => {
try {
const response = await fetch('/api/health');
const data = await response.json();
if (data.status !== 'ok') {
displayError('Datenbankverbindung fehlgeschlagen. Bitte überprüfen Sie die Konfiguration.');
}
} catch (error) {
console.error('Health check failed:', error);
}
});
</script>
</body>
</html>