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 'rxjs/add/operator/switch';
9
import 'rxjs/add/operator/switchMap';
10

    
11
import {EnvProperties}                      from '../../utils/properties/env-properties';
12

    
13
import {DataProviderInfo}                   from '../../utils/entities/dataProviderInfo';
14
import {DataProviderService}                from './dataProvider.service';
15
import {FetchPublications}                  from '../../utils/fetchEntitiesClasses/fetchPublications.class';
16
import {SearchPublicationsService}          from '../../services/searchPublications.service';
17
import {FetchDatasets}                      from '../../utils/fetchEntitiesClasses/fetchDatasets.class';
18
import {SearchDatasetsService}              from '../../services/searchDatasets.service';
19
import {FetchSoftware}                      from '../../utils/fetchEntitiesClasses/fetchSoftware.class';
20
import {SearchSoftwareService}              from '../../services/searchSoftware.service';
21
import {FetchOrps}                      from '../../utils/fetchEntitiesClasses/fetchOrps.class';
22
import {SearchOrpsService}              from '../../services/searchOrps.service';
23
import {FetchProjects}                      from '../../utils/fetchEntitiesClasses/fetchProjects.class';
24
import {SearchProjectsService}              from '../../services/searchProjects.service';
25
import {FetchDataproviders}                 from '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
26
import {SearchDataprovidersService}         from '../../services/searchDataproviders.service';
27
import {RelatedDatasourcesTabComponent}     from './relatedDatasourcesTab.component';
28
import {ErrorCodes}                         from '../../utils/properties/errorCodes';
29
import {RouterHelper}                       from '../../utils/routerHelper.class';
30
import {PiwikService}                       from '../../utils/piwik/piwik.service';
31
import { SEOService } from '../../sharedComponents/SEO/SEO.service';
32

    
33

    
34
@Component({
35
    selector: 'dataprovider',
36
     templateUrl: 'dataProvider.component.html',
37
 })
