Project

General

Profile

1
import {Component, Input} from '@angular/core';
2
import {ActivatedRoute} from '@angular/router';
3
import {PiwikHelper} from '../../utils/piwikHelper';
4
import {ConnectHelper} from '../../openaireLibrary/connect/connectHelper';
5
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
6

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

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

    
14

    
15
@Component({
16
    selector: 'openaire-deposit-publications-result',
17
    template: `
18
        <deposit-publications-result [piwikSiteId]=piwikSiteId [zenodoInformation]="zenodoInformation"></deposit-publications-result>
19
    `
20
})
21

    
22
export class OpenaireDepositPublicationsResultComponent {
23
  public zenodoInformation: ZenodoInformationClass = new ZenodoInformationClass();
24
  properties:EnvProperties;
25
  fetchZenodoInformation: FetchZenodoInformation;
26

    
27
  piwikSiteId = null;
28

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

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

    
45
             this.piwikSiteId = PiwikHelper.siteIDs[communityId];
46

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

    
69
  private handleError(message: string, error) {
70
      console.error("Deposit Publications Result Page: "+message, error);
71
  }
72
}
(5-5/6)