Project

General

Profile

1
import {Component, ViewChild}         from '@angular/core';
2
import {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';
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
import { SEOService } from '../../sharedComponents/SEO/SEO.service';
15
import {HelperFunctions} from "../../utils/HelperFunctions.class";
16

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

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

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

    
32
    public thresholdDescription: number = 270;
33
    public showNumDescription: number = 270;
34

    
35
    // Metrics tab variables
36
    public metricsClicked: boolean;
37
    public viewsFrameUrl: string;
38
    public downloadsFrameUrl: string;
39
    public totalViews: number;
40
    public totalDownloads: number;
41
    public pageViews: number;
42

    
43
    // Active tab variable for responsiveness
44
    public activeTab: string = "Related Research Results";
45

    
46
    // Map counting variable
47
    public relatedResearchResultsNum: number = 0;
48

    
49
    // Message variables
50
    public warningMessage = "";
51
    public errorMessage = "";
52
    public showLoading: boolean = true;
53

    
54
    public routerHelper:RouterHelper = new RouterHelper();
55

    
56
    private result ;
57
    sub: any; piwiksub: any; infoSub: any;
58
    properties:EnvProperties;
59

    
60
    constructor (private _softwareService: SoftwareService,
61
                 private _piwikService:PiwikService,
62
                 private  route: ActivatedRoute,
63
                 private _meta: Meta,
64
                 private _title: Title,
65
                 private _router: Router,
66
               private seoService: SEOService) {
67
    }
68

    
69
    ngOnInit() {
70
      this.route.data
71
        .subscribe((data: { envSpecific: EnvProperties }) => {
72
           this.properties = data.envSpecific;
73
           this.updateUrl(data.envSpecific.baseLink+this._router.url);
74

    
75
        });
76
      this.sub =  this.route.queryParams.subscribe(params => {
77
          this.softwareInfo = null;
78
          this.updateTitle("Software");
79
          this.updateDescription("Software, search, open access");
80

    
81
            this.softwareId = params['softwareId'];
82

    
83
             if(this.softwareId){
84
                this.getSoftwareInfo(this.softwareId);
85
            }else{
86
              this.showLoading = false;
87
                this.warningMessage="No valid software id";
88
            }
89

    
90
            this.metricsClicked = false;
91

    
92
            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';
93
            /*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';
94
            */
95

    
96
            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';
97
            /*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';
98
            */
99
            this.scroll();
100
        });
101

    
102
    }
103

    
104
    ngOnDestroy() {
105
      if(this.sub){
106
        this.sub.unsubscribe();
107
      }
108
      if(this.piwiksub){
109
        this.piwiksub.unsubscribe();
110
      }
111
      if(this.infoSub) {
112
        this.infoSub.unsubscribe();
113
      }
114
    }
115

    
116
    private getSoftwareInfo(id:string) {
117
        this.warningMessage = '';
118
        this.errorMessage=""
119
        this.showLoading = true;
120

    
121
        this.softwareInfo = null;
122

    
123
        this.infoSub = this._softwareService.getSoftwareInfo(id, this.properties).subscribe(
124
            data => {
125
                this.softwareInfo = data;
126
                this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToSoftwareLanding + this.softwareInfo.record["result"]["header"]["dri:objIdentifier"]);
127
                /*if(this.softwareInfo.title.name != undefined && this.softwareInfo.title.name!= ''){
128
                  this.updateTitle(this.softwareInfo.title.name);
129
                  this.updateDescription("Software, search, repositories, open access,"+this.softwareInfo.title.name);
130
                }*/
131
                if(this.softwareInfo.title){
132
                  this.updateTitle(this.softwareInfo.title);
133
                  this.updateDescription("Software, "+this.softwareInfo.title);
134
                }
135
                if( this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
136
                  this.piwiksub = this._piwikService.trackView(this.properties, this.softwareInfo.title/*.name*/, this.piwikSiteId).subscribe();
137
                }
138

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

    
142
                let relatedResearchResultsNum = 0;
143
                if(this.softwareInfo.relatedResearchResults != undefined) {
144
                    this.softwareInfo.relatedResearchResults.forEach(function (value, key, map) {
145
                        relatedResearchResultsNum += value.length;
146
                    });
147
                }
148
                this.relatedResearchResultsNum = relatedResearchResultsNum;
149

    
150
                this.showLoading = false;
151
            },
152
            err => {
153
                //console.log(err)
154
                this.handleError("Error getting software for id: "+this.softwareId, err);
155
                this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToSoftware);
156
                this.errorMessage = 'No software found';
157
                this.showLoading = false;
158
            }
159
        );
160
    }
161

    
162
    // showChange($event) {
163
    //     this.showAllReferences=$event.value;
164
    // }
165

    
166
    public metricsResults($event) {
167
      this.totalViews = $event.totalViews;
168
      this.totalDownloads = $event.totalDownloads;
169
      this.pageViews = $event.pageViews;
170
    }
171

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

    
186
    public buildCurationTooltip() {
187
        let tooltipContent: string = "<div class='uk-padding-small uk-light'>";
188

    
189
        tooltipContent += "<h4>Record in preview</h4>";
190
        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>";
191

    
192
        return tooltipContent;
193
    }
194
    public getKeys( map) {
195
      return Array.from(map.keys());
196
    }
197

    
198
    public scroll() {
199
      HelperFunctions.scroll();
200
    }
201

    
202
    private handleError(message: string, error) {
203
        console.error("Software Landing Page: "+message, error);
204
    }
205
}
(3-3/5)