mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Render filter options as a template
- This allows the values to be seen by the translation layer - Also means that whenever a new option is added, it will be automatically available to the front-end!
This commit is contained in:
parent
57c5d6c97a
commit
c1b59eeaab
@ -97,51 +97,6 @@ function addTableFilter(tableKey, filterKey, filterValue) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the custom filtering options available for a particular table
|
|
||||||
*
|
|
||||||
* @param {*} tableKey - string key lookup for the table
|
|
||||||
*/
|
|
||||||
function getAvailableTableFilters(tableKey) {
|
|
||||||
|
|
||||||
tableKey = tableKey.toLowerCase();
|
|
||||||
|
|
||||||
// Filters for the "Stock" table
|
|
||||||
if (tableKey == 'stock') {
|
|
||||||
return {
|
|
||||||
'cascade': {
|
|
||||||
'type': 'bool',
|
|
||||||
'description': 'Include stock in sublocations',
|
|
||||||
'title': 'Include sublocations',
|
|
||||||
},
|
|
||||||
'active': {
|
|
||||||
'type': 'bool',
|
|
||||||
'title': 'Acitve parts',
|
|
||||||
'description': 'Show stock for active parts',
|
|
||||||
},
|
|
||||||
'status': {
|
|
||||||
'options': {
|
|
||||||
'OK': 10,
|
|
||||||
'ATTENTION': 50,
|
|
||||||
'DAMAGED': 55,
|
|
||||||
'DESTROYED': 60,
|
|
||||||
'LOST': 70
|
|
||||||
},
|
|
||||||
'title': 'Stock status',
|
|
||||||
'description': 'Stock status',
|
|
||||||
},
|
|
||||||
'test': {
|
|
||||||
title: 'A test parameter',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Finally, no matching key
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return a list of the "available" filters for a given table key.
|
* Return a list of the "available" filters for a given table key.
|
||||||
* A filter is "available" if it is not already being used to filter the table.
|
* A filter is "available" if it is not already being used to filter the table.
|
||||||
|
@ -2,6 +2,26 @@ from django.utils.translation import ugettext as _
|
|||||||
|
|
||||||
|
|
||||||
class StatusCode:
|
class StatusCode:
|
||||||
|
"""
|
||||||
|
Base class for representing a set of StatusCodes.
|
||||||
|
This is used to map a set of integer values to text.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def list(cls):
|
||||||
|
"""
|
||||||
|
Return the StatusCode options as a list of mapped key / value items
|
||||||
|
"""
|
||||||
|
|
||||||
|
codes = []
|
||||||
|
|
||||||
|
for key in cls.options.keys():
|
||||||
|
codes.append({
|
||||||
|
'key': key,
|
||||||
|
'value': cls.options[key]
|
||||||
|
})
|
||||||
|
|
||||||
|
return codes
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def items(cls):
|
def items(cls):
|
||||||
|
@ -7,10 +7,22 @@ from InvenTree import version
|
|||||||
from InvenTree.helpers import decimal2string
|
from InvenTree.helpers import decimal2string
|
||||||
|
|
||||||
from common.models import InvenTreeSetting
|
from common.models import InvenTreeSetting
|
||||||
|
from InvenTree.status_codes import OrderStatus, StockStatus, BuildStatus
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=True)
|
||||||
|
def load_status_codes(context):
|
||||||
|
|
||||||
|
context['order_status_codes'] = OrderStatus.list()
|
||||||
|
context['stock_status_codes'] = StockStatus.list()
|
||||||
|
context['build_status_codes'] = BuildStatus.list()
|
||||||
|
|
||||||
|
# Need to return something as the result is rendered to the page
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def decimal(x, *args, **kwargs):
|
def decimal(x, *args, **kwargs):
|
||||||
""" Simplified rendering of a decimal number """
|
""" Simplified rendering of a decimal number """
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
@ -116,7 +117,10 @@ InvenTree
|
|||||||
{% block js_load %}
|
{% block js_load %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% include "table_filters.html" %}
|
||||||
|
|
||||||
<script type='text/javascript'>
|
<script type='text/javascript'>
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
{% block js_ready %}
|
{% block js_ready %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@ -125,6 +129,7 @@ $(document).ready(function () {
|
|||||||
|
|
||||||
showCachedAlerts();
|
showCachedAlerts();
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% block js %}
|
{% block js %}
|
||||||
|
40
InvenTree/templates/table_filters.html
Normal file
40
InvenTree/templates/table_filters.html
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
{% load inventree_extras %}
|
||||||
|
|
||||||
|
<script type='text/javascript'>
|
||||||
|
|
||||||
|
{% load_status_codes %}
|
||||||
|
|
||||||
|
function getAvailableTableFilters(tableKey) {
|
||||||
|
|
||||||
|
// Filters for the "Stock" table
|
||||||
|
if (tableKey == 'stock') {
|
||||||
|
return {
|
||||||
|
'cascade': {
|
||||||
|
'type': 'bool',
|
||||||
|
'description': '{% trans "Include stock in sublocations" %}',
|
||||||
|
'title': '{% trans "Include sublocations" %}',
|
||||||
|
},
|
||||||
|
'active': {
|
||||||
|
'type': 'bool',
|
||||||
|
'title': '{% trans "Active parts" %}',
|
||||||
|
'description': '{% trans "Show stock for active parts" %}',
|
||||||
|
},
|
||||||
|
'status': {
|
||||||
|
'options': {
|
||||||
|
{% for opt in stock_status_codes %}'{{ opt.value }}': '{{ opt.key }}',
|
||||||
|
{% endfor %}
|
||||||
|
},
|
||||||
|
'title': 'Stock status',
|
||||||
|
'description': 'Stock status',
|
||||||
|
},
|
||||||
|
'test': {
|
||||||
|
title: 'A test parameter',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally, no matching key
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
</script>
|
Loading…
Reference in New Issue
Block a user