Project

General

Profile

« Previous | Next » 

Revision 59141

[Trunk | Connect]:
1. app.module.ts & directLinking.module.ts & linkingGeneric.module.ts & community.module.ts & deposit.module.ts &
searchDataprovidersToDeposit.module.ts & shareInZenodo.module.ts & subjects.module.ts &
invite.module.ts & inviteBasic.module.ts & subscribe.module.ts:
Remove CommunityService from providers (singleton service, providedIn: 'root').
2. community.component.ts & curators.component.ts & deposit.component.ts &
searchDataprovidersToDeposit.component.ts & shareInZenodo.component.ts & statistics.component.ts & subjects.component.ts &
invite.component.ts & subscribe.component.ts:
Get community from state (call communityService.getCommunityByState) | Add subscriptions in array to unsubscribe in ngOnDestroy | Get properties from environment (no service needed).

View differences:

shareInZenodo.component.ts
17 17
import {PiwikService} from "../../openaireLibrary/utils/piwik/piwik.service";
18 18
import {PiwikHelper} from "../../utils/piwikHelper";
19 19
import {Breadcrumb} from "../../openaireLibrary/utils/breadcrumbs/breadcrumbs.component";
20
import {properties} from "../../../environments/environment";
21
import {Subscription} from "rxjs";
20 22

  
21 23
@Component({
22 24
  selector: 'share-in-zenodo',
......
26 28
  public url: string = null;
27 29
  public title: string = "Share in Zenodo";
28 30

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

  
32 33
  properties: EnvProperties;
......
52 53
  depositLearnHowPage: string = null;
53 54
  public routerHelper:RouterHelper = new RouterHelper();
54 55
  breadcrumbs:Breadcrumb[] = [];
56

  
57
  subs: Subscription[] = [];
58

  
55 59
  constructor(private  route: ActivatedRoute,
56 60
              private _router: Router,
57 61
              private _meta: Meta,
......
67 71
  public ngOnInit() {
68 72
    this.zenodoSearchUtils.status = this.errorCodes.LOADING;
69 73

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

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

  
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
          }
81
    this.properties = properties;
82
    this.subs.push(this.route.queryParams.subscribe(params => {
83
      this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
84
      if (!this.communityId) {
85
        this.communityId = params['communityId'];
86
      }
85 87

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

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

  
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
      this.depositLearnHowPage = this.properties.depositLearnHowPage;
95
      this.breadcrumbs.push({name: 'home', route: '/'}, {name: "Deposit", route: this.depositLearnHowPage},{name:"Deposit in zenodo",route:null});
94 96

  
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;
97
      //this.getDivContents();
98
      this.getPageContents();
99
      if (this.communityId && this.communityId != '') {
100
        this.subs.push(this._communityService.getCommunityByState(this.properties, this.properties.communityAPI + this.communityId).subscribe(
101
          community => {
102
            this.community = community;
103
            this.masterZenodoCommunityId = this.community.zenodoCommunity;
104
            if (typeof document !== 'undefined') {
105
              HelperFunctions.scroll();
106
            }
107
            if (this.masterZenodoCommunityId) {
108
              this.subs.push(this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.masterZenodoCommunityId, null).subscribe(
109
                result => {
110
                  this.masterZenodoCommunity = result;
109 111

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

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

  
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
                    }
121
            this.subs.push(this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
122
              result => {
123
                this.CommunityIds = result;
124
                this.zenodoSearchUtils.totalResults = this.CommunityIds.length;
125
                if (this.CommunityIds.length == 0) {
126
                  this.zenodoSearchUtils.status = this.errorCodes.NONE;
127
                }
128
                for (let i = 0; i < this.CommunityIds.length; i++) {
129
                  this.getZenodoCommunityById(this.CommunityIds[i]["zenodoid"], this.CommunityIds[i]["id"]);
130
                }
129 131

  
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 132
              },
139 133
              error => {
140
                //console.error("Community couldn't be loaded");
141
                this.handleError("Error getting community with id: " + this.communityId, error);
134
                //console.error("list of zenodo communities couldn't be loaded");
135
                this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
142 136
                this.zenodoSearchUtils.status = this.errorCodes.ERROR;
143
              }
144
            );
137
              } //this.handleError('System error retrieving community profile', error)
138
            ));
139

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

  
151
  public ngOnDestroy() {
152
    for (let sub of this.subs) {
153
      sub.unsubscribe();
154
    }
155
  }
150 156

  
151 157
  private updateDescription(description: string) {
152 158
    this._meta.updateTag({content: description}, "name='description'");
......
164 170
  }
165 171

  
166 172
  private getPageContents() {
167
    this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
173
    this.subs.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
168 174
      this.pageContents = contents;
169
    })
175
    }));
170 176
  }
171 177

  
172 178
  private getDivContents() {
173
    this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
179
    this.subs.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
174 180
      this.divContents = contents;
175
    })
181
    }));
176 182
  }
177 183

  
178 184
  getZenodoCommunityById(zenodoid, openaireId) {
179
    this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + zenodoid, openaireId).subscribe(
185
    this.subs.push(this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + zenodoid, openaireId).subscribe(
180 186
      result => {
181 187
        this.communities.push(result);
182 188
        this.zenodocommunitiesloadedCount++;
......
200 206
        this.handleError("Error getting Zenodo community with id: " + zenodoid + " and openaire id: " + openaireId, error);
201 207

  
202 208
      }
203
    );
209
    ));
204 210
  }
205 211

  
206 212
  private handleError(message: string, error) {

Also available in: Unified diff