Project

General

Profile

« Previous | Next » 

Revision 60187

[Library | Trunk]: Change b2note button position and change condition if b2note url propert exists

View differences:

modules/uoa-services-library/trunk/ng-openaire-library/src/app/connect/connectHelper.ts
4 4
export class ConnectHelper {
5 5

  
6 6
  public static  getCommunityFromDomain(domain: string): string{
7
    //domain = "beta.covid-19.openaire.eu"; //for testing
7
    domain = "beta.covid-19.openaire.eu"; //for testing
8 8
    domain = domain.indexOf("//") != -1? domain.split("//")[1]:domain; //remove https:// prefix
9 9
    if (domain.indexOf('openaire.eu') === -1) {
10 10
      return null;
modules/uoa-services-library/trunk/ng-openaire-library/src/app/landingPages/annotation/annotation.component.ts
1
import {Component, ElementRef, HostListener, Input, OnDestroy, OnInit, ViewChild} from "@angular/core";
1
import {
2
  Component,
3
  ElementRef,
4
  EventEmitter,
5
  HostListener,
6
  Input,
7
  OnDestroy,
8
  OnInit,
9
  Output,
10
  ViewChild
11
} from "@angular/core";
2 12
import {Annotation, AnnotationService} from "./annotation.service";
3 13
import {ResultLandingInfo} from "../../utils/entities/resultLandingInfo";
4 14
import {EnvProperties} from "../../utils/properties/env-properties";
5 15
import {properties} from "../../../../environments/environment";
6 16
import {UserManagementService} from "../../services/user-management.service";
7
import {COOKIE} from "../../login/utils/helper.class";
17
import {COOKIE, User} from "../../login/utils/helper.class";
8 18
import {Subscriber} from "rxjs";
9 19

  
10 20
@Component({
......
12 22
  template: `
13 23
    <div class="sideInfoTitle uk-margin-small-bottom">Annotations</div>
14 24
    <div class="b2note">
15
      <form ngNoForm *ngIf="pid && user"
25
      <form #form ngNoForm *ngIf="pid && user"
16 26
            [action]="properties.b2noteAPIURL + 'widget'"
17 27
            method="post"
18 28
            target="b2note_iframe"
......
27 37
            type="hidden"
28 38
            name="pid_tofeed"
29 39
            [value]="pid">
30
        <!--URL of the record contents for downloading-->
31
        <button class="uk-flex uk-flex-middle uk-button"
32
                (click)="toggleAnnotation($event)"
33
                type="submit"
34
                title="Click to annotate this page using B2Note.">
35
          <img src="assets/common-assets/b2note.png" width="48" height="24">
36
          <span>add annotation</span>
37
        </button>
38 40
      </form>
39
      <div *ngIf="!pid || !user">
40
        <button class="uk-flex uk-flex-middle disabled"
41
                [title]="!pid?'Annotations are only available for resources with a PID (persistent identifier) like DOI, handle, PMID':
42
                'Annotations are only available for logged in users'">
43
          <img src="assets/common-assets/b2note.png" width="48" height="24">
44
          <span>add annotation</span>
45
        </button>
46
      </div>
47
      <div *ngIf="loading" class="loading-gif uk-margin-medium-top"></div>
41
      <loading *ngIf="loading" class="uk-margin-medium-top"></loading>
48 42
      <ul *ngIf="annotations && !loading" class="uk-list uk-list-divider">
49 43
        <li *ngFor="let annotation of annotations.slice(0, visibleAnnotations); let i=index" uk-grid
50 44
            class="uk-flex uk-flex-top uk-margin-remove-left">
......
54 48
          <ul class="uk-width-expand uk-list uk-margin-remove-top" *ngIf="annotation.targets">
55 49
            <li *ngFor="let target of annotation.targets.slice(0, annotation.targetSize)">
56 50
              <a *ngIf="target.url" [href]="target.url" target="_blank">{{target.id}}</a>
57
              <a *ngIf="!target.url" routerLink="/search/advanced/research-outcomes" [queryParams]="searchPid(target.id)">{{target.id}}</a>
51
              <a *ngIf="!target.url" routerLink="/search/advanced/research-outcomes"
52
                 [queryParams]="searchPid(target.id)">{{target.id}}</a>
58 53
            </li>
59 54
            <li *ngIf="annotation.targetSize < annotation.targets.length"><a
60 55
                (click)="open(i)">+ {{annotation.targets.length - annotation.targetSize}}
......
95 90
  public user;
96 91
  public visibleAnnotations: number;
97 92
  public loading: boolean = false;
93
  public submitted: boolean = false;
94
  @Output()
95
  public userEmitter: EventEmitter<User> = new EventEmitter<User>();
96
  @Output()
97
  public pidEmitter: EventEmitter<string> = new EventEmitter<string>();
98 98
  @ViewChild('iframe') iframe: ElementRef;
99
  @ViewChild('form') form: ElementRef;
99 100
  private subscriptions: any[] = [];
100 101
  
101 102
  constructor(private annotationService: AnnotationService,
......
117 118
  ngOnInit(): void {
118 119
    this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
119 120
      this.user = user;
121
      this.userEmitter.emit(this.user);
120 122
    }));
121 123
    this.visibleAnnotations = this.annotationSize;
122 124
    if (typeof window !== "undefined") {
......
139 141
      if (this.pid) {
140 142
        this.getAnnotations();
141 143
      }
144
      this.pidEmitter.emit(this.pid);
142 145
    }
143 146
  }
144 147
  
148
  public get enabled(): boolean {
149
    return this.pid && this.user;
150
  }
151
  
145 152
  private clearSubscriptions() {
146 153
    this.subscriptions.forEach(subscription => {
147 154
      if (subscription instanceof Subscriber) {
......
196 203
    });
197 204
  }
198 205
  
199
  public searchPid(pid: string): { [k: string]: any;} {
206
  public searchPid(pid: string): { [k: string]: any; } {
200 207
    return {
201 208
      f0: 'pid',
202 209
      fv0: pid,
......
204 211
    }
205 212
  }
206 213
  
207
  ngOnDestroy()
208
    :
209
    void {
214
  ngOnDestroy() {
210 215
    this.clearSubscriptions();
211 216
  }
212 217
  
213
  public
214
  
215 218
  toggleAnnotation(event) {
216 219
    if (this.visible) {
217 220
      event.preventDefault();
221
    } else if(!this.submitted) {
222
      this.form.nativeElement.submit();
223
      this.submitted = true;
218 224
    }
219 225
    this.visible = !this.visible;
220 226
  }
221 227
  
222 228
  open(i: number) {
223 229
    this.annotations.forEach((annotation, index) => {
224
      if(index != i) {
230
      if (index != i) {
225 231
        annotation.targetSize = 3;
226 232
      } else {
227 233
        annotation.targetSize = annotation.targets.length
modules/uoa-services-library/trunk/ng-openaire-library/src/app/landingPages/annotation/annotation.module.ts
3 3
import {CommonModule} from "@angular/common";
4 4
import {DragDropModule} from "@angular/cdk/drag-drop";
5 5
import {RouterModule} from "@angular/router";
6
import {LoadingModule} from "../../utils/loading/loading.module";
6 7

  
7 8
@NgModule({
8
  imports: [CommonModule, DragDropModule, RouterModule],
9
  imports: [CommonModule, DragDropModule, RouterModule, LoadingModule],
9 10
    declarations: [AnnotationComponent],
10 11
    exports: [AnnotationComponent]
11 12
})
modules/uoa-services-library/trunk/ng-openaire-library/src/app/landingPages/result/resultLanding.component.html
100 100
                  <span class="uk-margin-small-left">Cite this {{getTypeName()}}</span>
101 101
                </a>
102 102
              </li>
103
              <li *ngIf="properties.b2noteAPIURL">
104
                <a *ngIf="user && pid" class="uk-link-text uk-text-bold uk-text-uppercase" (click)="annotation.toggleAnnotation($event)">
105
                  <span class="uk-icon-button uk-button-primary uk-icon">
106
                    <img src="assets/common-assets/b2note.png">
107
                  </span>
108
                  <span class="uk-margin-small-left">add annotation</span>
109
                </a>
110
                <span *ngIf="!pid || !user" class="uk-link-text uk-text-bold uk-text-uppercase disabled"
111
                   [attr.uk-tooltip]="!pid?'Annotations are only available for resources with a PID (persistent identifier) like DOI, handle, PMID':
112
                'Annotations are only available for logged in users'">
113
                  <span class="uk-icon-button uk-button-primary uk-icon disabled">
114
                    <img src="assets/common-assets/b2note.png">
115
                  </span>
116
                  <span class="uk-margin-small-left">add annotation</span>
117
                </span>
118
              </li>
103 119
              <!-- Metrics -->
104 120
              <li *ngIf="hasAltMetrics || hasMetrics" class="uk-margin-medium-top">
105 121
                <div uk-grid
......
484 500
              </div>
485 501
            </div>
486 502
            <!-- B2 Note-->
487
            <div *ngIf="properties.environment !== 'production' && properties.adminToolsPortalType !== 'monitor' && properties.adminToolsPortalType !== 'aggregator' && resultLandingInfo" class="uk-margin-medium-top">
488
              <b2note [id]="id" [landingInfo]="resultLandingInfo"></b2note>
503
            <div *ngIf="properties.b2noteAPIURL && resultLandingInfo" class="uk-margin-medium-top">
504
              <b2note #annotation [id]="id" [landingInfo]="resultLandingInfo" (userEmitter)="userInit($event)" (pidEmitter)="pidInit($event)"></b2note>
489 505
            </div>
490 506
          </div>
491 507
        </div>
modules/uoa-services-library/trunk/ng-openaire-library/src/app/landingPages/result/resultLanding.component.ts
20 20
import {properties} from "../../../../environments/environment";
21 21
import {ISVocabulariesService} from "../../utils/staticAutoComplete/ISVocabularies.service";
22 22
import {Subscriber} from "rxjs";
23
import {AnnotationComponent} from "../annotation/annotation.component";
24
import {User} from "../../login/utils/helper.class";
23 25

  
24 26

  
25 27
@Component({
......
98 100
    'Title', 'Authors', 'Access rights',
99 101
    'Publisher information', 'Funding Information',
100 102
    'Persistent identifiers', 'Other'];
103
  public user: User;
104
  public pid: string;
105
  @ViewChild("annotation") annotation: AnnotationComponent;
101 106
  
102 107
  constructor(private _resultLaningService: ResultLandingService,
103 108
              private _vocabulariesService: ISVocabulariesService,
......
112 117
              private metricsService: MetricsService,
113 118
              private cdr: ChangeDetectorRef,
114 119
              private _location: Location,
115
              private indexInfoService: IndexInfoService,
116
              private fb: FormBuilder) {
120
              private indexInfoService: IndexInfoService) {
117 121
  }
118 122
  
119 123
  ngOnInit() {
......
214 218
    this._vocabulariesService.clearSubscriptions();
215 219
  }
216 220
  
221
  public userInit(event) {
222
    this.user = event;
223
    this.cdr.detectChanges();
224
  }
225
  
226
  public pidInit(event) {
227
    this.pid = event;
228
    this.cdr.detectChanges();
229
  }
230
  
231
  
217 232
  public getTypeName(): string {
218 233
    if (this.type === "dataset") {
219 234
      return "research data";

Also available in: Unified diff