mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Use tree-grid instead of group-by for showing test results
- Much more predictable display
This commit is contained in:
parent
b10410ca1f
commit
f0cf83a0b8
@ -32,24 +32,19 @@ function removeStockRow(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function passFailBadge(result) {
|
function passFailBadge(result, align='float-right') {
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
return `<span class='label label-green float-right'>{% trans "PASS" %}</span>`;
|
return `<span class='label label-green ${align}'>{% trans "PASS" %}</span>`;
|
||||||
} else {
|
} else {
|
||||||
return `<span class='label label-red float-right'>{% trans "FAIL" %}</span>`;
|
return `<span class='label label-red ${align}'>{% trans "FAIL" %}</span>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function noResultBadge() {
|
function noResultBadge(align='float-right') {
|
||||||
return `<span class='label label-blue float-right'>{% trans "NO RESULT" %}</span>`;
|
return `<span class='label label-blue ${align}'>{% trans "NO RESULT" %}</span>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadStockTestResultsTable(table, options) {
|
|
||||||
/*
|
|
||||||
* Load StockItemTestResult table
|
|
||||||
*/
|
|
||||||
|
|
||||||
function formatDate(row) {
|
function formatDate(row) {
|
||||||
// Function for formatting date field
|
// Function for formatting date field
|
||||||
var html = row.date;
|
var html = row.date;
|
||||||
@ -65,6 +60,11 @@ function loadStockTestResultsTable(table, options) {
|
|||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadStockTestResultsTable(table, options) {
|
||||||
|
/*
|
||||||
|
* Load StockItemTestResult table
|
||||||
|
*/
|
||||||
|
|
||||||
function makeButtons(row, grouped) {
|
function makeButtons(row, grouped) {
|
||||||
var html = `<div class='btn-group float-right' role='group'>`;
|
var html = `<div class='btn-group float-right' role='group'>`;
|
||||||
|
|
||||||
@ -81,17 +81,28 @@ function loadStockTestResultsTable(table, options) {
|
|||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, load all the test templates
|
|
||||||
table.inventreeTable({
|
table.inventreeTable({
|
||||||
url: "{% url 'api-part-test-template-list' %}",
|
url: "{% url 'api-part-test-template-list' %}",
|
||||||
method: 'get',
|
method: 'get',
|
||||||
name: 'testresult',
|
name: 'testresult',
|
||||||
|
treeEnable: true,
|
||||||
|
rootParentId: options.stock_item,
|
||||||
|
parentIdField: 'parent',
|
||||||
|
idField: 'pk',
|
||||||
|
uniqueId: 'pk',
|
||||||
|
treeShowField: 'test_name',
|
||||||
formatNoMatches: function() {
|
formatNoMatches: function() {
|
||||||
return "{% trans 'No test results found' %}";
|
return '{% trans "No test results found" %}';
|
||||||
},
|
},
|
||||||
queryParams: {
|
queryParams: {
|
||||||
part: options.part,
|
part: options.part,
|
||||||
},
|
},
|
||||||
|
onPostBody: function() {
|
||||||
|
table.treegrid({
|
||||||
|
treeColumn: 0,
|
||||||
|
});
|
||||||
|
table.treegrid("collapseAll");
|
||||||
|
},
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
field: 'pk',
|
field: 'pk',
|
||||||
@ -130,100 +141,85 @@ function loadStockTestResultsTable(table, options) {
|
|||||||
{
|
{
|
||||||
field: 'date',
|
field: 'date',
|
||||||
title: '{% trans "Test Date" %}',
|
title: '{% trans "Test Date" %}',
|
||||||
|
sortable: true,
|
||||||
formatter: function(value, row) {
|
formatter: function(value, row) {
|
||||||
return formatDate(row);
|
return formatDate(row);
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'buttons',
|
field: 'buttons',
|
||||||
formatter: function(value, row) {
|
formatter: function(value, row) {
|
||||||
return makeButtons(row, false);
|
return makeButtons(row, false);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
],
|
|
||||||
groupBy: true,
|
|
||||||
groupByField: 'test_name',
|
|
||||||
groupByFormatter: function(field, id, data) {
|
|
||||||
|
|
||||||
// Extract the "latest" row (data are returned in date order from the server)
|
|
||||||
var latest = data[data.length-1];
|
|
||||||
|
|
||||||
switch (field) {
|
|
||||||
case 'test_name':
|
|
||||||
return latest.test_name + ` <i>(${data.length})</i>` + passFailBadge(latest.result);
|
|
||||||
case 'value':
|
|
||||||
return latest.value;
|
|
||||||
case 'notes':
|
|
||||||
return latest.notes;
|
|
||||||
case 'date':
|
|
||||||
return formatDate(latest);
|
|
||||||
case 'buttons':
|
|
||||||
// Buttons are done differently for grouped rows
|
|
||||||
return makeButtons(latest, true);
|
|
||||||
default:
|
|
||||||
return "---";
|
|
||||||
}
|
}
|
||||||
},
|
],
|
||||||
onLoadSuccess: function(tableData) {
|
onLoadSuccess: function(tableData) {
|
||||||
// Once the test template data are loaded, query for results
|
|
||||||
|
// Set "parent" for each existing row
|
||||||
|
tableData.forEach(function(item, idx) {
|
||||||
|
tableData[idx].parent = options.stock_item;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Once the test template data are loaded, query for test results
|
||||||
inventreeGet(
|
inventreeGet(
|
||||||
"{% url 'api-stock-test-result-list' %}",
|
'{% url "api-stock-test-result-list" %}',
|
||||||
{
|
{
|
||||||
stock_item: options.stock_item,
|
stock_item: options.stock_item,
|
||||||
user_detail: true,
|
user_detail: true,
|
||||||
attachment_detail: true,
|
attachment_detail: true,
|
||||||
|
ordering: "-date",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
// Iterate through the returned test data
|
||||||
|
data.forEach(function(item, index) {
|
||||||
|
|
||||||
// Iterate through the returned test result data, and group by test
|
|
||||||
data.forEach(function(item) {
|
|
||||||
var match = false;
|
var match = false;
|
||||||
var override = false;
|
var override = false;
|
||||||
|
|
||||||
var key = item.key;
|
var key = item.key;
|
||||||
|
|
||||||
// Try to associate this result with a test row
|
// Attempt to associate this result with an existing test
|
||||||
tableData.forEach(function(row, index) {
|
tableData.forEach(function(row, index) {
|
||||||
|
|
||||||
|
|
||||||
// The result matches the test template row
|
|
||||||
if (key == row.key) {
|
if (key == row.key) {
|
||||||
|
|
||||||
// Force the names to be the same!
|
|
||||||
item.test_name = row.test_name;
|
item.test_name = row.test_name;
|
||||||
item.required = row.required;
|
item.required = row.required;
|
||||||
|
|
||||||
|
match = true;
|
||||||
|
|
||||||
if (row.result == null) {
|
if (row.result == null) {
|
||||||
// The original row has not recorded a result - override!
|
item.parent = options.stock_item;
|
||||||
tableData[index] = item;
|
tableData[index] = item;
|
||||||
override = true;
|
override = true;
|
||||||
|
} else {
|
||||||
|
item.parent = row.pk;
|
||||||
}
|
}
|
||||||
|
|
||||||
match = true;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// No match could be found (this is a new test!)
|
// No match could be found
|
||||||
if (!match) {
|
if (!match) {
|
||||||
|
|
||||||
item.test_name = item.test;
|
item.test_name = item.test;
|
||||||
|
item.parent = options.stock_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!override) {
|
if (!override) {
|
||||||
tableData.push(item);
|
tableData.push(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Finally, push the data back into the table!
|
// Push data back into the table
|
||||||
table.bootstrapTable("load", tableData);
|
table.bootstrapTable("load", tableData);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function loadStockTable(table, options) {
|
function loadStockTable(table, options) {
|
||||||
/* Load data into a stock table with adjustable options.
|
/* Load data into a stock table with adjustable options.
|
||||||
|
Loading…
Reference in New Issue
Block a user