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

fix sorting of notated concepts in hierarchy #887

Merged
merged 1 commit into from
Nov 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
});
}