API endpoint for build list

- Changed part/build table to bootstrap table (ajax)
This commit is contained in:
Oliver Walters 2019-04-16 08:31:43 +10:00
parent 94b280eed3
commit 338a30b50e
4 changed files with 103 additions and 25 deletions

View File

@ -14,6 +14,7 @@ from build.urls import build_urls
from part.api import part_api_urls
from company.api import company_api_urls
from stock.api import stock_api_urls
from build.api import build_api_urls
from django.conf import settings
from django.conf.urls.static import static
@ -31,6 +32,7 @@ apipatterns = [
url(r'^part/', include(part_api_urls)),
url(r'^company/', include(company_api_urls)),
url(r'^stock/', include(stock_api_urls)),
url(r'^build/', include(build_api_urls)),
# User URLs
url(r'^user/', include(user_urls)),

35
InvenTree/build/api.py Normal file
View File

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters
from rest_framework import generics, permissions
from django.conf.urls import url, include
from .models import Build
from .serializers import BuildSerializer
class BuildList(generics.ListAPIView):
queryset = Build.objects.all()
serializer_class = BuildSerializer
permission_classes = [
permissions.IsAuthenticatedOrReadOnly,
]
filter_backends = [
DjangoFilterBackend,
filters.SearchFilter,
filters.OrderingFilter,
]
filter_fields = [
'part',
]
build_api_urls = [
url(r'^.*$', BuildList.as_view(), name='api-build-list')
]

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from rest_framework import serializers
from .models import Build
class BuildSerializer(serializers.ModelSerializer):
url = serializers.CharField(source='get_absolute_url', read_only=True)
class Meta:
model = Build
fields = [
'pk',
'url',
'title',
'creation_date',
'completion_date',
'part',
'quantity',
'notes']

View File

@ -6,35 +6,14 @@
<h3>Part Builds</h3>
<table class='table table-striped'>
<tr>
<th>Title</th>
<th>Quantity</th>
<th>Status</th>
<th>Completion Date</th>
</tr>
{% if part.active_builds|length > 0 %}
<tr>
<td colspan="4"><b>Active Builds</b></td>
</tr>
{% include "part/build_list.html" with builds=part.active_builds %}
{% endif %}
{% if part.inactive_builds|length > 0 %}
<tr><td colspan="4"></td></tr>
<tr>
<td colspan="4"><b>Inactive Builds</b></td>
</tr>
{% include "part/build_list.html" with builds=part.inactive_builds %}
{% endif %}
</table>
<div class='container-fluid'>
<div id='button-toolbar'>
<button class="btn btn-success" id='start-build'>Start New Build</button>
</div>
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='build-table'>
</table>
{% endblock %}
{% block js_ready %}
@ -49,4 +28,43 @@
}
});
});
$("#build-table").bootstrapTable({
sortable: true,
search: true,
pagination: true,
queryParams: function(p) {
return {
part: {{ part.id }},
}
},
columns: [
{
field: 'pk',
title: 'ID',
visible: false,
},
{
field: 'title',
title: 'Title',
formatter: function(value, row, index, field) {
return renderLink(value, row.url);
}
},
{
field: 'quantity',
title: 'Quantity',
},
{
field: 'status',
title: 'Status',
},
{
field: 'completion_date',
title: 'Completed'
}
],
url: "{% url 'api-build-list' %}",
});
{% endblock %}