Skip to content

Commit

Permalink
Merge pull request #2321 from nextcloud/backport/2318/stable29
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Aug 7, 2024
2 parents d033c17 + d494688 commit ed28d89
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 6 additions & 1 deletion js/viewer-main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23100,13 +23100,18 @@ const sortCompare = function(fileInfo1, fileInfo2, key, asc = true) {
return 1;
}
if (isNumber(fileInfo1[key]) && isNumber(fileInfo2[key])) {
return Number(fileInfo1[key]) - Number(fileInfo2[key]);
const result = Number(fileInfo1[key]) - Number(fileInfo2[key]);
return asc ? result : -result;
}
if (fileInfo1.type === "directory" && fileInfo2.type !== "directory") {
return -1;
} else if (fileInfo1.type !== "directory" && fileInfo2.type === "directory") {
return 1;
}
if (key === "lastmod") {
const result = new Date(fileInfo1[key]).getTime() - new Date(fileInfo2[key]).getTime();
return asc ? -result : result;
}
return asc ? fileInfo1[key].localeCompare(fileInfo2[key], OC.getLanguage(), { numeric: true }) : -fileInfo1[key].localeCompare(fileInfo2[key], OC.getLanguage(), { numeric: true });
};
const genFileInfo = function(obj) {
Expand Down
2 changes: 1 addition & 1 deletion js/viewer-main.mjs.map

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions src/utils/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const sortCompare = function(fileInfo1, fileInfo2, key, asc = true) {

// if this is a number, let's sort by integer
if (isNumber(fileInfo1[key]) && isNumber(fileInfo2[key])) {
return Number(fileInfo1[key]) - Number(fileInfo2[key])
const result = Number(fileInfo1[key]) - Number(fileInfo2[key])
return asc ? result : -result
}

// else we sort by string, so let's sort directories first
Expand All @@ -70,7 +71,11 @@ const sortCompare = function(fileInfo1, fileInfo2, key, asc = true) {
} else if (fileInfo1.type !== 'directory' && fileInfo2.type === 'directory') {
return 1
}

// sort by date if key is lastmod
if (key === 'lastmod') {
const result = new Date(fileInfo1[key]).getTime() - new Date(fileInfo2[key]).getTime()
return asc ? -result : result
}
// finally sort by name
return asc
? fileInfo1[key].localeCompare(fileInfo2[key], OC.getLanguage(), { numeric: true })
Expand Down

0 comments on commit ed28d89

Please sign in to comment.