Project

General

Profile

« Previous | Next » 

Revision 59125

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

View differences:

modules/uoa-services-library/trunk/ng-openaire-library/src/app/landingPages/annotation/annotation.component.ts
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 {
modules/uoa-services-library/trunk/ng-openaire-library/src/app/landingPages/annotation/annotation.service.ts
18 18
})
19 19
export class AnnotationService {
20 20

  
21
    api = 'api/';
21 22

  
22 23
    constructor(private http: HttpClient) {
23 24
    }
24 25

  
25 26
    getAllAnnotations(properties: EnvProperties, source: string): Observable<Annotation[]> {
26
        let url = properties.b2noteAPIURL + 'annotations?type[]=semantic&type[]=keyword&type[]=comment&format=json-ld&download=false&target-source=' + encodeURIComponent(source);
27
        let url = properties.b2noteAPIURL + this.api + 'annotations?type[]=semantic&type[]=keyword&type[]=comment&format=json-ld&download=false&target-source=' + encodeURIComponent(source);
27 28
        return this.http.get<Annotation[]>(url).pipe(map((response: any[]) => {
28 29
            return this.parseAnnotations(response);
29 30
        }));
modules/uoa-services-library/trunk/ng-openaire-library/src/app/landingPages/result/resultLanding.component.html
481 481
            </div>
482 482
            <!-- B2 Note-->
483 483
            <div *ngIf=" properties.environment === 'development' && resultLandingInfo" class="uk-margin-medium-top">
484
              <b2note [id]="id" [properties]="properties"
485
                      [landingInfo]="resultLandingInfo"></b2note>
484
              <b2note [id]="id" [landingInfo]="resultLandingInfo"></b2note>
486 485
            </div>
487 486
          </div>
488 487
        </div>

Also available in: Unified diff