Skip to content

Commit

Permalink
Harmonized comment annotation tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-TBT committed Nov 24, 2024
1 parent 9515de1 commit 594f7b4
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ var CommentsPane = function CommentsPane($element, opts) {
},
});

var compareParentName = function(a, b){
if (!a.parent.name || !b.parent.name) {
return 1;
}
return a.parent.name.toLowerCase() > b.parent.name.toLowerCase() ? 1 : -1;
};


this.render = function render() {

Expand Down Expand Up @@ -138,6 +145,83 @@ var CommentsPane = function CommentsPane($element, opts) {
});
}

// If we are batch annotating multiple objects, we show a summary of each ann
if (objects.length > 1) {

// Map ann.id to summary for that ann
var summary = {};
anns.forEach(function(ann){
var annId = ann.id,
linkOwner = ann.link.owner.id;
if (summary[annId] === undefined) {
ann.canRemove = false;
ann.canRemoveCount = 0;
ann.links = [];
ann.addedBy = [];
summary[annId] = ann;
}
// Add link to list...
var l = ann.link;
// slice parent class 'ProjectI' > 'Project'
l.parent.class = l.parent.class.slice(0, -1);
summary[annId].links.push(l);

// ...and summarise other properties on the ann
if (l.permissions.canDelete) {
summary[annId].canRemoveCount += 1;
}
summary[annId].canRemove = summary[annId].canRemove || l.permissions.canDelete;
if (summary[annId].addedBy.indexOf(linkOwner) === -1) {
summary[annId].addedBy.push(linkOwner);
}
});

// convert summary back to list of 'anns'
anns = [];
for (var annId in summary) {
if (summary.hasOwnProperty(annId)) {
summary[annId].links.sort(compareParentName);
anns.push(summary[annId]);
}
}

// Map ann.id to summary for that ann
summary = {};
inh_anns.forEach(function(ann){
var annId = ann.id,
linkOwner = ann.link.owner.id;
if (summary[annId] === undefined) {
ann.canRemove = false;
ann.canRemoveCount = 0;
ann.links = [];
ann.addedBy = [];
summary[annId] = ann;
}
// Add link to list...
var l = ann.link;
// slice parent class 'ProjectI' > 'Project'
l.parent.class = l.parent.class.slice(0, -1);
summary[annId].links.push(l);

// ...and summarise other properties on the ann
if (summary[annId].addedBy.indexOf(linkOwner) === -1) {
summary[annId].addedBy.push(linkOwner);
}
for(j = 0; j < ann.childNames; j++){
summary[annId].childNames.push(ann.childNames[j]);
}
});

// convert summary back to list of 'anns'
inh_anns = [];
for (var annId in summary) {
if (summary.hasOwnProperty(annId)) {
summary[annId].links.sort(compareParentName);
inh_anns.push(summary[annId]);
}
}
}

// Show most recent comments at the top
anns.sort(function(a, b) {
return a.date < b.date ? 1 : -1;
Expand All @@ -151,24 +235,20 @@ var CommentsPane = function CommentsPane($element, opts) {
}
});

// Remove duplicates (same comment on multiple objects)
anns = anns.filter(function(ann, idx){
// already sorted, so just compare with last item
return (idx === 0 || anns[idx - 1].id !== ann.id);
});

// Update html...
var html = "";
if (anns.length > 0) {
html = commentsTempl({'anns': anns,
'static': WEBCLIENT.URLS.static_webclient,
'webindex': WEBCLIENT.URLS.webindex,
'userId': WEBCLIENT.USER.id,
'isInherited': false});
}
if (inh_anns.length > 0) {
html = html + commentsTempl({'anns': inh_anns,
'static': WEBCLIENT.URLS.static_webclient,
'webindex': WEBCLIENT.URLS.webindex,
'userId': WEBCLIENT.USER.id,
'isInherited': true});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</strong>
<% if (isInherited) { %>
on
<%- ann.link.parent.class.substring(0, ann.link.parent.class.length - 1) %> <%- ann.link.parent.name.slice(0, 30) %>
<%- ann.link.parent.class %> <%- ann.link.parent.name.slice(0, 30) %>
<% } else { %>
at
<% print(OME.formatDate(ann.link.date)) %>
Expand All @@ -36,13 +36,42 @@
</div>

<span class="tooltip_html" style='display:none'>
<b>ID:</b> <%- ann.id %><br />
<% if (ann.ns) { %><b>Namespace:</b> <%- ann.ns %><br /><% } %>
<% if (ann.description) { %><b>Description:</b> <%- ann.description %><br /><% } %>
<% if (isInherited) { %>
<!-- show different tooltip for batch_annotate panel -->
<% if (ann.links && !isInherited) { %>
Can remove File from <b><%- ann.canRemoveCount %> object<% if(ann.canRemoveCount !== 1) {print('s')} %></b>:<br/>
<% } %>
<b>Annotation ID:</b> <%- ann.id %><br />
<b>Owner:</b> <%- ann.owner.firstName %> <%- ann.owner.lastName %><br />
<% if (ann.links) { %>
<b>Linked to:</b><br />
<% _.each(ann.links, function(link, idx) { %>
<div>
&nbsp
<% if (idx < 20) { %>
- <b><%- link.parent.class %> <%- link.parent.id %>:</b> <% print(_.escape(link.parent.name).slice(0, 28)) %>
<% if (link.owner.id !== userId){
print("(" + link.owner.firstName.slice(0, 1) + " " + _.escape(link.owner.lastName) + ")")
} %>
<% } else if (idx === 20) { %>
and <b><% print(ann.links.length - 20) %></b> other objects...
<% } %>
</div>
<% }) %>
<% } else if (isInherited) { %>
<b>Linked to:</b> <% print(_.escape(ann.link.parent.name).slice(0, 28)) %><br />
<% } else { %>
<b>Linked by:</b> <%- ann.link.owner.firstName %> <%- ann.link.owner.lastName %><br />
<b>On:</b> <% print(OME.formatDate(ann.link.date)) %><br />
<% } %>
<% if (ann.description){ %>
<b>Description:</b> <%- ann.description %><br/>
<% } %><% if (ann.ns){ %>
<b>Namespace:</b> <%- ann.ns %><br/>
<% } %>
<% if (isInherited && ann.links) { %>
<b>Inherited by:</b><br />
<% _.each(ann.childNames, function(cname) { %>
&nbsp <%- cname %><br />
&nbsp- <%- cname.slice(0, 28) %><br />
<% }) %>
<% } %>
</span>
Expand Down

0 comments on commit 594f7b4

Please sign in to comment.