38

    
39
export class DataProviderComponent {
40
  @Input() piwikSiteId = null;
41
  public dataProviderInfo: DataProviderInfo;
42
  public datasourceId: string;
43

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

    
49
  // Variable to specify requests with either collectedFrom or hostedBy
50
  public paramsForSearchLink = {};
51

    
52
  // Metrics tab variables
53
  public metricsClicked: boolean;
54
  public viewsFrameUrl: string;
55
  public downloadsFrameUrl: string;
56
  public totalViews: number;
57
  public totalDownloads: number;
58
  public pageViews: number;
59

    
60
  // Statistics tab variables
61
  public statsClicked: boolean = false;
62
  public docsTimelineUrl: string;
63
  public docsTypesUrl:string;
64
  public docsFunderUrl:string;
65
  public dataProjectsUrl:string ;
66
  public pubsProjectsUrl:string;
67

    
68
  // Variables for publications, research data, projects, content providers, related content providers tabs
69
  public fetchPublications : FetchPublications;
70
  public fetchDatasets: FetchDatasets;
71
  public fetchSoftware: FetchSoftware;
72
  public fetchOrps: FetchOrps;
73
  public fetchProjects: FetchProjects;
74
  public fetchDataproviders: FetchDataproviders;
75
  public fetchAggregatorsPublications: FetchPublications;
76
  public fetchAggregatorsDatasets: FetchDatasets;
77
  public fetchAggregatorsSoftware: FetchSoftware;
78
  public fetchAggregatorsOrps: FetchOrps;
79

    
80
  public loadingRelatedDatasources: boolean = true;
81

    
82
  // Active tab variable for responsiveness - show tabs only if main request is completed
83
  public activeTab: string = "";
84
  public showTabs:boolean = false;
85

    
86
  public routerHelper:RouterHelper = new RouterHelper();
87
  public errorCodes:ErrorCodes = new ErrorCodes();
88

    
89
  // Request results of each tab only the one time (first time tab is clicked)
90
  private reloadPublications: boolean = true;
91
  private reloadDatasets: boolean = true;
92
  private reloadSoftware: boolean = true;
93
  private reloadOrps: boolean = true;
94
  private reloadProjects: boolean = true;
95
  private reloadDataproviders: boolean = true;
96
  private reloadRelatedDatasources: boolean = true;
97

    
98
  private nativeElement : Node;
99

    
100
  sub: any;
101
  piwiksub: any;
102
  subInfo: any;
103
  relatedDatasourcesSub: any;
104
  properties:EnvProperties;
105

    
106
  constructor (private element: ElementRef,
107
               private _dataproviderService: DataProviderService,
108
               private _piwikService:PiwikService,
109
               private route: ActivatedRoute,
110
               private _meta: Meta,
111
               private _title: Title,
112
               private _router: Router,
113
               private _searchPublicationsService: SearchPublicationsService,
114
               private _searchDatasetsService: SearchDatasetsService,
115
               private _searchSoftwareService: SearchSoftwareService,
116
               private _searchOrpsService: SearchOrpsService,
117
               private _searchProjectsService: SearchProjectsService,
118
               private _searchDataprovidersService: SearchDataprovidersService,
119
             private seoService: SEOService) {
120
                 this.fetchPublications = new FetchPublications(this._searchPublicationsService);
121
                 this.fetchDatasets = new FetchDatasets(this._searchDatasetsService);
122
                 this.fetchSoftware = new FetchSoftware(this._searchSoftwareService);
123
                 this.fetchOrps = new FetchOrps(this._searchOrpsService);
124
                 this.fetchProjects = new FetchProjects(this._searchProjectsService);
125
                 this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
126

    
127
 }
128

    
129
 ngOnInit() {
130
   this.route.data
131
     .subscribe((data: { envSpecific: EnvProperties }) => {
132
        this.properties = data.envSpecific;
133
        this.updateUrl(data.envSpecific.baseLink+this._router.url);
134

    
135
     });
136
   this.sub =  this.route.queryParams.subscribe(data => {
137
      this.updateTitle("Content provider");
138
      this.updateDescription("Content provider, search, repositories, open access");
139
      this.seoService.createLinkForCanonicalURL();
140
      this.datasourceId = data['datasourceId'];
141
      if(this.datasourceId){
142
       this.getDataProviderInfo(this.datasourceId);
143
      }else{
144
       // console.info("Content Provider id not found");
145
      }
146

    
147
      if (typeof document !== 'undefined') {
148
        this.element.nativeElement.scrollIntoView();
149
      }
150
   });
151
 }
152

    
153
   ngOnDestroy() {
154
     if(this.sub){
155
       this.sub.unsubscribe();
156
     }
157
     if(this.piwiksub){
158
       this.piwiksub.unsubscribe();
159
     }
160
     if(this.subInfo) {
161
      this.subInfo.unsubscribe();
162
     }
163

    
164
     if(this.relatedDatasourcesSub) {
165
       this.relatedDatasourcesSub.unsubscribe();
166
     }
167
   }
168
  private getDataProviderInfo(id:string) {
169
    this.warningMessage = '';
170
    this.errorMessage=""
171
    this.showLoading = true;
172

    
173
    this.dataProviderInfo = null;
174

    
175
    this.showTabs = false ;
176
    if(this.datasourceId==null || this.datasourceId==''){
177
      this.showLoading = false;
178
      this.warningMessage="No valid datasource id";
179
    }else{
180
      this.subInfo = this._dataproviderService.getDataproviderInfo(this.datasourceId, this.properties).subscribe(
181
        data => {
182
            this.dataProviderInfo = data;
183

    
184
            this.getDataProviderAggregationStatus(this.dataProviderInfo.originalId);
185

    
186
            this.initTabs();
187
            this.showTabs = true ;
188
            this.updateTitle(this.dataProviderInfo.title.name);
189
            this.updateDescription("Content provider, search, repositories, open access,"+this.dataProviderInfo.title.name);
190
            if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
191
              this.piwiksub = this._piwikService.trackView(this.properties, this.dataProviderInfo.title.name, this.piwikSiteId).subscribe();
192
            }
193

    
194
            this.showLoading = false;
195

    
196
            if(this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
197
              this.activeTab = this.dataProviderInfo.tabs[0].name;
198
            }
199
        },
200
        err => {
201
          console.log(err);
202
          // console.info("error");
203
          this.errorMessage = 'No dataProvider found';
204
          this.showLoading = false;
205
        }
206
      );
207
    }
208
   }
209

    
210
   private getDataProviderAggregationStatus(originalId: string) {
211
     this.subInfo = this._dataproviderService.getDataproviderAggregationStatus(originalId, this.properties).subscribe(
212
       data => {
213
           this.dataProviderInfo.aggregationStatus = data;
214
       },
215
       err => {
216
         console.log(err);
217
       }
218
     );
219
   }
