Project

General

Profile

1
import {Component, ViewChild}         from '@angular/core';
2
import {ElementRef, Input}            from '@angular/core';
3
import {ActivatedRoute, Router}       from '@angular/router';
4
import {Title, Meta}                  from '@angular/platform-browser';
5

    
6
import {Observable}                   from 'rxjs/Observable';
7

    
8
import {SoftwareService}              from './software.service';
9
import {SoftwareInfo}                 from '../../utils/entities/softwareInfo';
10

    
11
import {RouterHelper}                 from '../../utils/routerHelper.class';
12
import {PiwikService}                 from '../../utils/piwik/piwik.service';
13
import {EnvProperties}                from '../../utils/properties/env-properties';
14

    
15
@Component({
16
    selector: 'software',
17
    templateUrl: 'software.component.html',
18
})
19

    
20
export class SoftwareComponent {
21
  @Input() piwikSiteId = null;
22
    public softwareInfo: SoftwareInfo;
23
    public softwareId : string ;
24

    
25
    // APP BOX variables
26
    public showAllCollectedFrom: boolean = false;
27
    public showAllDownloadFrom: boolean = false;
28
    public showAllPublishedIn: boolean = false;
29

    
30
    // Metrics tab variables
31
    public metricsClicked: boolean;
32
    public viewsFrameUrl: string;
33
    public downloadsFrameUrl: string;
34
    public totalViews: number;
35
    public totalDownloads: number;
36
    public pageViews: number;
37

    
38
    // Active tab variable for responsiveness
39
    public activeTab: string = "Related Research Results";
40

    
41
    // Map counting variable
42
    public relatedResearchResultsNum: number = 0;
43

    
44
    // Message variables
45
    public warningMessage = "";
46
    public errorMessage = "";
47
    public showLoading: boolean = true;
48

    
49
    public routerHelper:RouterHelper = new RouterHelper();
50

    
51
    private result ;
52
    sub: any; piwiksub: any; infoSub: any;
53
    properties:EnvProperties;
54

    
55
    constructor (private element: ElementRef,
56
                 private _softwareService: SoftwareService,
57
                 private _piwikService:PiwikService,
58
                 private  route: ActivatedRoute,
59
                 private _meta: Meta,
60
                 private _title: Title,
61
                 private _router: Router) {
62
    }
63

    
64
    ngOnInit() {
65
      this.route.data
66
        .subscribe((data: { envSpecific: EnvProperties }) => {
67
           this.properties = data.envSpecific;
68
           this.updateUrl(data.envSpecific.baseLink+this._router.url);
69

    
70
        });
71
      this.sub =  this.route.queryParams.subscribe(params => {
72
          this.softwareInfo = null;
73
          this.updateTitle("Software");
74
          this.updateDescription("Software, search, open access");
75

    
76
            this.softwareId = params['softwareId'];
77
             console.info("Id is :"+this.softwareId);
78

    
79
             if(this.softwareId){
80
                this.getSoftwareInfo(this.softwareId);
81
            }else{
82
              this.showLoading = false;
83
                this.warningMessage="No valid software id";
84
            }
85

    
86
            this.metricsClicked = false;
87

    
88
            this.viewsFrameUrl = this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resRepoViews", "resTitle":"'+this.softwareId+'", "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';
89
            /*this.viewsFrameUrl = this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resViewsTimeline", "resTitle":"'+this.softwareId+'", "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';
90
            */
91

    
92
            this.downloadsFrameUrl =  this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resRepoDownloads", "resTitle":"'+this.softwareId+'", "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';
93
            /*this.downloadsFrameUrl = this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resRepoDownloadTimeline", "resTitle":"'+this.softwareId+'", "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';
94
            */
95
            if (typeof document !== 'undefined') {
96
               this.element.nativeElement.scrollIntoView();
97
            }
98
        });
99

    
100
    }
101

    
102
    ngOnDestroy() {
103
      this.sub.unsubscribe();
104
      if(this.piwiksub){
105
        this.piwiksub.unsubscribe();
106
      }
107
      if(this.infoSub) {
108
        this.infoSub.unsubscribe();
109
      }
110
    }
111

    
112
    private getSoftwareInfo(id:string) {
113
        this.warningMessage = '';
114
        this.errorMessage=""
115
        this.showLoading = true;
116

    
117
        this.softwareInfo = null;
118

    
119
        this.infoSub = this._softwareService.getSoftwareInfo(id, this.properties).subscribe(
120
            data => {
121
                this.softwareInfo = data;
122
                /*if(this.softwareInfo.title.name != undefined && this.softwareInfo.title.name!= ''){
123
                  this.updateTitle(this.softwareInfo.title.name);
124
                  this.updateDescription("Software, search, repositories, open access,"+this.softwareInfo.title.name);
125
                }*/
126
                if(this.softwareInfo.title){
127
                  this.updateTitle(this.softwareInfo.title);
128
                  this.updateDescription("Software, search, repositories, open access,"+this.softwareInfo.title);
129
                }
130
                if( this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
131
                  this.piwiksub = this._piwikService.trackView(this.properties, this.softwareInfo.title/*.name*/, this.piwikSiteId).subscribe();
132
                }
133

    
134
                this.result = []
135
                this.result = {id: id, type :"software", source : "openaire", title: this.softwareInfo.title,url: '', result: '', accessRights: /*this.softwareInfo.title.accessMode*/this.softwareInfo.accessMode, embargoEndDate: ''};
136

    
137
                let relatedResearchResultsNum = 0;
138
                if(this.softwareInfo.relatedResearchResults != undefined) {
139
                    this.softwareInfo.relatedResearchResults.forEach(function (value, key, map) {
140
                        relatedResearchResultsNum += value.length;
141
                    });
142
                }
143
                this.relatedResearchResultsNum = relatedResearchResultsNum;
144

    
145
                this.showLoading = false;
146
            },
147
            err => {
148
                console.log(err)
149
                console.info("error");
150

    
151
                this.errorMessage = 'No software found';
152
                this.showLoading = false;
153
            }
154
        );
155
    }
156

    
157
    // showChange($event) {
158
    //     this.showAllReferences=$event.value;
159
    // }
160

    
161
    public metricsResults($event) {
162
      this.totalViews = $event.totalViews;
163
      this.totalDownloads = $event.totalDownloads;
164
      this.pageViews = $event.pageViews;
165
    }
166

    
167
    private updateDescription(description:string) {
168
      this._meta.updateTag({content:description},"name='description'");
169
      this._meta.updateTag({content:description},"property='og:description'");
170
    }
171
    private updateTitle(title:string) {
172
      var _prefix ="OpenAIRE | ";
173
      var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
174
      this._title.setTitle(_title);
175
      this._meta.updateTag({content:_title},"property='og:title'");
176
    }
177
    private updateUrl(url:string) {
178
      this._meta.updateTag({content:url},"property='og:url'");
179
    }
180

    
181
    public buildCurationTooltip() {
182
        let tooltipContent: string = "<div class='uk-padding-small uk-light'>";
183

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

    
187
        return tooltipContent;
188
    }
189
    public getKeys( map) {
190
      return Array.from(map.keys());
191
    }
192
}
(3-3/5)