Project

General

Profile

1
import {Component, ViewChild, ElementRef} from '@angular/core';
2
import {Observable}       from 'rxjs/Observable';
3
import {SoftwareService} from './software.service';
4
import {SoftwareInfo} from '../../utils/entities/softwareInfo';
5
import {ActivatedRoute, Router} from '@angular/router';
6
import {OpenaireProperties} from '../../utils/properties/openaireProperties'
7
import {RouterHelper} from '../../utils/routerHelper.class';
8
import { Meta} from '../../../angular2-meta';
9
import {PiwikService} from '../../utils/piwik/piwik.service';
10

    
11
@Component({
12
    selector: 'software',
13
    templateUrl: 'software.component.html',
14
})
15

    
16
export class SoftwareComponent {
17
    public softwareInfo: SoftwareInfo;
18
    public softwareId : string ;
19

    
20
    // APP BOX variables
21
    public showAllCollectedFrom: boolean = false;
22
    public showAllDownloadFrom: boolean = false;
23
    public showAllPublishedIn: boolean = false;
24

    
25
    // Metrics tab variables
26
    public metricsClicked: boolean;
27
    public viewsFrameUrl: string;
28
    public downloadsFrameUrl: string;
29
    public totalViews: number;
30
    public totalDownloads: number;
31
    public pageViews: number;
32

    
33
    // Active tab variable for responsiveness
34
    public activeTab: string = "Related Research Results";
35

    
36
    // Map counting variable
37
    public relatedResearchResultsNum: number = 0;
38

    
39
    // Message variables
40
    public warningMessage = "";
41
    public errorMessage = "";
42
    public showLoading: boolean = true;
43

    
44
    public routerHelper:RouterHelper = new RouterHelper();
45

    
46
    private result ;
47
    sub: any; piwiksub: any; infoSub: any;
48

    
49
    constructor (private element: ElementRef,
50
                 private _softwareService: SoftwareService,
51
                 private _piwikService:PiwikService,
52
                 private  route: ActivatedRoute,
53
                 private _meta: Meta,
54
                 private _router: Router) {
55
                   this.updateUrl(OpenaireProperties.getBaseLink()+this._router.url);
56
    }
57

    
58
    ngOnInit() {
59
      this.sub =  this.route.queryParams.subscribe(params => {
60
          this.softwareInfo = null;
61
          this.updateTitle("Software");
62
          this.updateDescription("Software, search, open access");
63

    
64
            this.softwareId = params['softwareId'];
65
             console.info("Id is :"+this.softwareId);
66

    
67
             if(this.softwareId){
68
                this.getSoftwareInfo(this.softwareId);
69
            }else{
70
              this.showLoading = false;
71
                this.warningMessage="No valid software id";
72
            }
73

    
74
            this.metricsClicked = false;
75

    
76
            this.viewsFrameUrl = OpenaireProperties.getFramesAPIURL()+'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';
77
            /*this.viewsFrameUrl = OpenaireProperties.getFramesAPIURL()+'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';
78
            */
79

    
80
            this.downloadsFrameUrl = OpenaireProperties.getFramesAPIURL()+'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';
81
            /*this.downloadsFrameUrl = OpenaireProperties.getFramesAPIURL()+'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';
82
            */
83
            if (typeof document !== 'undefined') {
84
               this.element.nativeElement.scrollIntoView();
85
            }
86
        });
87

    
88
    }
89

    
90
    ngOnDestroy() {
91
      this.sub.unsubscribe();
92
      if(this.piwiksub){
93
        this.piwiksub.unsubscribe();
94
      }
95
      if(this.infoSub) {
96
        this.infoSub.unsubscribe();
97
      }
98
    }
99

    
100
    private getSoftwareInfo(id:string) {
101
        this.warningMessage = '';
102
        this.errorMessage=""
103
        this.showLoading = true;
104

    
105
        this.infoSub = this._softwareService.getSoftwareInfo(id).subscribe(
106
            data => {
107
                this.softwareInfo = data;
108
                this.updateTitle(this.softwareInfo.title.name);
109
                this.updateDescription("Software, search, repositories, open access,"+this.softwareInfo.title.name);
110
                if(OpenaireProperties.isPiwikTrackEnabled() && (typeof document !== 'undefined')){
111
                  this.piwiksub = this._piwikService.trackView(this.softwareInfo.title.name).subscribe();
112
                }
113

    
114
                this.result = []
115
                this.result = {id: id, type :"software", source : "openaire", title: this.softwareInfo.title,url: '', result: '', accessRights: this.softwareInfo.title.accessMode, embargoEndDate: ''};
116

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

    
125
                this.showLoading = false;
126
            },
127
            err => {
128
                console.log(err)
129
                console.info("error");
130

    
131
                this.errorMessage = 'No software found';
132
                this.showLoading = false;
133
            }
134
        );
135
    }
136

    
137
    // showChange($event) {
138
    //     this.showAllReferences=$event.value;
139
    // }
140

    
141
    public metricsResults($event) {
142
      this.totalViews = $event.totalViews;
143
      this.totalDownloads = $event.totalDownloads;
144
      this.pageViews = $event.pageViews;
145
    }
146

    
147
    private updateDescription(description:string){
148
      this._meta.updateMeta("description", description);
149
      this._meta.updateProperty("og:description", description);
150
    }
151
    private updateTitle(title:string){
152
      var _prefix ="OpenAIRE | ";
153
      var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
154
      this._meta.setTitle(_title );
155
      this._meta.updateProperty("og:title",_title);
156
    }
157
    private updateUrl(url:string){
158
      this._meta.updateProperty("og:url", url);
159
    }
160

    
161
    public buildCurationTooltip() {
162
        let tooltipContent: string = "<div class='uk-padding-small uk-light'>";
163

    
164
        tooltipContent += "<h4>Record in preview</h4>";
165
        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>";
166

    
167
        return tooltipContent;
168
    }
169
    public getKeys( map) {
170
      return Array.from(map.keys());
171
    }
172
}
(3-3/5)