220

    
221
   private updateDescription(description:string) {
222
     this._meta.updateTag({content:description},"name='description'");
223
     this._meta.updateTag({content:description},"property='og:description'");
224
   }
225
   private updateTitle(title:string) {
226
     var _prefix ="OpenAIRE | ";
227
     var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
228
     this._title.setTitle(_title);
229
     this._meta.updateTag({content:_title},"property='og:title'");
230
   }
231
   private updateUrl(url:string) {
232
     this._meta.updateTag({content:url},"property='og:url'");
233
   }
234

    
235
   private initTabs(){
236

    
237
           if(this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
238
               this.reloadPublications = true;
239
               this.reloadDatasets = true;
240
               this.reloadSoftware = true;
241
               this.reloadOrps = true;
242
               this.reloadProjects = true;
243
               this.reloadDataproviders = true;
244
               this.reloadRelatedDatasources = true;
245
               this.statsClicked = false;
246

    
247
               //this.search(this.dataProviderInfo.tabs[0].content, 1, 10);
248
               this.count(1, 0);
249

    
250
               this.metricsClicked = false;
251

    
252
               this.viewsFrameUrl = this.properties.framesAPIURL +'merge.php?com=query&data=[{"query":"dtsrcRepoViews","dtsrcName":"'+this.datasourceId+'","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":"","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[]}]&info_types=["column"]&stacking=&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';
253
               /*this.viewsFrameUrl = this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"dtsrcOpenAIRETimeline", "dtsrcName":"'+this.datasourceId+'", "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":"OpenAIRE","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]},{"query":"dtsrcRepoTimeline", "dtsrcName":"'+this.datasourceId+'", "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":[""],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column","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';
254
               */
255

    
256
               this.downloadsFrameUrl = this.properties.framesAPIURL +'merge.php?com=query&data=[{"query":"dtsrcRepoDownloads","dtsrcName":"'+this.datasourceId+'","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":"","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[]}]&info_types=["column"]&stacking=&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';
257
               /*
258
               this.downloadsFrameUrl = this.properties.framesAPIURL +'merge.php?com=query&data=[{"query":"dtsrcDownloadsTimeline","dtsrcName":"'+this.datasourceId+'","table":"","fields":[{"fld":"sum","agg":"sum","type":"chart","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":"","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[]}]&info_types=["spline"]&stacking=&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';
259
               */
260

    
261
               this.docsTimelineUrl =this.properties.statisticsFrameAPIURL+'chart.php?com=query&persistent=false&data={"query":"dtsrcYear","dtsrcName":"'+this.datasourceId+'","table": "result", "fields": [{"fld": "number", "agg": "count", "type": "line", "yaxis":1, "c":true}], "xaxis":{"name": "year", "agg": "avg"}, "group": "", "color": "", "type": "chart", "size":30, "sort": "xaxis", "xStyle":{"r": -30, "s": "-", "l": "-", "ft": "-", "wt": "-"}, "yaxisheaders": [""], "fieldsheaders": ["Research Results"], "in": [{"f":0, "text": "Yearly"}], "filters": [{"name":"year","max":"2016","min":"1997"},{"name": "result_datasources-datasource-name", "values":[""], "to": "-1"}],"having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": "Year"}&w=100%&h=250';
262
               this.docsTypesUrl = this.properties.statisticsFrameAPIURL+'chart.php?com=query&persistent=false&data={"query":"dtsrcPubs","dtsrcName":"'+this.datasourceId+'", "table": "result", "fields": [{"fld": "number", "agg": "count", "type": "pie", "yaxis":1, "c":false}], "xaxis":{"name": "result_classifications-type", "agg": "avg"}, "group": "", "color": "", "type": "chart", "size":30, "sort": "xaxis", "xStyle":{"r": "-", "s": "-", "l": "-", "ft": "-", "wt": "-"}, "yaxisheaders": [""], "fieldsheaders": ["Research Results"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [""], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=100%&h=250';
263
               this.docsFunderUrl =this.properties.statisticsFrameAPIURL+'chart.php?com=query&persistent=false&data={"query":"dtsrcPubsFund","dtsrcName":"'+this.datasourceId+'", "table": "result", "fields": [{"fld": "number", "agg": "count", "type": "pie", "yaxis":1, "c":false}], "xaxis":{"name": "result_classifications-type", "agg": "avg"}, "group": "", "color": "", "type": "chart", "size":30, "sort": "xaxis", "xStyle":{"r": "-", "s": "-", "l": "-", "ft": "-", "wt": "-"}, "yaxisheaders": [""], "fieldsheaders": ["Research Results"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [""], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=100%&h=250';
264
               this.dataProjectsUrl =this.properties.statisticsFrameAPIURL+'chart.php?com=query&persistent=false&data={"query":"dtsrcProjData","dtsrcName":"'+this.datasourceId+'", "table": "result", "fields": [{"fld": "number", "agg": "count", "type": "bar", "yaxis":1, "c":false}], "xaxis":{"name": "result_classifications-type", "agg": "avg"}, "group": "", "color": "", "type": "chart", "size":30, "sort": "xaxis", "xStyle":{"r": "-", "s": "-", "l": "-", "ft": "-", "wt": "-"}, "yaxisheaders": [""], "fieldsheaders": ["Research Data"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [""], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=100%&h=250';
265
               this.pubsProjectsUrl =this.properties.statisticsFrameAPIURL+'chart.php?com=query&persistent=false&data={"query":"dtsrcProjPubs","dtsrcName":"'+this.datasourceId+'", "table": "result", "fields": [{"fld": "number", "agg": "count", "type": "bar", "yaxis":1, "c":false}], "xaxis":{"name": "result_classifications-type", "agg": "avg"}, "group": "", "color": "", "type": "chart", "size":30, "sort": "xaxis", "xStyle":{"r": "-", "s": "-", "l": "-", "ft": "-", "wt": "-"}, "yaxisheaders": [""], "fieldsheaders": ["Publications"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [""], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=100%&h=250';
266

    
267
               //if({"name": "Publications", "content": "publicationsTab"} in this.dataProviderInfo.tabs) {
268
               //if(this.dataProviderInfo.tabs.some(function (tab) {
269
               //    return tab.name === 'Publications';
270
               //})) {
271
               //    this.relatedDataprovidersResultsType = 'publications';
272
                   this.fetchAggregatorsPublications = new FetchPublications(this._searchPublicationsService);
273
               //} else {
274
               //   this.relatedDataprovidersResultsType = 'datasets';
275
                   this.fetchAggregatorsDatasets = new FetchDatasets(this._searchDatasetsService);
276
               //}
277
               this.fetchAggregatorsSoftware = new FetchSoftware(this._searchSoftwareService);
278
               this.fetchAggregatorsOrps = new FetchOrps(this._searchOrpsService);
279
           }
280
           if(this.dataProviderInfo.resultsBy == "collectedFrom") {
281
               //this.paramsForSearchLink = "?collectedFrom="+this.datasourceId+"&co=and";
282
               this.paramsForSearchLink = this.routerHelper.createQueryParams(['collectedFrom', 'cl'], [this.datasourceId, 'and']);
283
           } else if (this.dataProviderInfo.resultsBy == "hostedBy") {
284
               //this.paramsForSearchLink = "?hostedBy="+this.datasourceId+"&ho=and";
285
               this.paramsForSearchLink = this.routerHelper.createQueryParams(['hostedBy', 'hs'], [this.datasourceId, 'and']);
286
           }
287

    
288
   }
