Project

General

Profile

1
import {Component, Input} from '@angular/core';
2
import {ActivatedRoute, Router} from '@angular/router';
3
import {Meta, Title} from '@angular/platform-browser';
4
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
5
import {ZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service';
6
import {SearchZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunities.service';
7
import {CommunityService} from '../../openaireLibrary/connect/community/community.service';
8
import {ConnectHelper} from '../../openaireLibrary/connect/connectHelper';
9

    
10
import {CommunityInfo} from '../../openaireLibrary/connect/community/communityInfo';
11
import {SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
12
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
13
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";
14
import {HelperService} from "../../openaireLibrary/utils/helper/helper.service";
15
import {RouterHelper} from "../../openaireLibrary/utils/routerHelper.class";
16
import {SEOService} from "../../openaireLibrary/sharedComponents/SEO/SEO.service";
17
import {PiwikService} from "../../openaireLibrary/utils/piwik/piwik.service";
18
import {PiwikHelper} from "../../utils/piwikHelper";
19
import {Breadcrumb} from "../../openaireLibrary/utils/breadcrumbs/breadcrumbs.component";
20

    
21
@Component({
22
  selector: 'share-in-zenodo',
23
  templateUrl: './shareInZenodo.component.html'
24
})
25
export class ShareInZenodoComponent {
26
  public url: string = null;
27
  public title: string = "Share in Zenodo";
28

    
29
  piwiksub:any;
30
  public piwikSiteId = null;
31

    
32
  properties: EnvProperties;
33
  communityId: string = null;
34
  private community: CommunityInfo = null;
35
  public pageContents = null;
36
  public divContents = null;
37

    
38

    
39
  // public warningMessage = "";
40
  // public infoMessage = "";
41

    
42
  masterZenodoCommunityId = null;
43
  masterZenodoCommunity = null;
44

    
45
  CommunityIds = null;
46
  communities = [];
47

    
48
  zenodocommunitiesloadedCount = 0;
49
  zenodoSearchUtils: SearchUtilsClass = new SearchUtilsClass();
50
  errorCodes: ErrorCodes = new ErrorCodes();
51
  depositLink = "https://zenodo.org/deposit/new?c=";
52
  depositLearnHowPage: string = null;
53
  public routerHelper:RouterHelper = new RouterHelper();
54
  breadcrumbs:Breadcrumb[] = [];
55
  constructor(private  route: ActivatedRoute,
56
              private _router: Router,
57
              private _meta: Meta,
58
              private _title: Title,
59
              private _ΖenodoCommunitieService: ZenodoCommunitiesService,
60
              private _communityService: CommunityService,
61
              private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService,
62
              private helper: HelperService,
63
              private _piwikService:PiwikService,
64
              private seoService: SEOService) {
65
  }
66

    
67
  public ngOnInit() {
68
    this.zenodoSearchUtils.status = this.errorCodes.LOADING;
69

    
70
    this.route.data
71
      .subscribe((data: { envSpecific: EnvProperties }) => {
72
        this.url = data.envSpecific.baseLink + this._router.url;
73

    
74
        this.seoService.createLinkForCanonicalURL(this.url, false);
75
        this.updateUrl(this.url);
76
        this.updateTitle(this.title);
77
        this.updateDescription("Zenodo, repository, deposit, share");
78

    
79
        this.properties = data.envSpecific;
80
        this.route.queryParams.subscribe(params => {
81
          this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
82
          if (!this.communityId) {
83
            this.communityId = params['communityId'];
84
          }
85

    
86
          this.piwikSiteId = PiwikHelper.getSiteId(this.communityId,this.properties.environment);
87

    
88
          if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
89
            this.piwiksub = this._piwikService.trackView(this.properties, this.title, this.piwikSiteId).subscribe();
90
          }
91

    
92
          this.depositLearnHowPage = this.properties.depositLearnHowPage;
93
          this.breadcrumbs.push({name: 'home', route: '/'}, {name: "Deposit", route: this.depositLearnHowPage},{name:"Deposit in zenodo",route:null});
94

    
95
          //this.getDivContents();
96
          this.getPageContents();
97
          if (this.communityId && this.communityId != '') {
98
            this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
99
              community => {
100
                this.community = community;
101
                this.masterZenodoCommunityId = this.community.zenodoCommunity;
102
                if (typeof document !== 'undefined') {
103
                  HelperFunctions.scroll();
104
                }
105
                if (this.masterZenodoCommunityId) {
106
                  this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.masterZenodoCommunityId, null).subscribe(
107
                    result => {
108
                      this.masterZenodoCommunity = result;
109

    
110
                    },
111
                    error => {
112
                      this.handleError("Error getting Master Zenodo community with id: " + this.masterZenodoCommunityId, error);
113

    
114
                    }
115
                  );
116
                }
117
                this.zenodoSearchUtils.status = this.errorCodes.LOADING;
118

    
119
                this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
120
                  result => {
121
                    this.CommunityIds = result;
122
                    this.zenodoSearchUtils.totalResults = this.CommunityIds.length;
123
                    if (this.CommunityIds.length == 0) {
124
                      this.zenodoSearchUtils.status = this.errorCodes.NONE;
125
                    }
126
                    for (let i = 0; i < this.CommunityIds.length; i++) {
127
                      this.getZenodoCommunityById(this.CommunityIds[i]["zenodoid"], this.CommunityIds[i]["id"]);
128
                    }
129

    
130
                  },
131
                  error => {
132
                    //console.error("list of zenodo communities couldn't be loaded");
133
                    this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
134
                    this.zenodoSearchUtils.status = this.errorCodes.ERROR;
135
                  } //this.handleError('System error retrieving community profile', error)
136
                );
137

    
138
              },
139
              error => {
140
                //console.error("Community couldn't be loaded");
141
                this.handleError("Error getting community with id: " + this.communityId, error);
142
                this.zenodoSearchUtils.status = this.errorCodes.ERROR;
143
              }
144
            );
145
          }
146
        });
147
      });
148
  }
