2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-01 04:56:45 +00:00

Refactor "search" page

This commit is contained in:
Oliver 2021-10-29 13:54:46 +11:00
parent 0f10936e65
commit 8afa39cd91
4 changed files with 52 additions and 85 deletions

View File

@ -917,6 +917,8 @@ input[type="date"].form-control, input[type="time"].form-control, input[type="da
.sidebar-wrapper { .sidebar-wrapper {
overflow-y: auto; overflow-y: auto;
background: var(--secondary-color); background: var(--secondary-color);
margin-top: 1rem;
padding-top: 0.25rem;
} }
.sidebar-item-icon { .sidebar-item-icon {

View File

@ -14,9 +14,7 @@
{% block content %} {% block content %}
<h3>{% inventree_title %} </h3> <div id='detail-panels'>
<hr>
<div class='container-fluid' id='detail-panels'>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -10,35 +10,19 @@
{% block content %} {% block content %}
<h3> <div class='panel panel-inventree'>
{% trans "Search Results" %} <div class='panel-content'>
</h3>
<div class="container" style='width: 100%'>
{% include "search_form.html" with query_text=query %} {% include "search_form.html" with query_text=query %}
</div> {% if query %}
{% else %}
{% if query %} <div id='empty-search-query'>
{% else %}
<div id='empty-search-query'>
<h4><em>{% trans "Enter a search query" %}</em></h4> <h4><em>{% trans "Enter a search query" %}</em></h4>
</div>
{% endif %}
</div>
</div> </div>
{% endif %}
<div class='col-sm-3' id='item-panel'> <div id='detail-panels'>
<div class='panel'>
<ul class='list-group' id='search-item-list'>
</ul>
</div>
</div>
<div class='col-sm-9' id='details-panel'>
<ul class='list-group' id='search-result-list'>
<li class='list-group-item panel'>
<div class='container'>
<img class='index-bg' src='{% static "img/inventree.png" %}'>
</div>
</li>
</ul>
</div> </div>
{% endblock %} {% endblock %}
@ -47,69 +31,50 @@
{{ block.super }} {{ block.super }}
function addItemTitle(title) { function addItemTitle(title) {
// Add header block to the results list addSidebarHeader({
$('#search-item-list').append( text: title,
`<li class='list-group-item'><strong>${title}</strong></li>` });
);
} }
function addItem(label, title, icon, options) { function addItem(label, title, icon, options) {
// Add a search itme to the action list
$('#search-item-list').append( // Construct a "badge" to add to the sidebar item
`<li class='list-group-item' id='search-item-${label}'> var badge = `
<a href='#'> <span id='sidebar-badge-${label}' class='sidebar-item-badge badge rounded-pill badge-right bg-dark'>
<span class='fas ${icon}'></span>
${title}
</a>
<span class='badge rounded-pill bg-dark' id='badge-${label}'>
<span class='fas fa-spin fa-spinner'></span> <span class='fas fa-spin fa-spinner'></span>
</span> </span>
</li>` `;
);
addSidebarItem({
label: label,
text: title,
icon: icon,
content_after: badge
});
// Add a results table // Add a results table
$('#search-result-list').append( $('#detail-panels').append(
`<li class='list-group-item panel' id='search-result-${label}'> `<div class='panel panel-inventree panel-hidden' id='panel-${label}'>
<div class='panel-heading'>
<h4>${title}</h4> <h4>${title}</h4>
</div>
<div class='panel-content'>
<table class='table table-condensed table-striped' id='table-${label}'></table> <table class='table table-condensed table-striped' id='table-${label}'></table>
</li>` </div>
</div>`
); );
// Hide the results table
$(`#search-result-${label}`).hide();
// Add callback when the action is clicked
$(`#search-item-${label}`).click(function() {
// Hide all childs
$('#search-result-list').children('li').each(function() {
$(this).hide();
});
// Show the one we want
$(`#search-result-${label}`).fadeIn();
// Remove css class from all action items
$("#search-item-list").children('li').each(function() {
$(this).removeClass('index-action-selected');
});
// Add css class to the action we are interested in
$(`#search-item-${label}`).addClass('index-action-selected');
});
// Connect a callback to the table // Connect a callback to the table
$(`#table-${label}`).on('load-success.bs.table', function() { $(`#table-${label}`).on('load-success.bs.table', function() {
var count = $(`#table-${label}`).bootstrapTable('getData').length; var count = $(`#table-${label}`).bootstrapTable('getData').length;
$(`#badge-${label}`).html(count); var badge = $(`#sidebar-badge-${label}`);
$(`#badge-${label}`).removeClass('bg-dark'); badge.html(count);
if (count > 0) { if (count > 0) {
$(`#badge-${label}`).addClass('bg-primary'); badge.removeClass('bg-dark');
} else { badge.addClass('bg-primary');
$(`#badge-${label}`).addClass('bg-warning');
} }
}); });
} }
@ -264,7 +229,11 @@
{% endif %} {% endif %}
enableSidebar(
'search',
{
hide_toggle: 'true',
}
);
{% endblock %} {% endblock %}

View File

@ -96,8 +96,6 @@ function enableSidebar(label, options={}) {
// Find the matching panel element to display // Find the matching panel element to display
var panel_name = el.attr('id').replace('select-', ''); var panel_name = el.attr('id').replace('select-', '');
console.log("activating panel:", panel_name);
activatePanel(label, panel_name, options); activatePanel(label, panel_name, options);
}); });