Hide result types which return no results

This commit is contained in:
Oliver Walters 2019-06-02 20:28:17 +10:00
parent 0b88953706
commit 64d541f453
4 changed files with 92 additions and 74 deletions

View File

@ -156,6 +156,7 @@
{% endif %}
},
buttons: ['#part-options'],
checkbox: true,
},
);

View File

@ -82,6 +82,7 @@ function loadPartTable(table, url, options={}) {
* - url: Base URL for API query
* - options: object containing following (optional) fields
* allowInactive: If true, allow display of inactive parts
* checkbox: Show the checkbox column
* query: extra query params for API request
* buttons: If provided, link buttons to selection status of this table
*/
@ -94,6 +95,84 @@ function loadPartTable(table, url, options={}) {
query.active = true;
}
var columns = [
{
field: 'pk',
title: 'ID',
visible: false,
}
];
if (options.checkbox) {
columns.push({
checkbox: true,
title: 'Select',
searchable: false,
});
}
columns.push({
field: 'full_name',
title: 'Part',
sortable: true,
formatter: function(value, row, index, field) {
if (row.is_template) {
value = '<i>' + value + '</i>';
}
var display = imageHoverIcon(row.image_url) + renderLink(value, row.url);
if (!row.active) {
display = display + "<span class='label label-warning' style='float: right;'>INACTIVE</span>";
}
return display;
}
});
columns.push({
sortable: true,
field: 'description',
title: 'Description',
formatter: function(value, row, index, field) {
if (row.is_template) {
value = '<i>' + value + '</i>';
}
return value;
}
});
columns.push({
sortable: true,
field: 'category_name',
title: 'Category',
formatter: function(value, row, index, field) {
if (row.category) {
return renderLink(row.category_name, "/part/category/" + row.category + "/");
}
else {
return '';
}
}
});
columns.push({
field: 'total_stock',
title: 'Stock',
searchable: false,
sortable: true,
formatter: function(value, row, index, field) {
if (value) {
return renderLink(value, row.url + 'stock/');
}
else {
return "<span class='label label-warning'>No Stock</span>";
}
}
});
$(table).bootstrapTable({
url: url,
sortable: true,
@ -107,76 +186,7 @@ function loadPartTable(table, url, options={}) {
queryParams: function(p) {
return query;
},
columns: [
{
checkbox: true,
title: 'Select',
searchable: false,
},
{
field: 'pk',
title: 'ID',
visible: false,
},
{
field: 'full_name',
title: 'Part',
sortable: true,
formatter: function(value, row, index, field) {
if (row.is_template) {
value = '<i>' + value + '</i>';
}
var display = imageHoverIcon(row.image_url) + renderLink(value, row.url);
if (!row.active) {
display = display + "<span class='label label-warning' style='float: right;'>INACTIVE</span>";
}
return display;
}
},
{
sortable: true,
field: 'description',
title: 'Description',
formatter: function(value, row, index, field) {
if (row.is_template) {
value = '<i>' + value + '</i>';
}
return value;
}
},
{
sortable: true,
field: 'category_name',
title: 'Category',
formatter: function(value, row, index, field) {
if (row.category) {
return renderLink(row.category_name, "/part/category/" + row.category + "/");
}
else {
return '';
}
}
},
{
field: 'total_stock',
title: 'Stock',
searchable: false,
sortable: true,
formatter: function(value, row, index, field) {
if (value) {
return renderLink(value, row.url + 'stock/');
}
else {
return "<span class='label label-warning'>No Stock</span>";
}
}
}
],
columns: columns,
});
if (options.buttons) {

View File

@ -17,6 +17,10 @@ InvenTree | Search Results
<br><br>
<hr>
<div id='no-search-results'>
<h4><i>No results found</i></h4>
</div>
{% include "InvenTree/search_part_category.html" with collapse_id="categories" %}
{% include "InvenTree/search_parts.html" with collapse_id='parts' %}
@ -35,10 +39,12 @@ InvenTree | Search Results
{% block js_ready %}
{{ block.super }}
$(".panel-group").hide();
function onSearchResults(table, output) {
$(table).on('load-success.bs.table', function() {
var panel = $(output).parent('.panel-group');
var panel = $(output).closest('.panel-group');
var n = $(table).bootstrapTable('getData').length;
@ -47,8 +53,6 @@ InvenTree | Search Results
text = '<i>No results</i>'
$(panel).hide();
$(table).hide();
} else {
@ -59,6 +63,8 @@ InvenTree | Search Results
}
$(panel).show();
$("#no-search-results").hide();
}
$(output).html(text);
@ -120,6 +126,7 @@ InvenTree | Search Results
search: "{{ query }}",
},
allowInactive: true,
checkbox: false,
}
);

View File

@ -3,5 +3,5 @@
<div class="form-group">
<input type="text" name='search' class="form-control" placeholder="Search"{% if query_text %} value="{{ query }}"{% endif %}>
</div>
<button type="submit" id='search-submit' class="btn btn-default">Submit</button>
<button type="submit" id='search-submit' class="btn btn-default">Search</button>
</form>