Skip to content

Commit

Permalink
Merge pull request #947 from girder/images-used-by-annotations
Browse files Browse the repository at this point in the history
Indicate when images are used by annotations.
  • Loading branch information
manthey authored Aug 29, 2022
2 parents 4e872af + bc58b3c commit f37f32d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def initialize(self):
('created', SortDir.ASCENDING),
('_version', SortDir.ASCENDING),
], {}),
'element.girderId',
])

self.exposeFields(AccessType.READ, (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,4 +766,8 @@ def getItemListAnnotationCounts(self, items):
{'_active': {'$ne': False}, 'itemId': item['_id']},
user=self.getCurrentUser(), level=AccessType.READ, limit=-1)
results[itemId] = annotations.count()
if Annotationelement().findOne({'element.girderId': itemId}):
if 'referenced' not in results:
results['referenced'] = {}
results['referenced'][itemId] = True
return results
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import '../stylesheets/itemList.styl';
wrap(ItemListWidget, 'render', function (render) {
render.apply(this, _.rest(arguments));

function addLargeImageAnnotationBadge(item, parent, numAnnotations) {
function addLargeImageAnnotationBadge(item, parent, numAnnotations, flag) {
const thumbnail = $('.large_image_thumbnail[g-item-cid="' + item.cid + '"]', parent).first();
if (!thumbnail.length) {
return;
Expand All @@ -24,7 +24,7 @@ wrap(ItemListWidget, 'render', function (render) {
}
// update badge
badge
.attr('title', `${numAnnotations} annotation${numAnnotations === 1 ? '' : 's'}`)
.attr('title', !flag ? `${numAnnotations} annotation${numAnnotations === 1 ? '' : 's'}` : 'Referenced by an annotation')
.text(numAnnotations)
.toggleClass('hidden', !numAnnotations);
}
Expand All @@ -43,6 +43,7 @@ wrap(ItemListWidget, 'render', function (render) {

const needCounts = items.filter((item) => item._annotationCount === undefined && item.has('largeImage')).map((item) => {
item._annotationCount = null; // pending
delete item._annotationReferenced;
return item.id;
});
let promise;
Expand All @@ -59,7 +60,13 @@ wrap(ItemListWidget, 'render', function (render) {
error: null
}).done((resp) => {
Object.entries(resp).forEach(([id, count]) => {
if (this.collection.get(id)) {
if (id === 'referenced') {
Object.keys(count).forEach((rid) => {
if (this.collection.get(rid)) {
this.collection.get(rid)._annotationReferenced = true;
}
});
} else if (this.collection.get(id)) {
this.collection.get(id)._annotationCount = count;
}
});
Expand All @@ -68,7 +75,11 @@ wrap(ItemListWidget, 'render', function (render) {
promise.then(() => {
this.collection.forEach((item) => {
if (item._annotationCount !== undefined) {
addLargeImageAnnotationBadge(item, this.$el, item._annotationCount);
if (!item._annotationReferenced) {
addLargeImageAnnotationBadge(item, this.$el, item._annotationCount);
} else {
addLargeImageAnnotationBadge(item, this.$el, '*', true);
}
}
});
return null;
Expand Down

0 comments on commit f37f32d

Please sign in to comment.