Project

General

Profile

« Previous | Next » 

Revision 56925

[mergeResultLandingPages | Library]:
1. Rename 'resultLanding.module' to 'resultLandingUtils.module'
2. Add property 'searchLinkToSoftwareLanding'
3. Add files: resultLandingInfo.ts, resultLanding.module.ts, resultLanding.component.ts, resultLanding.component.html for merging result landing pages (publication, dataset, software, orp)

View differences:

software.component.ts
1 1
import {Component, Input} from '@angular/core';
2
import {ActivatedRoute, Router} from '@angular/router';
3
import {Meta, Title} from '@angular/platform-browser';
4 2

  
5
import {SoftwareService} from './software.service';
6
import {SoftwareInfo} from '../../utils/entities/softwareInfo';
7

  
8
import {RouterHelper} from '../../utils/routerHelper.class';
9
import {PiwikService} from '../../utils/piwik/piwik.service';
10
import {EnvProperties} from '../../utils/properties/env-properties';
11
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
12
import {HelperFunctions} from "../../utils/HelperFunctions.class";
13
import {HelperService} from "../../utils/helper/helper.service";
14

  
15 3
@Component({
16 4
  selector: 'software',
17
  templateUrl: 'software.component.html',
5
  template: `
6
    <result-landing type="software" [piwikSiteId]="piwikSiteId" [communityId]="communityId" [activeTab]="'Related Research Results'"></result-landing>
7
  `
18 8
})
19 9

  
20 10
export class SoftwareComponent {
21 11
  @Input() piwikSiteId = null;
22 12
  @Input() communityId = null;
23
  public softwareInfo: SoftwareInfo;
24
  public softwareId: string;
25 13

  
26
  // APP BOX variables
27
  public showAllCollectedFrom: boolean = false;
28
  public showAllDownloadFrom: boolean = false;
29
  public showAllPublishedIn: boolean = false;
14
  constructor() {}
30 15

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

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

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

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

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

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

  
55
  private result;
56
  sub: any;
57
  piwiksub: any;
58
  infoSub: any;
59
  properties: EnvProperties;
60
  public pageContents = null;
61
  public divContents = null;
62

  
63
  constructor(private _softwareService: SoftwareService,
64
              private _piwikService: PiwikService,
65
              private  route: ActivatedRoute,
66
              private router: Router,
67
              private _meta: Meta,
68
              private _title: Title,
69
              private _router: Router,
70
              private helper: HelperService,
71
              private seoService: SEOService) {
72
  }
73

  
74
  ngOnInit() {
75
    this.route.data
76
      .subscribe((data: { envSpecific: EnvProperties }) => {
77
        this.properties = data.envSpecific;
78
        //this.getDivContents();
79
        this.getPageContents();
80
        this.updateUrl(data.envSpecific.baseLink + this._router.url);
81

  
82
      });
83
    this.sub = this.route.queryParams.subscribe(params => {
84
      this.softwareInfo = null;
85
      this.updateTitle("Software");
86
      this.updateDescription("Software, search, open access");
87

  
88
      this.softwareId = params['softwareId'];
89

  
90
      if (this.softwareId) {
91
        this.getSoftwareInfo(this.softwareId);
92
      } else {
93
        this.showLoading = false;
94
        this.warningMessage = "No valid software id";
95
      }
96

  
97
      this.metricsClicked = false;
98

  
99
      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';
100
      /*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';
101
      */
102

  
103
      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';
104
      /*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';
105
      */
106
      this.scroll();
107
    });
108

  
109
  }
110

  
111
  private getPageContents() {
112
    this.helper.getPageHelpContents(this._router.url, this.properties, this.communityId).subscribe(contents => {
113
      this.pageContents = contents;
114
    })
115
  }
116

  
117
  private getDivContents() {
118
    this.helper.getDivHelpContents(this._router.url, this.properties, this.communityId).subscribe(contents => {
119
      this.divContents = contents;
120
    })
121
  }
122

  
123
  ngOnDestroy() {
124
    if (this.sub) {
125
      this.sub.unsubscribe();
126
    }
127
    if (this.piwiksub) {
128
      this.piwiksub.unsubscribe();
129
    }
130
    if (this.infoSub) {
131
      this.infoSub.unsubscribe();
132
    }
133
  }
134

  
135
  private getSoftwareInfo(id: string) {
136
    this.warningMessage = '';
137
    this.errorMessage = ""
138
    this.showLoading = true;
139

  
140
    this.softwareInfo = null;
141

  
142
    this.infoSub = this._softwareService.getSoftwareInfo(id, this.properties).subscribe(
143
      data => {
144
        this.softwareInfo = data;
145
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToSoftwareLanding + this.softwareInfo.record["result"]["header"]["dri:objIdentifier"]);
146
        /*if(this.softwareInfo.title.name != undefined && this.softwareInfo.title.name!= ''){
147
          this.updateTitle(this.softwareInfo.title.name);
148
          this.updateDescription("Software, search, repositories, open access,"+this.softwareInfo.title.name);
149
        }*/
150
        if (this.softwareInfo.title) {
151
          this.updateTitle(this.softwareInfo.title);
152
          this.updateDescription("Software, " + this.softwareInfo.title);
153
        }
154
        if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
155
          this.piwiksub = this._piwikService.trackView(this.properties, this.softwareInfo.title/*.name*/, this.piwikSiteId).subscribe();
156
        }
157

  
158
        this.result = []
159
        this.result = {
160
          id: id,
161
          type: "software",
162
          source: "openaire",
163
          title: this.softwareInfo.title,
164
          url: '',
165
          result: '',
166
          accessRights: /*this.softwareInfo.title.accessMode*/this.softwareInfo.accessMode,
167
          embargoEndDate: ''
168
        };
169

  
170
        let relatedResearchResultsNum = 0;
171
        if (this.softwareInfo.relatedResearchResults != undefined) {
172
          this.softwareInfo.relatedResearchResults.forEach(function (value, key, map) {
173
            relatedResearchResultsNum += value.length;
174
          });
175
        }
176
        this.relatedResearchResultsNum = relatedResearchResultsNum;
177

  
178
        this.showLoading = false;
179
      },
180
      err => {
181
        //console.log(err)
182
        this.handleError("Error getting software for id: " + this.softwareId, err);
183
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToSoftware);
184
        this.errorMessage = 'No software found';
185
        this.showLoading = false;
186
      }
