-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1972 from owncloud/default-sort
Add default client side sort
- Loading branch information
Showing
6 changed files
with
153 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Compare two strings to provide a natural sort | ||
* @param a first string to compare | ||
* @param b second string to compare | ||
* @return -1 if b comes before a, 1 if a comes before b | ||
* or 0 if the strings are identical | ||
*/ | ||
function _chunkify (t) { | ||
// Adapted from http://my.opera.com/GreyWyvern/blog/show.dml/1671288 | ||
const tz = []; let x = 0; let y = -1; let n = 0; let c | ||
|
||
while (x < t.length) { | ||
c = t.charAt(x) | ||
// only include the dot in strings | ||
const m = ((!n && c === '.') || (c >= '0' && c <= '9')) | ||
if (m !== n) { | ||
// next chunk | ||
y++ | ||
tz[y] = '' | ||
n = m | ||
} | ||
tz[y] += c | ||
x++ | ||
} | ||
return tz | ||
} | ||
|
||
function _naturalSortCompare (a, b) { | ||
const aa = _chunkify(a) | ||
const bb = _chunkify(b) | ||
let x, aNum, bNum | ||
|
||
for (x = 0; aa[x] && bb[x]; x++) { | ||
if (aa[x] !== bb[x]) { | ||
aNum = Number(aa[x]) | ||
bNum = Number(bb[x]) | ||
// note: == is correct here | ||
// eslint-disable-next-line eqeqeq | ||
if (aNum == aa[x] && bNum == bb[x]) { | ||
return aNum - bNum | ||
} else { | ||
// Forcing 'en' locale to match the server-side locale which is | ||
// always 'en'. | ||
// | ||
// Note: This setting isn't supported by all browsers but for the ones | ||
// that do there will be more consistency between client-server sorting | ||
return aa[x].localeCompare(bb[x], 'en') | ||
} | ||
} | ||
} | ||
return aa.length - bb.length | ||
} | ||
|
||
function name (fileInfo1, fileInfo2) { | ||
if (fileInfo1.type === 'folder' && fileInfo2.type !== 'folder') { | ||
return -1 | ||
} | ||
if (fileInfo1.type !== 'folder' && fileInfo2.type === 'folder') { | ||
return 1 | ||
} | ||
return _naturalSortCompare(fileInfo1.name, fileInfo2.name) | ||
} | ||
|
||
export const fileSortFunctions = { | ||
name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
Feature: Filter files/folders | ||
|
||
As a user | ||
I would like to sort files/folders | ||
So that I can make the file/folder list more clear | ||
|
||
Background: | ||
Given user "user1" has been created with default attributes | ||
And user "user1" has logged in using the webUI | ||
And the user has created folder "test_sort" | ||
And the user has created the following folders | ||
| entry_name | | ||
| test_sort/a | | ||
| test_sort/a 文件 | | ||
| test_sort/10 | | ||
| test_sort/1 | | ||
| test_sort/2 | | ||
| test_sort/z | | ||
And the user has created the following files | ||
| entry_name | | ||
| test_sort/a.txt | | ||
| test_sort/a space.txt | | ||
| test_sort/a space (2).txt | | ||
| test_sort/a space 文件 | | ||
| test_sort/a space 文件夹 | | ||
| test_sort/b1.txt | | ||
| test_sort/b2.txt | | ||
| test_sort/b10.txt | | ||
| test_sort/z.txt | | ||
|
||
Scenario: Folders are listed before files alphabetically by default and sorted using natural sort | ||
When the user has browsed to the files page | ||
Then these resources should be listed in the folder "test_sort" on the webUI | ||
| entry_name | | ||
| a | | ||
| a 文件 | | ||
| 1 | | ||
| 2 | | ||
| 10 | | ||
| z | | ||
| a.txt | | ||
| a space.txt | | ||
| a space (2).txt | | ||
| a space 文件 | | ||
| a space 文件夹 | | ||
| b1.txt | | ||
| b2.txt | | ||
| b10.txt | | ||
| z.txt | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters