Refactor BOM page

This commit is contained in:
Oliver 2021-07-15 16:42:28 +10:00
parent 57851b0eaf
commit e7c7bdcd00
4 changed files with 133 additions and 142 deletions

View File

@ -1,16 +1,5 @@
{% extends "part/part_base.html" %}
{% load static %}
{% load i18n %}
{% block menubar %}
{% include 'part/navbar.html' with tab='bom' %}
{% endblock %}
{% block heading %}
{% trans "Bill of Materials" %}
{% endblock %}
{% block details %}
{% load inventree_extras %}
{% if roles.part.change != True and editing_enabled %}
<div class='alert alert-danger alert-block'>
@ -32,7 +21,7 @@
</div>
{% endif %}
<div id='button-toolbar'>
<div id='bom-button-toolbar'>
<div class="btn-group" role="group" aria-label="...">
{% if editing_enabled %}
<button class='btn btn-default' type='button' title='{% trans "Remove selected BOM items" %}' id='bom-item-delete'>
@ -76,131 +65,6 @@
</div>
</div>
<table class='table table-bom table-condensed' data-toolbar="#button-toolbar" id='bom-table'>
<table class='table table-bom table-condensed' data-toolbar="#bom-button-toolbar" id='bom-table'>
</table>
{% endif %}
{% endblock %}
{% block js_ready %}
{{ block.super }}
// Load the BOM table data
loadBomTable($("#bom-table"), {
editable: {{ editing_enabled }},
bom_url: "{% url 'api-bom-list' %}",
part_url: "{% url 'api-part-list' %}",
parent_id: {{ part.id }} ,
sub_part_detail: true,
});
linkButtonsToSelection($("#bom-table"),
[
"#bom-item-delete",
]
);
{% if editing_enabled %}
$("#editing-finished").click(function() {
location.href = "{% url 'part-bom' part.id %}";
});
$('#bom-item-delete').click(function() {
// Get a list of the selected BOM items
var rows = $("#bom-table").bootstrapTable('getSelections');
// TODO - In the future, display (in the dialog) which items are going to be deleted
showQuestionDialog(
'{% trans "Delete selected BOM items?" %}',
'{% trans "All selected BOM items will be deleted" %}',
{
accept: function() {
// Keep track of each DELETE request
var requests = [];
rows.forEach(function(row) {
requests.push(
inventreeDelete(
`/api/bom/${row.pk}/`,
)
);
});
// Wait for *all* the requests to complete
$.when.apply($, requests).then(function() {
location.reload();
});
}
}
);
});
$('#bom-upload').click(function() {
location.href = "{% url 'upload-bom' part.id %}";
});
$('#bom-duplicate').click(function() {
launchModalForm(
"{% url 'duplicate-bom' part.id %}",
{
success: function() {
$('#bom-table').bootstrapTable('refresh');
}
}
);
});
$("#bom-item-new").click(function () {
launchModalForm(
"{% url 'bom-item-create' %}?parent={{ part.id }}",
{
success: function() {
$("#bom-table").bootstrapTable('refresh');
},
secondary: [
{
field: 'sub_part',
label: '{% trans "New Part" %}',
title: '{% trans "Create New Part" %}',
url: "{% url 'part-create' %}",
},
]
}
);
});
{% else %}
$("#validate-bom").click(function() {
launchModalForm(
"{% url 'bom-validate' part.id %}",
{
reload: true,
}
);
});
$("#edit-bom").click(function () {
location.href = "{% url 'part-bom' part.id %}?edit=1";
});
$("#download-bom").click(function () {
launchModalForm("{% url 'bom-export' part.id %}",
{
success: function(response) {
location.href = response.url;
},
}
);
});
{% endif %}
$("#print-bom-report").click(function() {
printBomReports([{{ part.pk }}]);
});
{% endblock %}

View File

