Project

General

Profile

1
import {Component, ViewChild, ElementRef} from '@angular/core';
2
import {Observable} from 'rxjs/Observable';
3
import {PublicationService} from './publication.service';
4
import {PublicationInfo} from '../../utils/entities/publicationInfo';
5
import {ActivatedRoute} from '@angular/router';
6
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
7
import {RouterHelper} from '../../utils/routerHelper.class';
8
import { Meta} from '../../../angular2-meta';
9

    
10

    
11

    
12
@Component({
13
    selector: 'publication',
14
    templateUrl: 'publication.component.html',
15

    
16
})
17

    
18
export class PublicationComponent {
19

    
20
  public showAllCollectedFrom: boolean = false;
21
  public showAllDownloadFrom: boolean = false;
22
  public showAllFundedBy: boolean = false;
23
  public showAllPublishedIn: boolean = false;
24

    
25
  sub: any;
26
  articleId: string;
27
  public publicationInfo: PublicationInfo;
28
  private metricsClicked: boolean;
29
  private viewsFrameUrl: string;
30
  private downloadsFrameUrl: string;
31
  private totalViews: number;
32
  private totalDownloads: number;
33
  private pageViews: number;
34

    
35
  public showAllReferences: boolean = false;
36
  public showAllRelResData: boolean = false;
37
  public showAllSimilPubl: boolean = false;
38
  public showAllBioentities: boolean = false;
39
  public showFundingDetails: boolean = false;
40

    
41
  public bioentitiesNum: number = 0;
42
  public relatedResearchResultsNum: number = 0;
43

    
44
  private doi: string;
45

    
46
  public result ;
47

    
48
  public warningMessage = "";
49
  public errorMessage = "";
50
  public routerHelper:RouterHelper = new RouterHelper();
51

    
52
  public activeTab: string = "References";
53

    
54
  constructor ( private element: ElementRef,
55
                private _publicationService: PublicationService,
56
                private route: ActivatedRoute, private _meta: Meta) { }
57

    
58
  ngOnInit() {
59
       this.sub =  this.route.queryParams.subscribe(data => {
60
           this.publicationInfo = null;
61
           this.updateTitle("Publication");
62
           this.updateDescription("Publication, open access, collected from");
63

    
64
          this.articleId = data['articleId'];
65
          console.info("Article id is :"+this.articleId);
66

    
67
          if(this.articleId){
68

    
69
              this.getPublicationInfo(this.articleId);
70
              // if (typeof document !== 'undefined') {
71
              //   switcher(UIkit);
72
              // }
73
          }else{
74
              this.warningMessage="No valid publication id";
75
          }
76
          this.metricsClicked = false;
77

    
78
          this.viewsFrameUrl = OpenaireProperties.getFramesAPIURL()+'merge.php?com=query&data=[{"query":"resRepoViews", "resTitle":"'+this.articleId+'", "table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":" ","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"Repository","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false';
79
          /*this.viewsFrameUrl = OpenaireProperties.getFramesAPIURL()+'merge.php?com=query&data=[{"query":"resViewsTimeline", "resTitle":"'+this.articleId+'", "table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":" ","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"Repository","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(124, 181, 236, 1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false';
80
          */
81

    
82
          this.downloadsFrameUrl = OpenaireProperties.getFramesAPIURL()+'merge.php?com=query&data=[{"query":"resRepoDownloads", "resTitle":"'+this.articleId+'", "table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":" ","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"Repository","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false';
83
          /*this.downloadsFrameUrl = OpenaireProperties.getFramesAPIURL()+'merge.php?com=query&data=[{"query":"resRepoDownloadTimeline", "resTitle":"'+this.articleId+'", "table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":" ","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"Repository","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true';
84
          */
85
          if (typeof document !== 'undefined') {
86
             this.element.nativeElement.scrollIntoView();
87
          }
88
    });
89
  }
90

    
91
    ngOnDestroy() {
92
        this.sub.unsubscribe();
93
    }
94

    
95
    getPublicationInfo(id:string) {
96
        this.warningMessage = '';
97
        this.errorMessage=""
98

    
99
        this._publicationService.getPublicationInfo(this.articleId).subscribe(
100
            data => {
101
                this.publicationInfo = data;
102

    
103

    
104
                // this.result = []
105
                // this.result = {id: id, type :"dataset", source : "openaire", title: this.publicationInfo.title,url: '', result: '', accessRights: this.publicationInfo.bestlicense, embargoEndDate: ''};
106
                this.updateTitle(this.publicationInfo.title.name);
107
                this.updateDescription("Dataset, search, repositories, open access,"+this.publicationInfo.title.name);
108

    
109
                let bioentitiesNum = 0;
110
                if(this.publicationInfo.bioentities != undefined) {
111
                    this.publicationInfo.bioentities.forEach(function (value, key, map) {
112
                        bioentitiesNum += value.size;
113
                    });
114
                }
115
                this.bioentitiesNum = bioentitiesNum;
116

    
117
                let relatedResearchResultsNum = 0;
118
                if(this.publicationInfo.relatedResearchResults != undefined) {
119
                    this.publicationInfo.relatedResearchResults.forEach(function (value, key, map) {
120
                        relatedResearchResultsNum += value.length;
121
                    });
122
                }
123
                this.relatedResearchResultsNum = relatedResearchResultsNum;
124

    
125
                this.result = {id: this.articleId, type :"publication", source : "openaire", title: this.publicationInfo.title,url: '', result: '', accessRights: this.publicationInfo.bestlicense, embargoEndDate: ''};
126
                // this.result.push(result_);
127

    
128
                if(this.publicationInfo.identifiers != undefined && this.publicationInfo.identifiers.has('doi')) {
129
                    this.doi = this.publicationInfo.identifiers.get('doi')[0];
130
                }
131
            },
132
            err => {
133
              console.log(err);
134
              console.info("error");
135

    
136
              this.errorMessage = 'No publication found';
137
            }
138
      );
139
    }
140

    
141
    showChange($event) {
142
        this.showAllReferences=$event.value;
143
    }
144

    
145
    public downloadClicked($event) {
146
        this.totalViews = $event.totalViews;
147
        this.totalDownloads = $event.totalDownloads;
148
    }
149

    
150
    public metricsResults($event) {
151
      this.totalViews = $event.totalViews;
152
      this.totalDownloads = $event.totalDownloads;
153
      this.pageViews = $event.pageViews;
154
    }
155

    
156
    public buildCurationTooltip() {
157
        let tooltipContent: string = "<div class='uk-margin'>";
158

    
159
        tooltipContent += "<h4>Record in preview</h4>";
160
        tooltipContent += "<p>Bibliographic record accepted by the system, but not yet processed by <br> OpenAIRE tools for information quality improvement and de-duplication</p>";
161

    
162
        return tooltipContent+= "</div>";
163
    }
164

    
165
    public buildFundingTooltip(item: { "id": string, "acronym": string, "title": string,
166
                        "funderShortname": string, "funderName": string,
167
                        "funding": string, "code": string, inline: boolean}) {
168
        let tooltipContent: string = "<div class='uk-margin'>";
169

    
170
        if(item.title) {
171
            tooltipContent += "<h4>"+item.title+"</h4>";
172
        }
173
        if(item.code) {
174
            tooltipContent += "Project Code: "+item.code;
175
        }
176
        if(item.funderName || item.funderShortname) {
177
            tooltipContent += "<div>Funder: ";
178
            if(item.funderName && item.funderShortname) {
179
                tooltipContent += item.funderName + " ("+ item.funderShortname +")";
180
            } else if(item.funderName) {
181
                tooltipContent += item.funderName;
182
            } else {
183
                tooltipContent += item.funderShortname;
184
            }
185

    
186
            tooltipContent += "</div>";
187
        }
188

    
189
        if(item.funding) {
190
            tooltipContent += "<div>Funding: "+ item.funding + "</div>";
191
        }
192

    
193
        if(tooltipContent) {
194
            tooltipContent = "<div>" + tooltipContent + "</div>";
195
        }
196
        tooltipContent+="</div>"
197
        return tooltipContent;
198
        /*<div>
199
            <h4>{{item['title']}}</h4>
200
            Project Code: {{item['code']}}
201
            <div>
202
                Funder: {{item['funderName']}} ({{item['funderShortname']}})
203
            </div>
204
            <div>
205
                Funding: {{item['funding']}}
206
            </div>
207
        </div>*/
208
    }
209
    updateDescription(description:string){
210
      this._meta.updateMeta("description", description);
211
      this._meta.updateMeta("og:description", description);
212
    }
213
    updateTitle(title:string){
214
      var _suffix ="| OpenAIRE";
215
      var _title = ((title.length> 50 ) ?title.substring(0,50):title) + _suffix;
216
      this._meta.setTitle(_title );
217
      this._meta.updateMeta("og:title",_title);
218
    }
219

    
220
}
(3-3/5)