diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 7303f06787..2f66225a90 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -1115,10 +1115,10 @@ part_api_urls = [ # Base URL for PartParameter API endpoints url(r'^parameter/', include([ - url(r'^template/$', PartParameterTemplateList.as_view(), name='api-part-param-template-list'), + url(r'^template/$', PartParameterTemplateList.as_view(), name='api-part-parameter-template-list'), - url(r'^(?P\d+)/', PartParameterDetail.as_view(), name='api-part-param-detail'), - url(r'^.*$', PartParameterList.as_view(), name='api-part-param-list'), + url(r'^(?P\d+)/', PartParameterDetail.as_view(), name='api-part-parameter-detail'), + url(r'^.*$', PartParameterList.as_view(), name='api-part-parameter-list'), ])), url(r'^thumbs/', include([ diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index cc533177d9..8fe5744f06 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -2164,7 +2164,7 @@ class PartParameterTemplate(models.Model): @staticmethod def get_api_url(): - return reverse('api-part-param-template-list') + return reverse('api-part-parameter-template-list') def __str__(self): s = str(self.name) @@ -2205,7 +2205,7 @@ class PartParameter(models.Model): @staticmethod def get_api_url(): - return reverse('api-part-param-list') + return reverse('api-part-parameter-list') def __str__(self): # String representation of a PartParameter (used in the admin interface) diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index 313e2cf920..6627639bca 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -508,19 +508,6 @@ class BomItemSerializer(InvenTreeModelSerializer): ] -class PartParameterSerializer(InvenTreeModelSerializer): - """ JSON serializers for the PartParameter model """ - - class Meta: - model = PartParameter - fields = [ - 'pk', - 'part', - 'template', - 'data' - ] - - class PartParameterTemplateSerializer(InvenTreeModelSerializer): """ JSON serializer for the PartParameterTemplate model """ @@ -533,6 +520,22 @@ class PartParameterTemplateSerializer(InvenTreeModelSerializer): ] +class PartParameterSerializer(InvenTreeModelSerializer): + """ JSON serializers for the PartParameter model """ + + template_detail = PartParameterTemplateSerializer(source='template', many=False, read_only=True) + + class Meta: + model = PartParameter + fields = [ + 'pk', + 'part', + 'template', + 'template_detail', + 'data' + ] + + class CategoryParameterTemplateSerializer(InvenTreeModelSerializer): """ Serializer for PartCategoryParameterTemplate """ diff --git a/InvenTree/part/templates/part/param_delete.html b/InvenTree/part/templates/part/param_delete.html deleted file mode 100644 index efb8ca3c26..0000000000 --- a/InvenTree/part/templates/part/param_delete.html +++ /dev/null @@ -1,5 +0,0 @@ -{% extends "modal_delete_form.html" %} - -{% block pre_form_content %} -Are you sure you want to remove this parameter? -{% endblock %} \ No newline at end of file diff --git a/InvenTree/part/templates/part/params.html b/InvenTree/part/templates/part/params.html index e1c21cd681..8909d2bbbd 100644 --- a/InvenTree/part/templates/part/params.html +++ b/InvenTree/part/templates/part/params.html @@ -21,41 +21,23 @@ - - - - - - - - - - {% for param in part.get_parameters %} - - - - - - {% endfor %} - -
{% trans "Name" %}{% trans "Value" %}{% trans "Units" %}
{{ param.template.name }}{{ param.data }} - {{ param.template.units }} -
- {% if roles.part.change %} - - {% endif %} - {% if roles.part.change %} - - {% endif %} -
-
- +
{% endblock %} {% block js_ready %} {{ block.super }} + loadPartParameterTable( + '#parameter-table', + '{% url "api-part-parameter-list" %}', + { + params: { + part: {{ part.pk }}, + } + } + ); + $('#param-table').inventreeTable({ }); diff --git a/InvenTree/part/test_api.py b/InvenTree/part/test_api.py index 0c1f083383..7700c5c61f 100644 --- a/InvenTree/part/test_api.py +++ b/InvenTree/part/test_api.py @@ -805,7 +805,7 @@ class PartParameterTest(InvenTreeAPITestCase): Test for listing part parameters """ - url = reverse('api-part-param-list') + url = reverse('api-part-parameter-list') response = self.client.get(url, format='json') @@ -838,7 +838,7 @@ class PartParameterTest(InvenTreeAPITestCase): Test that we can create a param via the API """ - url = reverse('api-part-param-list') + url = reverse('api-part-parameter-list') response = self.client.post( url, @@ -860,7 +860,7 @@ class PartParameterTest(InvenTreeAPITestCase): Tests for the PartParameter detail endpoint """ - url = reverse('api-part-param-detail', kwargs={'pk': 5}) + url = reverse('api-part-parameter-detail', kwargs={'pk': 5}) response = self.client.get(url) diff --git a/InvenTree/part/urls.py b/InvenTree/part/urls.py index 96560a7ad7..41880d9878 100644 --- a/InvenTree/part/urls.py +++ b/InvenTree/part/urls.py @@ -35,8 +35,6 @@ part_parameter_urls = [ url(r'^template/(?P\d+)/delete/', views.PartParameterTemplateDelete.as_view(), name='part-param-template-edit'), url(r'^new/', views.PartParameterCreate.as_view(), name='part-param-create'), - url(r'^(?P\d+)/edit/', views.PartParameterEdit.as_view(), name='part-param-edit'), - url(r'^(?P\d+)/delete/', views.PartParameterDelete.as_view(), name='part-param-delete'), ] part_detail_urls = [ diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index d9f79262d1..360a47ac1e 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -2307,28 +2307,6 @@ class PartParameterCreate(AjaxCreateView): return form -class PartParameterEdit(AjaxUpdateView): - """ View for editing a PartParameter """ - - model = PartParameter - form_class = part_forms.EditPartParameterForm - ajax_form_title = _('Edit Part Parameter') - - def get_form(self): - - form = super().get_form() - - return form - - -class PartParameterDelete(AjaxDeleteView): - """ View for deleting a PartParameter """ - - model = PartParameter - ajax_template_name = 'part/param_delete.html' - ajax_form_title = _('Delete Part Parameter') - - class CategoryDetail(InvenTreeRoleMixin, DetailView): """ Detail view for PartCategory """ diff --git a/InvenTree/templates/InvenTree/settings/part.html b/InvenTree/templates/InvenTree/settings/part.html index d4b386e77f..57ffc95ba8 100644 --- a/InvenTree/templates/InvenTree/settings/part.html +++ b/InvenTree/templates/InvenTree/settings/part.html @@ -75,7 +75,7 @@ {{ block.super }} $("#param-table").inventreeTable({ - url: "{% url 'api-part-param-template-list' %}", + url: "{% url 'api-part-parameter-template-list' %}", queryParams: { ordering: 'name', }, diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index f764ea9062..9c67622753 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -741,19 +741,19 @@ function handleFormSuccess(response, options) { var cache = (options.follow && response.url) || options.redirect || options.reload; // Display any messages - if (response.success) { + if (response && response.success) { showAlertOrCache("alert-success", response.success, cache); } - if (response.info) { + if (response && response.info) { showAlertOrCache("alert-info", response.info, cache); } - if (response.warning) { + if (response && response.warning) { showAlertOrCache("alert-warning", response.warning, cache); } - if (response.danger) { + if (response && response.danger) { showAlertOrCache("alert-danger", response.danger, cache); } diff --git a/InvenTree/templates/js/part.js b/InvenTree/templates/js/part.js index 7fa63098e1..e106098ad4 100644 --- a/InvenTree/templates/js/part.js +++ b/InvenTree/templates/js/part.js @@ -220,6 +220,107 @@ function loadSimplePartTable(table, url, options={}) { } +function loadPartParameterTable(table, url, options) { + + var params = options.params || {}; + + // Load filters + var filters = loadTableFilters("part-parameters"); + + for (var key in params) { + filters[key] = params[key]; + } + + // setupFilterLsit("#part-parameters", $(table)); + + $(table).inventreeTable({ + url: url, + original: params, + queryParams: filters, + name: 'partparameters', + groupBy: false, + formatNoMatches: function() { return '{% trans "No parameters found" %}'; }, + columns: [ + { + checkbox: true, + switchable: false, + visible: true, + }, + { + field: 'name', + title: '{% trans "Name" %}', + switchable: false, + sortable: true, + formatter: function(value, row) { + return row.template_detail.name; + } + }, + { + field: 'data', + title: '{% trans "Value" %}', + switchable: false, + sortable: true, + }, + { + field: 'units', + title: '{% trans "Units" %}', + switchable: true, + sortable: true, + formatter: function(value, row) { + return row.template_detail.units; + } + }, + { + field: 'actions', + title: '', + switchable: false, + sortable: false, + formatter: function(value, row) { + var pk = row.pk; + + var html = `
`; + + html += makeIconButton('fa-edit icon-blue', 'button-parameter-edit', pk, '{% trans "Edit parameter" %}'); + html += makeIconButton('fa-trash-alt icon-red', 'button-parameter-delete', pk, '{% trans "Delete parameter" %}'); + + html += `
`; + + return html; + } + } + ], + onPostBody: function() { + // Setup button callbacks + $(table).find('.button-parameter-edit').click(function() { + var pk = $(this).attr('pk'); + + constructForm(`/api/part/parameter/${pk}/`, { + fields: { + data: {}, + }, + title: '{% trans "Edit Parameter" %}', + onSuccess: function() { + $(table).bootstrapTable('refresh'); + } + }); + }); + + $(table).find('.button-parameter-delete').click(function() { + var pk = $(this).attr('pk'); + + constructForm(`/api/part/parameter/${pk}/`, { + method: 'DELETE', + title: '{% trans "Delete Parameter" %}', + onSuccess: function() { + $(table).bootstrapTable('refresh'); + } + }); + }); + } + }); +} + + function loadParametricPartTable(table, options={}) { /* Load parametric table for part parameters *