187
    );
188
  }
189

  
190
  // showChange($event) {
191
  //     this.showAllReferences=$event.value;
192
  // }
193

  
194
  public metricsResults($event) {
195
    this.totalViews = $event.totalViews;
196
    this.totalDownloads = $event.totalDownloads;
197
    this.pageViews = $event.pageViews;
198
  }
199

  
200
  private updateDescription(description: string) {
201
    this._meta.updateTag({content: description}, "name='description'");
202
    this._meta.updateTag({content: description}, "property='og:description'");
203
  }
204

  
205
  private updateTitle(title: string) {
206
    var _prefix = "";
207
    if(!this.communityId) {
208
      _prefix = "OpenAIRE | ";
209
    }
210
    var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
211
    this._title.setTitle(_title);
212
    this._meta.updateTag({content: _title}, "property='og:title'");
213
  }
214

  
215
  private updateUrl(url: string) {
216
    this._meta.updateTag({content: url}, "property='og:url'");
217
  }
218

  
219
  public buildCurationTooltip() {
220
    let tooltipContent: string = "<div class='uk-padding-small uk-light'>";
221

  
222
    tooltipContent += "<h4>Record in preview</h4>";
223
    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>";
224

  
225
    return tooltipContent;
226
  }
227

  
228
  public getKeys(map) {
229
    return Array.from(map.keys());
230
  }
231

  
232
  public scroll() {
233
    HelperFunctions.scroll();
234
  }
235

  
236
  private handleError(message: string, error) {
237
    console.error("Software Landing Page: " + message, error);
238
  }
239

  
240
  isRouteAvailable(routeToCheck: string) {
241
    for (let i = 0; i < this.router.config.length; i++) {
242
      let routePath: string = this.router.config[i].path;
243
      if (routePath == routeToCheck) {
244
        return true;
245
      }
246
    }
247
    return false;
248
  }
16
  ngOnInit() {}
249 17
}

Also available in: Unified diff