Wrap server queries in onPanelLoad calls, to reduce initial page load time

This commit is contained in:
Oliver 2022-03-09 13:14:04 +11:00
parent 7986e0752d
commit 9f8f900e17

View File

@ -323,17 +323,8 @@
{% block js_ready %} {% block js_ready %}
{{ block.super }} {{ block.super }}
$('#btn-create-output').click(function() { onPanelLoad('completed', function() {
loadStockTable($("#build-stock-table"), {
createBuildOutput(
{{ build.pk }},
{
trackable_parts: {% if build.part.has_trackable_parts %}true{% else %}false{% endif%},
}
);
});
loadStockTable($("#build-stock-table"), {
params: { params: {
location_detail: true, location_detail: true,
part_detail: true, part_detail: true,
@ -345,11 +336,70 @@ loadStockTable($("#build-stock-table"), {
'#stock-options', '#stock-options',
], ],
url: "{% url 'api-stock-list' %}", url: "{% url 'api-stock-list' %}",
});
}); });
onPanelLoad('children', function() {
loadBuildTable($('#sub-build-table'), {
url: '{% url "api-build-list" %}',
filterTarget: "#filter-list-sub-build",
params: {
ancestor: {{ build.pk }},
}
});
});
// Get the list of BOM items required for this build onPanelLoad('attachments', function() {
inventreeGet(
enableDragAndDrop(
'#attachment-dropzone',
'{% url "api-build-attachment-list" %}',
{
data: {
build: {{ build.id }},
},
label: 'attachment',
success: function(data, status, xhr) {
location.reload();
}
}
);
loadAttachmentTable('{% url "api-build-attachment-list" %}', {
filters: {
build: {{ build.pk }},
},
fields: {
build: {
value: {{ build.pk }},
hidden: true,
}
}
});
});
onPanelLoad('notes', function() {
$('#edit-notes').click(function() {
constructForm('{% url "api-build-detail" build.pk %}', {
fields: {
notes: {
multiline: true,
}
},
title: '{% trans "Edit Notes" %}',
reload: true,
});
});
});
function reloadTable() {
$('#allocation-table-untracked').bootstrapTable('refresh');
}
onPanelLoad('allocate', function() {
// Get the list of BOM items required for this build
inventreeGet(
'{% url "api-bom-list" %}', '{% url "api-bom-list" %}',
{ {
part: {{ build.part.pk }}, part: {{ build.part.pk }},
@ -434,62 +484,21 @@ inventreeGet(
{% endif %} {% endif %}
} }
} }
); );
loadBuildTable($('#sub-build-table'), { $('#btn-create-output').click(function() {
url: '{% url "api-build-list" %}',
filterTarget: "#filter-list-sub-build",
params: {
ancestor: {{ build.pk }},
}
});
createBuildOutput(
enableDragAndDrop( {{ build.pk }},
'#attachment-dropzone',
'{% url "api-build-attachment-list" %}',
{ {
data: { trackable_parts: {% if build.part.has_trackable_parts %}true{% else %}false{% endif%},
build: {{ build.id }},
},
label: 'attachment',
success: function(data, status, xhr) {
location.reload();
} }
} );
);
loadAttachmentTable('{% url "api-build-attachment-list" %}', {
filters: {
build: {{ build.pk }},
},
fields: {
build: {
value: {{ build.pk }},
hidden: true,
}
}
});
$('#edit-notes').click(function() {
constructForm('{% url "api-build-detail" build.pk %}', {
fields: {
notes: {
multiline: true,
}
},
title: '{% trans "Edit Notes" %}',
reload: true,
}); });
});
function reloadTable() { {% if build.active %}
$('#allocation-table-untracked').bootstrapTable('refresh');
}
{% if build.active %} $("#btn-auto-allocate").on('click', function() {
$("#btn-auto-allocate").on('click', function() {
autoAllocateStockToBuild( autoAllocateStockToBuild(
{{ build.pk }}, {{ build.pk }},
@ -500,9 +509,9 @@ $("#btn-auto-allocate").on('click', function() {
{% endif %} {% endif %}
} }
); );
}); });
$("#btn-allocate").on('click', function() { $("#btn-allocate").on('click', function() {
var bom_items = $("#allocation-table-untracked").bootstrapTable("getData"); var bom_items = $("#allocation-table-untracked").bootstrapTable("getData");
@ -535,15 +544,15 @@ $("#btn-allocate").on('click', function() {
} }
); );
} }
}); });
$('#btn-unallocate').on('click', function() { $('#btn-unallocate').on('click', function() {
unallocateStock({{ build.id }}, { unallocateStock({{ build.id }}, {
table: '#allocation-table-untracked', table: '#allocation-table-untracked',
}); });
}); });
$('#allocate-selected-items').click(function() { $('#allocate-selected-items').click(function() {
var bom_items = $("#allocation-table-untracked").bootstrapTable("getSelections"); var bom_items = $("#allocation-table-untracked").bootstrapTable("getSelections");
@ -564,19 +573,19 @@ $('#allocate-selected-items').click(function() {
} }
} }
); );
}); });
$("#btn-order-parts").click(function() { $("#btn-order-parts").click(function() {
launchModalForm("/order/purchase-order/order-parts/", { launchModalForm("/order/purchase-order/order-parts/", {
data: { data: {
build: {{ build.id }}, build: {{ build.id }},
}, },
}); });
}); });
{% endif %} {% endif %}
});
enableSidebar('buildorder'); enableSidebar('buildorder');
{% endblock %} {% endblock %}