mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Improvements for status code generation
- Now includes labels - Python template generates javascript which is then rendered? I don't even follow it any more
This commit is contained in:
parent
5d70f496a5
commit
ba7c0bdea0
@ -50,12 +50,17 @@ function loadBuildTable(table, options) {
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
field: 'status_text',
|
||||
field: 'status',
|
||||
title: 'Status',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
return buildStatusDisplay(value);
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'creation_date',
|
||||
title: 'Created',
|
||||
sortable: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -216,8 +216,9 @@ function generateFilterInput(tableKey, filterKey) {
|
||||
// Return a 'select' input with the available values
|
||||
html = `<select class='form-control' id='${id}' name='value'>`;
|
||||
|
||||
for (var opt in options) {
|
||||
html += `<option value='${options[opt]}'>${opt}</option>`;
|
||||
for (var key in options) {
|
||||
option = options[key];
|
||||
html += `<option value='${key}'>${option.value}</option>`;
|
||||
}
|
||||
|
||||
html += `</select>`;
|
||||
@ -368,7 +369,6 @@ function getFilterOptionValue(tableKey, filterKey, valueKey) {
|
||||
|
||||
var filter = getFilterSettings(tableKey, filterKey);
|
||||
|
||||
|
||||
var value = String(valueKey);
|
||||
|
||||
// Lookup for boolean options
|
||||
@ -381,11 +381,10 @@ function getFilterOptionValue(tableKey, filterKey, valueKey) {
|
||||
|
||||
// Iterate through a list of options
|
||||
if ('options' in filter) {
|
||||
for (var option in filter.options) {
|
||||
var v = String(filter.options[option]);
|
||||
for (var key in filter.options) {
|
||||
|
||||
if (v == valueKey) {
|
||||
return option;
|
||||
if (key == valueKey) {
|
||||
return filter.options[key].value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,5 @@ function orderStatusLabel(code, label) {
|
||||
html += label;
|
||||
html += "</span>";
|
||||
|
||||
console.log(html);
|
||||
|
||||
return html;
|
||||
}
|
@ -7,6 +7,8 @@ class StatusCode:
|
||||
This is used to map a set of integer values to text.
|
||||
"""
|
||||
|
||||
labels = {}
|
||||
|
||||
@classmethod
|
||||
def list(cls):
|
||||
"""
|
||||
@ -16,10 +18,18 @@ class StatusCode:
|
||||
codes = []
|
||||
|
||||
for key in cls.options.keys():
|
||||
codes.append({
|
||||
|
||||
opt = {
|
||||
'key': key,
|
||||
'value': cls.options[key]
|
||||
})
|
||||
}
|
||||
|
||||
label = cls.labels.get(key)
|
||||
|
||||
if label:
|
||||
opt['label'] = label
|
||||
|
||||
codes.append(opt)
|
||||
|
||||
return codes
|
||||
|
||||
@ -61,6 +71,15 @@ class OrderStatus(StatusCode):
|
||||
RETURNED: _("Returned"),
|
||||
}
|
||||
|
||||
labels = {
|
||||
PENDING: "primary",
|
||||
PLACED: "primary",
|
||||
COMPLETE: "success",
|
||||
CANCELLED: "danger",
|
||||
LOST: "warning",
|
||||
RETURNED: "warning",
|
||||
}
|
||||
|
||||
# Open orders
|
||||
OPEN = [
|
||||
PENDING,
|
||||
@ -91,6 +110,12 @@ class StockStatus(StatusCode):
|
||||
LOST: _("Lost"),
|
||||
}
|
||||
|
||||
labels = {
|
||||
OK: 'success',
|
||||
ATTENTION: 'warning',
|
||||
DAMAGED: 'danger',
|
||||
}
|
||||
|
||||
# The following codes correspond to parts that are 'available' or 'in stock'
|
||||
AVAILABLE_CODES = [
|
||||
OK,
|
||||
@ -120,6 +145,13 @@ class BuildStatus(StatusCode):
|
||||
COMPLETE: _("Complete"),
|
||||
}
|
||||
|
||||
labels = {
|
||||
PENDING: 'primary',
|
||||
ALLOCATED: 'info',
|
||||
COMPLETE: 'success',
|
||||
CANCELLED: 'danger',
|
||||
}
|
||||
|
||||
ACTIVE_CODES = [
|
||||
PENDING,
|
||||
ALLOCATED
|
||||
|
27
InvenTree/templates/status_codes.html
Normal file
27
InvenTree/templates/status_codes.html
Normal file
@ -0,0 +1,27 @@
|
||||
var {{ label }}Codes = {
|
||||
{% for opt in options %}'{{ opt.key }}': {
|
||||
key: '{{ opt.key }}',
|
||||
value: '{{ opt.value }}',{% if opt.label %}
|
||||
label: '{{ opt.label }}',{% endif %}
|
||||
},{% endfor %}
|
||||
};
|
||||
|
||||
function {{ label }}StatusDisplay(key) {
|
||||
|
||||
key = String(key);
|
||||
|
||||
var label = {{ label }}Codes[key].label;
|
||||
|
||||
var value = {{ label }}Codes[key].value;
|
||||
|
||||
if (value == null || value.length == 0) {
|
||||
value = key;
|
||||
}
|
||||
|
||||
// Label not found, return the original string
|
||||
if (label == null || label.length == 0) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return `<span class='label label-${label}'>${value}</span>`;
|
||||
}
|
@ -5,6 +5,11 @@
|
||||
|
||||
<script type='text/javascript'>
|
||||
|
||||
{% include "status_codes.html" with label='stock' options=stock_status_codes %}
|
||||
{% include "status_codes.html" with label='build' options=build_status_codes %}
|
||||
{% include "status_codes.html" with label='order' options=order_status_codes %}
|
||||
|
||||
|
||||
function getAvailableTableFilters(tableKey) {
|
||||
|
||||
tableKey = tableKey.toLowerCase();
|
||||
@ -23,10 +28,7 @@ function getAvailableTableFilters(tableKey) {
|
||||
description: '{% trans "Show stock for active parts" %}',
|
||||
},
|
||||
'status': {
|
||||
options: {
|
||||
{% for opt in stock_status_codes %}'{{ opt.value }}': '{{ opt.key }}',
|
||||
{% endfor %}
|
||||
},
|
||||
options: stockCodes,
|
||||
title: '{% trans "Stock status" %}',
|
||||
description: '{% trans "Stock status" %}',
|
||||
},
|
||||
@ -38,10 +40,7 @@ function getAvailableTableFilters(tableKey) {
|
||||
return {
|
||||
status: {
|
||||
title: '{% trans "Build status" %}',
|
||||
options: {
|
||||
{% for opt in build_status_codes %}'{{ opt.value }}': '{{ opt.key }}',
|
||||
{% endfor %}
|
||||
},
|
||||
options: buildCodes,
|
||||
},
|
||||
|
||||
};
|
||||
@ -52,10 +51,7 @@ function getAvailableTableFilters(tableKey) {
|
||||
return {
|
||||
status: {
|
||||
title: '{% trans "Order status" %}',
|
||||
options: {
|
||||
{% for opt in order_status_codes %}'{{ opt.value }}': '{{ opt.key }}',
|
||||
{% endfor %}
|
||||
},
|
||||
options: orderCodes,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user