1 |
|
import {Component, Input, OnDestroy, OnInit} from "@angular/core";
|
|
1 |
import {Component, HostListener, Input, OnDestroy, OnInit} from "@angular/core";
|
2 |
2 |
import {Annotation, AnnotationService} from "./annotation.service";
|
3 |
3 |
import {ResultLandingInfo} from "../../utils/entities/resultLandingInfo";
|
4 |
4 |
import {EnvProperties} from "../../utils/properties/env-properties";
|
|
5 |
import {properties} from "../../../../environments/environment";
|
5 |
6 |
|
6 |
7 |
@Component({
|
7 |
8 |
selector: 'b2note',
|
... | ... | |
9 |
10 |
<div class="sideInfoTitle uk-margin-small-bottom">Annotations</div>
|
10 |
11 |
<div class="b2note">
|
11 |
12 |
<form ngNoForm *ngIf="pid"
|
12 |
|
action="https://b2note-dev.bsc.es/widget/"
|
|
13 |
[action]="properties.b2noteAPIURL + 'widget'"
|
13 |
14 |
method="post"
|
14 |
15 |
target="b2note_iframe"
|
15 |
16 |
class="uk-padding-small uk-padding-remove-vertical">
|
... | ... | |
29 |
30 |
name="pid_tofeed"
|
30 |
31 |
[value]="pid">
|
31 |
32 |
<!--URL of the record contents for downloading-->
|
32 |
|
<button class="uk-flex uk-flex-middle"
|
|
33 |
<button class="uk-flex uk-flex-middle uk-button"
|
33 |
34 |
(click)="toggleAnnotation($event)"
|
34 |
35 |
type="submit"
|
35 |
36 |
title="Click to annotate this page using B2Note.">
|
... | ... | |
76 |
77 |
public landingInfo: ResultLandingInfo = null;
|
77 |
78 |
@Input()
|
78 |
79 |
public id: string = null;
|
79 |
|
@Input()
|
80 |
|
public properties: EnvProperties;
|
|
80 |
public properties: EnvProperties = properties;
|
81 |
81 |
public url: string = null;
|
82 |
82 |
public pid: string = null;
|
83 |
83 |
public keywords: string[] = [];
|
... | ... | |
89 |
89 |
constructor(private annotationService: AnnotationService) {
|
90 |
90 |
}
|
91 |
91 |
|
|
92 |
@HostListener('window:message', ['$event'])
|
|
93 |
public onChange(event) {
|
|
94 |
if(this.properties.b2noteAPIURL.includes(event.origin)) {
|
|
95 |
this.getAnnotations();
|
|
96 |
}
|
|
97 |
}
|
|
98 |
|
92 |
99 |
ngOnInit(): void {
|
93 |
100 |
this.visibleAnnotations = this.annotationSize;
|
94 |
101 |
if (typeof window !== "undefined") {
|
... | ... | |
109 |
116 |
}
|
110 |
117 |
}
|
111 |
118 |
if(this.pid) {
|
112 |
|
this.annotationService.getAllAnnotations(this.properties, this.pid).subscribe(annotations => {
|
113 |
|
this.annotations = annotations;
|
114 |
|
this.annotations.forEach(annotation => {
|
115 |
|
annotation.urlSize = 3;
|
116 |
|
});
|
117 |
|
});
|
|
119 |
this.getAnnotations();
|
118 |
120 |
}
|
119 |
121 |
}
|
120 |
122 |
}
|
121 |
123 |
|
122 |
|
public getTypeName(): string {
|
123 |
|
if (this.landingInfo.resultType === "dataset") {
|
124 |
|
return "research data";
|
125 |
|
} else if (this.landingInfo.resultType === "other") {
|
126 |
|
return "research product";
|
127 |
|
} else {
|
128 |
|
return this.landingInfo.resultType;
|
129 |
|
}
|
|
124 |
private getAnnotations() {
|
|
125 |
this.annotationService.getAllAnnotations(this.properties, this.pid).subscribe(annotations => {
|
|
126 |
this.annotations = annotations;
|
|
127 |
this.annotations.forEach(annotation => {
|
|
128 |
annotation.urlSize = 3;
|
|
129 |
});
|
|
130 |
});
|
130 |
131 |
}
|
131 |
132 |
|
132 |
133 |
ngOnDestroy(): void {
|
[Library | Trunk]: Update annotation list if something changes on the iframe