Revision 57061
Added by Konstantinos Triantafyllou over 4 years ago
invite.component.ts | ||
---|---|---|
14 | 14 |
import {CommunityService} from "../../../openaireLibrary/connect/community/community.service"; |
15 | 15 |
import {ErrorCodes} from '../../../openaireLibrary/utils/properties/errorCodes'; |
16 | 16 |
import {ErrorMessagesComponent} from '../../../openaireLibrary/utils/errorMessages.component'; |
17 |
import {Session} from '../../../openaireLibrary/login/utils/helper.class'; |
|
17 |
import {Session, User} from '../../../openaireLibrary/login/utils/helper.class';
|
|
18 | 18 |
import {HelperFunctions} from "../../../openaireLibrary/utils/HelperFunctions.class"; |
19 | 19 |
import {HelperService} from "../../../openaireLibrary/utils/helper/helper.service"; |
20 | 20 |
import {Meta, Title} from "@angular/platform-browser"; |
21 | 21 |
import {SEOService} from "../../../openaireLibrary/sharedComponents/SEO/SEO.service"; |
22 | 22 |
import {PiwikService} from "../../../openaireLibrary/utils/piwik/piwik.service"; |
23 | 23 |
import {PiwikHelper} from "../../piwikHelper"; |
24 |
import {UserManagementService} from "../../../openaireLibrary/services/user-management.service"; |
|
24 | 25 |
|
25 | 26 |
@Component({ |
26 | 27 |
selector: 'invite', |
... | ... | |
68 | 69 |
public url: string = null; |
69 | 70 |
public pageTitle: string = "Invite"; |
70 | 71 |
piwiksub: any; |
72 |
private user: User; |
|
71 | 73 |
|
72 | 74 |
constructor( |
73 | 75 |
private route: ActivatedRoute, |
... | ... | |
79 | 81 |
private _meta: Meta, |
80 | 82 |
private _title: Title, |
81 | 83 |
private seoService: SEOService, |
82 |
private _piwikService: PiwikService) { |
|
84 |
private _piwikService: PiwikService, |
|
85 |
private userManageService: UserManagementService) { |
|
83 | 86 |
|
84 | 87 |
this.errorCodes = new ErrorCodes(); |
85 | 88 |
this.errorMessages = new ErrorMessagesComponent(); |
... | ... | |
92 | 95 |
this.errorMessage = ""; |
93 | 96 |
this.missingCommunityId = ""; |
94 | 97 |
this.status = this.errorCodes.LOADING; |
95 |
this.route.queryParams.subscribe( |
|
96 |
communityId => { |
|
97 |
//if(!this.communityId && typeof document !== 'undefined'){ |
|
98 |
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain); |
|
99 |
if (!this.communityId) { |
|
100 |
this.communityId = communityId['communityId']; |
|
101 |
} |
|
98 |
this.userManageService.getUserInfo(this.properties.userInfoUrl).subscribe(user => { |
|
99 |
this.user = user; |
|
100 |
this.route.queryParams.subscribe( |
|
101 |
communityId => { |
|
102 |
//if(!this.communityId && typeof document !== 'undefined'){ |
|
103 |
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain); |
|
104 |
if (!this.communityId) { |
|
105 |
this.communityId = communityId['communityId']; |
|
106 |
} |
|
102 | 107 |
|
103 |
if(this.longView) { |
|
104 |
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { |
|
105 |
this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe(); |
|
108 |
if (this.longView) { |
|
109 |
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { |
|
110 |
this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe(); |
|
111 |
} |
|
112 |
this.url = this.properties.baseLink + this._router.url; |
|
113 |
this.seoService.createLinkForCanonicalURL(this.url); |
|
114 |
this.updateUrl(this.url); |
|
115 |
this.updateTitle(this.pageTitle); |
|
116 |
this.updateDescription("OpenAIRE - Connect, Community Gateway, research community, invite"); |
|
106 | 117 |
} |
107 |
this.url = this.properties.baseLink + this._router.url; |
|
108 |
this.seoService.createLinkForCanonicalURL(this.url); |
|
109 |
this.updateUrl(this.url); |
|
110 |
this.updateTitle(this.pageTitle); |
|
111 |
this.updateDescription("OpenAIRE - Connect, Community Gateway, research community, invite"); |
|
112 |
} |
|
113 |
this.communityIdParam = (this.properties.environment != "development") ? {} : {communityId: this.communityId}; |
|
114 |
if (this.communityId != null && this.communityId != '') { |
|
115 |
//this.getDivContents(); |
|
116 |
this.getPageContents(); |
|
117 |
this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe( |
|
118 |
community => { |
|
119 |
this.community = community; |
|
120 |
this.fullname = Session.getUserFullName(); |
|
121 |
//console.log("Fullname from session " + Session.getUserFullName()); |
|
118 |
this.communityIdParam = (this.properties.environment != "development") ? {} : {communityId: this.communityId}; |
|
119 |
if (this.communityId != null && this.communityId != '') { |
|
120 |
//this.getDivContents(); |
|
121 |
this.getPageContents(); |
|
122 |
this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe( |
|
123 |
community => { |
|
124 |
this.community = community; |
|
125 |
this.fullname = this.user.fullname; |
|
126 |
//console.log("Fullname from session " + Session.getUserFullName()); |
|
122 | 127 |
|
123 |
this.body = Composer.initializeInvitationsBody(this.communityId, this.community.title, this.fullname); |
|
124 |
this.email = Composer.initializeInvitationsEmail(community.title); |
|
125 |
this.recipients = ""; |
|
128 |
this.body = Composer.initializeInvitationsBody(this.communityId, this.community.title, this.fullname);
|
|
129 |
this.email = Composer.initializeInvitationsEmail(community.title);
|
|
130 |
this.recipients = "";
|
|
126 | 131 |
|
127 |
this.status = this.errorCodes.DONE; |
|
128 |
}, |
|
129 |
error => { |
|
130 |
//this.handleError(error) |
|
131 |
this.handleError("Error getting community with id: " + this.communityId, error); |
|
132 |
this.status = this.errorMessages.getErrorCode(error.status); |
|
133 |
} |
|
134 |
); |
|
135 |
} else { |
|
136 |
this.status = this.errorCodes.DONE; |
|
137 |
this.missingCommunityId = "There is no community selected!"; |
|
138 |
} |
|
132 |
this.status = this.errorCodes.DONE;
|
|
133 |
},
|
|
134 |
error => {
|
|
135 |
//this.handleError(error)
|
|
136 |
this.handleError("Error getting community with id: " + this.communityId, error);
|
|
137 |
this.status = this.errorMessages.getErrorCode(error.status);
|
|
138 |
}
|
|
139 |
);
|
|
140 |
} else {
|
|
141 |
this.status = this.errorCodes.DONE;
|
|
142 |
this.missingCommunityId = "There is no community selected!";
|
|
143 |
}
|
|
139 | 144 |
|
140 |
}); |
|
145 |
});
|
|
141 | 146 |
|
142 |
HelperFunctions.scroll(); |
|
147 |
HelperFunctions.scroll(); |
|
148 |
}); |
|
143 | 149 |
}); |
144 | 150 |
} |
145 | 151 |
|
146 | 152 |
ngOnDestroy() { |
147 |
if(this.piwiksub) { |
|
153 |
if (this.piwiksub) {
|
|
148 | 154 |
this.piwiksub.unsubscribe(); |
149 | 155 |
} |
150 | 156 |
} |
... | ... | |
277 | 283 |
} |
278 | 284 |
*/ |
279 | 285 |
allowEdit() { |
280 |
var email = Session.getUserEmail(); |
|
286 |
if (!this.user) { |
|
287 |
return false; |
|
288 |
} |
|
289 |
var email = this.user.email; |
|
281 | 290 |
var index = -1; |
282 | 291 |
if (email && this.community != null && this.community.managers != null) { |
283 | 292 |
index = this.community.managers.indexOf(email); |
284 | 293 |
} |
285 |
|
|
286 |
return Session.isPortalAdministrator() || Session.isCommunityCurator() || index != -1; |
|
287 |
|
|
288 |
|
|
294 |
return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || index != -1; |
|
289 | 295 |
} |
290 | 296 |
|
291 | 297 |
private handleError(message: string, error) { |
Also available in: Unified diff
[Connect]: Change user login check with user management service.