Update app.py
Browse files
app.py
CHANGED
|
@@ -1576,21 +1576,20 @@ POS_TEMPLATE = '''
|
|
| 1576 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
| 1577 |
<style>
|
| 1578 |
* { box-sizing: border-box; margin: 0; padding: 0; }
|
| 1579 |
-
body { font-family: 'Montserrat', sans-serif; background-color: #
|
| 1580 |
|
| 1581 |
-
.top-bar { padding:
|
| 1582 |
-
.cart-toggle { background: transparent; border: none; color: white; font-size: 1.
|
| 1583 |
-
.cart-badge { position: absolute; top: -8px; right: -12px; background: #E57373; color: white; font-size: 0.75rem; font-weight: bold; border-radius: 50%; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; border: 2px solid #
|
| 1584 |
|
| 1585 |
-
.search-input { flex-grow: 1; padding:
|
| 1586 |
-
.products-grid { flex: 1; overflow-y: auto; padding: 15px; display:
|
| 1587 |
-
.product-card { border: 1px solid #e0e0e0; border-radius:
|
| 1588 |
-
.product-card
|
| 1589 |
-
.product-
|
| 1590 |
-
.product-
|
| 1591 |
-
.product-
|
| 1592 |
-
.product-
|
| 1593 |
-
.product-stock { font-size: 0.75rem; color: #666; margin-top: 4px; }
|
| 1594 |
|
| 1595 |
.cart-sidebar { position: fixed; top: 0; left: -100%; width: 100%; max-width: 400px; height: 100%; height: 100dvh; background: #fdfdff; z-index: 1000; transition: left 0.3s ease; display: flex; flex-direction: column; box-shadow: 2px 0 10px rgba(0,0,0,0.2); }
|
| 1596 |
.cart-sidebar.open { left: 0; }
|
|
@@ -1637,7 +1636,6 @@ POS_TEMPLATE = '''
|
|
| 1637 |
<i class="fas fa-shopping-cart"></i>
|
| 1638 |
<span class="cart-badge" id="cart-badge" style="display:none;">0</span>
|
| 1639 |
</button>
|
| 1640 |
-
<h2 style="margin:0; font-size: 1.2rem; display:none; @media min-width:600px {display:block;}">POS</h2>
|
| 1641 |
<input type="text" class="search-input" id="search-input" placeholder="Поиск товаров..." oninput="renderProducts()">
|
| 1642 |
</div>
|
| 1643 |
|
|
@@ -1692,7 +1690,10 @@ POS_TEMPLATE = '''
|
|
| 1692 |
const currencyCode = '{{ currency_code }}';
|
| 1693 |
const repoId = '{{ repo_id }}';
|
| 1694 |
const bType = '{{ settings.business_type }}';
|
| 1695 |
-
let cart =[];
|
|
|
|
|
|
|
|
|
|
| 1696 |
|
| 1697 |
function toggleCart() {
|
| 1698 |
document.getElementById('cart-sidebar').classList.toggle('open');
|
|
@@ -1701,41 +1702,69 @@ POS_TEMPLATE = '''
|
|
| 1701 |
|
| 1702 |
function renderProducts() {
|
| 1703 |
const query = document.getElementById('search-input').value.toLowerCase();
|
| 1704 |
-
|
| 1705 |
-
let html = '';
|
| 1706 |
|
| 1707 |
allProducts.forEach(p => {
|
| 1708 |
-
if(query && !p.name.toLowerCase().includes(query))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1709 |
|
| 1710 |
p.tags.forEach(tag => {
|
| 1711 |
if(query && !tag.name.toLowerCase().includes(query) && !p.name.toLowerCase().includes(query)) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1712 |
|
| 1713 |
-
|
| 1714 |
-
|
| 1715 |
-
|
| 1716 |
-
|
| 1717 |
-
|
| 1718 |
-
|
| 1719 |
-
const tagData = JSON.stringify({
|
| 1720 |
-
id: tag.id, pid: p.product_id, name: `${p.name} - ${tag.name}`,
|
| 1721 |
-
price: tag.price, box_price: tag.box_price, box_qty: tag.box_qty, photo: p.photos ? p.photos[tag.photo_index] : null
|
| 1722 |
-
}).replace(/"/g, '"');
|
| 1723 |
|
| 1724 |
-
|
| 1725 |
-
|
| 1726 |
-
|
| 1727 |
-
|
| 1728 |
-
|
| 1729 |
-
|
| 1730 |
-
|
| 1731 |
-
</div>
|
| 1732 |
</div>
|
| 1733 |
-
|
| 1734 |
-
|
| 1735 |
-
}
|
| 1736 |
-
grid.
|
|
|
|
| 1737 |
}
|
| 1738 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1739 |
let currentModalData = null;
|
| 1740 |
|
| 1741 |
function openPosModal(data) {
|
|
@@ -1816,7 +1845,7 @@ POS_TEMPLATE = '''
|
|
| 1816 |
if(existing) {
|
| 1817 |
existing.quantity += qty;
|
| 1818 |
} else {
|
| 1819 |
-
let itemName = currentModalData.name + (unitType === 'box' ? `
|
| 1820 |
let itemPrice = unitType === 'box' ? currentModalData.box_price : currentModalData.price;
|
| 1821 |
|
| 1822 |
cart.push({
|
|
@@ -2438,8 +2467,8 @@ ADMIN_TEMPLATE = '''
|
|
| 2438 |
</details>
|
| 2439 |
|
| 2440 |
<h3 style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-top: 30px;">Список товаров:</h3>
|
| 2441 |
-
<form method="GET" action="{{ url_for('admin', env_id=env_id) }}" style="margin-bottom: 20px; display: flex; gap: 10px; flex-wrap: wrap;">
|
| 2442 |
-
<input type="text" name="q" value="{{ search_q }}" placeholder="Поиск по товарам..." style="flex-grow: 1; margin: 0;">
|
| 2443 |
<button type="submit" class="button" style="margin: 0;"><i class="fas fa-search"></i> Поиск</button>
|
| 2444 |
{% if search_q %}
|
| 2445 |
<a href="{{ url_for('admin', env_id=env_id) }}" class="button" style="background-color: #6c757d; margin: 0; justify-content: center;"><i class="fas fa-times"></i> Сброс</a>
|
|
@@ -2598,6 +2627,27 @@ ADMIN_TEMPLATE = '''
|
|
| 2598 |
const formStates = {};
|
| 2599 |
let adminAiHistory =[];
|
| 2600 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2601 |
function showLoadingOverlay() {
|
| 2602 |
document.getElementById('loadingOverlay').style.display = 'flex';
|
| 2603 |
}
|
|
@@ -2762,7 +2812,7 @@ ADMIN_TEMPLATE = '''
|
|
| 2762 |
markersContainer.innerHTML = '';
|
| 2763 |
listContainer.innerHTML = '';
|
| 2764 |
|
| 2765 |
-
const tags = formStates[scope].tags ||
|
| 2766 |
tags.forEach(tag => {
|
| 2767 |
if (tag.photo_index === formStates[scope].currentIdx) {
|
| 2768 |
const marker = document.createElement('div');
|
|
@@ -2775,9 +2825,9 @@ ADMIN_TEMPLATE = '''
|
|
| 2775 |
|
| 2776 |
const listItem = document.createElement('div');
|
| 2777 |
listItem.className = 'tag-list-item';
|
| 2778 |
-
let varText = tag.variants ? `
|
| 2779 |
let boxText = (bType === 'wholesale' || bType === 'combined') ? `[Упак: ${tag.box_qty}шт за ${tag.box_price}]` : '';
|
| 2780 |
-
let stockText = tag.stock !== null && tag.stock !== undefined ? `
|
| 2781 |
listItem.innerHTML = `
|
| 2782 |
<span>[Фото ${tag.photo_index + 1}] ${tag.name} (Шт: ${tag.price})${boxText}${varText}${stockText}</span>
|
| 2783 |
<button type="button" class="delete-button" style="padding: 5px 10px; font-size: 0.9rem; margin:0;" onclick="removeTag('${scope}', '${tag.id}')"><i class="fas fa-times"></i></button>
|
|
@@ -3664,4 +3714,4 @@ if __name__ == '__main__':
|
|
| 3664 |
backup_thread = threading.Thread(target=periodic_backup, daemon=True)
|
| 3665 |
backup_thread.start()
|
| 3666 |
port = int(os.environ.get('PORT', 7860))
|
| 3667 |
-
app.run(debug=False, host='0.0.0.0', port=port)
|
|
|
|
| 1576 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
| 1577 |
<style>
|
| 1578 |
* { box-sizing: border-box; margin: 0; padding: 0; }
|
| 1579 |
+
body { font-family: 'Montserrat', sans-serif; background-color: #f8f9fa; color: #333; height: 100vh; overflow: hidden; display: flex; flex-direction: column;}
|
| 1580 |
|
| 1581 |
+
.top-bar { padding: 10px 15px; background: #1a5e63; display: flex; gap: 15px; align-items: center; flex-shrink: 0;}
|
| 1582 |
+
.cart-toggle { background: transparent; border: none; color: white; font-size: 1.8rem; cursor: pointer; position: relative; display: flex; align-items: center;}
|
| 1583 |
+
.cart-badge { position: absolute; top: -8px; right: -12px; background: #E57373; color: white; font-size: 0.75rem; font-weight: bold; border-radius: 50%; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; border: 2px solid #1a5e63;}
|
| 1584 |
|
| 1585 |
+
.search-input { flex-grow: 1; padding: 12px 15px; border-radius: 8px; border: none; font-size: 1rem; outline: none; }
|
| 1586 |
+
.products-grid { flex: 1; overflow-y: auto; padding: 15px; display: flex; flex-direction: column; gap: 12px; background: #f4f6f9; }
|
| 1587 |
+
.product-card { background: #fff; border: 1px solid #e0e0e0; border-radius: 12px; display: flex; flex-direction: row; align-items: center; padding: 15px; gap: 15px; cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.02); }
|
| 1588 |
+
.product-card img { width: 80px; height: 80px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
|
| 1589 |
+
.product-info { flex-grow: 1; display: flex; flex-direction: column; justify-content: center; gap: 5px; }
|
| 1590 |
+
.product-name { font-weight: 600; font-size: 1.1rem; color: #333; }
|
| 1591 |
+
.product-price { color: #135D66; font-weight: 700; font-size: 1.1rem; }
|
| 1592 |
+
.product-stock { font-size: 0.9rem; color: #888; }
|
|
|
|
| 1593 |
|
| 1594 |
.cart-sidebar { position: fixed; top: 0; left: -100%; width: 100%; max-width: 400px; height: 100%; height: 100dvh; background: #fdfdff; z-index: 1000; transition: left 0.3s ease; display: flex; flex-direction: column; box-shadow: 2px 0 10px rgba(0,0,0,0.2); }
|
| 1595 |
.cart-sidebar.open { left: 0; }
|
|
|
|
| 1636 |
<i class="fas fa-shopping-cart"></i>
|
| 1637 |
<span class="cart-badge" id="cart-badge" style="display:none;">0</span>
|
| 1638 |
</button>
|
|
|
|
| 1639 |
<input type="text" class="search-input" id="search-input" placeholder="Поиск товаров..." oninput="renderProducts()">
|
| 1640 |
</div>
|
| 1641 |
|
|
|
|
| 1690 |
const currencyCode = '{{ currency_code }}';
|
| 1691 |
const repoId = '{{ repo_id }}';
|
| 1692 |
const bType = '{{ settings.business_type }}';
|
| 1693 |
+
let cart = [];
|
| 1694 |
+
let posFilteredTags =[];
|
| 1695 |
+
let posCurrentRendered = 0;
|
| 1696 |
+
const POS_CHUNK_SIZE = 20;
|
| 1697 |
|
| 1698 |
function toggleCart() {
|
| 1699 |
document.getElementById('cart-sidebar').classList.toggle('open');
|
|
|
|
| 1702 |
|
| 1703 |
function renderProducts() {
|
| 1704 |
const query = document.getElementById('search-input').value.toLowerCase();
|
| 1705 |
+
posFilteredTags =[];
|
|
|
|
| 1706 |
|
| 1707 |
allProducts.forEach(p => {
|
| 1708 |
+
if(query && !p.name.toLowerCase().includes(query)) {
|
| 1709 |
+
let tagMatches = false;
|
| 1710 |
+
p.tags.forEach(tag => {
|
| 1711 |
+
if(tag.name.toLowerCase().includes(query)) tagMatches = true;
|
| 1712 |
+
});
|
| 1713 |
+
if(!tagMatches) return;
|
| 1714 |
+
}
|
| 1715 |
|
| 1716 |
p.tags.forEach(tag => {
|
| 1717 |
if(query && !tag.name.toLowerCase().includes(query) && !p.name.toLowerCase().includes(query)) return;
|
| 1718 |
+
posFilteredTags.push({p, tag});
|
| 1719 |
+
});
|
| 1720 |
+
});
|
| 1721 |
+
|
| 1722 |
+
document.getElementById('products-grid').innerHTML = '';
|
| 1723 |
+
posCurrentRendered = 0;
|
| 1724 |
+
loadMorePosProducts();
|
| 1725 |
+
}
|
| 1726 |
+
|
| 1727 |
+
function loadMorePosProducts() {
|
| 1728 |
+
const grid = document.getElementById('products-grid');
|
| 1729 |
+
let html = '';
|
| 1730 |
+
const end = Math.min(posCurrentRendered + POS_CHUNK_SIZE, posFilteredTags.length);
|
| 1731 |
+
|
| 1732 |
+
for (let i = posCurrentRendered; i < end; i++) {
|
| 1733 |
+
const {p, tag} = posFilteredTags[i];
|
| 1734 |
+
const photoUrl = p.photos && p.photos[tag.photo_index]
|
| 1735 |
+
? `https://huggingface.co/datasets/${repoId}/resolve/main/photos/${p.photos[tag.photo_index]}`
|
| 1736 |
+
: 'https://via.placeholder.com/150';
|
| 1737 |
|
| 1738 |
+
const stockText = tag.stock !== undefined ? `Остаток: ${tag.stock}` : 'В наличии';
|
| 1739 |
+
|
| 1740 |
+
const tagData = JSON.stringify({
|
| 1741 |
+
id: tag.id, pid: p.product_id, name: `${p.name} - ${tag.name}`,
|
| 1742 |
+
price: tag.price, box_price: tag.box_price, box_qty: tag.box_qty, photo: p.photos ? p.photos[tag.photo_index] : null
|
| 1743 |
+
}).replace(/"/g, '"');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1744 |
|
| 1745 |
+
html += `
|
| 1746 |
+
<div class="product-card" onclick="openPosModal(${tagData})">
|
| 1747 |
+
<img src="${photoUrl}" alt="${tag.name}">
|
| 1748 |
+
<div class="product-info">
|
| 1749 |
+
<div class="product-name">${p.name} - ${tag.name}</div>
|
| 1750 |
+
<div class="product-price">${tag.price} ${currencyCode}</div>
|
| 1751 |
+
<div class="product-stock">${stockText}</div>
|
|
|
|
| 1752 |
</div>
|
| 1753 |
+
</div>
|
| 1754 |
+
`;
|
| 1755 |
+
}
|
| 1756 |
+
grid.insertAdjacentHTML('beforeend', html);
|
| 1757 |
+
posCurrentRendered = end;
|
| 1758 |
}
|
| 1759 |
|
| 1760 |
+
document.getElementById('products-grid').addEventListener('scroll', function() {
|
| 1761 |
+
if (this.scrollTop + this.clientHeight >= this.scrollHeight - 50) {
|
| 1762 |
+
if (posCurrentRendered < posFilteredTags.length) {
|
| 1763 |
+
loadMorePosProducts();
|
| 1764 |
+
}
|
| 1765 |
+
}
|
| 1766 |
+
});
|
| 1767 |
+
|
| 1768 |
let currentModalData = null;
|
| 1769 |
|
| 1770 |
function openPosModal(data) {
|
|
|
|
| 1845 |
if(existing) {
|
| 1846 |
existing.quantity += qty;
|
| 1847 |
} else {
|
| 1848 |
+
let itemName = currentModalData.name + (unitType === 'box' ? `[Упак: ${currentModalData.box_qty}шт]` : '[Шт]');
|
| 1849 |
let itemPrice = unitType === 'box' ? currentModalData.box_price : currentModalData.price;
|
| 1850 |
|
| 1851 |
cart.push({
|
|
|
|
| 2467 |
</details>
|
| 2468 |
|
| 2469 |
<h3 style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-top: 30px;">Список товаров:</h3>
|
| 2470 |
+
<form method="GET" action="{{ url_for('admin', env_id=env_id) }}" style="margin-bottom: 20px; display: flex; gap: 10px; flex-wrap: wrap;" id="admin-search-form">
|
| 2471 |
+
<input type="text" name="q" value="{{ search_q }}" placeholder="Поиск по товарам..." style="flex-grow: 1; margin: 0;" id="admin-search-input">
|
| 2472 |
<button type="submit" class="button" style="margin: 0;"><i class="fas fa-search"></i> Поиск</button>
|
| 2473 |
{% if search_q %}
|
| 2474 |
<a href="{{ url_for('admin', env_id=env_id) }}" class="button" style="background-color: #6c757d; margin: 0; justify-content: center;"><i class="fas fa-times"></i> Сброс</a>
|
|
|
|
| 2627 |
const formStates = {};
|
| 2628 |
let adminAiHistory =[];
|
| 2629 |
|
| 2630 |
+
document.addEventListener("DOMContentLoaded", function() {
|
| 2631 |
+
const adminSearchInput = document.getElementById('admin-search-input');
|
| 2632 |
+
const adminSearchForm = document.getElementById('admin-search-form');
|
| 2633 |
+
|
| 2634 |
+
if (adminSearchInput && adminSearchForm) {
|
| 2635 |
+
if (adminSearchInput.value.length > 0) {
|
| 2636 |
+
adminSearchInput.focus();
|
| 2637 |
+
const valLen = adminSearchInput.value.length;
|
| 2638 |
+
adminSearchInput.setSelectionRange(valLen, valLen);
|
| 2639 |
+
}
|
| 2640 |
+
|
| 2641 |
+
let debounceTimer;
|
| 2642 |
+
adminSearchInput.addEventListener('input', function() {
|
| 2643 |
+
clearTimeout(debounceTimer);
|
| 2644 |
+
debounceTimer = setTimeout(() => {
|
| 2645 |
+
adminSearchForm.submit();
|
| 2646 |
+
}, 700);
|
| 2647 |
+
});
|
| 2648 |
+
}
|
| 2649 |
+
});
|
| 2650 |
+
|
| 2651 |
function showLoadingOverlay() {
|
| 2652 |
document.getElementById('loadingOverlay').style.display = 'flex';
|
| 2653 |
}
|
|
|
|
| 2812 |
markersContainer.innerHTML = '';
|
| 2813 |
listContainer.innerHTML = '';
|
| 2814 |
|
| 2815 |
+
const tags = formStates[scope].tags ||[];
|
| 2816 |
tags.forEach(tag => {
|
| 2817 |
if (tag.photo_index === formStates[scope].currentIdx) {
|
| 2818 |
const marker = document.createElement('div');
|
|
|
|
| 2825 |
|
| 2826 |
const listItem = document.createElement('div');
|
| 2827 |
listItem.className = 'tag-list-item';
|
| 2828 |
+
let varText = tag.variants ? `[Вар: ${tag.variants}]` : '';
|
| 2829 |
let boxText = (bType === 'wholesale' || bType === 'combined') ? `[Упак: ${tag.box_qty}шт за ${tag.box_price}]` : '';
|
| 2830 |
+
let stockText = tag.stock !== null && tag.stock !== undefined ? `[Остаток: ${tag.stock}]` : '';
|
| 2831 |
listItem.innerHTML = `
|
| 2832 |
<span>[Фото ${tag.photo_index + 1}] ${tag.name} (Шт: ${tag.price})${boxText}${varText}${stockText}</span>
|
| 2833 |
<button type="button" class="delete-button" style="padding: 5px 10px; font-size: 0.9rem; margin:0;" onclick="removeTag('${scope}', '${tag.id}')"><i class="fas fa-times"></i></button>
|
|
|
|
| 3714 |
backup_thread = threading.Thread(target=periodic_backup, daemon=True)
|
| 3715 |
backup_thread.start()
|
| 3716 |
port = int(os.environ.get('PORT', 7860))
|
| 3717 |
+
app.run(debug=False, host='0.0.0.0', port=port)
|