[Library | Trunk]: Update annotation list if something changes on the iframe

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59125 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2020-07-15 11:32:03 +00:00
parent 72eeff6561
commit 716a8cb5af
3 changed files with 23 additions and 22 deletions

View File

@ -1,7 +1,8 @@
import {Component, Input, OnDestroy, OnInit} from "@angular/core";
import {Component, HostListener, Input, OnDestroy, OnInit} from "@angular/core";
import {Annotation, AnnotationService} from "./annotation.service";
import {ResultLandingInfo} from "../../utils/entities/resultLandingInfo";
import {EnvProperties} from "../../utils/properties/env-properties";
import {properties} from "../../../../environments/environment";
@Component({
selector: 'b2note',
@ -9,7 +10,7 @@ import {EnvProperties} from "../../utils/properties/env-properties";
<div class="sideInfoTitle uk-margin-small-bottom">Annotations</div>
<div class="b2note">
<form ngNoForm *ngIf="pid"
action="https://b2note-dev.bsc.es/widget/"
[action]="properties.b2noteAPIURL + 'widget'"
method="post"
target="b2note_iframe"
class="uk-padding-small uk-padding-remove-vertical">
@ -29,7 +30,7 @@ import {EnvProperties} from "../../utils/properties/env-properties";
name="pid_tofeed"
[value]="pid">
<!--URL of the record contents for downloading-->
<button class="uk-flex uk-flex-middle"
<button class="uk-flex uk-flex-middle uk-button"
(click)="toggleAnnotation($event)"
type="submit"
title="Click to annotate this page using B2Note.">
@ -76,8 +77,7 @@ export class AnnotationComponent implements OnInit, OnDestroy {
public landingInfo: ResultLandingInfo = null;
@Input()
public id: string = null;
@Input()
public properties: EnvProperties;
public properties: EnvProperties = properties;
public url: string = null;
public pid: string = null;
public keywords: string[] = [];
@ -89,6 +89,13 @@ export class AnnotationComponent implements OnInit, OnDestroy {
constructor(private annotationService: AnnotationService) {
}
@HostListener('window:message', ['$event'])
public onChange(event) {
if(this.properties.b2noteAPIURL.includes(event.origin)) {
this.getAnnotations();
}
}
ngOnInit(): void {
this.visibleAnnotations = this.annotationSize;
if (typeof window !== "undefined") {
@ -109,24 +116,18 @@ export class AnnotationComponent implements OnInit, OnDestroy {
}
}
if(this.pid) {
this.annotationService.getAllAnnotations(this.properties, this.pid).subscribe(annotations => {
this.annotations = annotations;
this.annotations.forEach(annotation => {
annotation.urlSize = 3;
});
});
this.getAnnotations();
}
}
}
public getTypeName(): string {
if (this.landingInfo.resultType === "dataset") {
return "research data";
} else if (this.landingInfo.resultType === "other") {
return "research product";
} else {
return this.landingInfo.resultType;
}
private getAnnotations() {
this.annotationService.getAllAnnotations(this.properties, this.pid).subscribe(annotations => {
this.annotations = annotations;
this.annotations.forEach(annotation => {
annotation.urlSize = 3;
});
});
}
ngOnDestroy(): void {

View File

@ -18,12 +18,13 @@ export interface Annotation {
})
export class AnnotationService {
api = 'api/';
constructor(private http: HttpClient) {
}
getAllAnnotations(properties: EnvProperties, source: string): Observable<Annotation[]> {
let url = properties.b2noteAPIURL + 'annotations?type[]=semantic&type[]=keyword&type[]=comment&format=json-ld&download=false&target-source=' + encodeURIComponent(source);
let url = properties.b2noteAPIURL + this.api + 'annotations?type[]=semantic&type[]=keyword&type[]=comment&format=json-ld&download=false&target-source=' + encodeURIComponent(source);
return this.http.get<Annotation[]>(url).pipe(map((response: any[]) => {
return this.parseAnnotations(response);
}));

View File

@ -481,8 +481,7 @@
</div>
<!-- B2 Note-->
<div *ngIf=" properties.environment === 'development' && resultLandingInfo" class="uk-margin-medium-top">
<b2note [id]="id" [properties]="properties"
[landingInfo]="resultLandingInfo"></b2note>
<b2note [id]="id" [landingInfo]="resultLandingInfo"></b2note>
</div>
</div>
</div>