[Library | Trunk]: B2Note add annotation targets

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59977 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2020-11-26 17:03:50 +00:00
parent 06bec851f5
commit f02f2a582a
2 changed files with 11 additions and 26 deletions

View File

@ -91,7 +91,7 @@ export class AnnotationComponent implements OnInit, OnDestroy {
public keywords: string[] = []; public keywords: string[] = [];
public visible: boolean = false; public visible: boolean = false;
public annotations: Annotation[] = []; public annotations: Annotation[] = [];
public annotationSize: number = 3; public annotationSize: number = 10;
public user; public user;
public visibleAnnotations: number; public visibleAnnotations: number;
public loading: boolean = false; public loading: boolean = false;
@ -164,7 +164,7 @@ export class AnnotationComponent implements OnInit, OnDestroy {
annotations.forEach(annotation => { annotations.forEach(annotation => {
if (!this.annotations.find(element => element.type === annotation.type && element.text === annotation.text)) { if (!this.annotations.find(element => element.type === annotation.type && element.text === annotation.text)) {
annotation.targetSize = 3; annotation.targetSize = 3;
this.annotationService.getAnnotationsTargets(annotation.text, annotation.type).subscribe(targets => { this.annotationService.getAnnotationTargets(annotation.text, annotation.type).subscribe(targets => {
annotation.targets = targets.filter(target => target.id !== this.pid); annotation.targets = targets.filter(target => target.id !== this.pid);
/*for(let i = 0; i < 10; i++) { /*for(let i = 0; i < 10; i++) {
annotation.targets.push(targets[0]); annotation.targets.push(targets[0]);

View File

@ -28,16 +28,16 @@ export class AnnotationService {
} }
getAllAnnotations(source: string): Observable<Annotation[]> { getAllAnnotations(source: string): Observable<Annotation[]> {
let url = properties.b2noteAPIURL + this.api + 'annotations?target-id=' + encodeURIComponent(source); let url = properties.b2noteAPIURL + this.api + 'annotations?target-id[]=' + encodeURIComponent(source);
return this.http.get<Annotation[]>(url).pipe(map((response: any[]) => { return this.http.get<Annotation[]>(url).pipe(map((response: any[]) => {
return this.parseAnnotations(response); return this.parseAnnotations(response);
})); }));
} }
getAnnotationsTargets(value: string, type: 'semantic' | 'keyword' | 'comment'): Observable<AnnotationTarget[]> { getAnnotationTargets(value: string, type: 'semantic' | 'keyword' | 'comment'): Observable<AnnotationTarget[]> {
let url = properties.b2noteAPIURL + this.api + 'annotations?value=' + encodeURIComponent(value); let url = properties.b2noteAPIURL + this.api + 'annotations?value=' + encodeURIComponent(value) + '&type[]=' + type;
return this.http.get<AnnotationTarget[]>(url).pipe(map((response: any[]) => { return this.http.get<AnnotationTarget[]>(url).pipe(map((response: any[]) => {
return this.parseAnnotationTargets(response, type); return this.parseAnnotationTargets(response);
})); }));
} }
@ -78,30 +78,15 @@ export class AnnotationService {
return annotations; return annotations;
} }
private parseAnnotationTargets(response: any[], type: 'semantic' | 'keyword' | 'comment'): AnnotationTarget[] { private parseAnnotationTargets(response: any[]): AnnotationTarget[] {
let targets: AnnotationTarget[] = []; let targets: AnnotationTarget[] = [];
if (response && response.length > 0) { if (response && response.length > 0) {
response.forEach(value => { response.forEach(value => {
if (value.visibility === 'public') { if (value.visibility === 'public') {
let body = value.body; targets.push({
if (body.type === 'TextualBody') { id: value.target.id,
if (body.purpose === 'tagging' && type === 'keyword') { url: value.target.source
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
});
}
} }
}); });
} }