149

    
150

    
151
  private updateDescription(description: string) {
152
    this._meta.updateTag({content: description}, "name='description'");
153
    this._meta.updateTag({content: description}, "property='og:description'");
154
  }
155

    
156
  private updateTitle(title: string) {
157
    var _title = ((title.length > 50) ? title.substring(0, 50) : title);
158
    this._title.setTitle(_title);
159
    this._meta.updateTag({content: _title}, "property='og:title'");
160
  }
161

    
162
  private updateUrl(url: string) {
163
    this._meta.updateTag({content: url}, "property='og:url'");
164
  }
165

    
166
  private getPageContents() {
167
    this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
168
      this.pageContents = contents;
169
    })
170
  }
171

    
172
  private getDivContents() {
173
    this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
174
      this.divContents = contents;
175
    })
176
  }
177

    
178
  getZenodoCommunityById(zenodoid, openaireId) {
179
    this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + zenodoid, openaireId).subscribe(
180
      result => {
181
        this.communities.push(result);
182
        this.zenodocommunitiesloadedCount++;
183
        if (this.zenodocommunitiesloadedCount >= this.CommunityIds.length) {
184
          this.zenodoSearchUtils.status = this.errorCodes.DONE;
185
        }
186

    
187

    
188
      },
189
      error => {
190
        // var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
191
        // emptyCommunity.id = zenodoid;
192
        // emptyCommunity.openaireId = openaireId;
193
        // emptyCommunity.title = zenodoid;
194
        // this.communities.push(emptyCommunity);
195
        this.zenodocommunitiesloadedCount++;
196
        if (this.zenodocommunitiesloadedCount >= this.CommunityIds.length) {
197
          this.zenodoSearchUtils.status = this.errorCodes.DONE;
198
        }
199
        //console.error("Zenodo community'"+zenodoid+"' couldn't be loaded");
200
        this.handleError("Error getting Zenodo community with id: " + zenodoid + " and openaire id: " + openaireId, error);
201

    
202
      }
203
    );
204
  }
205

    
206
  private handleError(message: string, error) {
207
    console.error("Share in Zenodo Page: " + message, error);
208
  }
209
}
(3-3/4)