Project

General

Profile

1
import {Component, Input} from '@angular/core';
2
import {ActivatedRoute} from '@angular/router';
3

    
4
import {PiwikHelper} from '../../utils/piwikHelper';
5
import {ConnectHelper} from '../../openaireLibrary/connect/connectHelper';
6
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
7

    
8
import {ZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service';
9
import {SearchZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunities.service';
10
import {CommunityService} from '../../openaireLibrary/connect/community/community.service';
11

    
12
import {ZenodoInformationClass} from '../../openaireLibrary/deposit/utils/zenodoInformation.class';
13
import {FetchZenodoInformation} from '../utils/fetchZenodoInformation.class';
14

    
15
@Component({
16
    selector: 'openaire-deposit-datasets',
17
    template: `
18
    <deposit-datasets [piwikSiteId]=piwikSiteId [zenodoInformation]="zenodoInformation">
19

    
20
</deposit-datasets>
21
    `
22
})
23

    
24
export class OpenaireDepositDatasetsComponent {
25
  public zenodoInformation: ZenodoInformationClass = new ZenodoInformationClass();
26
  properties:EnvProperties;
27
  fetchZenodoInformation: FetchZenodoInformation;
28

    
29
  piwikSiteId = null;
30
  constructor ( private  route: ActivatedRoute,
31
                private _ΖenodoCommunitieService: ZenodoCommunitiesService,
32
                private _communityService: CommunityService,private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService ) {
33
    this.fetchZenodoInformation = new FetchZenodoInformation(this._ΖenodoCommunitieService, this._searchZenodoCommunitiesService);
34
  }
35

    
36
  public ngOnInit() {
37
    this.route.data
38
      .subscribe((data: { envSpecific: EnvProperties }) => {
39
          this.properties = data.envSpecific;
40
          this.route.queryParams.subscribe(params => {
41
             var communityId = params['communityId'];
42
             if(!communityId){
43
                communityId  = ConnectHelper.getCommunityFromDomain(this.properties.domain);
44
              }
45
             this.piwikSiteId = PiwikHelper.siteIDs[communityId];
46

    
47
             if(communityId) {
48

    
49
                if (communityId != null && communityId != '') {
50

    
51
                    this._communityService.getCommunity(this.properties, this.properties.communityAPI+communityId).subscribe (
52
                      community => {
53
                            var community = community;
54
                            var masterZenodoCommunityId = community.zenodoCommunity;
55
                            if(masterZenodoCommunityId){
56
                              this.fetchZenodoInformation.getZenodoCommunityNameAndUrlById(masterZenodoCommunityId, this.properties, this.zenodoInformation);
57
                            }
58
                            this.fetchZenodoInformation.searchNumberOfZCommunities(communityId, this.properties, this.zenodoInformation);
59
                       },
60
                      error => {
61
                        //console.error("Community couldn't be loaded");
62
                        this.handleError("Error getting community with id: "+communityId, error);
63
                      }
64
                    );
65
                }
66
            }
67
          });
68
        });
69
  }
70

    
71
  private handleError(message: string, error) {
72
      console.error("Deposit Research Data Page: "+message, error);
73
  }
74
}
(5-5/9)