Project

General

Profile

1
import {Component} 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

    
16
@Component({
17
  selector: 'share-in-zenodo',
18
  templateUrl: './shareInZenodo.component.html'
19
})
20
export class ShareInZenodoComponent {
21
  properties: EnvProperties;
22
  private communityId: string = null;
23
  private community: CommunityInfo = null;
24
  public pageContents = null;
25
  public divContents = null;
26

    
27

    
28
  // public warningMessage = "";
29
  // public infoMessage = "";
30

    
31
  masterZenodoCommunityId = null;
32
  masterZenodoCommunity = null;
33

    
34
  CommunityIds = null;
35
  communities = [];
36

    
37
  zenodocommunitiesloadedCount = 0;
38
  zenodoSearchUtils: SearchUtilsClass = new SearchUtilsClass();
39
  errorCodes: ErrorCodes = new ErrorCodes();
40
  depositLink = "https://zenodo.org/deposit/new?c=";
41

    
42

    
43
  constructor(private  route: ActivatedRoute,
44
              private _router: Router,
45
              private _meta: Meta,
46
              private _title: Title,
47
              private _ΖenodoCommunitieService: ZenodoCommunitiesService,
48
              private _communityService: CommunityService,
49
              private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService,
50
              private helper: HelperService) {
51
  }
52

    
53
  public ngOnInit() {
54
    this.zenodoSearchUtils.status = this.errorCodes.LOADING;
55
    ;
56
    this.route.data
57
      .subscribe((data: { envSpecific: EnvProperties }) => {
58
        this.updateUrl(data.envSpecific.baseLink + this._router.url);
59
        this.updateTitle("Share in Zenodo");
60
        this.updateDescription("Zenodo, repository, deposit, share");
61
        this.properties = data.envSpecific;
62
        this.route.queryParams.subscribe(params => {
63
          this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
64
          if (!this.communityId) {
65
            this.communityId = params['communityId'];
66
          }
67
          //this.getDivContents();
68
          this.getPageContents();
69
          if (this.communityId) {
70

    
71
            if (this.communityId != null && this.communityId != '') {
72

    
73
              this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
74
                community => {
75
                  this.community = community;
76
                  this.masterZenodoCommunityId = this.community.zenodoCommunity;
77
                  if (typeof document !== 'undefined') {
78
                    HelperFunctions.scroll();
79
                  }
80
                  if (this.masterZenodoCommunityId) {
81
                    this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.masterZenodoCommunityId, null).subscribe(
82
                      result => {
83
                        this.masterZenodoCommunity = result;
84

    
85
                      },
86
                      error => {
87
                        this.handleError("Error getting Master Zenodo community with id: " + this.masterZenodoCommunityId, error);
88

    
89
                      }
90
                    );
91
                  }
92
                  this.zenodoSearchUtils.status = this.errorCodes.LOADING;
93
                  ;
94
                  this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
95
                    result => {
96
                      this.CommunityIds = result;
97
                      this.zenodoSearchUtils.totalResults = this.CommunityIds.length;
98
                      if (this.CommunityIds.length == 0) {
99
                        this.zenodoSearchUtils.status = this.errorCodes.NONE;
100
                      }
101
                      for (let i = 0; i < this.CommunityIds.length; i++) {
102
                        this.getZenodoCommunityById(this.CommunityIds[i]["zenodoid"], this.CommunityIds[i]["id"]);
103
                      }
104

    
105
                    },
106
                    error => {
107
                      //console.error("list of zenodo communities couldn't be loaded");
108
                      this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
109
                      this.zenodoSearchUtils.status = this.errorCodes.ERROR;
110
                    } //this.handleError('System error retrieving community profile', error)
111
                  );
112

    
113
                },
114
                error => {
115
                  //console.error("Community couldn't be loaded");
116
                  this.handleError("Error getting community with id: " + this.communityId, error);
117
                  this.zenodoSearchUtils.status = this.errorCodes.ERROR;
118
                }
119
              );
120

    
121

    
122
            }
123

    
124

    
125
          }
126
        });
127
      });
128
  }
129

    
130

    
131
  private updateDescription(description: string) {
132
    this._meta.updateTag({content: description}, "name='description'");
133
    this._meta.updateTag({content: description}, "property='og:description'");
134
  }
135

    
136
  private updateTitle(title: string) {
137
    var _prefix = "OpenAIRE | ";
138
    var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
139
    this._title.setTitle(_title);
140
    this._meta.updateTag({content: _title}, "property='og:title'");
141
  }
142

    
143
  private updateUrl(url: string) {
144
    this._meta.updateTag({content: url}, "property='og:url'");
145
  }
146

    
147
  private getPageContents() {
148
    this.helper.getPageHelpContents(this._router.url, this.properties, 'connect').subscribe(contents => {
149
      this.pageContents = contents;
150
    })
151
  }
152

    
153
  private getDivContents() {
154
    this.helper.getDivHelpContents(this._router.url, this.properties, 'connect').subscribe(contents => {
155
      this.divContents = contents;
156
    })
157
  }
158

    
159
  getZenodoCommunityById(zenodoid, openaireId) {
160
    this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + zenodoid, openaireId).subscribe(
161
      result => {
162
        this.communities.push(result);
163
        this.zenodocommunitiesloadedCount++;
164
        if (this.zenodocommunitiesloadedCount >= this.CommunityIds.length) {
165
          this.zenodoSearchUtils.status = this.errorCodes.DONE;
166
        }
167

    
168

    
169
      },
170
      error => {
171
        // var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
172
        // emptyCommunity.id = zenodoid;
173
        // emptyCommunity.openaireId = openaireId;
174
        // emptyCommunity.title = zenodoid;
175
        // this.communities.push(emptyCommunity);
176
        this.zenodocommunitiesloadedCount++;
177
        if (this.zenodocommunitiesloadedCount >= this.CommunityIds.length) {
178
          this.zenodoSearchUtils.status = this.errorCodes.DONE;
179
        }
180
        //console.error("Zenodo community'"+zenodoid+"' couldn't be loaded");
181
        this.handleError("Error getting Zenodo community with id: " + zenodoid + " and openaire id: " + openaireId, error);
182

    
183
      }
184
    );
185
  }
186

    
187
  private handleError(message: string, error) {
188
    console.error("Share in Zenodo Page: " + message, error);
189
  }
190
}
(3-3/4)