Skip to content

Commit

Permalink
Make ItemMetadataView self-rendering and -updating, clean and correct
Browse files Browse the repository at this point in the history
The lack of self-updating prevented the item metadata table from
populating in a deep-linked annotation panel.
  • Loading branch information
jgonggrijp committed Jan 6, 2022
1 parent fee5d31 commit 43807db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
29 changes: 12 additions & 17 deletions frontend/src/item-metadata/item-metadata-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,33 @@ export interface ViewOptions extends BaseOpt<Node> {

export default class ItemMetadataView extends View<Node> {
title: string;
metadata: any;

constructor(options?: ViewOptions) {
super(options);
}

initialize(options: ViewOptions): this {
this.title = 'Item metadata';
if (options.title) this.title = options.title;
this.metadata = new Object();
this.collectDetails();
return this;
initialize(options: ViewOptions): void {
this.title = options.title || 'Item metadata';
this.render().listenTo(this.model, 'change', this.render);
}

render(): this {
this.$el.html(this.template(this));
this.initAccordions();
return this;
this.$el.html(this.template(this.collectDetails()));
return this.initAccordions();
}

collectDetails(): this {
collectDetails() {
const metadata: any = {};
if (this.model.has(dcterms.creator)) {
this.metadata['creator'] = getLabel(this.model.get(dcterms.creator)[0] as Node);
metadata['creator'] = getLabel(this.model.get(dcterms.creator)[0] as Node);
}
if (this.model.has(dcterms.created)) {
this.metadata['created'] = this.model.get(dcterms.created)[0];
metadata['created'] = this.model.get(dcterms.created)[0];
}
if (this.model.has(dcterms.modified)) {
this.metadata['modified'] = this.model.get(dcterms.modified)[0];
metadata['modified'] = this.model.get(dcterms.modified)[0];
}
return this;
return { metadata, title: this.title };
}

initAccordions(): this {
Expand All @@ -62,10 +58,9 @@ export default class ItemMetadataView extends View<Node> {
return this;
}
}

extend(ItemMetadataView.prototype, {
tagName: 'div',
className: 'item-metadata accordions',
template: itemMetadataTemplate,
events: {
}
});
4 changes: 2 additions & 2 deletions frontend/src/panel-annotation/annotation-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class AnnotationView extends CompositeView<FlatItem> {
this.annotationMetadataView = new ItemMetadataView({
model: annotation,
title: 'Annotation metadata'
}).render();
});
}
}

Expand All @@ -66,7 +66,7 @@ export default class AnnotationView extends CompositeView<FlatItem> {
if (item) {
this.itemMetadataView = new ItemMetadataView({
model: item,
}).render();
});
this.listenTo(item, 'change', this.collectDetails)
.collectDetails(item);
this.listenTo(item, 'change', this.render);
Expand Down

0 comments on commit 43807db

Please sign in to comment.