[Connect]: Add check if isClient to getUserInfo

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@57546 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-11-08 11:04:10 +00:00
parent 624cf9b11b
commit 3b8776b00e
6 changed files with 176 additions and 188 deletions

View File

@ -22,11 +22,13 @@ import {UserManagementService} from "./openaireLibrary/services/user-management.
<navbar *ngIf="properties && showMenu && !community && loginCheck" [portal]="properties.dashboard" [onlyTop]=false
[userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
[showMenu]=showMenu [properties]="properties" [showHomeMenuItem]="true"></navbar>
<navbar *ngIf="properties && showMenu && community && loginCheck" [portal]="properties.dashboard" [onlyTop]=false [communityId]="community.id"
<navbar *ngIf="properties && showMenu && community && loginCheck" [portal]="properties.dashboard" [onlyTop]=false
[communityId]="community.id"
[userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
[community]=community [showMenu]=showMenu [properties]="properties" [enableSearch]="true"
[showHomeMenuItem]="true"></navbar>
<customization *ngIf="properties && community" [properties]="properties" [communityId]="community.id"></customization>
<customization *ngIf="properties && community" [properties]="properties"
[communityId]="community.id"></customization>
<div class="custom-main-content">
<main>
<router-outlet></router-outlet>
@ -85,10 +87,31 @@ export class AppComponent {
this.propertiesService.loadEnvironment()
.then(es => {
this.properties = this.propertiesService.envSpecific;
var communityId: string = "";
this._communitiesService.updateCommunities(this.properties, this.properties.communitiesAPI);
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
if (typeof document !== 'undefined') {
try {
this.isClient = true;
} catch (e) {
}
}
if(this.isClient) {
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.init();
});
} else {
this.user = null;
this.init();
}
}, error => {
console.log("App couldn't fetch properties");
console.log(error);
});
}
private init() {
let communityId: string = "";
this.loginCheck = true;
if (this.properties.environment == "development") {
this.showMenu = false;
@ -101,18 +124,6 @@ export class AppComponent {
communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
this.buildMenu(communityId);
}
if (typeof document !== 'undefined') {
try {
this.isClient = true;
} catch (e) {
}
}
}, error => {
console.log("App couldn't fetch properties");
console.log(error);
});
});
}
public buildMenu(communityId: string) {
@ -170,13 +181,7 @@ export class AppComponent {
this.menuItems.push({
rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
items: [
/*
new MenuItem("","Zenodo Communities","","/participate/share-zenodo",false,[],["/participate/share-zenodo"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
new MenuItem("","Publications","","/participate/deposit-publications",false,["publication"],["/participate/deposit-publications"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
new MenuItem("","Research Data","","/participate/deposit-datasets",false,["dataset"],["/participate/deposit-datasets"],this.properties.environment!="development"?{}:{communityId:community.communityId})
*/
]
items: []
});
this.menuItems.push(
{
@ -203,21 +208,6 @@ export class AppComponent {
rootItem: new MenuItem("about", "About", "", "/about/learn-how", false, [], null, {}),
items: []
});
var myCommunities = [];
/*if(this.managerOfCommunities){
myCommunities.push( new MenuItem("","Managing communities","","/search/find/communities",false,[],[],{role:"%22manager%22"}))
}
if(Session.isLoggedIn()){
this._subscribeService.getCommunitiesSubscribedTo(this.properties, Session.getUserEmail()).subscribe (
pids => {
if(pids.length > 0 ) {
myCommunities.push( new MenuItem("","Subscribed to communities","","/search/find/communities",false,[],[],{status:"%22subscribed%22"}))
}
},
error => {
console.error("Error fetching your subscribed communities")
});
}*/
this.menuItems.push({
rootItem: new MenuItem("communities", "Communities", "", "/search/find/communities", false, [], null, {}),
items: []
@ -226,52 +216,24 @@ export class AppComponent {
rootItem: new MenuItem("join", "Join", "", "/contact-us", false, [], null, {}),
items: []
});
/*if(this.managerOfCommunities || this.subscriberOfCommunities){
let myCommunitiesMenu = new MenuItem("myCommunities","My Communities","","",false,[],[],{});
myCommunitiesMenu.setMarkAsActive(false);
this.menuItems.push({rootItem: myCommunitiesMenu, items: myCommunities});
}*/
this.bottomMenuItems = [
new MenuItem("", "About", "https://beta.openaire.eu/project-factsheets", "", false, [], [], {}),
new MenuItem("", "News - Events", "https://beta.openaire.eu/news-events", "", false, [], [], {}),
new MenuItem("", "Blog", "https://blogs.openaire.eu/", "", false, [], [], {}),
new MenuItem("", "Contact us", "https://beta.openaire.eu/contact-us", "", false, [], [], {})
];
// if(this.properties.showContent){
// this.bottomMenuItems.push(new MenuItem("","Content Policy","","/content",false,[],[],{}));
// }
this.userMenuItems = [
// new MenuItem("","My links","","/myclaims",false,[],["/myclaims"],(data['communityId'] && typeof document !== 'undefined' && ConnectHelper.isProduction(document.location.hostname))?{}:{communityId:data['communityId']}),
];
this.userMenuItems = [];
if (Session.isPortalAdministrator(this.user)) {
//((this.properties.environment == "beta") ? "https://beta.admin.connect.openaire.eu" : "https://admin.explore.openaire.eu") + "/dashboard?communityId=openaire"
this.userMenuItems.push(new MenuItem("", "Manage Helptexts",
((this.properties.environment == "production") ? "https://admin.explore.openaire.eu" : "https://beta.admin.connect.openaire.eu") + "/dashboard?communityId=connect",
"", false, [], [], {}))
}
/*if(this.managerOfCommunities){
this.userMenuItems.push( new MenuItem("","Managing communities","","/search/find/communities",false,[],[],{role:"%22manager%22"}))
}
if(Session.isLoggedIn()){
this._subscribeService.getCommunitiesSubscribedTo(this.properties, Session.getUserEmail()).subscribe (
pids => {
if(pids.length > 0 ) {
this.userMenuItems.push( new MenuItem("","Subscribed to communities","","/search/find/communities",false,[],[],{status:"%22subscribed%22"}))
}
},
error => {
console.error("Error fetching your subscribed communities")
});
}*/
if (this.user) {
this.userMenuItems.push(new MenuItem("my-communities", "My Communities", "",
"/myCommunities", false, [], [], {}));
}
} else {
this.bottomMenuItems = [
// new MenuItem("","About","","/about",false,[],["/about"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
new MenuItem("", "Organizations", "", "/organizations", false, [], ["/organizations"], this.properties.environment != "development" ? {} : {communityId: community.communityId})
];
if (this.properties.showContent) {

View File

@ -123,10 +123,15 @@ export class CommunityComponent {
this.url = data.envSpecific.baseLink + this._router.url;
this.seoService.createLinkForCanonicalURL(this.url, false);
this._meta.updateTag({content: this.url}, "property='og:url'");
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
if (typeof document !== 'undefined') {
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.loginCheck = true;
})
});
} else {
this.user = null;
this.loginCheck = true;
}
if (this.communityId != null && this.communityId != '') {
this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
community => {

View File

@ -76,12 +76,14 @@ export class MyCommunitiesComponent {
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE Connect", this.properties.piwikSiteId).subscribe();
}
if (typeof document !== 'undefined') {
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.getCommunities();
//this.getDivContents();
//this.getPageContents();
});
}
});
}

View File

@ -81,10 +81,14 @@ export class SearchCommunitiesComponent {
}
this.searchPage.refineFields = this.refineFields;
let queryParams = this.searchPage.getQueryParamsFromUrl(params);
if(typeof document !== 'undefined') {
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.initCommunities(queryParams);
});
} else {
this.initCommunities(queryParams);
}
});
}

View File

@ -95,8 +95,24 @@ export class InviteComponent implements OnInit {
this.errorMessage = "";
this.missingCommunityId = "";
this.status = this.errorCodes.LOADING;
if (typeof document !== 'undefined') {
this.userManageService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.init();
});
} else {
this.init();
}
});
}
ngOnDestroy() {
if (this.piwiksub) {
this.piwiksub.unsubscribe();
}
}
private init() {
this.route.queryParams.subscribe(
communityId => {
//if(!this.communityId && typeof document !== 'undefined'){
@ -122,7 +138,7 @@ export class InviteComponent implements OnInit {
this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
community => {
this.community = community;
this.fullname = this.user.fullname;
this.fullname = (this.user) ? this.user.fullname : null;
//console.log("Fullname from session " + Session.getUserFullName());
this.body = Composer.initializeInvitationsBody(this.communityId, this.community.title, this.fullname);
@ -143,16 +159,7 @@ export class InviteComponent implements OnInit {
}
});
HelperFunctions.scroll();
});
});
}
ngOnDestroy() {
if (this.piwiksub) {
this.piwiksub.unsubscribe();
}
}
private getPageContents() {

View File

@ -69,8 +69,18 @@ export class SubscribeComponent {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
if (typeof document !== 'undefined') {
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.init();
});
} else {
this.init();
}
});
}
private init() {
if (!this.showNumbers) {
let email = (this.user)?this.user.email:null;
if (email == null) {
@ -115,8 +125,6 @@ export class SubscribeComponent {
}
);
}
});
});
}
subscribe() {