new network model and mfBaseModelV2

This commit is contained in:
2025-12-14 22:15:00 +01:00
parent 12a7598447
commit b4961fd423
12 changed files with 1944 additions and 335 deletions
@@ -0,0 +1,530 @@
/**
* ADBNetzgebiet - Netzgebietverwaltung Styles
* Optimized for ~1720px width (50% of 21:9 1440p)
*/
/* ===== Container ===== */
.tt-scope.netzgebiet-container {
background: transparent;
color: var(--tt-text);
display: grid;
gap: 16px;
max-width: 90vw;
margin: 24px auto 0;
padding: 20px 0;
}
.tt-scope.netzgebiet-container .card {
margin: 0;
border-radius: var(--tt-radius, 10px);
border: none;
box-shadow: var(--tt-shadow, 0 8px 24px rgba(0, 83, 132, .08));
}
/* ===== Header ===== */
.tt-scope.netzgebiet-container .pane-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
flex-wrap: wrap;
background: linear-gradient(135deg, #f8fbff 0%, #f0f7fd 100%);
padding: 16px 20px;
margin: -14px -14px 14px -14px;
border-radius: var(--tt-radius, 10px) var(--tt-radius, 10px) 0 0;
border-bottom: 2px solid #e3f0f8;
}
.tt-scope.netzgebiet-container .pane-header .title {
display: flex;
align-items: center;
gap: 12px;
font-weight: 800;
letter-spacing: .4px;
font-size: 22px;
user-select: none;
color: var(--tt-accent, #005384);
text-shadow: 0 1px 2px rgba(0,83,132,.1);
}
.tt-scope.netzgebiet-container .logo-dot {
width: 14px;
height: 14px;
border-radius: 50%;
background: radial-gradient(circle at 30% 30%, #37d26b, #0f9d58 70%);
box-shadow: 0 0 0 3px rgba(15,157,88,.15);
display: inline-block;
}
.tt-scope.netzgebiet-container .content-divider {
border: none;
height: 1px;
background-color: var(--tt-border);
margin: 16px 0;
}
/* ===== Filter Bar ===== */
.tt-scope.netzgebiet-container .filter-bar {
display: flex;
align-items: center;
justify-content: center;
padding: 14px 20px;
background: #f8fafc;
border-bottom: 1px solid var(--tt-border);
}
.tt-scope.netzgebiet-container .filter-center {
display: flex;
align-items: center;
gap: 10px;
flex-wrap: wrap;
justify-content: center;
}
.tt-scope.netzgebiet-container .filter-main { width: 200px; }
.tt-scope.netzgebiet-container .filter-md { width: 140px; }
.tt-scope.netzgebiet-container .filter-sm { width: 120px; }
.tt-scope.netzgebiet-container .filter-bar .ri,
.tt-scope.netzgebiet-container .filter-bar select {
height: 34px;
font-size: 13px;
}
.tt-scope.netzgebiet-container .filter-bar .ri {
padding: 6px 10px 6px 34px;
}
.tt-scope.netzgebiet-container .filter-bar .select select {
padding: 6px 28px 6px 10px;
}
.tt-scope.netzgebiet-container .filter-bar .input-icon {
font-size: 13px;
left: 11px;
}
/* ===== Table Container ===== */
.tt-scope .table-container {
overflow-x: auto;
overflow-y: auto;
max-height: calc(100vh - 200px);
}
/* ===== Table ===== */
.tt-scope .netzgebiet-table {
width: 100%;
min-width: 900px;
table-layout: fixed;
border-collapse: collapse;
font-size: 13px;
}
.tt-scope .netzgebiet-table th,
.tt-scope .netzgebiet-table td {
padding: 10px 12px;
vertical-align: top;
border-bottom: 1px solid #eef1f5;
}
.tt-scope .netzgebiet-table thead th {
position: sticky;
top: 0;
background: #f6f9fc;
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.03em;
color: #667085;
z-index: 10;
vertical-align: middle;
}
.tt-scope .netzgebiet-table tbody tr:hover {
background: #fafbfc;
}
/* Column Widths - optimized for 1720px */
.tt-scope .col-name { width: 20%; }
.tt-scope .col-source { width: 14%; }
.tt-scope .col-freigabe { width: 10%; }
.tt-scope .col-network { width: 18%; }
.tt-scope .col-campaign { width: 16%; }
.tt-scope .col-consent { width: 16%; }
.tt-scope .col-actions { width: 6%; text-align: right; }
/* ===== Name Cell ===== */
.tt-scope .name-link {
font-weight: 600;
color: var(--tt-accent);
}
.tt-scope .name-link:hover {
text-decoration: underline;
}
.tt-scope .sub-text {
font-size: 11px;
color: var(--tt-muted);
margin-top: 2px;
}
.tt-scope .truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
display: block;
}
/* ===== Source Badge ===== */
.tt-scope .source-badge {
display: inline-block;
font-size: 11px;
font-weight: 600;
padding: 3px 8px;
border-radius: 4px;
background: #e8f0f6;
color: #3a5a70;
}
/* ===== Freigabe Badges ===== */
.tt-scope .freigabe-badges {
display: flex;
gap: 4px;
}
.tt-scope .freigabe-badge {
width: 20px;
height: 20px;
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 10px;
font-weight: 700;
border-radius: 4px;
color: #fff;
cursor: default;
}
.tt-scope .freigabe-badge.f-interest { background: #1565c0; }
.tt-scope .freigabe-badge.f-provision { background: #e65100; }
.tt-scope .freigabe-badge.f-order { background: #2e7d32; }
.tt-scope .freigabe-badge.f-reorder { background: #7b1fa2; }
/* ===== Related Links ===== */
.tt-scope .related-link {
display: block;
font-size: 12px;
color: var(--tt-accent);
text-decoration: none;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
line-height: 1.5;
}
.tt-scope .related-link:hover {
text-decoration: underline;
}
.tt-scope .more-badge {
display: inline-block;
font-size: 10px;
font-weight: 600;
padding: 1px 5px;
border-radius: 3px;
background: var(--tt-accent);
color: #fff;
margin-left: 4px;
}
.tt-scope .create-link {
display: inline-flex;
align-items: center;
gap: 4px;
font-size: 12px;
color: var(--tt-muted);
text-decoration: none;
opacity: 0.7;
transition: opacity 0.15s, color 0.15s;
}
.tt-scope .create-link:hover {
opacity: 1;
color: var(--tt-accent);
}
.tt-scope .create-link i {
font-size: 11px;
}
/* ===== Action Buttons ===== */
.tt-scope .col-actions {
white-space: nowrap;
}
.tt-scope .col-actions .icon-btn {
padding: 5px 7px;
}
/* ===== Pagination Bar ===== */
.tt-scope .pagination-bar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 20px;
background: #f8fafc;
border-top: 1px solid var(--tt-border);
font-size: 13px;
}
.tt-scope .pagination-info {
color: var(--tt-muted);
}
.tt-scope .pagination-controls {
display: flex;
align-items: center;
gap: 10px;
}
.tt-scope .page-size-select {
height: 30px;
font-size: 12px;
padding: 4px 24px 4px 8px;
border-radius: 6px;
border: 1px solid var(--tt-border);
background: #fff;
}
.tt-scope .page-indicator {
font-size: 12px;
color: var(--tt-muted);
min-width: 60px;
text-align: center;
}
/* ===== Table Placeholder ===== */
.tt-scope .table-placeholder {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 10px;
padding: 60px 20px;
color: var(--tt-muted);
font-size: 14px;
}
.tt-scope .table-placeholder.compact {
padding: 30px 16px;
}
.tt-scope .table-placeholder i {
font-size: 28px;
color: var(--tt-brand-blue);
opacity: 0.5;
}
/* ===== Modal Form ===== */
.tt-scope .modal-form {
display: flex;
flex-direction: column;
gap: 20px;
}
.tt-scope .form-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 16px;
}
.tt-scope .form-grid .field {
display: flex;
flex-direction: column;
gap: 6px;
}
.tt-scope .form-grid .span-2 {
grid-column: span 2;
}
.tt-scope .form-grid label,
.tt-scope .form-section label:not(.checkbox-field) {
font-size: 11px;
font-weight: 600;
color: var(--tt-muted);
text-transform: uppercase;
letter-spacing: 0.03em;
}
.tt-scope .form-section {
border-top: 1px solid var(--tt-border);
padding-top: 16px;
}
.tt-scope .section-label {
display: block;
font-size: 13px;
font-weight: 700;
margin-bottom: 12px;
color: var(--tt-text);
}
/* ===== Checkbox Fields ===== */
.tt-scope .checkbox-row {
display: flex;
gap: 20px;
flex-wrap: wrap;
}
.tt-scope .checkbox-field {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
font-size: 13px;
}
.tt-scope .checkbox-field input[type="checkbox"] {
width: 16px;
height: 16px;
accent-color: var(--tt-brand-blue);
}
.tt-scope .options-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
}
/* ===== History ===== */
.tt-scope .history-container {
max-height: 60vh;
overflow-y: auto;
}
.tt-scope .history-list {
display: flex;
flex-direction: column;
gap: 4px;
}
.tt-scope .history-entry {
display: flex;
gap: 10px;
padding: 8px 12px;
background: #fff;
border-radius: 6px;
border: 1px solid var(--tt-border);
border-left-width: 3px;
}
.tt-scope .history-entry.action-update { border-left-color: #f59f0b; }
.tt-scope .history-entry.action-create { border-left-color: var(--tt-ok); }
.tt-scope .history-entry.action-delete { border-left-color: var(--tt-bad); }
.tt-scope .history-icon {
font-size: 12px;
width: 18px;
text-align: center;
padding-top: 1px;
color: var(--tt-muted);
}
.tt-scope .history-entry.action-update .history-icon { color: #f59f0b; }
.tt-scope .history-entry.action-create .history-icon { color: var(--tt-ok); }
.tt-scope .history-entry.action-delete .history-icon { color: var(--tt-bad); }
.tt-scope .history-content {
flex: 1;
min-width: 0;
}
.tt-scope .history-header {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
flex-wrap: wrap;
}
.tt-scope .history-header strong {
font-weight: 600;
}
.tt-scope .history-header .field-label {
background: #f1f3f5;
padding: 1px 6px;
border-radius: 3px;
font-family: var(--tt-mono);
font-size: 10px;
}
.tt-scope .history-meta {
margin-left: auto;
font-size: 10px;
color: var(--tt-muted);
}
.tt-scope .history-diff {
display: flex;
align-items: center;
gap: 8px;
margin-top: 4px;
font-size: 11px;
}
.tt-scope .history-diff i {
color: var(--tt-muted);
font-size: 9px;
}
.tt-scope .history-diff .diff-old,
.tt-scope .history-diff .diff-new {
display: inline-block;
padding: 2px 8px;
border-radius: 3px;
font-family: var(--tt-mono);
max-width: 320px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
transition: all 0.15s ease;
}
.tt-scope .history-diff .diff-old.expandable,
.tt-scope .history-diff .diff-new.expandable {
cursor: pointer;
}
.tt-scope .history-diff .diff-old.expandable:hover,
.tt-scope .history-diff .diff-new.expandable:hover {
filter: brightness(0.97);
}
.tt-scope .history-diff .diff-old.expanded,
.tt-scope .history-diff .diff-new.expanded {
max-width: 400px;
white-space: normal;
word-break: break-word;
}
.tt-scope .history-diff .diff-old {
background: #fff5f5;
color: #c92a2a;
border: 1px solid #ffc9c9;
}
.tt-scope .history-diff .diff-new {
background: #eaf7ef;
color: #15803d;
border: 1px solid #c9e6d8;
}
/* ===== Utilities ===== */
.tt-scope .mono { font-family: var(--tt-mono); }
.tt-scope .muted { color: var(--tt-muted); }
.tt-scope .mt-3 { margin-top: 12px; }
@@ -0,0 +1,489 @@
/**
* ADBNetzgebiet - Netzgebietverwaltung (Vue 3 + TT-Core)
*/
const ADBNetzgebiet = {
name: 'ADBNetzgebiet',
template: `
<div class="tt-scope netzgebiet-container">
<section class="card card-in">
<!-- Header -->
<div class="pane-header">
<div class="title">
<span class="logo-dot"></span>
<span>Netzgebietverwaltung</span>
</div>
<button class="primary-btn" @click="openCreateModal">
<i class="fa-duotone fa-plus"></i> Neues Netzgebiet
</button>
</div>
<hr class="content-divider" />
<!-- Filter Bar -->
<div class="filter-bar">
<div class="filter-center">
<div class="input-wrap filter-main">
<i class="fa-duotone fa-magnifying-glass input-icon"></i>
<input class="ri" v-model.trim="filters.name" placeholder="Name suchen..." @input="debouncedFilter">
</div>
<div class="input-wrap filter-md">
<i class="fa-duotone fa-key input-icon"></i>
<input class="ri" v-model.trim="filters.extref" placeholder="ExtRef..." @input="debouncedFilter">
</div>
<div class="select filter-sm">
<select v-model="filters.source" @change="applyFilter">
<option value="">Alle Quellen</option>
<option v-for="source in availableSources" :key="source" :value="source">{{ source }}</option>
</select>
</div>
<div class="select filter-sm">
<select v-model="filters.hasNetwork" @change="applyFilter">
<option value="">Netzwerk</option>
<option value="yes">Mit Netzwerk</option>
<option value="no">Ohne Netzwerk</option>
</select>
</div>
<div class="select filter-sm">
<select v-model="filters.hasCampaign" @change="applyFilter">
<option value="">Kampagne</option>
<option value="yes">Mit Kampagne</option>
<option value="no">Ohne Kampagne</option>
</select>
</div>
<div class="select filter-sm">
<select v-model="filters.hasConsent" @change="applyFilter">
<option value="">Zustimmung</option>
<option value="yes">Mit Zustimmung</option>
<option value="no">Ohne Zustimmung</option>
</select>
</div>
<button v-if="hasActiveFilters" class="icon-btn" @click="clearFilters" title="Filter zurücksetzen">
<i class="fa-duotone fa-xmark"></i>
</button>
</div>
</div>
<!-- Data Table -->
<div class="table-container">
<table class="tt-table netzgebiet-table" v-if="!isLoading && paginatedItems.length">
<thead>
<tr>
<th class="col-name">Name / ExtRef</th>
<th class="col-source">Quelle</th>
<th class="col-freigabe">Freigaben</th>
<th class="col-network">Netzwerk</th>
<th class="col-campaign">Kampagne</th>
<th class="col-consent">Zustimmung</th>
<th class="col-actions"></th>
</tr>
</thead>
<tbody>
<tr v-for="item in paginatedItems" :key="item.netzgebiet.id">
<td class="col-name">
<a class="link name-link" href="#" @click.prevent="openEditModal(item)">{{ item.netzgebiet.name || '(Ohne Name)' }}</a>
<div v-if="item.netzgebiet.extref" class="sub-text mono">{{ item.netzgebiet.extref }}</div>
</td>
<td class="col-source">
<span class="source-badge">{{ item.netzgebiet.source || '—' }}</span>
<div v-if="item.netzgebiet.source_id" class="sub-text mono truncate" :title="item.netzgebiet.source_id">{{ item.netzgebiet.source_id }}</div>
</td>
<td class="col-freigabe">
<div class="freigabe-badges">
<span v-for="f in parsedFreigabe(item.netzgebiet.freigabe)" :key="f" class="freigabe-badge" :class="'f-' + f" :title="freigabeLabels[f]">{{ f.charAt(0).toUpperCase() }}</span>
<span v-if="!parsedFreigabe(item.netzgebiet.freigabe).length" class="muted">—</span>
</div>
</td>
<td class="col-network">
<template v-if="item.related.networks.length">
<a v-for="net in item.related.networks.slice(0, 2)" :key="net.id"
:href="window.TT_CONFIG.NETWORK_URL + '?id=' + net.id"
target="_blank" class="related-link">
{{ net.name }}
</a>
<span v-if="item.related.networks.length > 2" class="more-badge">+{{ item.related.networks.length - 2 }}</span>
</template>
<a v-else :href="window.TT_CONFIG.NETWORK_CREATE_URL + '?adb_netzgebiet_id=' + item.netzgebiet.id" class="create-link" title="Netzwerk erstellen">
<i class="fa-duotone fa-plus-circle"></i> Erstellen
</a>
</td>
<td class="col-campaign">
<template v-if="item.related.campaigns.length">
<a v-for="camp in item.related.campaigns.slice(0, 1)" :key="camp.id"
:href="window.TT_CONFIG.CAMPAIGN_URL + '?id=' + camp.id"
target="_blank" class="related-link">
{{ camp.name }}
</a>
<span v-if="item.related.campaigns.length > 1" class="more-badge">+{{ item.related.campaigns.length - 1 }}</span>
</template>
<a v-else-if="item.related.networks.length" :href="window.TT_CONFIG.CAMPAIGN_CREATE_URL + '?network_id=' + item.related.networks[0].id" class="create-link" title="Kampagne erstellen">
<i class="fa-duotone fa-plus-circle"></i> Erstellen
</a>
<span v-else class="muted">—</span>
</td>
<td class="col-consent">
<template v-if="item.related.consent_projects.length">
<a v-for="cons in item.related.consent_projects.slice(0, 1)" :key="cons.id"
:href="window.TT_CONFIG.CONSENT_URL + '?id=' + cons.id"
target="_blank" class="related-link">
{{ cons.name }}
</a>
<span v-if="item.related.consent_projects.length > 1" class="more-badge">+{{ item.related.consent_projects.length - 1 }}</span>
</template>
<a v-else :href="window.TT_CONFIG.CONSENT_CREATE_URL + '?adb_netzgebiet_id=' + item.netzgebiet.id" class="create-link" title="Zustimmungsprojekt erstellen">
<i class="fa-duotone fa-plus-circle"></i> Erstellen
</a>
</td>
<td class="col-actions">
<button class="icon-btn" @click.prevent="openEditModal(item)" title="Bearbeiten"><i class="fa-duotone fa-pen"></i></button>
<button class="icon-btn" @click.prevent="openHistoryModal(item)" title="Verlauf"><i class="fa-duotone fa-clock-rotate-left"></i></button>
</td>
</tr>
</tbody>
</table>
<!-- Loading State -->
<div v-if="isLoading" class="table-placeholder">
<i class="fa-duotone fa-spinner fa-spin"></i>
<span>Lade Netzgebiete...</span>
</div>
<!-- Empty State -->
<div v-if="!isLoading && !filteredNetzgebiete.length" class="table-placeholder">
<i class="fa-duotone fa-database"></i>
<span>Keine Netzgebiete gefunden.</span>
</div>
</div>
<!-- Pagination -->
<div class="pagination-bar" v-if="!isLoading && filteredNetzgebiete.length">
<div class="pagination-info">
{{ paginationStart }}{{ paginationEnd }} von {{ filteredNetzgebiete.length }} Netzgebieten
</div>
<div class="pagination-controls">
<select v-model.number="pageSize" @change="currentPage = 1" class="page-size-select">
<option :value="25">25</option>
<option :value="50">50</option>
<option :value="100">100</option>
</select>
<button class="icon-btn" :disabled="currentPage <= 1" @click="currentPage--"><i class="fa-duotone fa-chevron-left"></i></button>
<span class="page-indicator">{{ currentPage }} / {{ totalPages }}</span>
<button class="icon-btn" :disabled="currentPage >= totalPages" @click="currentPage++"><i class="fa-duotone fa-chevron-right"></i></button>
</div>
</div>
</section>
<!-- Edit/Create Modal -->
<tt-dialog :show="showEditModal" :title="editItem && editItem.id ? 'Netzgebiet bearbeiten' : 'Neues Netzgebiet'" size="wide" @close="showEditModal = false">
<div v-if="editItem" class="modal-form">
<div class="form-grid">
<div class="field span-2">
<label>Name *</label>
<input class="ri" v-model="editItem.name" placeholder="Name des Netzgebiets">
</div>
<div class="field">
<label>Externe Referenz</label>
<input class="ri" v-model="editItem.extref" placeholder="ExtRef">
</div>
<div class="field">
<label>Quelle</label>
<div class="select">
<select v-model="editItem.source">
<option value="">Bitte wählen...</option>
<option value="rimo-rest-api">rimo-rest-api</option>
<option value="csv">csv</option>
<option value="csv-rimo">csv-rimo</option>
<option value="manual">manual</option>
<option value="xinon_qgis">xinon_qgis</option>
<option value="citycom-oan-api">citycom-oan-api</option>
<option value="test">test</option>
</select>
</div>
</div>
<div class="field">
<label>Source ID</label>
<input class="ri" v-model="editItem.source_id" placeholder="Source ID">
</div>
</div>
<div class="form-section">
<label class="section-label">Freigaben</label>
<div class="checkbox-row">
<label v-for="f in freigabeOptions" :key="f.key" class="checkbox-field">
<input type="checkbox" v-model="editItem.freigabe[f.key]">
<span>{{ f.label }}</span>
</label>
</div>
</div>
<div class="form-section">
<label class="section-label">Optionen</label>
<div class="options-grid">
<label v-for="opt in optionsConfig" :key="opt.key" class="checkbox-field" :title="opt.tooltip">
<input type="checkbox" v-model="editItem.options[opt.key]" :true-value="1" :false-value="0">
<span>{{ opt.label }}</span>
</label>
</div>
<div class="form-grid mt-3">
<div class="field">
<label>MPH Min Homes (Auto-Zählung)</label>
<input class="ri" type="number" v-model.number="editItem.options.mph_min_homes_tool_automatic_count" min="0">
</div>
</div>
</div>
</div>
<template #footer>
<button class="ghost-btn" @click="showEditModal = false" :disabled="isSaving">Abbrechen</button>
<button class="primary-btn" @click="saveNetzgebiet" :disabled="isSaving || !editItem?.name">
<span v-if="!isSaving">Speichern</span>
<span v-else class="btn-loader"></span>
</button>
</template>
</tt-dialog>
<!-- History Modal -->
<tt-dialog :show="showHistoryModal" :title="historyTitle" size="wide" @close="showHistoryModal = false">
<div class="history-container">
<div v-if="historyLoading" class="table-placeholder compact">
<i class="fa-duotone fa-spinner fa-spin"></i>
</div>
<div v-else-if="!filteredHistory.length" class="table-placeholder compact">
<i class="fa-duotone fa-clock-rotate-left"></i>
<span>Kein Verlauf vorhanden.</span>
</div>
<div v-else class="history-list">
<div v-for="entry in filteredHistory" :key="entry.id" class="history-entry" :class="'action-' + entry.action">
<div class="history-icon">
<i v-if="entry.action === 'update'" class="fa-duotone fa-pen-to-square"></i>
<i v-else-if="entry.action === 'create'" class="fa-duotone fa-plus-circle"></i>
<i v-else-if="entry.action === 'delete'" class="fa-duotone fa-trash-can"></i>
</div>
<div class="history-content">
<div class="history-header">
<strong>{{ translateAction(entry.action) }}</strong>
<span v-if="entry.action === 'update'" class="field-label">{{ translateField(entry.field) }}</span>
<span class="history-meta">{{ entry.user_name || 'System' }} · {{ formatTimestamp(entry.timestamp) }}</span>
</div>
<div v-if="entry.action === 'update'" class="history-diff">
<span class="diff-old" :class="{ expandable: isLongValue(entry.field, entry.old_value), expanded: expandedIds[entry.id + '_old'] }" @click="toggleExpand(entry.id + '_old')">{{ formatValue(entry.field, entry.old_value) }}</span>
<i class="fa-duotone fa-arrow-right"></i>
<span class="diff-new" :class="{ expandable: isLongValue(entry.field, entry.new_value), expanded: expandedIds[entry.id + '_new'] }" @click="toggleExpand(entry.id + '_new')">{{ formatValue(entry.field, entry.new_value) }}</span>
</div>
</div>
</div>
</div>
</div>
</tt-dialog>
</div>
`,
data() {
return {
window: window,
isLoading: true,
isSaving: false,
netzgebiete: [],
currentPage: 1,
pageSize: 50,
filters: { name: '', extref: '', source: '', hasNetwork: '', hasCampaign: '', hasConsent: '' },
filterDebounce: null,
showEditModal: false,
editItem: null,
showHistoryModal: false,
historyLoading: false,
historyItems: [],
historyTitle: 'Verlauf',
expandedIds: {},
freigabeLabels: { interest: 'Interest', provision: 'Provision', order: 'Order', reorder: 'Reorder' },
freigabeOptions: [
{ key: 'interest', label: 'Interest' },
{ key: 'provision', label: 'Provision' },
{ key: 'order', label: 'Order' },
{ key: 'reorder', label: 'Reorder' }
],
optionsConfig: [
{ key: 'create_address_parts', label: 'create_address_parts', tooltip: 'Neue Straßen/PLZ/Ort anlegen' },
{ key: 'update_freigabe', label: 'update_freigabe', tooltip: 'Setzt Freigabe auf Basis Netzgebiet' },
{ key: 'update_address', label: 'update_address', tooltip: 'Straßennamen ändern' },
{ key: 'hausnummer_dont_overwrite_netzgebiet', label: 'dont_overwrite_netzgebiet', tooltip: 'Netzgebiete nicht überschreiben' },
{ key: 'create_preorder', label: 'create_preorder', tooltip: 'Bestellungen erstellen (SBIDI)' },
{ key: 'preorder_only_oaid', label: 'preorder_only_oaid', tooltip: 'SBIDI OAID aus RIMO' },
{ key: 'wo_ignore_status', label: 'wo_ignore_status', tooltip: 'Status ignorieren' },
{ key: 'delete_units', label: 'delete_units', tooltip: 'Homes löschen die nicht in RIMO sind' },
{ key: 'unit_create_oaid', label: 'unit_create_oaid', tooltip: 'OAID bei Unit erstellen' }
],
defaultOptions: {
create_address_parts: 0, update_freigabe: 1, update_address: 1,
hausnummer_dont_overwrite_netzgebiet: 0, create_preorder: 0,
preorder_only_oaid: 0, wo_ignore_status: 0, delete_units: 0,
mph_min_homes_tool_automatic_count: 3, unit_create_oaid: 0
}
};
},
computed: {
availableSources() {
const sources = new Set();
this.netzgebiete.forEach(item => {
if (item.netzgebiet?.source) sources.add(item.netzgebiet.source);
});
return Array.from(sources).sort();
},
hasActiveFilters() {
return Object.values(this.filters).some(v => v);
},
filteredNetzgebiete() {
return this.netzgebiete.filter(item => {
const n = item.netzgebiet;
if (!n) return false;
if (this.filters.name && !n.name?.toLowerCase().includes(this.filters.name.toLowerCase())) return false;
if (this.filters.extref && !n.extref?.toLowerCase().includes(this.filters.extref.toLowerCase())) return false;
if (this.filters.source && n.source !== this.filters.source) return false;
const hasNetwork = item.related?.networks?.length > 0;
const hasCampaign = item.related?.campaigns?.length > 0;
const hasConsent = item.related?.consent_projects?.length > 0;
if (this.filters.hasNetwork === 'yes' && !hasNetwork) return false;
if (this.filters.hasNetwork === 'no' && hasNetwork) return false;
if (this.filters.hasCampaign === 'yes' && !hasCampaign) return false;
if (this.filters.hasCampaign === 'no' && hasCampaign) return false;
if (this.filters.hasConsent === 'yes' && !hasConsent) return false;
if (this.filters.hasConsent === 'no' && hasConsent) return false;
return true;
});
},
totalPages() { return Math.ceil(this.filteredNetzgebiete.length / this.pageSize) || 1; },
paginatedItems() {
const start = (this.currentPage - 1) * this.pageSize;
return this.filteredNetzgebiete.slice(start, start + this.pageSize);
},
paginationStart() { return this.filteredNetzgebiete.length ? (this.currentPage - 1) * this.pageSize + 1 : 0; },
paginationEnd() { return Math.min(this.currentPage * this.pageSize, this.filteredNetzgebiete.length); },
filteredHistory() {
return this.historyItems.filter(e => !['edit', 'create'].includes(e.field));
}
},
watch: {
filteredNetzgebiete() { if (this.currentPage > this.totalPages) this.currentPage = 1; }
},
async mounted() { await this.fetchNetzgebiete(); },
methods: {
debouncedFilter() {
clearTimeout(this.filterDebounce);
this.filterDebounce = setTimeout(() => this.currentPage = 1, 300);
},
applyFilter() { this.currentPage = 1; },
clearFilters() {
this.filters = { name: '', extref: '', source: '', hasNetwork: '', hasCampaign: '', hasConsent: '' };
this.currentPage = 1;
},
async fetchNetzgebiete() {
this.isLoading = true;
try {
const response = await axios.get(window.TT_CONFIG.GET_URL);
this.netzgebiete = response.data.success ? (response.data.data || []) : (response.data || []);
} catch (error) {
console.error('Fehler:', error);
window.notify?.('error', 'Netzgebiete konnten nicht geladen werden.');
} finally {
this.isLoading = false;
}
},
parsedFreigabe(json) {
try { return JSON.parse(json || '[]') || []; }
catch { return []; }
},
openCreateModal() {
this.editItem = {
id: null, name: '', extref: '', source: '', source_id: '',
freigabe: { interest: true, provision: true, order: true, reorder: true },
options: { ...this.defaultOptions }
};
this.showEditModal = true;
},
openEditModal(item) {
const n = item.netzgebiet;
let options = {};
try { options = JSON.parse(n.options || '{}'); } catch {}
let freigabeArr = [];
try { freigabeArr = JSON.parse(n.freigabe || '[]') || []; } catch {}
const freigabeObj = {};
['interest', 'provision', 'order', 'reorder'].forEach(f => freigabeObj[f] = freigabeArr.includes(f));
this.editItem = {
id: n.id, name: n.name || '', extref: n.extref || '',
source: n.source || '', source_id: n.source_id || '',
freigabe: freigabeObj,
options: { ...this.defaultOptions, ...options }
};
this.showEditModal = true;
},
async saveNetzgebiet() {
if (!this.editItem?.name) return;
this.isSaving = true;
const freigabeArray = Object.keys(this.editItem.freigabe).filter(k => this.editItem.freigabe[k]);
const payload = {
id: this.editItem.id, name: this.editItem.name, extref: this.editItem.extref,
source: this.editItem.source, source_id: this.editItem.source_id,
freigabe: freigabeArray, options: this.editItem.options
};
try {
const response = await axios.post(window.TT_CONFIG.SAVE_URL, payload);
if (response.data.success) {
window.notify?.('success', response.data.message);
this.showEditModal = false;
await this.fetchNetzgebiete();
} else {
window.notify?.('error', response.data.message || 'Fehler beim Speichern.');
}
} catch { window.notify?.('error', 'Netzwerkfehler.'); }
finally { this.isSaving = false; }
},
async openHistoryModal(item) {
this.historyTitle = `Verlauf: ${item.netzgebiet.name}`;
this.showHistoryModal = true;
this.historyLoading = true;
this.historyItems = [];
try {
const response = await axios.get(window.TT_CONFIG.HISTORY_URL + '?id=' + item.netzgebiet.id);
this.historyItems = response.data.success ? (response.data.data || []) : (response.data || []);
} catch { window.notify?.('error', 'Verlauf konnte nicht geladen werden.'); }
finally { this.historyLoading = false; }
},
translateAction(action) { return { create: 'Erstellt', update: 'Geändert', delete: 'Gelöscht' }[action] || action; },
translateField(field) {
return { name: 'Name', extref: 'ExtRef', source: 'Quelle', source_id: 'Source ID',
freigabe: 'Freigaben', options: 'Optionen', unit_counts: 'Einheiten' }[field] || field;
},
formatTimestamp(ts) {
if (!ts) return '—';
try { return new Date(ts.replace(' ', 'T')).toLocaleString('de-AT'); }
catch { return ts; }
},
formatValue(field, value) {
if (value === null || value === undefined || value === '') return '—';
if (['freigabe', 'options'].includes(field)) {
try {
const parsed = typeof value === 'string' ? JSON.parse(value) : value;
if (field === 'freigabe' && Array.isArray(parsed)) return parsed.join(', ') || '—';
if (field === 'options' && typeof parsed === 'object') {
const entries = Object.entries(parsed).filter(([,v]) => v !== 0 && v !== '0');
return entries.map(([k,v]) => `${k}: ${v}`).join(', ') || '—';
}
} catch {}
}
return String(value);
},
isLongValue(field, value) {
return this.formatValue(field, value).length > 40;
},
toggleExpand(id) {
this.expandedIds[id] = !this.expandedIds[id];
}
}
};
if (window.VueApp) {
window.VueApp.component('a-d-b-netzgebiet', ADBNetzgebiet);
}