Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alphabetic sorting in Viewer is wrong with numbers #547

Closed
jancborchardt opened this issue Jul 24, 2020 · 5 comments · Fixed by #2088
Closed

Alphabetic sorting in Viewer is wrong with numbers #547

jancborchardt opened this issue Jul 24, 2020 · 5 comments · Fixed by #2088
Labels
1. to develop Accepted and waiting to be taken care of enhancement New feature or request good first issue Good for newcomers papercut Small issues that doesn't break the ux/ui pending fix Waiting for a fix on one of our dependencies

Comments

@jancborchardt
Copy link
Member

Related to Slideshow viewer not adapting sorting mode of files app #366 but different.

If you have these Files:

  • 1.jpg
  • 2.jpg
  • 9.jpg
  • 10.jpg
  • 11.jpg

And then you open 1.jpg to start going through them, the Viewer will show them in this order:

  • 1.jpg
  • 10.jpg
  • 11.jpg
  • 2.jpg
  • 9.jpg

Of course it should be the same order as in Files, the "human" order to sort numbers. ;)

@skjnldsv if you point out where this would have to be changed, this could be a good first issue?

@jancborchardt jancborchardt added enhancement New feature or request good first issue Good for newcomers 1. to develop Accepted and waiting to be taken care of papercut Small issues that doesn't break the ux/ui labels Jul 24, 2020
@skjnldsv
Copy link
Member

skjnldsv commented Jul 26, 2020

viewer/src/views/Viewer.vue

Lines 365 to 367 in 8eafdca

// https://github.com/nextcloud/server/blob/a83b79c5f8ab20ed9b4d751167417a65fa3c42b8/apps/files/lib/Controller/ApiController.php#L247
this.fileList = filteredFiles.sort((a, b) => sortCompare(a, b, 'basename'))

@skjnldsv
Copy link
Member

const sortCompare = function(fileInfo1, fileInfo2, key, asc = true) {
if (fileInfo1.isFavorite && !fileInfo2.isFavorite) {
return -1
} else if (!fileInfo1.isFavorite && fileInfo2.isFavorite) {
return 1
}
// if this is a number, let's sort by integer
if (isNumber(fileInfo1[key]) && isNumber(fileInfo2[key])) {
return Number(fileInfo1[key]) - Number(fileInfo2[key])
}
// else we sort by string, so let's sort directories first
if (fileInfo1.type === 'directory' && fileInfo2.type !== 'directory') {
return -1
} else if (fileInfo1.type !== 'directory' && fileInfo2.type === 'directory') {
return 1
}
// finally sort by name
return asc
? fileInfo1[key].localeCompare(fileInfo2[key], OC.getLanguage())
: -fileInfo1[key].localeCompare(fileInfo2[key], OC.getLanguage())
}

@skjnldsv
Copy link
Member

Related nextcloud/server#13661

@skjnldsv skjnldsv added the pending fix Waiting for a fix on one of our dependencies label Sep 30, 2020
@florianwgnr
Copy link

Just experienced this issue - is there any update on it?

My files are ordered like this:

  • Image 01.jpg
  • Image 02.jpg
  • ...

The viewer displays them in the wrong order:

  1. Image 01.jpg
  2. Image 010.jpg
  3. Image 011.jpg
  4. ...

@Snake16547

This comment was marked as abuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1. to develop Accepted and waiting to be taken care of enhancement New feature or request good first issue Good for newcomers papercut Small issues that doesn't break the ux/ui pending fix Waiting for a fix on one of our dependencies
Projects
None yet
4 participants