Skip to content

Commit c8a5149

Browse files
Sort json data rather than index of table data
1 parent a87dcf2 commit c8a5149

File tree

1 file changed

+6
-43
lines changed

1 file changed

+6
-43
lines changed

supervisor/shared/web_workflow/static/directory.js

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ var editable = undefined;
88
async function refresh_list() {
99

1010
function compareValues(a, b) {
11-
if (a.value === b.value) {
11+
if (a.directory == b.directory && a.name.toLowerCase() === b.name.toLowerCase()) {
1212
return 0;
1313
} else {
14-
return a.value < b.value ? -1 : 1;
14+
return a.directory.toString().substring(3,4)+a.name.toLowerCase() <
15+
b.directory.toString().substring(3,4)+b.name.toLowerCase() ? -1 : 1;
1516
}
1617
}
1718

@@ -52,10 +53,6 @@ async function refresh_list() {
5253
}
5354
}
5455

55-
var dirCells = [];
56-
var dataCells = [];
57-
var index = 0;
58-
5956
if (window.location.path != "/fs/") {
6057
var clone = template.content.cloneNode(true);
6158
var td = clone.querySelectorAll("td");
@@ -66,16 +63,11 @@ async function refresh_list() {
6663
path.textContent = "..";
6764
// Remove the delete button
6865
td[4].replaceChildren();
69-
70-
var sortdata = {};
71-
sortdata.value = "..";
72-
sortdata.index = index;
73-
dirCells.push(sortdata);
74-
index += 1;
75-
7666
new_children.push(clone);
7767
}
7868

69+
data.sort(compareValues);
70+
7971
for (const f of data) {
8072
// Clone the new row and insert it into the table
8173
var clone = template.content.cloneNode(true);
@@ -118,39 +110,10 @@ async function refresh_list() {
118110
edit_link.href = edit_url
119111
}
120112

121-
var dataCell = td[2];
122-
123-
var sortdata = {};
124-
sortdata.value = dataCell.textContent.toLowerCase().trim();
125-
sortdata.index = index;
126-
if (!f.directory) {
127-
dataCells.push(sortdata);
128-
index += 1;
129-
} else {
130-
dirCells.push(sortdata);
131-
index += 1;
132-
}
133-
134113
new_children.push(clone);
135114
}
136-
137-
dirCells.sort(compareValues);
138-
dataCells.sort(compareValues);
139-
140115
var tbody = document.querySelector("tbody");
141-
142-
// remove rows
143-
while (tbody.firstChild) {
144-
tbody.removeChild(tbody.lastChild);
145-
}
146-
147-
// add sorted rows
148-
for (var i = 0; i < dirCells.length; i += 1) {
149-
tbody.appendChild(new_children[dirCells[i].index]);
150-
}
151-
for (var i = 0; i < dataCells.length; i += 1) {
152-
tbody.appendChild(new_children[dataCells[i].index]);
153-
}
116+
tbody.replaceChildren(...new_children);
154117
}
155118

156119
async function find_devices() {

0 commit comments

Comments
 (0)