2021-01-05 14:25:02 +01:00
|
|
|
|
import {
|
|
|
|
|
Component,
|
|
|
|
|
ElementRef,
|
|
|
|
|
EventEmitter,
|
|
|
|
|
HostListener,
|
|
|
|
|
Input,
|
|
|
|
|
OnDestroy,
|
|
|
|
|
OnInit,
|
|
|
|
|
Output,
|
|
|
|
|
ViewChild
|
|
|
|
|
} 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-07-15 13:32:03 +02:00
|
|
|
|
import {properties} from "../../../../environments/environment";
|
2020-08-06 13:50:08 +02:00
|
|
|
|
import {UserManagementService} from "../../services/user-management.service";
|
2021-01-05 14:25:02 +01:00
|
|
|
|
import {COOKIE, User} from "../../login/utils/helper.class";
|
2020-08-06 13:50:08 +02:00
|
|
|
|
import {Subscriber} from "rxjs";
|
2020-01-28 15:09:32 +01:00
|
|
|
|
|
|
|
|
|
@Component({
|
2020-03-27 11:06:09 +01:00
|
|
|
|
selector: 'b2note',
|
|
|
|
|
template: `
|
2021-01-05 16:12:05 +01:00
|
|
|
|
<div *ngIf="annotations && annotations.length > 0" class="sideInfoTitle uk-margin-small-bottom">Annotations</div>
|
2020-03-30 10:45:08 +02:00
|
|
|
|
<div class="b2note">
|
2021-01-05 14:25:02 +01:00
|
|
|
|
<form #form ngNoForm *ngIf="pid && user"
|
2020-07-15 13:32:03 +02:00
|
|
|
|
[action]="properties.b2noteAPIURL + 'widget'"
|
2020-03-30 10:45:08 +02:00
|
|
|
|
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">
|
|
|
|
|
<!--PID of the annotated record-->
|
|
|
|
|
<input
|
|
|
|
|
type="hidden"
|
|
|
|
|
name="pid_tofeed"
|
|
|
|
|
[value]="pid">
|
|
|
|
|
</form>
|
2021-01-05 14:25:02 +01:00
|
|
|
|
<loading *ngIf="loading" class="uk-margin-medium-top"></loading>
|
2020-10-12 15:10:07 +02:00
|
|
|
|
<ul *ngIf="annotations && !loading" class="uk-list uk-list-divider">
|
2020-11-25 17:09:36 +01:00
|
|
|
|
<li *ngFor="let annotation of annotations.slice(0, visibleAnnotations); let i=index" uk-grid
|
2020-10-12 15:10:07 +02:00
|
|
|
|
class="uk-flex uk-flex-top uk-margin-remove-left">
|
2020-11-25 17:09:36 +01:00
|
|
|
|
<div [ngClass]="annotation.type" class="type">{{annotation.type}}</div>
|
|
|
|
|
<div [class.uk-width-1-3]="annotation.targets"
|
|
|
|
|
[class.uk-width-1-6@s]="annotation.targets">{{annotation.text}}</div>
|
|
|
|
|
<ul class="uk-width-expand uk-list uk-margin-remove-top" *ngIf="annotation.targets">
|
|
|
|
|
<li *ngFor="let target of annotation.targets.slice(0, annotation.targetSize)">
|
|
|
|
|
<a *ngIf="target.url" [href]="target.url" target="_blank">{{target.id}}</a>
|
2021-01-05 14:25:02 +01:00
|
|
|
|
<a *ngIf="!target.url" routerLink="/search/advanced/research-outcomes"
|
|
|
|
|
[queryParams]="searchPid(target.id)">{{target.id}}</a>
|
2020-11-25 17:09:36 +01:00
|
|
|
|
</li>
|
|
|
|
|
<li *ngIf="annotation.targetSize < annotation.targets.length"><a
|
|
|
|
|
(click)="open(i)">+ {{annotation.targets.length - annotation.targetSize}}
|
2020-10-12 15:10:07 +02:00
|
|
|
|
more</a></li>
|
2020-04-07 19:09:31 +02:00
|
|
|
|
</ul>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<div *ngIf="visibleAnnotations < annotations.length" class="uk-margin-medium-top uk-text-center">
|
2020-10-12 15:10:07 +02:00
|
|
|
|
<button class="uk-button uk-button-primary"
|
|
|
|
|
(click)="visibleAnnotations = (visibleAnnotations + annotationSize)">Load More
|
|
|
|
|
</button>
|
2020-04-07 19:09:31 +02:00
|
|
|
|
</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
|
|
|
|
<button type="button" class="close" aria-label="Close" (click)="toggleAnnotation($event)">
|
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
|
</button>
|
2020-08-06 13:50:08 +02:00
|
|
|
|
<iframe #iframe id="b2note_iframe" name="b2note_iframe" class="b2note-iframe">
|
2020-04-07 19:09:31 +02:00
|
|
|
|
</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-07-15 13:32:03 +02:00
|
|
|
|
public properties: EnvProperties = properties;
|
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[] = [];
|
2020-11-26 18:03:50 +01:00
|
|
|
|
public annotationSize: number = 10;
|
2020-08-06 13:50:08 +02:00
|
|
|
|
public user;
|
2020-04-07 19:09:31 +02:00
|
|
|
|
public visibleAnnotations: number;
|
2020-10-12 15:10:07 +02:00
|
|
|
|
public loading: boolean = false;
|
2021-01-05 14:25:02 +01:00
|
|
|
|
public submitted: boolean = false;
|
|
|
|
|
@Output()
|
|
|
|
|
public userEmitter: EventEmitter<User> = new EventEmitter<User>();
|
|
|
|
|
@Output()
|
|
|
|
|
public pidEmitter: EventEmitter<string> = new EventEmitter<string>();
|
2020-08-06 13:50:08 +02:00
|
|
|
|
@ViewChild('iframe') iframe: ElementRef;
|
2021-01-05 14:25:02 +01:00
|
|
|
|
@ViewChild('form') form: ElementRef;
|
2020-08-06 13:50:08 +02:00
|
|
|
|
private subscriptions: any[] = [];
|
2020-03-27 11:06:09 +01:00
|
|
|
|
|
2020-08-06 13:50:08 +02:00
|
|
|
|
constructor(private annotationService: AnnotationService,
|
|
|
|
|
private userManagementService: UserManagementService) {
|
2020-03-27 11:06:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-15 13:32:03 +02:00
|
|
|
|
@HostListener('window:message', ['$event'])
|
|
|
|
|
public onChange(event) {
|
2020-10-12 15:10:07 +02:00
|
|
|
|
if (this.properties.b2noteAPIURL.includes(event.origin)) {
|
|
|
|
|
if (event.data === "B2NOTE loaded") {
|
|
|
|
|
let token = COOKIE.getCookie('AccessToken');
|
|
|
|
|
this.iframe.nativeElement.contentWindow.postMessage({token: token}, this.properties.b2noteAPIURL);
|
2020-08-06 13:50:08 +02:00
|
|
|
|
} else {
|
|
|
|
|
this.getAnnotations();
|
|
|
|
|
}
|
2020-07-15 13:32:03 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-27 11:06:09 +01:00
|
|
|
|
ngOnInit(): void {
|
2020-08-06 13:50:08 +02:00
|
|
|
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
|
|
|
|
this.user = user;
|
2021-01-05 14:25:02 +01:00
|
|
|
|
this.userEmitter.emit(this.user);
|
2020-08-06 13:50:08 +02:00
|
|
|
|
}));
|
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];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-12 15:10:07 +02:00
|
|
|
|
if (this.pid) {
|
2020-07-15 13:32:03 +02:00
|
|
|
|
this.getAnnotations();
|
2020-05-29 11:50:49 +02:00
|
|
|
|
}
|
2021-01-05 14:25:02 +01:00
|
|
|
|
this.pidEmitter.emit(this.pid);
|
2020-05-29 11:50:49 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-05 14:25:02 +01:00
|
|
|
|
public get enabled(): boolean {
|
|
|
|
|
return this.pid && this.user;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-06 13:50:08 +02:00
|
|
|
|
private clearSubscriptions() {
|
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
|
subscription.unsubscribe();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.subscriptions = [];
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-15 13:32:03 +02:00
|
|
|
|
private getAnnotations() {
|
2020-11-25 17:09:36 +01:00
|
|
|
|
if (!this.annotations || this.annotations.length === 0) {
|
2020-10-12 15:10:07 +02:00
|
|
|
|
this.loading = true;
|
|
|
|
|
}
|
2020-11-25 17:09:36 +01:00
|
|
|
|
this.subscriptions.push(this.annotationService.getAllAnnotations(this.pid).subscribe(annotations => {
|
|
|
|
|
this.annotations.forEach((annotation, index) => {
|
|
|
|
|
if (!annotations.find(element => element.type === annotation.type && element.text === annotation.text)) {
|
|
|
|
|
this.annotations.splice(index, 1);
|
|
|
|
|
}
|
2020-07-15 13:32:03 +02:00
|
|
|
|
});
|
2020-11-25 17:09:36 +01:00
|
|
|
|
annotations.forEach(annotation => {
|
|
|
|
|
if (!this.annotations.find(element => element.type === annotation.type && element.text === annotation.text)) {
|
|
|
|
|
annotation.targetSize = 3;
|
2020-11-26 18:03:50 +01:00
|
|
|
|
this.annotationService.getAnnotationTargets(annotation.text, annotation.type).subscribe(targets => {
|
2020-11-25 17:09:36 +01:00
|
|
|
|
annotation.targets = targets.filter(target => target.id !== this.pid);
|
|
|
|
|
/*for(let i = 0; i < 10; i++) {
|
|
|
|
|
annotation.targets.push(targets[0]);
|
|
|
|
|
}*/
|
|
|
|
|
});
|
|
|
|
|
this.annotations.push(annotation);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.annotations = this.sort(this.annotations);
|
|
|
|
|
this.loading = false;
|
|
|
|
|
}, error => {
|
2020-10-12 15:10:07 +02:00
|
|
|
|
this.loading = false;
|
2020-11-11 15:43:13 +01:00
|
|
|
|
}));
|
2020-03-27 11:06:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-25 17:09:36 +01:00
|
|
|
|
public sort(annotations: Annotation[]): Annotation[] {
|
|
|
|
|
return annotations.sort((a, b) => {
|
|
|
|
|
if (a.type === b.type) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else if (a.type === 'semantic') {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (b.type === 'semantic') {
|
|
|
|
|
return 1;
|
|
|
|
|
} else if (a.type === 'keyword') {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (b.type === 'keyword') {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-05 14:25:02 +01:00
|
|
|
|
public searchPid(pid: string): { [k: string]: any; } {
|
2020-11-25 17:09:36 +01:00
|
|
|
|
return {
|
|
|
|
|
f0: 'pid',
|
|
|
|
|
fv0: pid,
|
|
|
|
|
qf: false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-05 14:25:02 +01:00
|
|
|
|
ngOnDestroy() {
|
2020-08-06 13:50:08 +02:00
|
|
|
|
this.clearSubscriptions();
|
2020-03-27 11:06:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-25 17:09:36 +01:00
|
|
|
|
toggleAnnotation(event) {
|
2020-03-27 11:06:09 +01:00
|
|
|
|
if (this.visible) {
|
2020-03-30 10:45:08 +02:00
|
|
|
|
event.preventDefault();
|
2021-01-05 14:25:02 +01:00
|
|
|
|
} else if(!this.submitted) {
|
|
|
|
|
this.form.nativeElement.submit();
|
|
|
|
|
this.submitted = true;
|
2020-01-28 15:09:32 +01:00
|
|
|
|
}
|
2020-03-27 11:06:09 +01:00
|
|
|
|
this.visible = !this.visible;
|
|
|
|
|
}
|
2020-11-25 17:09:36 +01:00
|
|
|
|
|
|
|
|
|
open(i: number) {
|
|
|
|
|
this.annotations.forEach((annotation, index) => {
|
2021-01-05 14:25:02 +01:00
|
|
|
|
if (index != i) {
|
2020-11-25 17:09:36 +01:00
|
|
|
|
annotation.targetSize = 3;
|
|
|
|
|
} else {
|
|
|
|
|
annotation.targetSize = annotation.targets.length
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-05-25 10:19:27 +02:00
|
|
|
|
}
|