Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 170a2a53ab | |||
| a8ac08d5b0 | |||
| 05c4c73635 | |||
| 76dd00831e | |||
| 205a56ff24 | |||
| 60ec21f34e |
+1
-1
@@ -32,4 +32,4 @@ RUN if [ "$NUITKA_BUILD" = "1" ]; then \
|
|||||||
WORKDIR /app/Web
|
WORKDIR /app/Web
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:8000", "--workers", "3", "--timeout", "60", "--graceful-timeout", "20", "--max-requests", "1000", "--max-requests-jitter", "100", "--log-level", "info", "--access-logfile", "-", "--error-logfile", "-"]
|
CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:8000", "--workers", "2", "--timeout", "30", "--graceful-timeout", "20", "--max-requests", "200", "--max-requests-jitter", "50", "--log-level", "info", "--access-logfile", "-", "--error-logfile", "-"]
|
||||||
|
|||||||
+98
-7
@@ -2950,6 +2950,7 @@ def get_items():
|
|||||||
available_only = str(request.args.get('available_only', '')).strip().lower() in ('1', 'true', 'yes', 'on')
|
available_only = str(request.args.get('available_only', '')).strip().lower() in ('1', 'true', 'yes', 'on')
|
||||||
offset_raw = request.args.get('offset')
|
offset_raw = request.args.get('offset')
|
||||||
limit_raw = request.args.get('limit')
|
limit_raw = request.args.get('limit')
|
||||||
|
light_mode_param = str(request.args.get('light_mode', '')).strip().lower()
|
||||||
pagination_requested = offset_raw is not None or limit_raw is not None
|
pagination_requested = offset_raw is not None or limit_raw is not None
|
||||||
|
|
||||||
if pagination_requested:
|
if pagination_requested:
|
||||||
@@ -2966,6 +2967,15 @@ def get_items():
|
|||||||
offset = 0
|
offset = 0
|
||||||
limit = None
|
limit = None
|
||||||
|
|
||||||
|
# Light mode: minimal fields for faster initial load (auto-enabled on offset=0 unless explicitly disabled)
|
||||||
|
# Can be manually controlled via ?light_mode=true/false parameter
|
||||||
|
if light_mode_param in ('1', 'true', 'yes', 'on'):
|
||||||
|
light_mode = True
|
||||||
|
elif light_mode_param in ('0', 'false', 'no', 'off'):
|
||||||
|
light_mode = False
|
||||||
|
else:
|
||||||
|
light_mode = (offset == 0) # Auto-enable light mode for first page
|
||||||
|
|
||||||
client = MongoClient(MONGODB_HOST, MONGODB_PORT)
|
client = MongoClient(MONGODB_HOST, MONGODB_PORT)
|
||||||
db = client[MONGODB_DB]
|
db = client[MONGODB_DB]
|
||||||
items_col = db['items']
|
items_col = db['items']
|
||||||
@@ -2977,18 +2987,98 @@ def get_items():
|
|||||||
|
|
||||||
total_count = items_col.count_documents(base_query)
|
total_count = items_col.count_documents(base_query)
|
||||||
|
|
||||||
items_cur = items_col.find(base_query).sort([('Name', 1), ('_id', 1)])
|
# Light projection: essentials only for fast initial render
|
||||||
|
light_projection = {
|
||||||
|
'Name': 1,
|
||||||
|
'Code_4': 1,
|
||||||
|
'Images': 1,
|
||||||
|
'ThumbnailInfo': 1,
|
||||||
|
'Verfuegbar': 1,
|
||||||
|
'Filter': 1,
|
||||||
|
'Filter2': 1,
|
||||||
|
'Filter3': 1,
|
||||||
|
'Ort': 1,
|
||||||
|
'User': 1,
|
||||||
|
'ItemType': 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Full projection: all details for detailed view
|
||||||
|
full_projection = {
|
||||||
|
'Name': 1,
|
||||||
|
'Ort': 1,
|
||||||
|
'Beschreibung': 1,
|
||||||
|
'Filter': 1,
|
||||||
|
'Filter2': 1,
|
||||||
|
'Filter3': 1,
|
||||||
|
'Code_4': 1,
|
||||||
|
'Images': 1,
|
||||||
|
'ThumbnailInfo': 1,
|
||||||
|
'Verfuegbar': 1,
|
||||||
|
'User': 1,
|
||||||
|
'BorrowerInfo': 1,
|
||||||
|
'appointments': 1,
|
||||||
|
'BlockedNow': 1,
|
||||||
|
'Reservierbar': 1,
|
||||||
|
'DamageReports': 1,
|
||||||
|
'ISBN': 1,
|
||||||
|
'Author': 1,
|
||||||
|
'Autor': 1,
|
||||||
|
'Anschaffungsjahr': 1,
|
||||||
|
'Anschaffungskosten': 1,
|
||||||
|
'Condition': 1,
|
||||||
|
'HasDamage': 1,
|
||||||
|
'ItemType': 1,
|
||||||
|
'SeriesGroupId': 1,
|
||||||
|
'LastUpdated': 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
parent_projection = light_projection if light_mode else full_projection
|
||||||
|
|
||||||
|
items_cur = items_col.find(base_query, parent_projection).sort([('Name', 1), ('_id', 1)])
|
||||||
if pagination_requested:
|
if pagination_requested:
|
||||||
items_cur = items_cur.skip(offset).limit(limit)
|
items_cur = items_cur.skip(offset).limit(limit)
|
||||||
|
|
||||||
items = []
|
parent_items = list(items_cur)
|
||||||
for itm in items_cur:
|
parent_ids = [str(item.get('_id')) for item in parent_items if item.get('_id') is not None]
|
||||||
item_id_str = str(itm['_id'])
|
|
||||||
grouped_children = list(items_col.find({
|
children_by_parent = {}
|
||||||
'ParentItemId': item_id_str,
|
if parent_ids:
|
||||||
|
# Light mode: minimal child data for counting only
|
||||||
|
light_child_projection = {
|
||||||
|
'_id': 1,
|
||||||
|
'ParentItemId': 1,
|
||||||
|
'Code_4': 1,
|
||||||
|
'Verfuegbar': 1,
|
||||||
|
'Name': 1,
|
||||||
|
}
|
||||||
|
# Full mode: complete child data with all details
|
||||||
|
full_child_projection = {
|
||||||
|
'_id': 1,
|
||||||
|
'ParentItemId': 1,
|
||||||
|
'Code_4': 1,
|
||||||
|
'Verfuegbar': 1,
|
||||||
|
'Name': 1,
|
||||||
|
'Images': 1,
|
||||||
|
'ThumbnailInfo': 1,
|
||||||
|
'Beschreibung': 1,
|
||||||
|
}
|
||||||
|
child_projection = light_child_projection if light_mode else full_child_projection
|
||||||
|
|
||||||
|
child_cursor = items_col.find({
|
||||||
|
'ParentItemId': {'$in': parent_ids},
|
||||||
'IsGroupedSubItem': True,
|
'IsGroupedSubItem': True,
|
||||||
'Deleted': {'$ne': True},
|
'Deleted': {'$ne': True},
|
||||||
}))
|
}, child_projection)
|
||||||
|
for child in child_cursor:
|
||||||
|
parent_id = str(child.get('ParentItemId') or '')
|
||||||
|
if not parent_id:
|
||||||
|
continue
|
||||||
|
children_by_parent.setdefault(parent_id, []).append(child)
|
||||||
|
|
||||||
|
items = []
|
||||||
|
for itm in parent_items:
|
||||||
|
item_id_str = str(itm['_id'])
|
||||||
|
grouped_children = children_by_parent.get(item_id_str, [])
|
||||||
grouped_count = 1 + len(grouped_children)
|
grouped_count = 1 + len(grouped_children)
|
||||||
|
|
||||||
grouped_units = [itm] + grouped_children
|
grouped_units = [itm] + grouped_children
|
||||||
@@ -3028,6 +3118,7 @@ def get_items():
|
|||||||
'limit': limit if limit is not None else count,
|
'limit': limit if limit is not None else count,
|
||||||
'count': count,
|
'count': count,
|
||||||
'total': total_count,
|
'total': total_count,
|
||||||
|
'light_mode': light_mode,
|
||||||
'has_more': pagination_requested and ((offset + count) < total_count)
|
'has_more': pagination_requested and ((offset + count) < total_count)
|
||||||
})
|
})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
+128
-2
@@ -728,11 +728,71 @@
|
|||||||
let mainItemsNextOffset = 0;
|
let mainItemsNextOffset = 0;
|
||||||
let mainItemsHasMore = false;
|
let mainItemsHasMore = false;
|
||||||
let mainItemsLoadingMore = false;
|
let mainItemsLoadingMore = false;
|
||||||
|
let mainItemsLightMode = true; // Track if we're in light mode to gradually request full data
|
||||||
let mainItemsObserver = null;
|
let mainItemsObserver = null;
|
||||||
let mainItemsSentinel = null;
|
let mainItemsSentinel = null;
|
||||||
|
let mainItemsLoadingIndicator = null;
|
||||||
|
let mainItemsScrollPrefetchBound = false;
|
||||||
|
|
||||||
|
function ensureMainItemsLoadingIndicator() {
|
||||||
|
const itemsContainer = document.querySelector('#items-container');
|
||||||
|
if (!itemsContainer) return null;
|
||||||
|
|
||||||
|
if (!mainItemsLoadingIndicator) {
|
||||||
|
mainItemsLoadingIndicator = document.createElement('div');
|
||||||
|
mainItemsLoadingIndicator.id = 'main-items-loading-indicator';
|
||||||
|
mainItemsLoadingIndicator.className = 'items-loading-indicator';
|
||||||
|
mainItemsLoadingIndicator.innerHTML = `
|
||||||
|
<div class="loading-track"><div class="loading-fill"></div></div>
|
||||||
|
<div class="loading-label">Weitere Objekte werden vorbereitet...</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemsContainer.appendChild(mainItemsLoadingIndicator);
|
||||||
|
return itemsContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateMainItemsLoadingIndicator() {
|
||||||
|
const itemsContainer = ensureMainItemsLoadingIndicator();
|
||||||
|
if (!itemsContainer || !mainItemsLoadingIndicator) return;
|
||||||
|
|
||||||
|
const shouldShow = mainItemsHasMore || mainItemsLoadingMore;
|
||||||
|
mainItemsLoadingIndicator.style.display = shouldShow ? 'flex' : 'none';
|
||||||
|
mainItemsLoadingIndicator.classList.toggle('is-loading', mainItemsLoadingMore);
|
||||||
|
|
||||||
|
const label = mainItemsLoadingIndicator.querySelector('.loading-label');
|
||||||
|
if (label) {
|
||||||
|
label.textContent = mainItemsLoadingMore
|
||||||
|
? 'Weitere Objekte werden geladen...'
|
||||||
|
: 'Weitere Objekte werden vorbereitet...';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function maybePrefetchMainItems() {
|
||||||
|
const itemsContainer = document.querySelector('#items-container');
|
||||||
|
if (!itemsContainer || !mainItemsHasMore || mainItemsLoadingMore) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const distanceToEnd = itemsContainer.scrollWidth - (itemsContainer.scrollLeft + itemsContainer.clientWidth);
|
||||||
|
const prefetchThreshold = Math.max(260, itemsContainer.clientWidth * 1.4);
|
||||||
|
if (distanceToEnd > prefetchThreshold) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mainItemsLoadingMore = true;
|
||||||
|
updateMainItemsLoadingIndicator();
|
||||||
|
loadItems(mainItemsNextOffset, true).finally(() => {
|
||||||
|
mainItemsLoadingMore = false;
|
||||||
|
updateMainItemsLoadingIndicator();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function loadItems(offset = 0, append = false) {
|
function loadItems(offset = 0, append = false) {
|
||||||
return fetch(`{{ url_for('get_items') }}?offset=${offset}&limit=${MAIN_ITEMS_PAGE_SIZE}`)
|
// Für Pages nach der ersten: Explizit vollständige Daten laden (light_mode=false)
|
||||||
|
// Erste Page: light_mode wird automatisch enablet
|
||||||
|
const lightModeParam = offset > 0 ? '&light_mode=false' : '';
|
||||||
|
return fetch(`{{ url_for('get_items') }}?offset=${offset}&limit=${MAIN_ITEMS_PAGE_SIZE}${lightModeParam}`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const itemsContainer = document.querySelector('#items-container');
|
const itemsContainer = document.querySelector('#items-container');
|
||||||
@@ -1035,10 +1095,15 @@
|
|||||||
|
|
||||||
mainItemsNextOffset = (data.offset || offset) + (data.count || pageItems.length);
|
mainItemsNextOffset = (data.offset || offset) + (data.count || pageItems.length);
|
||||||
mainItemsHasMore = Boolean(data.has_more);
|
mainItemsHasMore = Boolean(data.has_more);
|
||||||
|
updateMainItemsLoadingIndicator();
|
||||||
setupMainItemsLazyLoading();
|
setupMainItemsLazyLoading();
|
||||||
|
maybePrefetchMainItems();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error fetching items:', error);
|
console.error('Error fetching items:', error);
|
||||||
|
mainItemsLoadingMore = false;
|
||||||
|
mainItemsHasMore = false;
|
||||||
|
updateMainItemsLoadingIndicator();
|
||||||
if (append) {
|
if (append) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1052,6 +1117,8 @@
|
|||||||
const itemsContainer = document.querySelector('#items-container');
|
const itemsContainer = document.querySelector('#items-container');
|
||||||
if (!itemsContainer) return null;
|
if (!itemsContainer) return null;
|
||||||
|
|
||||||
|
ensureMainItemsLoadingIndicator();
|
||||||
|
|
||||||
if (!mainItemsSentinel) {
|
if (!mainItemsSentinel) {
|
||||||
mainItemsSentinel = document.createElement('div');
|
mainItemsSentinel = document.createElement('div');
|
||||||
mainItemsSentinel.id = 'main-items-sentinel';
|
mainItemsSentinel.id = 'main-items-sentinel';
|
||||||
@@ -1080,6 +1147,11 @@
|
|||||||
mainItemsObserver = null;
|
mainItemsObserver = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mainItemsScrollPrefetchBound) {
|
||||||
|
itemsContainer.addEventListener('scroll', maybePrefetchMainItems, { passive: true });
|
||||||
|
mainItemsScrollPrefetchBound = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!mainItemsHasMore) return;
|
if (!mainItemsHasMore) return;
|
||||||
|
|
||||||
mainItemsObserver = new IntersectionObserver(entries => {
|
mainItemsObserver = new IntersectionObserver(entries => {
|
||||||
@@ -1092,16 +1164,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
mainItemsLoadingMore = true;
|
mainItemsLoadingMore = true;
|
||||||
|
updateMainItemsLoadingIndicator();
|
||||||
loadItems(mainItemsNextOffset, true).finally(() => {
|
loadItems(mainItemsNextOffset, true).finally(() => {
|
||||||
mainItemsLoadingMore = false;
|
mainItemsLoadingMore = false;
|
||||||
|
updateMainItemsLoadingIndicator();
|
||||||
});
|
});
|
||||||
}, {
|
}, {
|
||||||
root: itemsContainer,
|
root: itemsContainer,
|
||||||
threshold: 0.15,
|
threshold: 0.15,
|
||||||
rootMargin: '0px 220px 0px 0px'
|
rootMargin: '0px 900px 0px 0px'
|
||||||
});
|
});
|
||||||
|
|
||||||
mainItemsObserver.observe(mainItemsSentinel);
|
mainItemsObserver.observe(mainItemsSentinel);
|
||||||
|
updateMainItemsLoadingIndicator();
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchByCode() {
|
function searchByCode() {
|
||||||
@@ -2821,6 +2896,57 @@
|
|||||||
scroll-behavior: smooth;
|
scroll-behavior: smooth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.items-loading-indicator {
|
||||||
|
display: none;
|
||||||
|
flex: 0 0 220px;
|
||||||
|
min-width: 220px;
|
||||||
|
max-width: 220px;
|
||||||
|
height: 180px;
|
||||||
|
align-self: center;
|
||||||
|
margin-right: 8px;
|
||||||
|
border: 1px solid #dbe3ee;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #f8fafc;
|
||||||
|
color: #334155;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
scroll-snap-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.items-loading-indicator .loading-label {
|
||||||
|
font-size: 0.84rem;
|
||||||
|
text-align: center;
|
||||||
|
line-height: 1.3;
|
||||||
|
max-width: 170px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.items-loading-indicator .loading-track {
|
||||||
|
width: 160px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: #e2e8f0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.items-loading-indicator .loading-fill {
|
||||||
|
width: 45%;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: inherit;
|
||||||
|
background: linear-gradient(90deg, #60a5fa, #2563eb);
|
||||||
|
transform: translateX(-100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.items-loading-indicator.is-loading .loading-fill {
|
||||||
|
animation: items-loader-slide 1.05s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes items-loader-slide {
|
||||||
|
0% { transform: translateX(-100%); }
|
||||||
|
100% { transform: translateX(260%); }
|
||||||
|
}
|
||||||
|
|
||||||
.item-card {
|
.item-card {
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
border: 1px solid #ddd;
|
border: 1px solid #ddd;
|
||||||
|
|||||||
@@ -323,6 +323,57 @@
|
|||||||
scroll-behavior: smooth;
|
scroll-behavior: smooth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.items-loading-indicator {
|
||||||
|
display: none;
|
||||||
|
flex: 0 0 220px;
|
||||||
|
min-width: 220px;
|
||||||
|
max-width: 220px;
|
||||||
|
height: 180px;
|
||||||
|
align-self: center;
|
||||||
|
margin-right: 8px;
|
||||||
|
border: 1px solid #dbe3ee;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #f8fafc;
|
||||||
|
color: #334155;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
scroll-snap-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.items-loading-indicator .loading-label {
|
||||||
|
font-size: 0.84rem;
|
||||||
|
text-align: center;
|
||||||
|
line-height: 1.3;
|
||||||
|
max-width: 170px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.items-loading-indicator .loading-track {
|
||||||
|
width: 160px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: #e2e8f0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.items-loading-indicator .loading-fill {
|
||||||
|
width: 45%;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: inherit;
|
||||||
|
background: linear-gradient(90deg, #60a5fa, #2563eb);
|
||||||
|
transform: translateX(-100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.items-loading-indicator.is-loading .loading-fill {
|
||||||
|
animation: items-loader-slide 1.05s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes items-loader-slide {
|
||||||
|
0% { transform: translateX(-100%); }
|
||||||
|
100% { transform: translateX(260%); }
|
||||||
|
}
|
||||||
|
|
||||||
.item-card {
|
.item-card {
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
border: 1px solid #ddd;
|
border: 1px solid #ddd;
|
||||||
@@ -2966,9 +3017,9 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
if (parsedFilters.filter3) activeFilters.filter3 = parsedFilters.filter3;
|
if (parsedFilters.filter3) activeFilters.filter3 = parsedFilters.filter3;
|
||||||
|
|
||||||
// Update UI to show selected filters
|
// Update UI to show selected filters
|
||||||
updateSelectedFilters(1);
|
updateSelectedFiltersDisplay(1);
|
||||||
updateSelectedFilters(2);
|
updateSelectedFiltersDisplay(2);
|
||||||
updateSelectedFilters(3);
|
updateSelectedFiltersDisplay(3);
|
||||||
|
|
||||||
// We'll rebuild Filter 3 options after items are loaded
|
// We'll rebuild Filter 3 options after items are loaded
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -3259,11 +3310,72 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
let mainAdminItemsNextOffset = 0;
|
let mainAdminItemsNextOffset = 0;
|
||||||
let mainAdminItemsHasMore = false;
|
let mainAdminItemsHasMore = false;
|
||||||
let mainAdminItemsLoadingMore = false;
|
let mainAdminItemsLoadingMore = false;
|
||||||
|
let mainAdminLightMode = true; // Track if we're in light mode to gradually request full data
|
||||||
let mainAdminItemsObserver = null;
|
let mainAdminItemsObserver = null;
|
||||||
let mainAdminItemsSentinel = null;
|
let mainAdminItemsSentinel = null;
|
||||||
|
let mainAdminItemsLoadingIndicator = null;
|
||||||
|
let mainAdminItemsScrollPrefetchBound = false;
|
||||||
|
let totalItemsInSystem = 0;
|
||||||
|
|
||||||
|
function ensureMainAdminItemsLoadingIndicator() {
|
||||||
|
const itemsContainer = document.querySelector('#items-container');
|
||||||
|
if (!itemsContainer) return null;
|
||||||
|
|
||||||
|
if (!mainAdminItemsLoadingIndicator) {
|
||||||
|
mainAdminItemsLoadingIndicator = document.createElement('div');
|
||||||
|
mainAdminItemsLoadingIndicator.id = 'main-admin-items-loading-indicator';
|
||||||
|
mainAdminItemsLoadingIndicator.className = 'items-loading-indicator';
|
||||||
|
mainAdminItemsLoadingIndicator.innerHTML = `
|
||||||
|
<div class="loading-track"><div class="loading-fill"></div></div>
|
||||||
|
<div class="loading-label">Weitere Objekte werden vorbereitet...</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemsContainer.appendChild(mainAdminItemsLoadingIndicator);
|
||||||
|
return itemsContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateMainAdminItemsLoadingIndicator() {
|
||||||
|
const itemsContainer = ensureMainAdminItemsLoadingIndicator();
|
||||||
|
if (!itemsContainer || !mainAdminItemsLoadingIndicator) return;
|
||||||
|
|
||||||
|
const shouldShow = mainAdminItemsHasMore || mainAdminItemsLoadingMore;
|
||||||
|
mainAdminItemsLoadingIndicator.style.display = shouldShow ? 'flex' : 'none';
|
||||||
|
mainAdminItemsLoadingIndicator.classList.toggle('is-loading', mainAdminItemsLoadingMore);
|
||||||
|
|
||||||
|
const label = mainAdminItemsLoadingIndicator.querySelector('.loading-label');
|
||||||
|
if (label) {
|
||||||
|
label.textContent = mainAdminItemsLoadingMore
|
||||||
|
? 'Weitere Objekte werden geladen...'
|
||||||
|
: 'Weitere Objekte werden vorbereitet...';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function maybePrefetchMainAdminItems() {
|
||||||
|
const itemsContainer = document.querySelector('#items-container');
|
||||||
|
if (!itemsContainer || !mainAdminItemsHasMore || mainAdminItemsLoadingMore) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const distanceToEnd = itemsContainer.scrollWidth - (itemsContainer.scrollLeft + itemsContainer.clientWidth);
|
||||||
|
const prefetchThreshold = Math.max(260, itemsContainer.clientWidth * 1.4);
|
||||||
|
if (distanceToEnd > prefetchThreshold) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mainAdminItemsLoadingMore = true;
|
||||||
|
updateMainAdminItemsLoadingIndicator();
|
||||||
|
loadItems(mainAdminItemsNextOffset, true).finally(() => {
|
||||||
|
mainAdminItemsLoadingMore = false;
|
||||||
|
updateMainAdminItemsLoadingIndicator();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function loadItems(offset = 0, append = false) {
|
function loadItems(offset = 0, append = false) {
|
||||||
return fetch(`{{ url_for('get_items') }}?offset=${offset}&limit=${MAIN_ADMIN_ITEMS_PAGE_SIZE}`)
|
// Für Pages nach der ersten: Explizit vollständige Daten laden (light_mode=false)
|
||||||
|
// Erste Page: light_mode wird automatisch enablet
|
||||||
|
const lightModeParam = offset > 0 ? '&light_mode=false' : '';
|
||||||
|
return fetch(`{{ url_for('get_items') }}?offset=${offset}&limit=${MAIN_ADMIN_ITEMS_PAGE_SIZE}${lightModeParam}`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const itemsContainer = document.querySelector('#items-container');
|
const itemsContainer = document.querySelector('#items-container');
|
||||||
@@ -3275,6 +3387,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
const filter3Values = new Set();
|
const filter3Values = new Set();
|
||||||
const pageItems = data.items || [];
|
const pageItems = data.items || [];
|
||||||
allItems = append ? allItems.concat(pageItems) : pageItems;
|
allItems = append ? allItems.concat(pageItems) : pageItems;
|
||||||
|
totalItemsInSystem = Number(data.total || totalItemsInSystem || pageItems.length || 0);
|
||||||
if (!append) {
|
if (!append) {
|
||||||
itemsContainer.innerHTML = '';
|
itemsContainer.innerHTML = '';
|
||||||
}
|
}
|
||||||
@@ -3291,9 +3404,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (itemsIndicator) {
|
if (itemsIndicator) {
|
||||||
const shownCount = allItems.length;
|
itemsIndicator.textContent = `Objekte im System: ${totalItemsInSystem}${data.has_more ? ' (lädt...)' : ''}`;
|
||||||
const totalCount = Number(data.total || shownCount);
|
|
||||||
itemsIndicator.textContent = `Objekte im System: ${shownCount}${data.has_more ? ` / ${totalCount} (lädt...)` : ''}`;
|
|
||||||
}
|
}
|
||||||
pageItems.sort((a, b) => {
|
pageItems.sort((a, b) => {
|
||||||
const nameA = a.Name ? a.Name.toLowerCase() : '';
|
const nameA = a.Name ? a.Name.toLowerCase() : '';
|
||||||
@@ -3563,10 +3674,15 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
|
|
||||||
mainAdminItemsNextOffset = (data.offset || offset) + (data.count || pageItems.length);
|
mainAdminItemsNextOffset = (data.offset || offset) + (data.count || pageItems.length);
|
||||||
mainAdminItemsHasMore = Boolean(data.has_more);
|
mainAdminItemsHasMore = Boolean(data.has_more);
|
||||||
|
updateMainAdminItemsLoadingIndicator();
|
||||||
setupMainAdminItemsLazyLoading();
|
setupMainAdminItemsLazyLoading();
|
||||||
|
maybePrefetchMainAdminItems();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error fetching items:', error);
|
console.error('Error fetching items:', error);
|
||||||
|
mainAdminItemsLoadingMore = false;
|
||||||
|
mainAdminItemsHasMore = false;
|
||||||
|
updateMainAdminItemsLoadingIndicator();
|
||||||
if (append) {
|
if (append) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -3584,6 +3700,8 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
const itemsContainer = document.querySelector('#items-container');
|
const itemsContainer = document.querySelector('#items-container');
|
||||||
if (!itemsContainer) return null;
|
if (!itemsContainer) return null;
|
||||||
|
|
||||||
|
ensureMainAdminItemsLoadingIndicator();
|
||||||
|
|
||||||
if (!mainAdminItemsSentinel) {
|
if (!mainAdminItemsSentinel) {
|
||||||
mainAdminItemsSentinel = document.createElement('div');
|
mainAdminItemsSentinel = document.createElement('div');
|
||||||
mainAdminItemsSentinel.id = 'main-admin-items-sentinel';
|
mainAdminItemsSentinel.id = 'main-admin-items-sentinel';
|
||||||
@@ -3607,6 +3725,11 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
mainAdminItemsObserver = null;
|
mainAdminItemsObserver = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mainAdminItemsScrollPrefetchBound) {
|
||||||
|
itemsContainer.addEventListener('scroll', maybePrefetchMainAdminItems, { passive: true });
|
||||||
|
mainAdminItemsScrollPrefetchBound = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!mainAdminItemsHasMore) return;
|
if (!mainAdminItemsHasMore) return;
|
||||||
|
|
||||||
mainAdminItemsObserver = new IntersectionObserver(entries => {
|
mainAdminItemsObserver = new IntersectionObserver(entries => {
|
||||||
@@ -3619,16 +3742,19 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
mainAdminItemsLoadingMore = true;
|
mainAdminItemsLoadingMore = true;
|
||||||
|
updateMainAdminItemsLoadingIndicator();
|
||||||
loadItems(mainAdminItemsNextOffset, true).finally(() => {
|
loadItems(mainAdminItemsNextOffset, true).finally(() => {
|
||||||
mainAdminItemsLoadingMore = false;
|
mainAdminItemsLoadingMore = false;
|
||||||
|
updateMainAdminItemsLoadingIndicator();
|
||||||
});
|
});
|
||||||
}, {
|
}, {
|
||||||
root: itemsContainer,
|
root: itemsContainer,
|
||||||
threshold: 0.15,
|
threshold: 0.15,
|
||||||
rootMargin: '0px 220px 0px 0px'
|
rootMargin: '0px 900px 0px 0px'
|
||||||
});
|
});
|
||||||
|
|
||||||
mainAdminItemsObserver.observe(mainAdminItemsSentinel);
|
mainAdminItemsObserver.observe(mainAdminItemsSentinel);
|
||||||
|
updateMainAdminItemsLoadingIndicator();
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchByCode() {
|
function searchByCode() {
|
||||||
@@ -3725,7 +3851,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (itemsIndicator) {
|
if (itemsIndicator) {
|
||||||
itemsIndicator.textContent = `Objekte im System: ${allItems.length} | Angezeigt: ${visibleCount}`;
|
itemsIndicator.textContent = `Objekte im System: ${totalItemsInSystem || allItems.length} | Angezeigt: ${visibleCount}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCodeSearch && visibleCount > 0 && (codeMatchCount > 0 || exactMatchCount > 0)) {
|
if (isCodeSearch && visibleCount > 0 && (codeMatchCount > 0 || exactMatchCount > 0)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user