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:

dataset.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 {DatasetInfo} from '../../utils/entities/datasetInfo';
6
import {EnvProperties} from '../../utils/properties/env-properties';
7
import {RouterHelper} from '../../utils/routerHelper.class';
8

  
9
import {DatasetService} from './dataset.service';
10
import {PiwikService} from '../../utils/piwik/piwik.service';
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

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

  
21 9
export class DatasetComponent {
22 10
  @Input() piwikSiteId = null;
23 11
  @Input() communityId = null;
24
  public datasetInfo: DatasetInfo;
25
  public datasetId: string;
26 12

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

  
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
  // Custom tab paging variables
44
  public referencesPage: number = 1;
45
  public pageSize: number = 10;
46

  
47
  // Active tab variable for responsiveness
48
  public activeTab: string = "References";
49

  
50
  // Map counting variable
51
  public relatedResearchResultsNum: number = 0;
52

  
53
  // Message variables
54
  public warningMessage = "";
55
  public errorMessage = "";
56
  public showLoading: boolean = true;
57
  public pageContents = null;
58
  public divContents = null;
59

  
60
  public routerHelper: RouterHelper = new RouterHelper();
61

  
62
  private result;
63
  sub: any;
64
  piwiksub: any;
65
  infoSub: any;
66
  properties: EnvProperties;
67

  
68
  constructor(private _datasetService: DatasetService,
69
              private _piwikService: PiwikService,
70
              private  route: ActivatedRoute,
71
              private router: Router,
72
              private _meta: Meta,
73
              private _title: Title,
74
              private _router: Router,
75
              private seoService: SEOService,
76
              private helper: HelperService) {
77
  }
78

  
79
  ngOnInit() {
80
    this.route.data
81
      .subscribe((data: { envSpecific: EnvProperties }) => {
82
        this.properties = data.envSpecific;
83
        //this.getDivContents();
84
        this.getPageContents();
85
        this.updateUrl(data.envSpecific.baseLink + this._router.url);
86

  
87
      });
88
    this.sub = this.route.queryParams.subscribe(params => {
89
      this.datasetInfo = null;
90
      this.updateTitle("Dataset");
91
      this.updateDescription("");
92

  
93
      this.datasetId = params['datasetId'];
94

  
95
      if (this.datasetId) {
96
        this.getDatasetInfo(this.datasetId);
97
      } else {
98
        this.showLoading = false;
99
        this.warningMessage = "No valid research data id";
100
      }
101

  
102
      this.metricsClicked = false;
103

  
104
      this.viewsFrameUrl = this.properties.framesAPIURL + 'merge.php?com=query&data=[{"query":"resRepoViews", "resTitle":"' + this.datasetId + '", "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';
105
      /*this.viewsFrameUrl = this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resViewsTimeline", "resTitle":"'+this.datasetId+'", "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';
106
      */
107

  
108
      this.downloadsFrameUrl = this.properties.framesAPIURL + 'merge.php?com=query&data=[{"query":"resRepoDownloads", "resTitle":"' + this.datasetId + '", "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';
109
      /*this.downloadsFrameUrl = this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resRepoDownloadTimeline", "resTitle":"'+this.datasetId+'", "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';
110
      */
111
      this.scroll();
112
    });
113

  
114
  }
115

  
116
  private getPageContents() {
117
    this.helper.getPageHelpContents(this.router.url, this.properties, this.communityId).subscribe(contents => {
118
      this.pageContents = contents;
119
    })
120
  }
121

  
122
  private getDivContents() {
123
    this.helper.getDivHelpContents(this.router.url, this.properties, this.communityId).subscribe(contents => {
124
      this.divContents = contents;
125
    })
126
  }
127

  
128
  ngOnDestroy() {
129
    if (this.sub) {
130
      this.sub.unsubscribe();
131
    }
132
    if (this.piwiksub) {
133
      this.piwiksub.unsubscribe();
134
    }
135
    if (this.infoSub) {
136
      this.infoSub.unsubscribe();
137
    }
138
  }
139

  
140
  private getDatasetInfo(id: string) {
141
    this.warningMessage = '';
142
    this.errorMessage = ""
143
    this.showLoading = true;
144

  
145
    this.datasetInfo = null;
146

  
147
    this.infoSub = this._datasetService.getDatasetInfo(id, this.properties).subscribe(
148
      data => {
149
        this.datasetInfo = data;
150
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToDataset + this.datasetInfo.record["result"]["header"]["dri:objIdentifier"]);
151
        /*
152
        if(this.datasetInfo.title.name != undefined && this.datasetInfo.title.name!= ''){
153
          this.updateTitle(this.datasetInfo.title.name);
154
          this.updateDescription("Dataset, search, repositories, open access,"+this.datasetInfo.title.name);
155
        }
156
        */
157
        if (this.datasetInfo.title) {
158
          this.updateTitle(this.datasetInfo.title);
159
          this.updateDescription((this.datasetInfo.description ? (this.datasetInfo.description) : ("," + this.datasetInfo.title)));
160
        }
161
        if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
162
          this.piwiksub = this._piwikService.trackView(this.properties, this.datasetInfo.title/*.name*/, this.piwikSiteId).subscribe();
163
        }
164

  
165
        this.result = []
166
        this.result = {
167
          id: id,
168
          type: "dataset",
169
          source: "openaire",
170
          title: this.datasetInfo.title,
171
          url: '',
172
          result: '',
173
          accessRights: /*this.datasetInfo.title.accessMode*/ this.datasetInfo.accessMode,
174
          embargoEndDate: ''
175
        };
176

  
177
        let relatedResearchResultsNum = 0;
178
        if (this.datasetInfo.relatedResearchResults != undefined) {
179
          this.datasetInfo.relatedResearchResults.forEach(function (value, key, map) {
180
            relatedResearchResultsNum += value.length;
181
          });
182
        }
183
        this.relatedResearchResultsNum = relatedResearchResultsNum;
184

  
185
        this.showLoading = false;
186
      },
187
      err => {
188
        //console.log(err)
189
        this.handleError("Error getting research data for id: " + this.datasetId, err);
190
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToDatasets);
191
        this.errorMessage = 'No research data found';
192
        this.showLoading = false;
193
      }
