Enhance filter retrieval: update get_filter API to return full filter lists and modify frontend to utilize them for improved item filtering
This commit is contained in:
+7
-3
@@ -6618,11 +6618,15 @@ def zurueckgeben(id):
|
|||||||
def get_filter():
|
def get_filter():
|
||||||
"""
|
"""
|
||||||
API endpoint to retrieve available item filters/categories.
|
API endpoint to retrieve available item filters/categories.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: Dictionary of available filters
|
dict: Dictionary of available filters by filter field
|
||||||
"""
|
"""
|
||||||
return it.get_filters()
|
return jsonify({
|
||||||
|
'filter1': it.get_primary_filters(),
|
||||||
|
'filter2': it.get_secondary_filters(),
|
||||||
|
'filter3': it.get_tertiary_filters(),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@app.route('/get_ausleihung_by_item/<id>')
|
@app.route('/get_ausleihung_by_item/<id>')
|
||||||
|
|||||||
+26
-10
@@ -665,18 +665,30 @@
|
|||||||
// Set up schedule form submission
|
// Set up schedule form submission
|
||||||
setupScheduleFormSubmission();
|
setupScheduleFormSubmission();
|
||||||
|
|
||||||
// Fetch user status to get current username
|
// Fetch user status to get current username and full filter lists
|
||||||
fetch('/user_status')
|
Promise.all([
|
||||||
.then(response => response.json())
|
fetch('/user_status').then(response => response.json()),
|
||||||
.then(data => {
|
fetch('/get_filter').then(response => response.json()),
|
||||||
currentUsername = data.username;
|
])
|
||||||
|
.then(([userData, filterData]) => {
|
||||||
|
currentUsername = userData.username;
|
||||||
|
if (filterData.filter1) {
|
||||||
|
allFilter1Values = new Set(filterData.filter1.filter(value => value && typeof value === 'string' && value.trim() !== ''));
|
||||||
|
}
|
||||||
|
if (filterData.filter2) {
|
||||||
|
allFilter2Values = new Set(filterData.filter2.filter(value => value && typeof value === 'string' && value.trim() !== ''));
|
||||||
|
}
|
||||||
|
if (filterData.filter3) {
|
||||||
|
allFilter3Values = new Set(filterData.filter3.filter(value => value && typeof value === 'string' && value.trim() !== ''));
|
||||||
|
}
|
||||||
|
|
||||||
// Now load items with username information
|
// Now load items with username information
|
||||||
loadItems();
|
loadItems();
|
||||||
// Setup card images display after a short delay to ensure items are loaded
|
// Setup card images display after a short delay to ensure items are loaded
|
||||||
setTimeout(setupCardImagesDisplay, 500);
|
setTimeout(setupCardImagesDisplay, 500);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error fetching user status:', error);
|
console.error('Error fetching user status or filters:', error);
|
||||||
loadItems(); // Load items anyway in case of error
|
loadItems(); // Load items anyway in case of error
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -721,6 +733,10 @@
|
|||||||
filter3: []
|
filter3: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let allFilter1Values = new Set();
|
||||||
|
let allFilter2Values = new Set();
|
||||||
|
let allFilter3Values = new Set();
|
||||||
|
|
||||||
// Add this line to define allItems globally
|
// Add this line to define allItems globally
|
||||||
let allItems = [];
|
let allItems = [];
|
||||||
|
|
||||||
@@ -1083,10 +1099,10 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Populate filter options
|
// Populate filter options using server-provided full filter lists when available.
|
||||||
populateFilterOptions('filter1-options', [...filter1Values].sort(), 1);
|
populateFilterOptions('filter1-options', allFilter1Values.size ? [...allFilter1Values].sort() : [...filter1Values].sort(), 1);
|
||||||
populateFilterOptions('filter2-options', [...filter2Values].sort(), 2);
|
populateFilterOptions('filter2-options', allFilter2Values.size ? [...allFilter2Values].sort() : [...filter2Values].sort(), 2);
|
||||||
populateFilterOptions('filter3-options', [...filter3Values].sort(), 3);
|
populateFilterOptions('filter3-options', allFilter3Values.size ? [...allFilter3Values].sort() : [...filter3Values].sort(), 3);
|
||||||
|
|
||||||
// Start display from leftmost position on full reload only.
|
// Start display from leftmost position on full reload only.
|
||||||
if (!append) {
|
if (!append) {
|
||||||
|
|||||||
Reference in New Issue
Block a user