import {Component, 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";
@Component({
selector: 'b2note',
template: `
Annotations
-
{{annotation.type}}
{{annotation.text}}
`,
styleUrls: ['annotation.css']
})
export class AnnotationComponent implements OnInit, OnDestroy {
@Input()
public landingInfo: ResultLandingInfo = null;
@Input()
public id: string = null;
@Input()
public properties: EnvProperties;
public url: string = null;
public pid: string = null;
public keywords: string[] = [];
public visible: boolean = false;
public annotations: Annotation[] = [];
public annotationSize: number = 10;
public visibleAnnotations: number;
public urlSize: number = 3;
constructor(private annotationService: AnnotationService) {
}
ngOnInit(): void {
this.visibleAnnotations = this.annotationSize;
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);
}
this.pid = this.url;
this.annotationService.getAllAnnotations(this.properties, this.url).subscribe(annotations => {
this.annotations = annotations;
console.log(this.annotations);
});
}
}
ngOnDestroy(): void {
}
public toggleAnnotation(event) {
if (this.visible) {
event.preventDefault();
}
this.visible = !this.visible;
}
}