2020-01-28 15:09:32 +01:00
|
|
|
|
import {Component, Input, OnDestroy, OnInit} from "@angular/core";
|
2020-04-07 19:09:31 +02:00
|
|
|
|
import {Annotation, AnnotationService} from "./annotation.service";
|
2020-01-28 15:09:32 +01:00
|
|
|
|
import {ResultLandingInfo} from "../../utils/entities/resultLandingInfo";
|
2020-04-07 19:09:31 +02:00
|
|
|
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
2020-01-28 15:09:32 +01:00
|
|
|
|
|
|
|
|
|
@Component({
|
2020-03-27 11:06:09 +01:00
|
|
|
|
selector: 'b2note',
|
|
|
|
|
template: `
|
2020-03-30 10:45:08 +02:00
|
|
|
|
<div class="sideInfoTitle uk-margin-small-bottom">Annotations</div>
|
|
|
|
|
<div class="b2note">
|
|
|
|
|
<form ngNoForm
|
|
|
|
|
action="https://b2note-dev.bsc.es/widget/"
|
|
|
|
|
method="post"
|
|
|
|
|
target="b2note_iframe"
|
|
|
|
|
class="uk-padding-small uk-padding-remove-vertical">
|
|
|
|
|
<!--URL of the annotated record-->
|
|
|
|
|
<input
|
|
|
|
|
type="hidden"
|
|
|
|
|
name="recordurl_tofeed"
|
|
|
|
|
[value]="url">
|
|
|
|
|
<!--URL of the record contents for downloading-->
|
|
|
|
|
<input
|
|
|
|
|
type="hidden"
|
|
|
|
|
name="subject_tofeed"
|
|
|
|
|
[value]="url">
|
|
|
|
|
<!--PID of the annotated record-->
|
|
|
|
|
<input
|
|
|
|
|
type="hidden"
|
|
|
|
|
name="pid_tofeed"
|
|
|
|
|
[value]="pid">
|
|
|
|
|
<!--URL of the record contents for downloading-->
|
|
|
|
|
<button class="uk-flex uk-flex-middle"
|
|
|
|
|
(click)="toggleAnnotation($event)"
|
|
|
|
|
type="submit"
|
|
|
|
|
title="Click to annotate this page using B2Note.">
|
|
|
|
|
<img src="assets/common-assets/b2note.png" width="48" height="24">
|
|
|
|
|
<span>add annotation</span>
|
|
|
|
|
</button>
|
|
|
|
|
</form>
|
2020-04-07 19:09:31 +02:00
|
|
|
|
<ul class="uk-list uk-list-divider">
|
|
|
|
|
<li *ngFor="let annotation of annotations.slice(0, visibleAnnotations)" uk-grid class="uk-flex uk-flex-top uk-margin-remove-left">
|
|
|
|
|
<div [ngClass]="annotation.type" class="uk-width-auto">{{annotation.type}}</div>
|
|
|
|
|
<div class="uk-width-auto">{{annotation.text}}</div>
|
|
|
|
|
<ul class="uk-width-expand uk-list uk-margin-remove-top" *ngIf="annotation.urls">
|
|
|
|
|
<li *ngFor="let url of annotation.urls.slice(0, urlSize)"><a [href]="url" target="_blank">{{url}}</a></li>
|
|
|
|
|
<li *ngIf="urlSize < annotation.urls.length"><a (click)="urlSize = annotation.urls.length">+ {{annotation.urls.length - urlSize}} more</a></li>
|
|
|
|
|
</ul>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<div *ngIf="visibleAnnotations < annotations.length" class="uk-margin-medium-top uk-text-center">
|
|
|
|
|
<button class="uk-button uk-button-default" (click)="visibleAnnotations = (visibleAnnotations + annotationSize)">Load More</button>
|
|
|
|
|
</div>
|
2020-03-30 10:45:08 +02:00
|
|
|
|
</div>
|
2020-04-08 16:24:30 +02:00
|
|
|
|
<div [class.uk-hidden]="!visible">
|
|
|
|
|
<div class="widget-container" cdkDrag>
|
2020-04-07 19:09:31 +02:00
|
|
|
|
<!--Close button, should be bound to hide the widget-->
|
|
|
|
|
<button type="button" class="close" aria-label="Close" (click)="toggleAnnotation($event)">
|
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
|
</button>
|
|
|
|
|
<!--The glorious iframe with the running app!-->
|
|
|
|
|
<iframe id="b2note_iframe" name="b2note_iframe" class="b2note-iframe">
|
|
|
|
|
</iframe>
|
|
|
|
|
</div>
|
2020-03-27 11:06:09 +01:00
|
|
|
|
</div>`,
|
|
|
|
|
styleUrls: ['annotation.css']
|
2020-01-28 15:09:32 +01:00
|
|
|
|
})
|
|
|
|
|
export class AnnotationComponent implements OnInit, OnDestroy {
|
2020-03-27 11:06:09 +01:00
|
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
|
public landingInfo: ResultLandingInfo = null;
|
|
|
|
|
@Input()
|
|
|
|
|
public id: string = null;
|
2020-04-07 19:09:31 +02:00
|
|
|
|
@Input()
|
|
|
|
|
public properties: EnvProperties;
|
2020-03-27 11:06:09 +01:00
|
|
|
|
public url: string = null;
|
|
|
|
|
public pid: string = null;
|
|
|
|
|
public keywords: string[] = [];
|
|
|
|
|
public visible: boolean = false;
|
2020-04-07 19:09:31 +02:00
|
|
|
|
public annotations: Annotation[] = [];
|
|
|
|
|
public annotationSize: number = 10;
|
|
|
|
|
public visibleAnnotations: number;
|
|
|
|
|
public urlSize: number = 3;
|
2020-03-27 11:06:09 +01:00
|
|
|
|
|
2020-04-07 19:09:31 +02:00
|
|
|
|
constructor(private annotationService: AnnotationService) {
|
2020-03-27 11:06:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2020-04-07 19:09:31 +02:00
|
|
|
|
this.visibleAnnotations = this.annotationSize;
|
2020-03-27 11:06:09 +01:00
|
|
|
|
if (typeof window !== "undefined") {
|
|
|
|
|
let id = this.id;
|
|
|
|
|
this.url = window.location.href;
|
|
|
|
|
if (this.landingInfo.deletedByInferenceIds) {
|
|
|
|
|
id = this.landingInfo.deletedByInferenceIds[0];
|
|
|
|
|
this.url = this.url.replace(this.id, id);
|
|
|
|
|
}
|
2020-05-05 12:37:36 +02:00
|
|
|
|
if (this.landingInfo.identifiers && this.landingInfo.identifiers.size > 0) {
|
|
|
|
|
if (this.landingInfo.identifiers.get('doi')) {
|
|
|
|
|
this.pid = this.landingInfo.identifiers.get('doi')[0];
|
|
|
|
|
} else {
|
|
|
|
|
const key: string = this.landingInfo.identifiers.keys().next().value;
|
|
|
|
|
if (key) {
|
|
|
|
|
this.pid = this.landingInfo.identifiers.get(key)[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.pid = id;
|
|
|
|
|
}
|
2020-04-07 19:09:31 +02:00
|
|
|
|
this.annotationService.getAllAnnotations(this.properties, this.url).subscribe(annotations => {
|
|
|
|
|
this.annotations = annotations;
|
|
|
|
|
});
|
2020-01-28 15:09:32 +01:00
|
|
|
|
}
|
2020-03-27 11:06:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public toggleAnnotation(event) {
|
|
|
|
|
if (this.visible) {
|
2020-03-30 10:45:08 +02:00
|
|
|
|
event.preventDefault();
|
2020-01-28 15:09:32 +01:00
|
|
|
|
}
|
2020-03-27 11:06:09 +01:00
|
|
|
|
this.visible = !this.visible;
|
|
|
|
|
}
|
2020-01-28 15:09:32 +01:00
|
|
|
|
}
|