mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Ability to include part_detail in build API
- Build list now uses bootstrapTable
This commit is contained in:
parent
a4e45eab13
commit
f0ffb0f8c0
@ -8,6 +8,8 @@ function loadBuildTable(table, options) {
|
||||
filters[key] = params[key];
|
||||
}
|
||||
|
||||
setupFilterList("build", table);
|
||||
|
||||
table.inventreeTable({
|
||||
method: 'get',
|
||||
formatNoMatches: function() {
|
||||
@ -26,14 +28,26 @@ function loadBuildTable(table, options) {
|
||||
{
|
||||
field: 'title',
|
||||
title: 'Build',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
return renderLink(value, '/build/' + row.pk + '/');
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'part',
|
||||
title: 'Part',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
|
||||
var name = row.part_detail.full_name;
|
||||
|
||||
return imageHoverIcon(row.part_detail.thumbnail) + renderLink(name, '/part/' + row.part + '/');
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'quantity',
|
||||
title: 'Quantity',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
field: 'status_text',
|
||||
|
@ -238,8 +238,8 @@ function setupFilterList(tableKey, table, target) {
|
||||
|
||||
var addClicked = false;
|
||||
|
||||
if (!target || target.length == 0) {
|
||||
target = '#filter-list-" + tableKey';
|
||||
if (target == null || target.length == 0) {
|
||||
target = `#filter-list-${tableKey}`;
|
||||
}
|
||||
|
||||
var tag = `filter-tag-${tableKey}`;
|
||||
|
@ -11,6 +11,8 @@ from rest_framework import generics, permissions
|
||||
|
||||
from django.conf.urls import url, include
|
||||
|
||||
from InvenTree.helpers import str2bool
|
||||
|
||||
from .models import Build, BuildItem
|
||||
from .serializers import BuildSerializer, BuildItemSerializer
|
||||
|
||||
@ -39,6 +41,17 @@ class BuildList(generics.ListCreateAPIView):
|
||||
'part',
|
||||
]
|
||||
|
||||
def get_serializer(self, *args, **kwargs):
|
||||
|
||||
try:
|
||||
part_detail = str2bool(self.request.GET.get('part_detail', None))
|
||||
except AttributeError:
|
||||
part_detail = None
|
||||
|
||||
kwargs['part_detail'] = part_detail
|
||||
|
||||
return self.serializer_class(*args, **kwargs)
|
||||
|
||||
|
||||
class BuildDetail(generics.RetrieveUpdateAPIView):
|
||||
""" API endpoint for detail view of a Build object """
|
||||
|
@ -10,6 +10,7 @@ from InvenTree.serializers import InvenTreeModelSerializer
|
||||
from stock.serializers import StockItemSerializerBrief
|
||||
|
||||
from .models import Build, BuildItem
|
||||
from part.serializers import PartBriefSerializer
|
||||
|
||||
|
||||
class BuildSerializer(InvenTreeModelSerializer):
|
||||
@ -18,6 +19,16 @@ class BuildSerializer(InvenTreeModelSerializer):
|
||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||
status_text = serializers.CharField(source='get_status_display', read_only=True)
|
||||
|
||||
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
part_detail = kwargs.pop('part_detail', False)
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
if part_detail is not True:
|
||||
self.fields.pop('part_detail')
|
||||
|
||||
class Meta:
|
||||
model = Build
|
||||
fields = [
|
||||
@ -27,6 +38,7 @@ class BuildSerializer(InvenTreeModelSerializer):
|
||||
'creation_date',
|
||||
'completion_date',
|
||||
'part',
|
||||
'part_detail',
|
||||
'quantity',
|
||||
'status',
|
||||
'status_text',
|
||||
|
@ -1,38 +0,0 @@
|
||||
{% extends "collapse.html" %}
|
||||
|
||||
{% block collapse_title %}
|
||||
<b>{{ title }}</b> - {{ builds | length }}
|
||||
{% endblock %}
|
||||
|
||||
{% block collapse_content %}
|
||||
<table class='table table-striped table-condensed build-table' id='build-table-{{collapse_id}}' data-toolbar='#button-toolbar'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Build</th>
|
||||
<th>Part</th>
|
||||
<th>Quantity</th>
|
||||
<th>Status</th>
|
||||
{% if completed %}
|
||||
<th>Completed</th>
|
||||
{% else %}
|
||||
<th>Created</th>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for build in builds %}
|
||||
<tr>
|
||||
<td><a href="{% url 'build-detail' build.id %}">{{ build.title }}</a></td>
|
||||
<td><a href="{% url 'part-build' build.part.id %}">{{ build.part.full_name }}</a></td>
|
||||
<td>{{ build.quantity }}</td>
|
||||
<td>{% include "build_status.html" with build=build %}
|
||||
{% if completed %}
|
||||
<td>{{ build.completion_date }}<span class='badge'>{{ build.completed_by.username }}</span></td>
|
||||
{% else %}
|
||||
<td>{{ build.creation_date }}</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
@ -13,25 +13,24 @@ InvenTree | Build List
|
||||
<h3>Part Builds</h3>
|
||||
</div>
|
||||
<div class='col-sm-6'>
|
||||
<div class='container' id='active-build-toolbar' style='float: right;'>
|
||||
<div class='btn-group' style='float: right;'>
|
||||
<button type='button' class="btn btn-success" id='new-build'>Start New Build</button>
|
||||
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div id='button-toolbar'>
|
||||
<div class='button-toolbar container-fluid' style='float: right;'>
|
||||
<button type='button' class="btn btn-success" id='new-build'>Start New Build</button>
|
||||
<div class='filter-list' id='filter-list-build'>
|
||||
<!-- An empty div in which the filter list will be constructed -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<table class='table table-striped table-condensed' id='build-table'>
|
||||
<table class='table table-striped table-condensed' id='build-table' data-toolbar='#button-toolbar'>
|
||||
</table>
|
||||
|
||||
{% include "build/build_list.html" with builds=active title="Active Builds" completed=False collapse_id='active' %}
|
||||
|
||||
{% include "build/build_list.html" with builds=completed completed=True title="Completed Builds" collapse_id="complete" %}
|
||||
|
||||
{% include "build/build_list.html" with builds=cancelled title="Cancelled Builds" completed=False collapse_id="cancelled" %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block js_ready %}
|
||||
@ -41,42 +40,18 @@ InvenTree | Build List
|
||||
|
||||
$("#new-build").click(function() {
|
||||
launchModalForm(
|
||||
"{% url 'build-create' %}",
|
||||
{
|
||||
follow: true
|
||||
});
|
||||
"{% url 'build-create' %}",
|
||||
{
|
||||
follow: true
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
loadBuildTable($("#build-table"), {
|
||||
url: "{% url 'api-build-list' %}"
|
||||
});
|
||||
|
||||
$(".build-table").inventreeTable({
|
||||
formatNoMatches: function() { return 'No builds found'; },
|
||||
columns: [
|
||||
{
|
||||
field: 'name',
|
||||
title: 'Build',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
field: 'part',
|
||||
title: 'Part',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
title: 'Quantity',
|
||||
sortable: true,
|
||||
searchable: false
|
||||
},
|
||||
{
|
||||
title: 'Status',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
sortable: true,
|
||||
},
|
||||
]
|
||||
url: "{% url 'api-build-list' %}",
|
||||
params: {
|
||||
part_detail: "true",
|
||||
},
|
||||
});
|
||||
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user