Skip to content

Commit

Permalink
Add option to sort uploads by filename
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanqui committed Aug 16, 2024
1 parent 495f31a commit 76f497b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions rhinventory/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class FileForm(Form):
category = Select2Field("Category", choices=[(el.value, el.name) for el in FileCategory], coerce=int)
batch_number = IntegerField("Batch number", render_kw={'readonly': True})
auto_assign = BooleanField("Auto assign", render_kw={'checked':''})
sort_by_filename = BooleanField("Sort uploads by filename", render_kw={'checked':''})

class FileAssignForm(Form):
asset = Select2Field("asset", coerce=int)
6 changes: 5 additions & 1 deletion rhinventory/templates/admin/file/upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
const uploadPromises = []

uploadedCount = 0;
files = Array.from(fileUploadElem.files);
if (formElem.querySelector('[name=sort_by_filename]').checked) {
files.sort((a, b) => a.name.localeCompare(b.name))
}
totalFileCount = fileUploadElem.files.length;
fail = false;

Expand All @@ -75,7 +79,7 @@
fileSlices = [];

for (let i=0; i < Math.ceil(totalFileCount / sliceBy); i++) {
fileSlices.push(Array.from(fileUploadElem.files).slice(i*sliceBy, (i+1)*sliceBy));
fileSlices.push(files.slice(i*sliceBy, (i+1)*sliceBy));
}

function uploadSlice() {
Expand Down

0 comments on commit 76f497b

Please sign in to comment.