289

    
290
   private count(page: number, size: number) {
291
       for(let i=0; i<this.dataProviderInfo.tabs.length; i++) {
292
           let content: string = this.dataProviderInfo.tabs[i].content;
293

    
294
           if(content=='publicationsTab') {
295
               this.countPublications(page, size);
296
           } else if(content=='datasetsTab') {
297
               this.countDatasets(page, size);
298
           } else if(content=='softwareTab') {
299
               this.countSoftware(page, size);
300
           } else if(content=='orpsTab') {
301
               this.countOrps(page, size);
302
           } else if(content=='projectsTab') {
303
               this.countProjects(page, size);
304
           } else if(content=='datasourcesTab') {
305
               this.countDatasources(page, size);
306
           }// else if(content=='relatedDatasourcesTab') {
307
           //    this.countRelatedDatasources(page, size);
308
           //}
309
       }
310
   }
311

    
312
   public search(content: string, page: number, size: number) {
313
       if(content=='publicationsTab') {
314
           this.searchPublications(page, size);
315
       } else if(content=='datasetsTab') {
316
           this.searchDatasets(page, size);
317
       } else if(content=='softwareTab') {
318
           this.searchSoftware(page, size);
319
       } else if(content=='orpsTab') {
320
           this.searchOrps(page, size);
321
       } else if(content=='projectsTab') {
322
           this.searchProjects(page, size);
323
       } else if(content=='datasourcesTab') {
324
           this.searchDatasources(page, size);
325
       } else if(content=='relatedDatasourcesTab') {
326
           this.searchRelatedDatasources(1, 0);
327
       } else if(content=='metricsTab') {
328
           this.metricsClicked = true;
329
       } else if(content=='statisticsTab') {
330
           this.statsClicked = !this.statsClicked;
331
       }
332
   }