@ -229,6 +229,15 @@
</div>
</div>
<div class='panel panel-default panel-inventree panel-hidden' id='panel-bom'>
<div class='panel-heading'>
<h4>{% trans "Bill of Materials" %}</h4>
</div>
<div class='panel-content'>
{% include "part/bom.html" with part=part %}
</div>
</div>
<div class='panel panel-default panel-inventree panel-hidden' id='panel-build-orders'>
<div class='panel-heading'>
<h4>{% trans "Part Builds" %}</h4>
@ -285,6 +294,124 @@
{% block js_ready %}
{{ block.super }}
// Load the BOM table data
loadBomTable($("#bom-table"), {
editable: {{ editing_enabled }},
bom_url: "{% url 'api-bom-list' %}",
part_url: "{% url 'api-part-list' %}",
parent_id: {{ part.id }} ,
sub_part_detail: true,
});
linkButtonsToSelection($("#bom-table"),
[
"#bom-item-delete",
]
);
{% if editing_enabled %}
$("#editing-finished").click(function() {
location.href = "{% url 'part-detail' part.id %}?display=bom";
});
$('#bom-item-delete').click(function() {
// Get a list of the selected BOM items
var rows = $("#bom-table").bootstrapTable('getSelections');
// TODO - In the future, display (in the dialog) which items are going to be deleted
showQuestionDialog(
'{% trans "Delete selected BOM items?" %}',
'{% trans "All selected BOM items will be deleted" %}',
{
accept: function() {
// Keep track of each DELETE request
var requests = [];
rows.forEach(function(row) {
requests.push(
inventreeDelete(
`/api/bom/${row.pk}/`,
)
);
});
// Wait for *all* the requests to complete
$.when.apply($, requests).then(function() {
location.reload();
});
}
}
);
});
$('#bom-upload').click(function() {
location.href = "{% url 'upload-bom' part.id %}";
});
$('#bom-duplicate').click(function() {
launchModalForm(
"{% url 'duplicate-bom' part.id %}",
{
success: function() {
$('#bom-table').bootstrapTable('refresh');
}
}
);
});
$("#bom-item-new").click(function () {
launchModalForm(
"{% url 'bom-item-create' %}?parent={{ part.id }}",
{
success: function() {
$("#bom-table").bootstrapTable('refresh');
},
secondary: [
{
field: 'sub_part',
label: '{% trans "New Part" %}',
title: '{% trans "Create New Part" %}',
url: "{% url 'part-create' %}",
},
]
}
);
});
{% else %}
$("#validate-bom").click(function() {
launchModalForm(
"{% url 'bom-validate' part.id %}",
{
reload: true,
}
);
});
$("#edit-bom").click(function () {
location.href = "{% url 'part-detail' part.id %}?display=bom&edit=1";
});
$("#download-bom").click(function () {
launchModalForm("{% url 'bom-export' part.id %}",
{
success: function(response) {
location.href = response.url;
},
}
);
});
{% endif %}
$("#print-bom-report").click(function() {
printBomReports([{{ part.pk }}]);
});
$("#start-build").click(function() {
newBuildOrder({
part: {{ part.pk }},

View File

@ -41,7 +41,7 @@
{% endif %}
{% if part.assembly %}
<li class='list-group-item' title='{% trans "Bill of Materials" %}'>
<a href='#' id='select-part-bom' class='nav-toggle'>
<a href='#' id='select-bom' class='nav-toggle'>
<span class='menu-tab-icon fas fa-list sidebar-icon'></span>
{% trans "Bill of Materials" %}
</a>

View File

@ -1441,7 +1441,7 @@ class BomUpload(InvenTreeRoleMixin, FileManagementFormView):
# BomItem already exists
pass
return HttpResponseRedirect(reverse('part-bom', kwargs={'pk': self.kwargs['pk']}))
return HttpResponseRedirect(reverse('part-detail', kwargs={'pk': self.kwargs['pk']}))
class PartExport(AjaxView):