-
Notifications
You must be signed in to change notification settings - Fork 94
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
Add "lexical" and "natural" sort strategies for notation codes #1205
Changes from 6 commits
3d4b80a
651a5fe
499a121
dbd4dc7
65714de
4b8a7c9
163f16a
e53e82b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,12 +178,21 @@ public function getTitle($lang = null) | |
} | ||
|
||
/** | ||
* Returns a boolean value set in the config.ttl config. | ||
* @return boolean | ||
* Returns the sorting strategy for notation codes set in the config.ttl | ||
* config: either "lexical" (default), "natural", or null if | ||
* sorting by notations is disabled. | ||
* @return string|bool | ||
*/ | ||
public function sortByNotation() | ||
public function getSortByNotation(): ?string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I renamed the method for better consistency with other getters, and redefined its return value. |
||
{ | ||
return $this->getBoolean('skosmos:sortByNotation'); | ||
$value = $this->getLiteral('skosmos:sortByNotation'); | ||
if ($value == "lexical" || $value == "natural") { | ||
return $value; | ||
} | ||
// not a special value - interpret as boolean instead | ||
$bvalue = $this->getBoolean('skosmos:sortByNotation'); | ||
// default sorting strategy is "lexical" | ||
return $bvalue ? "lexical" : null; | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -326,7 +326,14 @@ function countAndSetOffset() { | |
} | ||
} | ||
|
||
// return -1 if the value is negative, 1 otherwise | ||
// used to coerce sort values so they are compatible with the jsTree sort plugin | ||
function negVsPos(val) { | ||
return (val < 0) ? -1 : 1; | ||
} | ||
|
||
// Natural sort from: http://stackoverflow.com/a/15479354/3894569 | ||
// adapted to return only -1 or 1 using negVsPos function above | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the documentation of the jsTree sort plugin, it expects that the return value of the sort function is either -1 or 1 (anything other than -1 will be interpreted as 1, AFAICT). To make sure that the return values meet those expectations, I added a coercing function. |
||
function naturalCompare(a, b) { | ||
var ax = [], bx = []; | ||
|
||
|
@@ -337,10 +344,10 @@ function naturalCompare(a, b) { | |
var an = ax.shift(); | ||
var bn = bx.shift(); | ||
var nn = (an[0] - bn[0]) || an[1].localeCompare(bn[1], lang); | ||
if(nn) return nn; | ||
if(nn) return negVsPos(nn); | ||
} | ||
|
||
return ax.length - bx.length; | ||
return negVsPos(ax.length - bx.length); | ||
} | ||
|
||
function makeCallbacks(data, pageType) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the notation here doesn't seem to have any effect on the sort order so I just removed it.