2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 20:16:44 +00:00

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 %} {% endif %}
}, },
buttons: ['#part-options'], buttons: ['#part-options'],
checkbox: true,
}, },
); );

View File

@ -82,6 +82,7 @@ function loadPartTable(table, url, options={}) {
* - url: Base URL for API query * - url: Base URL for API query
* - options: object containing following (optional) fields * - options: object containing following (optional) fields
* allowInactive: If true, allow display of inactive parts * allowInactive: If true, allow display of inactive parts
* checkbox: Show the checkbox column
* query: extra query params for API request * query: extra query params for API request
* buttons: If provided, link buttons to selection status of this table * buttons: If provided, link buttons to selection status of this table
*/ */
@ -94,6 +95,84 @@ function loadPartTable(table, url, options={}) {
query.active = true; 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({ $(table).bootstrapTable({
url: url, url: url,
sortable: true, sortable: true,
@ -107,76 +186,7 @@ function loadPartTable(table, url, options={}) {
queryParams: function(p) { queryParams: function(p) {
return query; return query;
}, },
columns: [ columns: 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>";
}
}
}
],
}); });
if (options.buttons) { if (options.buttons) {

View File

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

View File

@ -3,5 +3,5 @@
<div class="form-group"> <div class="form-group">
<input type="text" name='search' class="form-control" placeholder="Search"{% if query_text %} value="{{ query }}"{% endif %}> <input type="text" name='search' class="form-control" placeholder="Search"{% if query_text %} value="{{ query }}"{% endif %}>
</div> </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> </form>