poprawki
This commit is contained in:
2
app.py
2
app.py
@@ -1952,7 +1952,7 @@ def suggest_products():
|
||||
@app.route("/all_products")
|
||||
def all_products():
|
||||
sort = request.args.get("sort", "popularity")
|
||||
limit = request.args.get("limit", type=int) or 100
|
||||
limit = request.args.get("limit", type=int) or 50
|
||||
offset = request.args.get("offset", type=int) or 0
|
||||
|
||||
rows = db.session.query(Item.name, Item.list_id).distinct().all()
|
||||
|
@@ -6,13 +6,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
const modalBody = modal?.querySelector('.modal-body');
|
||||
|
||||
function normalize(str) {
|
||||
return str
|
||||
? str.normalize("NFD")
|
||||
.replace(/[\u0300-\u036f]/g, "")
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
: '';
|
||||
return str?.trim().toLowerCase() || '';
|
||||
}
|
||||
|
||||
let sortMode = 'popularity';
|
||||
@@ -69,7 +63,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
try {
|
||||
const res = await fetch(`/all_products?sort=${sortMode}&limit=${limit}&offset=${offset}`);
|
||||
const data = await res.json();
|
||||
const products = data.products || data.allproducts || [];
|
||||
const products = data.products || [];
|
||||
|
||||
if (products.length < limit) reachedEnd = true;
|
||||
allProducts = reset ? products : allProducts.concat(products);
|
||||
@@ -114,12 +108,23 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
function renderProducts(products) {
|
||||
addedProducts = getAlreadyAddedProducts();
|
||||
products.forEach(name => {
|
||||
if (typeof name === "object" && name.name) name = name.name;
|
||||
|
||||
const existingNames = new Set();
|
||||
document.querySelectorAll('#mass-add-list li').forEach(li => {
|
||||
const name = li.querySelector('span')?.textContent;
|
||||
if (name) existingNames.add(normalize(name));
|
||||
});
|
||||
|
||||
products.forEach(product => {
|
||||
const name = typeof product === "object" ? product.name : product;
|
||||
const normName = normalize(name);
|
||||
if (existingNames.has(normName)) return;
|
||||
existingNames.add(normName);
|
||||
|
||||
const li = document.createElement('li');
|
||||
li.className = 'list-group-item d-flex justify-content-between align-items-center bg-dark text-light';
|
||||
|
||||
if (addedProducts.has(normalize(name))) {
|
||||
if (addedProducts.has(normName)) {
|
||||
const nameSpan = document.createElement('span');
|
||||
nameSpan.textContent = name;
|
||||
li.appendChild(nameSpan);
|
||||
|
Reference in New Issue
Block a user