Skip to content

Commit

Permalink
Merge pull request #383 from girder/annotationbadge-2.x
Browse files Browse the repository at this point in the history
Add annotation count badge.
  • Loading branch information
manthey authored Oct 7, 2019
2 parents 593385c + 697afa5 commit 341cf19
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
27 changes: 27 additions & 0 deletions web_client/stylesheets/itemListAnnot.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.large_image_thumbnail
position relative

.large_image_annotation_badge
position absolute
top 0
right 0
transform scale(1)translate(50%, -50%)
transform-origin 100% 0

height 20px
padding 0 6px
z-index 10
min-width 20px
display flex
align-items center
justify-content center
font-size 80%

line-height 1

background-color lightgrey
color black
border-radius 10px

&.hidden
display none
4 changes: 3 additions & 1 deletion web_client/views/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import ConfigView from './configView';
import ImageViewerSelectWidget from './imageViewerSelectWidget';
import ItemListWidget from './itemListAnnot';
import * as imageViewerWidget from './imageViewerWidget';

export {
ConfigView,
ImageViewerSelectWidget,
imageViewerWidget
imageViewerWidget,
ItemListWidget
};
58 changes: 58 additions & 0 deletions web_client/views/itemListAnnot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import $ from 'jquery';
import _ from 'underscore';

import { wrap } from 'girder/utilities/PluginUtils';
import ItemListWidget from 'girder/views/widgets/ItemListWidget';

import largeImageConfig from './configView';
import AnnotationCollection from '../collections/AnnotationCollection';

import '../stylesheets/itemListAnnot.styl';

wrap(ItemListWidget, 'render', function (render) {
render.apply(this, _.rest(arguments));

function addLargeImageAnnotationBadge(item, parent) {
const collection = new AnnotationCollection([]);
collection.fetch({
itemId: item.id
}).done(() => {
const thumbnail = $('a[g-item-cid="' + item.cid + '"] .large_image_thumbnail', parent).first();

let badge = thumbnail.find('.large_image_annotation_badge');
if (badge.length === 0) {
badge = $(`<div class="large_image_annotation_badge"></div>`).appendTo(thumbnail);
}
// update badge
const numAnnotations = collection.length;
badge
.attr('title', `${numAnnotations} Annotation${numAnnotations === 1 ? '' : 's'}`)
.text(numAnnotations)
.toggleClass('hidden', numAnnotations === 0);
});
}

largeImageConfig.getSettings((settings) => {
// don't render or already rendered
if (settings['large_image.show_thumbnails'] === false || this.$('.large_image_annotation_badge').length > 0) {
return;
}
const items = this.collection.toArray();
const parent = this.$el;
const hasAnyLargeImage = _.some(items, (item) => item.has('largeImage'));

if (!hasAnyLargeImage) {
return;
}

_.each(items, (item) => {
if (item.get('largeImage')) {
item.getAccessLevel(function () {
addLargeImageAnnotationBadge(item, parent);
});
}
});
});
});

export default ItemListWidget;

0 comments on commit 341cf19

Please sign in to comment.