mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 21:45:41 +00:00
feat: buscar reativa em products
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -19,10 +19,12 @@ Produtos
|
||||
|
||||
<body>
|
||||
<div class="grid-container">
|
||||
<div ><input type="text"></div>
|
||||
<div >
|
||||
<input type="text" id="search-product" name="search-product" placeholder="Buscar Produto" hx-get="{% url 'searchProduct' %}" hx-trigger="keyup" hx-target="#product-list"><br>
|
||||
</div>
|
||||
<button onclick="openModal()" id="openModal">Adicionar Novo Produto</button>
|
||||
|
||||
<table id="list-products">
|
||||
<table id="product-list">
|
||||
<tr>
|
||||
<th style="text-align: left;">Produto</th>
|
||||
<th style="text-align: left;width: 20%;">Preço</th>
|
||||
|
||||
@@ -6,6 +6,7 @@ urlpatterns = [
|
||||
path('', views.products, name='products'),
|
||||
path('create_product', views.createProduct, name='create_product'),
|
||||
path('onOffproduct', views.onOffProduct, name='onOffproduct'),
|
||||
path('searchProduct', views.searchProduct, name='searchProduct'),
|
||||
path('editProduct/<int:productId>/', views.editProduct, name='editProduct'),
|
||||
|
||||
]
|
||||
|
||||
@@ -9,6 +9,11 @@ def products(request):
|
||||
categories = Categories.objects.all()
|
||||
return render(request, 'products.html', {'products': protucts, 'categories': categories})
|
||||
|
||||
def searchProduct(request):
|
||||
product = request.GET.get("search-product")
|
||||
products = Product.objects.filter(name__icontains=product)
|
||||
return render(request, "htmx_components/products/htmx_search_products.html", {"products": products})
|
||||
|
||||
|
||||
def createProduct(request):
|
||||
name = request.POST.get('name')
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
|
||||
<tr>
|
||||
<th style="text-align: left;">Produto</th>
|
||||
<th style="text-align: left;width: 20%;">Preço</th>
|
||||
<th style="text-align: left;">Quantidade</th>
|
||||
<th style="text-align: left;">Categoria</th>
|
||||
<th style="text-align: left;width: 20%;">Ações</th>
|
||||
</tr>
|
||||
|
||||
{% for product in products %}
|
||||
|
||||
<tr>
|
||||
<td id="name-{{product.id}}" >{{product.name}}</td>
|
||||
<td id="price-{{product.id}}" >R$ {{product.price}}</td>
|
||||
<td id="quantity-{{product.id}}" >{{product.quantity}}</td>
|
||||
<td id="category-{{product.id}}" >{{product.category.name}}</td>
|
||||
<td>
|
||||
<div class="grid-buttons">
|
||||
<h2 onclick="editProduct({{product.id}})" style="cursor: pointer;" >📝</h2>
|
||||
<input type="hidden" id="h-category-{{product.id}}" value="{{ product.category.id }}">
|
||||
<input type="hidden" id="description-{{product.id}}" value="{{ product.description }}">
|
||||
|
||||
<form action="{% url 'onOffproduct' %}" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="id-product" id="id-{{product.id}}" value="{{ product.id }}">
|
||||
|
||||
{% if product.active == True %}
|
||||
<button style="background-color: rgba(255, 0, 0, 0);">✅</button>
|
||||
{% else %}
|
||||
<button style="background-color: rgba(0, 128, 0, 0);" >🚫</button>
|
||||
|
||||
{% endif %}
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
{% endfor %}
|
||||
|
||||
</table>
|
||||
Reference in New Issue
Block a user