Skip to content

Commit

Permalink
Merge pull request #887 from NatLibFi/issue861-sort-notations
Browse files Browse the repository at this point in the history
fix sorting of notated concepts in hierarchy
  • Loading branch information
joelit authored Nov 7, 2019
2 parents d33cd8e + 79f61ea commit 6e315dc
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion resource/js/hierarchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function createObjectsFromChildren(conceptData, conceptUri) {
text: getLabel(conceptData.narrower[i]),
a_attr: getConceptHref(conceptData.narrower[i]),
uri: conceptData.narrower[i].uri,
notation: conceptData.narrower[i].notation,
parents: conceptUri,
state: { opened: true }
};
Expand All @@ -103,6 +104,7 @@ function createConceptObject(conceptUri, conceptData) {
text: getLabel(conceptData),
a_attr: getConceptHref(conceptData),
uri: conceptUri,
notation: conceptData.notation,
parents: conceptData.broader,
state: { opened: true },
children: []
Expand Down Expand Up @@ -218,6 +220,7 @@ function vocabRoot(topConcepts) {
text: conceptData.label,
a_attr : getConceptHref(conceptData),
uri: conceptData.uri,
notation: conceptData.notation,
state: { opened: false }
};
if (conceptData.hasChildren)
Expand Down Expand Up @@ -257,13 +260,15 @@ function appendChildrenToParents() {
}

function createObjectsFromNarrowers(narrowerResponse) {

var childArray = [];
for (var i = 0; i < narrowerResponse.narrower.length; i++) {
var conceptObject = narrowerResponse.narrower[i];
var childObject = {
text : getLabel(conceptObject),
a_attr : getConceptHref(conceptObject),
uri: conceptObject.uri,
notation: conceptObject.notation,
parents: narrowerResponse.uri,
state: { opened: false, disabled: false, selected: false }
};
Expand Down Expand Up @@ -301,6 +306,7 @@ function schemeRoot(schemes) {
text: label,
a_attr : { "href" : vocab + '/' + lang + '/page/?uri=' + scheme.uri, 'class': 'scheme'},
uri: scheme.uri,
notation: scheme.notation,
children: true,
state: { opened: false }
};
Expand Down Expand Up @@ -333,6 +339,7 @@ function topConceptsToSchemes(topConcepts, schemes) {
text : getLabel(topConcept),
a_attr : { "href" : vocab + '/' + lang + '/page/?uri=' + encodeURIComponent(topConcept.uri) },
uri: topConcept.uri,
notation: topConcept.notation,
state: { opened: false, disabled: false, selected: false }
};
if (hasChildren) {
Expand Down Expand Up @@ -426,7 +433,29 @@ function getTreeConfiguration() {
}
},
'plugins' : ['sort'],
'sort' : function (a,b) { return naturalCompare(this.get_text(a).toLowerCase(), this.get_text(b).toLowerCase()); }
'sort' : function (a,b) {
var aNode = this.get_node(a);
var bNode = this.get_node(b);

if (window.showNotation) {
var aNotation = aNode.original.notation;
var bNotation = bNode.original.notation;

if (aNotation) {
if (bNotation) {
if (aNotation < bNotation) {
return -1;
}
else if (aNotation > bNotation) {
return 1;
}
}
else return -1;
}
else if (bNotation) return 1;
}
return naturalCompare(aNode.text.toLowerCase(), bNode.text.toLowerCase());
}
});
}

0 comments on commit 6e315dc

Please sign in to comment.