194
    );
195
  }
196

  
197
  // showChange($event) {
198
  //     this.showAllReferences=$event.value;
199
  // }
200

  
201
  public metricsResults($event) {
202
    this.totalViews = $event.totalViews;
203
    this.totalDownloads = $event.totalDownloads;
204
    this.pageViews = $event.pageViews;
205
  }
206

  
207
  private updateDescription(description: string) {
208
    this._meta.updateTag({content: description}, "name='description'");
209
    this._meta.updateTag({content: description}, "property='og:description'");
210
  }
211

  
212
  private updateTitle(title: string) {
213
    var _prefix = "";
214
    if(!this.communityId) {
215
      _prefix = "OpenAIRE | ";
216
    }
217
    var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
218
    this._title.setTitle(_title);
219
    this._meta.updateTag({content: _title}, "property='og:title'");
220
  }
221

  
222
  private updateUrl(url: string) {
223
    this._meta.updateTag({content: url}, "property='og:url'");
224
  }
225

  
226
  public buildCurationTooltip() {
227
    let tooltipContent: string = "<div class='uk-padding-small uk-light'>";
228

  
229
    tooltipContent += "<h4>Record in preview</h4>";
230
    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>";
231

  
232
    return tooltipContent;
233
  }
234

  
235
  public getKeys(map) {
236
    return Array.from(map.keys());
237
  }
238

  
239
  private handleError(message: string, error) {
240
    console.error("Research Data Landing Page: " + message, error);
241
  }
242

  
243
  public updateReferencesPage($event) {
244
    this.referencesPage = $event.value;
245
  }
246

  
247
  public totalPages(totalResults: number): number {
248
    let totalPages: any = totalResults / this.pageSize;
249
    if (!(Number.isInteger(totalPages))) {
250
      totalPages = (parseInt(totalPages, this.pageSize) + 1);
251
    }
252
    return totalPages;
253
  }
254

  
255
  public scroll() {
256
    HelperFunctions.scroll();
257
  }
258

  
259
  isRouteAvailable(routeToCheck: string) {
260
    for (let i = 0; i < this.router.config.length; i++) {
261
      let routePath: string = this.router.config[i].path;
262
      if (routePath == routeToCheck) {
263
        return true;
264
      }
265
    }
266
    return false;
267
  }
15
  ngOnInit() {}
268 16
}

Also available in: Unified diff