Compare commits
4
Commits
v1.1.1-dev.3
...
v1.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04c8505531 | ||
|
|
c9edf4a4c8 | ||
|
|
0e0a99569e | ||
|
|
6e94ca20c4 |
No files matched your search
+60
-4
@@ -1560,7 +1560,7 @@ def update_appointment_statuses():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# STUFE 2: >= 2 * student_ausleih_dauer Tage überfällig -> Ausweis sperren, Stufe 2 setzen & Admins benachrichtigen
|
# STUFE 2: >= 2 * student_ausleih_dauer Tage überfällig -> Ausweis sperren, Stufe 2 setzen & Admins benachrichtigen
|
||||||
if days_overdue >= (int(student_ausleih_dauer) * 2) and mahnstufe < 2:
|
if days_overdue >= (int(student_ausleih_dauer) * 2) and mahnstufe == 1 and card.get('is_blocked') is not True:
|
||||||
ausleihungen.update_one(
|
ausleihungen.update_one(
|
||||||
{'_id': appt['_id']},
|
{'_id': appt['_id']},
|
||||||
{'$set': {'Mahnstufe': 2, 'LastUpdated': current_time}}
|
{'$set': {'Mahnstufe': 2, 'LastUpdated': current_time}}
|
||||||
@@ -5597,6 +5597,8 @@ def get_items():
|
|||||||
favorites = set(session.get('favorites', []))
|
favorites = set(session.get('favorites', []))
|
||||||
|
|
||||||
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')
|
||||||
|
search_term = str(request.args.get('search', '')).strip()
|
||||||
|
search_scope = str(request.args.get('search_scope', 'all')).strip().lower()
|
||||||
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()
|
light_mode_param = str(request.args.get('light_mode', '')).strip().lower()
|
||||||
@@ -5632,6 +5634,42 @@ def get_items():
|
|||||||
'Deleted': {'$ne': True},
|
'Deleted': {'$ne': True},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if search_term:
|
||||||
|
search_pattern = re.escape(search_term[:200])
|
||||||
|
if search_scope in ('description', 'title_description'):
|
||||||
|
search_fields = ['Name', 'Beschreibung']
|
||||||
|
else:
|
||||||
|
search_fields = [
|
||||||
|
'Name', 'Beschreibung', 'Code_4', 'ISBN',
|
||||||
|
'Author', 'Autor',
|
||||||
|
]
|
||||||
|
|
||||||
|
direct_matches = [{field: {'$regex': search_pattern, '$options': 'i'}}
|
||||||
|
for field in search_fields]
|
||||||
|
if search_scope not in ('description', 'title_description') and search_term.isdigit():
|
||||||
|
direct_matches.append({'Code_4': int(search_term)})
|
||||||
|
grouped_parent_ids = [
|
||||||
|
child.get('ParentItemId')
|
||||||
|
for child in items_col.find(
|
||||||
|
{
|
||||||
|
'IsGroupedSubItem': True,
|
||||||
|
'Deleted': {'$ne': True},
|
||||||
|
'$or': direct_matches,
|
||||||
|
},
|
||||||
|
{'ParentItemId': 1},
|
||||||
|
)
|
||||||
|
if child.get('ParentItemId')
|
||||||
|
]
|
||||||
|
if grouped_parent_ids:
|
||||||
|
direct_matches.append({'_id': {'$in': grouped_parent_ids}})
|
||||||
|
|
||||||
|
base_query = {
|
||||||
|
'$and': [
|
||||||
|
base_query,
|
||||||
|
{'$or': direct_matches},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
total_count = items_col.count_documents(base_query)
|
total_count = items_col.count_documents(base_query)
|
||||||
|
|
||||||
light_projection = {
|
light_projection = {
|
||||||
@@ -5698,6 +5736,7 @@ def get_items():
|
|||||||
'ParentItemId': 1,
|
'ParentItemId': 1,
|
||||||
'Code_4': 1,
|
'Code_4': 1,
|
||||||
'Verfuegbar': 1,
|
'Verfuegbar': 1,
|
||||||
|
'User': 1,
|
||||||
'Name': 1,
|
'Name': 1,
|
||||||
}
|
}
|
||||||
# Full mode: complete child data with all details
|
# Full mode: complete child data with all details
|
||||||
@@ -5706,6 +5745,7 @@ def get_items():
|
|||||||
'ParentItemId': 1,
|
'ParentItemId': 1,
|
||||||
'Code_4': 1,
|
'Code_4': 1,
|
||||||
'Verfuegbar': 1,
|
'Verfuegbar': 1,
|
||||||
|
'User': 1,
|
||||||
'Name': 1,
|
'Name': 1,
|
||||||
'Images': 1,
|
'Images': 1,
|
||||||
'ThumbnailInfo': 1,
|
'ThumbnailInfo': 1,
|
||||||
@@ -5733,13 +5773,26 @@ def get_items():
|
|||||||
grouped_units = [itm] + grouped_children
|
grouped_units = [itm] + grouped_children
|
||||||
available_units = []
|
available_units = []
|
||||||
grouped_all_codes = []
|
grouped_all_codes = []
|
||||||
|
grouped_unit_states = []
|
||||||
for unit in grouped_units:
|
for unit in grouped_units:
|
||||||
|
unit_id = str(unit['_id']) if not isinstance(unit['_id'], str) else unit['_id']
|
||||||
unit_code = unit.get('Code_4')
|
unit_code = unit.get('Code_4')
|
||||||
if unit_code is not None and str(unit_code).strip() != '':
|
if unit_code is not None and str(unit_code).strip() != '':
|
||||||
grouped_all_codes.append(str(unit_code).strip())
|
normalized_code = str(unit_code).strip()
|
||||||
|
grouped_all_codes.append(normalized_code)
|
||||||
|
else:
|
||||||
|
normalized_code = ''
|
||||||
|
|
||||||
|
grouped_unit_states.append({
|
||||||
|
'id': unit_id,
|
||||||
|
'code': normalized_code,
|
||||||
|
'available': bool(unit.get('Verfuegbar', True)),
|
||||||
|
'borrowed_by_current_user': bool(
|
||||||
|
username and str(unit.get('User') or '') == str(username)
|
||||||
|
),
|
||||||
|
})
|
||||||
|
|
||||||
if unit.get('Verfuegbar', True):
|
if unit.get('Verfuegbar', True):
|
||||||
unit_id = str(unit['_id']) if not isinstance(unit['_id'], str) else unit['_id']
|
|
||||||
code = unit.get('Code_4') or '-'
|
code = unit.get('Code_4') or '-'
|
||||||
available_units.append({
|
available_units.append({
|
||||||
'id': unit_id,
|
'id': unit_id,
|
||||||
@@ -5752,6 +5805,7 @@ def get_items():
|
|||||||
itm['AvailableGroupedCount'] = len(available_units)
|
itm['AvailableGroupedCount'] = len(available_units)
|
||||||
itm['GroupedAvailableUnits'] = available_units
|
itm['GroupedAvailableUnits'] = available_units
|
||||||
itm['GroupedAllCodes'] = grouped_all_codes
|
itm['GroupedAllCodes'] = grouped_all_codes
|
||||||
|
itm['GroupedUnitStates'] = grouped_unit_states
|
||||||
if grouped_count > 1:
|
if grouped_count > 1:
|
||||||
itm['Verfuegbar'] = len(available_units) > 0
|
itm['Verfuegbar'] = len(available_units) > 0
|
||||||
if available_only and not itm.get('Verfuegbar', False):
|
if available_only and not itm.get('Verfuegbar', False):
|
||||||
@@ -10775,7 +10829,9 @@ def search_word(word):
|
|||||||
if (term_lower in text.lower()) or (term_lower in title_text.lower()):
|
if (term_lower in text.lower()) or (term_lower in title_text.lower()):
|
||||||
_id = i.get("_id")
|
_id = i.get("_id")
|
||||||
if _id is not None:
|
if _id is not None:
|
||||||
id_set.add(str(_id))
|
item_id = str(_id)
|
||||||
|
parent_id = i.get('ParentItemId')
|
||||||
|
id_set.add(str(parent_id or item_id))
|
||||||
|
|
||||||
return jsonify({"success": True, "response": list(id_set)})
|
return jsonify({"success": True, "response": list(id_set)})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -3206,9 +3206,12 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadItems(offset = 0, append = false) {
|
function loadItems(offset = 0, append = false, searchTerm = '', searchScope = 'all') {
|
||||||
// Keep list payload lightweight; full details are fetched on-demand in openItemQuick.
|
// Keep list payload lightweight; full details are fetched on-demand in openItemQuick.
|
||||||
return fetch(`{{ url_for('get_items') }}?offset=${offset}&limit=${MAIN_ADMIN_ITEMS_PAGE_SIZE}&light_mode=true`)
|
const searchParams = searchTerm
|
||||||
|
? `&search=${encodeURIComponent(searchTerm)}&search_scope=${encodeURIComponent(searchScope)}`
|
||||||
|
: '';
|
||||||
|
return fetch(`{{ url_for('get_items') }}?offset=${offset}&limit=${MAIN_ADMIN_ITEMS_PAGE_SIZE}&light_mode=true${searchParams}`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const itemsContainer = document.querySelector('#items-container');
|
const itemsContainer = document.querySelector('#items-container');
|
||||||
@@ -3241,7 +3244,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
}
|
}
|
||||||
pageItems.sort((a, b) => {
|
pageItems.sort((a, b) => {
|
||||||
const nameA = a.Name ? a.Name.toLowerCase() : '';
|
const nameA = a.Name ? a.Name.toLowerCase() : '';
|
||||||
const nameB = a.Name ? a.Name.toLowerCase() : '';
|
const nameB = b.Name ? b.Name.toLowerCase() : '';
|
||||||
return nameA.localeCompare(nameB);
|
return nameA.localeCompare(nameB);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -3285,6 +3288,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
card.dataset.code = (item.Code_4 !== undefined && item.Code_4 !== null) ?
|
card.dataset.code = (item.Code_4 !== undefined && item.Code_4 !== null) ?
|
||||||
String(item.Code_4).trim() : '';
|
String(item.Code_4).trim() : '';
|
||||||
card.dataset.groupCodes = JSON.stringify(Array.isArray(item.GroupedAllCodes) ? item.GroupedAllCodes : []);
|
card.dataset.groupCodes = JSON.stringify(Array.isArray(item.GroupedAllCodes) ? item.GroupedAllCodes : []);
|
||||||
|
card.dataset.groupedUnits = JSON.stringify(Array.isArray(item.GroupedUnitStates) ? item.GroupedUnitStates : []);
|
||||||
|
|
||||||
// Add filter values to their respective sets
|
// Add filter values to their respective sets
|
||||||
filter1Array.forEach(value => {
|
filter1Array.forEach(value => {
|
||||||
@@ -3415,7 +3419,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
</div>
|
</div>
|
||||||
{% if current_permissions.actions.get('can_borrow', False) %}
|
{% if current_permissions.actions.get('can_borrow', False) %}
|
||||||
${isAvailableForBorrow && !item.BlockedNow ?
|
${isAvailableForBorrow && !item.BlockedNow ?
|
||||||
`<form method="POST" action="{{ url_for('ausleihen', id='') }}${item._id}">
|
`<form method="POST" action="{{ url_for('ausleihen', id='') }}${item._id}" data-grouped-borrow-form>
|
||||||
${isGroupedItem ? `
|
${isGroupedItem ? `
|
||||||
<div class="grouped-borrow-controls" style="display:flex; gap:8px; flex-wrap:wrap; margin-bottom:8px; align-items:center;">
|
<div class="grouped-borrow-controls" style="display:flex; gap:8px; flex-wrap:wrap; margin-bottom:8px; align-items:center;">
|
||||||
<label style="font-size:0.85rem; margin:0;">Anzahl:</label>
|
<label style="font-size:0.85rem; margin:0;">Anzahl:</label>
|
||||||
@@ -3445,6 +3449,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
:
|
:
|
||||||
`<button class="ausleihen disabled-button" disabled>${item.BlockedNow ? 'Reserviert' : 'Ausgeliehen'}</button>`
|
`<button class="ausleihen disabled-button" disabled>${item.BlockedNow ? 'Reserviert' : 'Ausgeliehen'}</button>`
|
||||||
}
|
}
|
||||||
|
${isGroupedItem ? '<div class="grouped-searched-action" data-grouped-searched-action style="display:none;"></div>' : ''}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if current_permissions.actions.get('can_delete', False) %}
|
{% if current_permissions.actions.get('can_delete', False) %}
|
||||||
<form method="POST" action="{{ url_for('delete_item', id='') }}${item._id}" style="display:inline;" onsubmit="return confirm('Sind Sie sicher, dass Sie dieses Objekt löschen möchten?')">
|
<form method="POST" action="{{ url_for('delete_item', id='') }}${item._id}" style="display:inline;" onsubmit="return confirm('Sind Sie sicher, dass Sie dieses Objekt löschen möchten?')">
|
||||||
@@ -3679,13 +3684,66 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
card.classList.remove('highlight-item', 'code-match', 'exact-code-match');
|
card.classList.remove('highlight-item', 'code-match', 'exact-code-match');
|
||||||
});
|
});
|
||||||
|
|
||||||
applyFilters(true);
|
if (codeSearchTerm) {
|
||||||
|
loadItems(0, false, codeSearchTerm, 'all');
|
||||||
|
} else {
|
||||||
|
loadItems();
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
searchInput.classList.remove('searching');
|
searchInput.classList.remove('searching');
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function syncSearchedGroupedAction(card, searchTerm, exactCodeMatch) {
|
||||||
|
const searchedAction = card.querySelector('[data-grouped-searched-action]');
|
||||||
|
if (!searchedAction) return;
|
||||||
|
|
||||||
|
const borrowForm = card.querySelector('[data-grouped-borrow-form]');
|
||||||
|
searchedAction.style.display = 'none';
|
||||||
|
searchedAction.innerHTML = '';
|
||||||
|
|
||||||
|
if (!exactCodeMatch || !searchTerm) {
|
||||||
|
if (borrowForm) borrowForm.style.display = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let groupedUnits = [];
|
||||||
|
try {
|
||||||
|
groupedUnits = JSON.parse(card.dataset.groupedUnits || '[]');
|
||||||
|
} catch {
|
||||||
|
groupedUnits = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const matchedUnit = groupedUnits.find(unit =>
|
||||||
|
String(unit.code || '').trim().toLowerCase() === searchTerm
|
||||||
|
);
|
||||||
|
if (!matchedUnit) return;
|
||||||
|
|
||||||
|
if (matchedUnit.available) {
|
||||||
|
if (borrowForm) borrowForm.style.display = '';
|
||||||
|
const specificSelect = borrowForm?.querySelector('[name="specific_item_id"]');
|
||||||
|
if (specificSelect) {
|
||||||
|
specificSelect.value = matchedUnit.id;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (borrowForm) borrowForm.style.display = 'none';
|
||||||
|
searchedAction.style.display = 'block';
|
||||||
|
if (matchedUnit.borrowed_by_current_user) {
|
||||||
|
searchedAction.innerHTML = `
|
||||||
|
<form method="POST" action="/zurueckgeben/${encodeURIComponent(matchedUnit.id)}">
|
||||||
|
<button class="ausleihen" type="submit">Zurückgeben (${escapeHtml(matchedUnit.code || 'Code')})</button>
|
||||||
|
</form>`;
|
||||||
|
} else {
|
||||||
|
searchedAction.innerHTML = `
|
||||||
|
<button class="ausleihen disabled-button" type="button" disabled>
|
||||||
|
${escapeHtml(matchedUnit.code || 'Code')} ausgeliehen
|
||||||
|
</button>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function applyFilters(isDirectSearch = false) {
|
function applyFilters(isDirectSearch = false) {
|
||||||
const itemsContainer = document.querySelector('#items-container');
|
const itemsContainer = document.querySelector('#items-container');
|
||||||
const items = itemsContainer.querySelectorAll('.item-card');
|
const items = itemsContainer.querySelectorAll('.item-card');
|
||||||
@@ -3732,6 +3790,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
if (passesAllFilters && matchesCodeSearch && matchesDesc && (!favoritesOnly || isFavoriteCard)) {
|
if (passesAllFilters && matchesCodeSearch && matchesDesc && (!favoritesOnly || isFavoriteCard)) {
|
||||||
item.style.display = 'block';
|
item.style.display = 'block';
|
||||||
visibleCount++;
|
visibleCount++;
|
||||||
|
syncSearchedGroupedAction(item, searchTerm, exactCodeMatch);
|
||||||
|
|
||||||
if (exactCodeMatch) {
|
if (exactCodeMatch) {
|
||||||
item.classList.add('highlight-item', 'exact-code-match');
|
item.classList.add('highlight-item', 'exact-code-match');
|
||||||
@@ -3756,6 +3815,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
item.style.display = 'none';
|
item.style.display = 'none';
|
||||||
|
syncSearchedGroupedAction(item, '', false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -3830,7 +3890,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
card.classList.remove('highlight-item', 'code-match', 'exact-code-match');
|
card.classList.remove('highlight-item', 'code-match', 'exact-code-match');
|
||||||
});
|
});
|
||||||
|
|
||||||
applyFilters();
|
loadItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Description search using backend substring match
|
// Description search using backend substring match
|
||||||
@@ -3839,21 +3899,12 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
const term = (input?.value || '').trim();
|
const term = (input?.value || '').trim();
|
||||||
if (!term){
|
if (!term){
|
||||||
descSearchIds = null;
|
descSearchIds = null;
|
||||||
applyFilters(true);
|
loadItems(0, false, codeSearchTerm, 'all');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
input?.classList.add('searching');
|
input?.classList.add('searching');
|
||||||
fetch(`/search_word/${encodeURIComponent(term)}`)
|
descSearchIds = null;
|
||||||
.then(r=>r.json())
|
loadItems(0, false, term, 'title_description')
|
||||||
.then(data=>{
|
|
||||||
if (data && data.success && Array.isArray(data.response)){
|
|
||||||
descSearchIds = new Set(data.response.map(String));
|
|
||||||
} else {
|
|
||||||
descSearchIds = new Set();
|
|
||||||
}
|
|
||||||
applyFilters(true);
|
|
||||||
})
|
|
||||||
.catch(()=>{ descSearchIds = new Set(); applyFilters(true); })
|
|
||||||
.finally(()=>{ setTimeout(()=> input?.classList.remove('searching'), 300); });
|
.finally(()=>{ setTimeout(()=> input?.classList.remove('searching'), 300); });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3861,7 +3912,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
const input = document.getElementById('desc-search');
|
const input = document.getElementById('desc-search');
|
||||||
if (input) input.value = '';
|
if (input) input.value = '';
|
||||||
descSearchIds = null;
|
descSearchIds = null;
|
||||||
applyFilters();
|
loadItems(0, false, codeSearchTerm, 'all');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open item modal with fresh details from backend.
|
// Open item modal with fresh details from backend.
|
||||||
|
|||||||
Reference in new issue
Block a user