Skip to content

Commit

Permalink
Fix: sorting by date and number
Browse files Browse the repository at this point in the history
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>

Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
  • Loading branch information
hamza221 authored and nextcloud-command committed May 23, 2024
1 parent 6dd5c4c commit 9429e72
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion js/viewer-main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ var b4=Object.defineProperty;var y4=(e,r,a)=>r in e?b4(e,r,{enumerable:!0,config
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/const lT=function(e){const r=e.split("/"),a=r[r.length-1];return[r.slice(0,r.length-1).join("/"),a]},Rj=function(e,r,a,n=!0){return e.isFavorite&&!r.isFavorite?-1:!e.isFavorite&&r.isFavorite?1:Rg(e[a])&&Rg(r[a])?Number(e[a])-Number(r[a]):e.type==="directory"&&r.type!=="directory"?-1:e.type!=="directory"&&r.type==="directory"?1:n?e[a].localeCompare(r[a],OC.getLanguage(),{numeric:!0}):-e[a].localeCompare(r[a],OC.getLanguage(),{numeric:!0})},B1=function(e){const r={};return Object.keys(e).forEach(a=>{const n=e[a];n&&typeof n=="object"&&!Array.isArray(n)?Object.assign(r,B1(n)):n==="false"?r[th(a)]=!1:n==="true"?r[th(a)]=!0:r[th(a)]=Rg(n)?Number(n):n}),r};function yc({filename:e,basename:r,source:a=""}){if(Gs())return Wo("/s/".concat(R1(),"/download?path={dirname}&files={basename}"),{dirname:tj(e),basename:r});const n=N1();return a&&!a.includes(n)?null:(e.startsWith(n)&&(e=e.slice(n.length)),k1()+nd(e))}/**
*/const lT=function(e){const r=e.split("/"),a=r[r.length-1];return[r.slice(0,r.length-1).join("/"),a]},Rj=function(e,r,a,n=!0){if(e.isFavorite&&!r.isFavorite)return-1;if(!e.isFavorite&&r.isFavorite)return 1;if(Rg(e[a])&&Rg(r[a])){const i=Number(e[a])-Number(r[a]);return n?i:-i}if(e.type==="directory"&&r.type!=="directory")return-1;if(e.type!=="directory"&&r.type==="directory")return 1;if(a==="lastmod"){const i=new Date(e[a]).getTime()-new Date(r[a]).getTime();return n?-i:i}return n?e[a].localeCompare(r[a],OC.getLanguage(),{numeric:!0}):-e[a].localeCompare(r[a],OC.getLanguage(),{numeric:!0})},B1=function(e){const r={};return Object.keys(e).forEach(a=>{const n=e[a];n&&typeof n=="object"&&!Array.isArray(n)?Object.assign(r,B1(n)):n==="false"?r[th(a)]=!1:n==="true"?r[th(a)]=!0:r[th(a)]=Rg(n)?Number(n):n}),r};function yc({filename:e,basename:r,source:a=""}){if(Gs())return Wo("/s/".concat(R1(),"/download?path={dirname}&files={basename}"),{dirname:tj(e),basename:r});const n=N1();return a&&!a.includes(n)?null:(e.startsWith(n)&&(e=e.slice(n.length)),k1()+nd(e))}/**
* @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
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 9429e72

Please sign in to comment.