-
-
@@ -156,26 +152,80 @@ export class AnnotationComponent implements OnInit, OnDestroy {
}
private getAnnotations() {
- if(!this.annotations || this.annotations.length === 0) {
+ if (!this.annotations || this.annotations.length === 0) {
this.loading = true;
}
- this.subscriptions.push(this.annotationService.getAllAnnotations(this.properties, this.pid).subscribe(annotations => {
- this.annotations = annotations;
- this.annotations.forEach(annotation => {
- annotation.urlSize = 3;
+ 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);
+ }
});
+ annotations.forEach(annotation => {
+ if (!this.annotations.find(element => element.type === annotation.type && element.text === annotation.text)) {
+ annotation.targetSize = 3;
+ this.annotationService.getAnnotationsTargets(annotation.text, annotation.type).subscribe(targets => {
+ 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 => {
this.loading = false;
}));
}
- ngOnDestroy(): void {
+ 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;
+ }
+ });
+ }
+
+ public searchPid(pid: string): { [k: string]: any;} {
+ return {
+ f0: 'pid',
+ fv0: pid,
+ qf: false
+ }
+ }
+
+ ngOnDestroy()
+ :
+ void {
this.clearSubscriptions();
}
- public toggleAnnotation(event) {
+ public
+
+ toggleAnnotation(event) {
if (this.visible) {
event.preventDefault();
}
this.visible = !this.visible;
}
+
+ open(i: number) {
+ this.annotations.forEach((annotation, index) => {
+ if(index != i) {
+ annotation.targetSize = 3;
+ } else {
+ annotation.targetSize = annotation.targets.length
+ }
+ });
+ }
}
diff --git a/landingPages/annotation/annotation.css b/landingPages/annotation/annotation.css
index 732f31bd..4a2961d3 100644
--- a/landingPages/annotation/annotation.css
+++ b/landingPages/annotation/annotation.css
@@ -2,7 +2,7 @@
position: fixed;
left: 50%;
top: 50%;
- z-index: 5;
+ z-index: 1000;
padding: 19px;
margin-left: -167px;
margin-top: -311px;
diff --git a/landingPages/annotation/annotation.module.ts b/landingPages/annotation/annotation.module.ts
index d9c240b0..da2d80b7 100644
--- a/landingPages/annotation/annotation.module.ts
+++ b/landingPages/annotation/annotation.module.ts
@@ -2,9 +2,10 @@ import {NgModule} from "@angular/core";
import {AnnotationComponent} from "./annotation.component";
import {CommonModule} from "@angular/common";
import {DragDropModule} from "@angular/cdk/drag-drop";
+import {RouterModule} from "@angular/router";
@NgModule({
- imports: [CommonModule, DragDropModule],
+ imports: [CommonModule, DragDropModule, RouterModule],
declarations: [AnnotationComponent],
exports: [AnnotationComponent]
})
diff --git a/landingPages/annotation/annotation.service.ts b/landingPages/annotation/annotation.service.ts
index db642fa3..bf678c99 100644
--- a/landingPages/annotation/annotation.service.ts
+++ b/landingPages/annotation/annotation.service.ts
@@ -3,79 +3,108 @@ import {HttpClient} from "@angular/common/http";
import {Observable} from "rxjs";
import {EnvProperties} from "../../utils/properties/env-properties";
import {map} from "rxjs/operators";
+import {properties} from "../../../../environments/environment";
+
+export interface AnnotationTarget {
+ id: string;
+ url: string;
+}
export interface Annotation {
- text: string;
- type: 'semantic' | 'keyword' | 'comment';
- urls?: string[];
- urlSize?: number;
+ text: string;
+ type: 'semantic' | 'keyword' | 'comment';
+ targets?: AnnotationTarget[];
+ targetSize?: number;
}
@Injectable({
- providedIn: "root"
+ providedIn: "root"
})
export class AnnotationService {
-
- api = 'api/';
-
- constructor(private http: HttpClient) {
- }
-
- getAllAnnotations(properties: EnvProperties, source: string): Observable
{
- 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(url).pipe(map((response: any[]) => {
- return this.parseAnnotations(response);
- }));
- }
-
- private parseAnnotations(response: any[]): Annotation[] {
- let annotations: Annotation[] = [];
- if(response && response.length > 0) {
- response.forEach(value => {
- let body = value.body;
- if(body.type === 'TextualBody') {
- if(body.purpose === 'tagging') {
- annotations.push({
- text: body.value,
- type: "keyword"
- });
- } else {
- annotations.push({
- text: body.value,
- type: "comment"
- });
- }
- } else {
- let items = body.items;
- let urls: string[] = [];
- let text: string = null;
- items.forEach(item => {
- if(item.type === 'SpecificResource') {
- urls.push(item.source);
- } else if(item.type === 'TextualBody') {
- text = item.value;
- }
- });
- annotations.push({
- text: text,
- type: "semantic",
- urls: urls
- });
- }
- });
- }
- return annotations.sort((a, b) => {
- if(a.type === b.type) {
- return 0;
- } 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;
+
+ api = 'api/';
+
+ constructor(private http: HttpClient) {
+ }
+
+ getAllAnnotations(source: string): Observable {
+ let url = properties.b2noteAPIURL + this.api + 'annotations?target-id=' + encodeURIComponent(source);
+ return this.http.get(url).pipe(map((response: any[]) => {
+ return this.parseAnnotations(response);
+ }));
+ }
+
+ getAnnotationsTargets(value: string, type: 'semantic' | 'keyword' | 'comment'): Observable {
+ let url = properties.b2noteAPIURL + this.api + 'annotations?value=' + encodeURIComponent(value);
+ return this.http.get(url).pipe(map((response: any[]) => {
+ return this.parseAnnotationTargets(response, type);
+ }));
+ }
+
+ private parseAnnotations(response: any[]): Annotation[] {
+ let annotations: Annotation[] = [];
+ if (response && response.length > 0) {
+ response.forEach(value => {
+ if (value.visibility === 'public') {
+ let body = value.body;
+ if (body.type === 'TextualBody') {
+ if (body.purpose === 'tagging') {
+ annotations.push({
+ text: body.value,
+ type: "keyword"
+ });
+ } else {
+ annotations.push({
+ text: body.value,
+ type: "comment"
+ });
}
- });
+ } else {
+ let items = body.items;
+ let text: string = null;
+ items.forEach(item => {
+ if (item.type === 'TextualBody') {
+ text = item.value;
+ }
+ });
+ annotations.push({
+ text: text,
+ type: "semantic"
+ });
+ }
+ }
+ });
}
+ return annotations;
+ }
+
+ private parseAnnotationTargets(response: any[], type: 'semantic' | 'keyword' | 'comment'): AnnotationTarget[] {
+ let targets: AnnotationTarget[] = [];
+ if (response && response.length > 0) {
+ response.forEach(value => {
+ if (value.visibility === 'public') {
+ let body = value.body;
+ if (body.type === 'TextualBody') {
+ if (body.purpose === 'tagging' && type === 'keyword') {
+ targets.push({
+ id: value.target.id,
+ url: value.target.source
+ });
+ } else if(type === 'comment'){
+ targets.push({
+ id: value.target.id,
+ url: value.target.source
+ });
+ }
+ } else if(type === 'semantic'){
+ targets.push({
+ id: value.target.id,
+ url: value.target.source
+ });
+ }
+ }
+ });
+ }
+ return targets;
+ }
}
diff --git a/landingPages/dataProvider/dataProvider.component.html b/landingPages/dataProvider/dataProvider.component.html
index d689affa..32b18019 100644
--- a/landingPages/dataProvider/dataProvider.component.html
+++ b/landingPages/dataProvider/dataProvider.component.html
@@ -75,7 +75,7 @@