333

    
334
   private searchPublications(page: number, size: number) {
335
     if(  this.reloadPublications &&
336
          ( this.fetchPublications.searchUtils.status == this.errorCodes.LOADING ||
337
            this.fetchPublications.searchUtils.status == this.errorCodes.DONE ) ) {
338
       this.fetchPublications.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
339
     }
340
     this.reloadPublications = false;
341
    }
342

    
343
    private countPublications(page: number, size: number) {
344
      this.fetchPublications.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
345
    }
346

    
347
    private searchDatasets(page: number, size: number) {
348
      if( this.reloadDatasets &&
349
          ( this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING ||
350
            this.fetchDatasets.searchUtils.status == this.errorCodes.DONE ) ) {
351
        this.fetchDatasets.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
352
      }
353
      this.reloadDatasets = false;
354
    }
355

    
356
    private countDatasets(page: number, size: number) {
357
      this.fetchDatasets.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
358
    }
359

    
360
    private searchSoftware(page: number, size: number) {
361
      if( this.reloadSoftware &&
362
          ( this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING ||
363
            this.fetchSoftware.searchUtils.status == this.errorCodes.DONE ) ) {
364
        this.fetchSoftware.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
365
      }
366
      this.reloadSoftware = false;
367
    }
368

    
369
    private countSoftware(page: number, size: number) {
370
      this.fetchSoftware.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
371
    }
372

    
373
    private searchOrps(page: number, size: number) {
374
      if( this.reloadOrps &&
375
          ( this.fetchOrps.searchUtils.status == this.errorCodes.LOADING ||
376
            this.fetchOrps.searchUtils.status == this.errorCodes.DONE ) ) {
377
        this.fetchOrps.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
378
      }
379
      this.reloadOrps = false;
380
    }
381

    
382
    private countOrps(page: number, size: number) {
383
      this.fetchOrps.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
384
    }
385

    
386
    private searchProjects(page: number, size: number) {
387
      if( this.reloadProjects &&
388
          ( this.fetchProjects.searchUtils.status == this.errorCodes.LOADING ||
389
            this.fetchProjects.searchUtils.status == this.errorCodes.DONE ) ) {
390
        this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
391
      }
392
      this.reloadProjects = false;
393
    }
394

    
395
    private countProjects(page: number, size: number) {
396
      this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
397
    }
398

    
399
    private searchDatasources(page: number, size: number) {
400
      if( this.reloadDataproviders &&
401
          ( this.fetchDataproviders.searchUtils.status == this.errorCodes.LOADING ||
402
            this.fetchDataproviders.searchUtils.status == this.errorCodes.DONE ) ) {
403
        this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
404
      }
405
      this.reloadDataproviders = false;
406
    }
407

    
408
    private countDatasources(page: number, size: number) {
409
      this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
410
    }
411

    
412
    private searchRelatedDatasources(page: number, size: number) {
413
      // Currently no counting is done for this tab. Following condition is always false
414

    
415
      if( this.reloadRelatedDatasources &&
416
          ( this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.LOADING ||
417
            this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.DONE )
418
          &&
419
          ( this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.LOADING ||
420
            this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.DONE )
421
          &&
422
          ( this.fetchAggregatorsSoftware.searchUtils.status == this.errorCodes.LOADING ||
423
            this.fetchAggregatorsSoftware.searchUtils.status == this.errorCodes.DONE )
424
          &&
425
          ( this.fetchAggregatorsOrps.searchUtils.status == this.errorCodes.LOADING ||
426
            this.fetchAggregatorsOrps.searchUtils.status == this.errorCodes.DONE )) {
427
        this.relatedDatasourcesSub = Observable.merge(this.fetchAggregatorsPublications.requestComplete, this.fetchAggregatorsDatasets.requestComplete, this.fetchAggregatorsSoftware.requestComplete, this.fetchAggregatorsOrps.requestComplete)
428
                               .subscribe(
429
                                 data => {},
430
                                 err => {},
431
                                 () => { this.preprocessRelatedDatasources(); }
432
                               )
433

    
434
         this.fetchAggregatorsPublications.getAggregatorResults(this.datasourceId, page, size, this.properties);
435
         this.fetchAggregatorsDatasets.getAggregatorResults(this.datasourceId, page, size, this.properties);
436
         this.fetchAggregatorsSoftware.getAggregatorResults(this.datasourceId, page, size, this.properties);
437
         this.fetchAggregatorsOrps.getAggregatorResults(this.datasourceId, page, size, this.properties);
438
       } else {
439
         this.loadingRelatedDatasources = false;
440
       }
441

    
442

    
443
      this.reloadRelatedDatasources = false;
444
    }
