chore: Make it a little beautiful

This commit is contained in:
Hussain Nagaria 2021-04-29 20:01:31 +05:30 committed by marination
parent f3421554ad
commit ba25460edf
4 changed files with 36 additions and 19 deletions

View File

@ -153,7 +153,6 @@ def reindex_all_web_items():
for item in items: for item in items:
web_item = create_web_item_map(item) web_item = create_web_item_map(item)
key = get_cache_key(item.name) key = get_cache_key(item.name)
print(key, web_item)
r.hset(key, mapping=web_item) r.hset(key, mapping=web_item)
def get_cache_key(name): def get_cache_key(name):

View File

@ -72,7 +72,7 @@ def search(query):
query_string = query query_string = query
for s in suggestions: for s in suggestions:
query_string += f"|({s.string})" query_string += f"|('{s.string}')"
q = Query(query_string) q = Query(query_string)

View File

@ -11,20 +11,29 @@
{% endblock header %} {% endblock header %}
{% block page_content %} {% block page_content %}
<input type="text" name="query" id="search-box"> <div class="input-group mb-3">
<input type="text" name="query" id="search-box" class="form-control" placeholder="Search for products..." aria-label="Product" aria-describedby="button-addon2">
<!-- Search Results --> <div class="input-group-append">
<h2>Products</h2> <button class="btn btn-outline-secondary" type="button" id="button-addon2">Search</button>
<ul id="results">Start typing...</ul> </div>
</div>
{% set show_categories = frappe.db.get_single_value('E Commerce Settings', 'show_categories_in_search_autocomplete') %}
<div class="row mt-2">
{% if show_categories %} <!-- Search Results -->
<div id="categories"> <div class="col-sm">
<h2>Categories</h2> <h2>Products</h2>
<ul id="category-suggestions"> <ul id="results" class="list-group"></ul>
</ul> </div>
{% set show_categories = frappe.db.get_single_value('E Commerce Settings', 'show_categories_in_search_autocomplete') %}
{% if show_categories %}
<div id="categories" class="col-sm">
<h2>Categories</h2>
<ul id="category-suggestions">
</ul>
</div>
{% endif %}
</div> </div>
{% endif %}
{% endblock %} {% endblock %}

View File

@ -1,4 +1,4 @@
console.log("search.js loaded"); let loading = false;
const searchBox = document.getElementById("search-box"); const searchBox = document.getElementById("search-box");
const results = document.getElementById("results"); const results = document.getElementById("results");
@ -7,7 +7,7 @@ const categoryList = document.getElementById("category-suggestions");
function populateResults(data) { function populateResults(data) {
html = "" html = ""
for (let res of data.message) { for (let res of data.message) {
html += `<li> html += `<li class="list-group-item list-group-item-action">
<img class="item-thumb" src="${res.thumbnail || ''}" /> <img class="item-thumb" src="${res.thumbnail || ''}" />
<a href="/${res.route}">${res.web_item_name}</a> <a href="/${res.route}">${res.web_item_name}</a>
</li>` </li>`
@ -17,7 +17,7 @@ function populateResults(data) {
function populateCategoriesList(data) { function populateCategoriesList(data) {
if (data.length === 0) { if (data.length === 0) {
categoryList.innerText = "No matches"; categoryList.innerHTML = 'Type something...';
return; return;
} }
@ -29,7 +29,15 @@ function populateCategoriesList(data) {
categoryList.innerHTML = html; categoryList.innerHTML = html;
} }
function updateLoadingState() {
if (loading) {
results.innerHTML = `<div class="spinner-border"><span class="sr-only">loading...<span></div>`;
}
}
searchBox.addEventListener("input", (e) => { searchBox.addEventListener("input", (e) => {
loading = true;
updateLoadingState();
frappe.call({ frappe.call({
method: "erpnext.templates.pages.product_search.search", method: "erpnext.templates.pages.product_search.search",
args: { args: {
@ -37,6 +45,7 @@ searchBox.addEventListener("input", (e) => {
}, },
callback: (data) => { callback: (data) => {
populateResults(data); populateResults(data);
loading = false;
} }
}); });