445

    
446
    private countRelatedDatasources(page: number, size: number) {
447
      this.fetchAggregatorsPublications.getAggregatorResults(this.datasourceId, page, size, this.properties);
448
      this.fetchAggregatorsDatasets.getAggregatorResults(this.datasourceId, page, size, this.properties);
449
      this.fetchAggregatorsSoftware.getAggregatorResults(this.datasourceId, page, size, this.properties);
450
      this.fetchAggregatorsOrps.getAggregatorResults(this.datasourceId, page, size, this.properties);
451
    }
452

    
453

    
454
    private preprocessRelatedDatasources() {
455
      if( this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.DONE ||
456
          this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.DONE ||
457
          this.fetchAggregatorsSoftware.searchUtils.status == this.errorCodes.DONE ||
458
          this.fetchAggregatorsOrps.searchUtils.status == this.errorCodes.DONE ) {
459
        this.dataProviderInfo.relatedDatasources = new Map<string, {"name": string, "countPublications": string, "countDatasets": string, "countSoftware": string, "countOrps": string}>();
460
      }
461
      for(let result of this.fetchAggregatorsPublications.results) {
462
        if(!this.dataProviderInfo.relatedDatasources.has(result.id)) {
463
          this.dataProviderInfo.relatedDatasources.set(result.id, {"name": result.name, "countPublications": result.count, "countDatasets": "0", "countSoftware": "0", "countOrps": "0"});
464
        } else {
465
          this.dataProviderInfo.relatedDatasources.get(result.id).countPublications = parseInt(this.dataProviderInfo.relatedDatasources.get(result.id).countPublications + result.count)+"";
466
        }
467
      }
468

    
469
      for(let result of this.fetchAggregatorsDatasets.results) {
470
        if(!this.dataProviderInfo.relatedDatasources.has(result.id)) {
471
          this.dataProviderInfo.relatedDatasources.set(result.id, {"name": result.name, "countPublications": "0", "countDatasets": result.count, "countSoftware": "0", "countOrps": "0"});
472
        } else {
473
          this.dataProviderInfo.relatedDatasources.get(result.id).countDatasets = parseInt(this.dataProviderInfo.relatedDatasources.get(result.id).countDatasets + result.count)+"";
474
        }
475
      }
476

    
477
      for(let result of this.fetchAggregatorsSoftware.results) {
478
        if(!this.dataProviderInfo.relatedDatasources.has(result.id)) {
479
          this.dataProviderInfo.relatedDatasources.set(result.id, {"name": result.name, "countPublications": "0", "countDatasets": "0", "countSoftware": result.count, "countOrps": "0"});
480
        } else {
481
          this.dataProviderInfo.relatedDatasources.get(result.id).countSoftware = parseInt(this.dataProviderInfo.relatedDatasources.get(result.id).countSoftware + result.count)+"";
482
        }
483
      }
484

    
485
      for(let result of this.fetchAggregatorsOrps.results) {
486
        if(!this.dataProviderInfo.relatedDatasources.has(result.id)) {
487
          this.dataProviderInfo.relatedDatasources.set(result.id, {"name": result.name, "countPublications": "0", "countDatasets": "0", "countSoftware": "0", "countOrps": result.count});
488
        } else {
489
          this.dataProviderInfo.relatedDatasources.get(result.id).countOrps = parseInt(this.dataProviderInfo.relatedDatasources.get(result.id).countOrps + result.count)+"";
490
        }
491
      }
492
      this.loadingRelatedDatasources = false;
493
    }
494

    
495
    public metricsResults($event) {
496
      this.totalViews = $event.totalViews;
497
      this.totalDownloads = $event.totalDownloads;
498
      this.pageViews = $event.pageViews;
499
    }
500
}
(3-3/14)