diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index c960e56..0eb1851 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -20,6 +20,8 @@ const routes: Routes = [ { path: 'organizations', loadChildren: './htmlPages/organizations/organizationsPage.module#OrganizationsPageModule', resolve: { envSpecific: EnvironmentSpecificResolver }}, { path: 'curators', loadChildren: './curators/curators.module#CuratorsModule', resolve: { envSpecific: EnvironmentSpecificResolver }}, + { path: 'myCommunities', loadChildren: './my-communities/my-communities.module#MyCommunitiesModule', resolve: { envSpecific: EnvironmentSpecificResolver }}, + // Testing Page for help contents { path: 'helper-test', loadChildren: './helper-test/helper-test.module#HelperTestModule', resolve: { envSpecific: EnvironmentSpecificResolver }}, diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 3115eac..90f2fe1 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,5 +1,5 @@ import {Component} from '@angular/core'; -import {ActivatedRoute, ActivationEnd, NavigationStart, Router, RoutesRecognized} from '@angular/router'; +import {ActivatedRoute, NavigationStart, Router} from '@angular/router'; import {EnvProperties} from './openaireLibrary/utils/properties/env-properties'; import {MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu'; @@ -17,242 +17,268 @@ import {HelperFunctions} from "./openaireLibrary/utils/HelperFunctions.class"; styles: [` `], template: ` -
- - - -
-
- -
-
- - - OpenAIRE uses cookies in order to function properly.
- Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing experience possible. - By using the OpenAIRE portal you accept our use of cookies. Read more - - -
- - +
+ + + +
+
+ +
-` + + + OpenAIRE uses cookies in order to function properly.
+ Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing + experience possible. + By using the OpenAIRE portal you accept our use of cookies. Read more + + +
+ + +
+ ` }) export class AppComponent { - isClient:boolean = false; + isClient: boolean = false; - userMenuItems:MenuItem[] =[]; + userMenuItems: MenuItem[] = []; - menuItems:RootMenuItem []=[]; - bottomMenuItems:MenuItem[] =[]; + menuItems: RootMenuItem [] = []; + bottomMenuItems: MenuItem[] = []; public community = null; - properties:EnvProperties; - showMenu:boolean = false; + properties: EnvProperties; + showMenu: boolean = false; communities = null; subscriberOfCommunities = false; managerOfCommunities = false; + // community: {id:string, name:string, logoUrl:string}; - constructor( private route: ActivatedRoute, private propertiesService:EnvironmentSpecificService, - private _communitiesService:CommunitiesService, private _subscribeService: SubscribeService, - private router: Router) { - router.events.forEach((event) => { - if (event instanceof NavigationStart) { - HelperFunctions.scroll(); - } - }); - } - - ngOnInit() { - this.propertiesService.loadEnvironment() - .then(es => { - this.properties = this.propertiesService.envSpecific; - var communityId: string = ""; - this._communitiesService.updateCommunities(this.properties, this.properties.communitiesAPI); - if (this.properties.environment == "development") { - this.showMenu = false; - this.route.queryParams.subscribe(params => { - communityId = (params['communityId'])?params['communityId'] : ''; - this.buildMenu(communityId); - }) - } else { - this.showMenu = false; - communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain); - this.buildMenu(communityId); - } + constructor(private route: ActivatedRoute, private propertiesService: EnvironmentSpecificService, + private _communitiesService: CommunitiesService, private _subscribeService: SubscribeService, + private router: Router) { + router.events.forEach((event) => { + if (event instanceof NavigationStart) { + HelperFunctions.scroll(); + } + }); + } + ngOnInit() { + this.propertiesService.loadEnvironment() + .then(es => { + this.properties = this.propertiesService.envSpecific; + var communityId: string = ""; + this._communitiesService.updateCommunities(this.properties, this.properties.communitiesAPI); + if (this.properties.environment == "development") { + this.showMenu = false; + this.route.queryParams.subscribe(params => { + communityId = (params['communityId']) ? params['communityId'] : ''; + this.buildMenu(communityId); + }) + } else { + this.showMenu = false; + 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); + try { + this.isClient = true; + } catch (e) { + } + } + }, error => { + console.log("App couldn't fetch properties"); + console.log(error); - }); - } + }); + } - public buildMenu(communityId: string) { - let community = null; - this.community = null; - this._communitiesService.getCommunitiesState().subscribe ( - communities => { - if( !communities || communities.length == 0 && communityId !== null && communityId !== '') { - return; - } - for(var com of communities){ - if( (communityId && communityId!="" && com.communityId == communityId - && community !=null) || - ( - !(communityId && communityId!="" && com.communityId == communityId) - && - this.managerOfCommunities && this.subscriberOfCommunities)) { - break; - } - if(Session.isLoggedIn() && com['status'] != "hidden"){ - if(Session.isCommunityCurator() || Session.isPortalAdministrator()){ - this.managerOfCommunities = true; - }else if(com.managers.indexOf(Session.getUserEmail())!=-1){ - this.managerOfCommunities = true; - } - } - - - - if(communityId && communityId!="" && com.communityId == communityId){ - community = com; - let isCommunityManager: boolean = false; - if(Session.isCommunityCurator() || Session.isPortalAdministrator()){ - isCommunityManager = true; - }else if(com.managers.indexOf(Session.getUserEmail())!=-1){ - isCommunityManager = true; - } - this.community = {id: community.communityId, name: (community.shortTitle)?community.shortTitle:community.title, logoUrl:community.logoUrl}; - this.menuItems= []; - - this.menuItems.push( - {rootItem: new MenuItem("search","Search","","/search/find",false,[],["/search/find", "/search/find/publications", "/search/find/datasets", "/search/find/software", "/search/find/other", "/search/find/projects", "/search/find/dataproviders"],this.properties.environment!="development"?{}:{communityId:community.communityId}), - items: [new MenuItem("","Publications","","/search/find/publications",false,["publication"],["/search/find/publications"],this.properties.environment!="development"?{}:{communityId:community.communityId}), - new MenuItem("","Research Data","","/search/find/datasets",false,["dataset"],["/search/find/datasets"],this.properties.environment!="development"?{}:{communityId:community.communityId}), - new MenuItem("","Software","","/search/find/software",false,["software"],["/search/find/software"],this.properties.environment!="development"?{}:{communityId:community.communityId}), - new MenuItem("","Other Research Products","","/search/find/other",false,["orp"],["/search/find/other"],this.properties.environment!="development"?{}:{communityId:community.communityId}), - new MenuItem("","Projects","","/search/find/projects/",false,["project"],["/search/find/projects"],this.properties.environment!="development"?{}:{communityId:community.communityId}), - new MenuItem("","Content Providers","","/search/find/dataproviders",false,["datasource"],["/search/find/dataproviders"],this.properties.environment!="development"?{}:{communityId:community.communityId}), - ]}); - - 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}) - */ - ] - }); - this.menuItems.push( - { - rootItem: new MenuItem("link","Link","","/participate/claim",false,[],["/participate/claim"],this.properties.environment!="development"?{}:{communityId:community.communityId}), - items: [ - new MenuItem("","Start linking","","/participate/claim",false,[],["/participate/claim"],this.properties.environment!="development"?{}:{communityId:community.communityId}), - new MenuItem("","Learn more",this.properties.claimsInformationLink,"",false,[],[],{}) - ] - }); - if(isCommunityManager){ - this.menuItems.push( - { - rootItem: new MenuItem("manage","Manage",'https://beta.admin.connect.openaire.eu/dashboard?communityId='+community.communityId,"",false,[],[],{}), - items: [] - }); - } - - } - - } - if(community == null){ - this.menuItems= []; - this.menuItems.push({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: []}); - this.menuItems.push({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']}), - ]; - if(Session.isPortalAdministrator()){ - //((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") - }); - } - }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){ - this.bottomMenuItems.push(new MenuItem("","Content Policy","","/content",false,[],[],{})); - } - this.userMenuItems =[ new MenuItem("","My profile","","",false,[],[],{}), - new MenuItem("","My links","","/myclaims",false,[],["/myclaims"],this.properties.environment!="development"?{}:{communityId:community.communityId}), - new MenuItem("","Invite users","","/invite",false,[],[],this.properties.environment!="development"?{}:{communityId:community.communityId}), - ]; - if(this.managerOfCommunities ){ - this.userMenuItems.push(new MenuItem("","Support","https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611","",false,[],[],{})) - } + public buildMenu(communityId: string) { + let community = null; + this.community = null; + this._communitiesService.getCommunitiesState().subscribe( + communities => { + if (!communities || communities.length == 0 && communityId !== null && communityId !== '') { + return; + } + for (var com of communities) { + if ((communityId && communityId != "" && com.communityId == communityId + && community != null) || + ( + !(communityId && communityId != "" && com.communityId == communityId) + && + this.managerOfCommunities && this.subscriberOfCommunities)) { + break; + } + if (Session.isLoggedIn() && com['status'] != "hidden") { + if (Session.isCommunityCurator() || Session.isPortalAdministrator()) { + this.managerOfCommunities = true; + } else if (com.managers.indexOf(Session.getUserEmail()) != -1) { + this.managerOfCommunities = true; } - this.showMenu = true; - }); - } + } + + + if (communityId && communityId != "" && com.communityId == communityId) { + community = com; + let isCommunityManager: boolean = false; + if (Session.isCommunityCurator() || Session.isPortalAdministrator()) { + isCommunityManager = true; + } else if (com.managers.indexOf(Session.getUserEmail()) != -1) { + isCommunityManager = true; + } + this.community = { + id: community.communityId, + name: (community.shortTitle) ? community.shortTitle : community.title, + logoUrl: community.logoUrl + }; + this.menuItems = []; + + this.menuItems.push( + { + rootItem: new MenuItem("search", "Search", "", "/search/find", false, [], ["/search/find", "/search/find/publications", "/search/find/datasets", "/search/find/software", "/search/find/other", "/search/find/projects", "/search/find/dataproviders"], this.properties.environment != "development" ? {} : {communityId: community.communityId}), + items: [new MenuItem("", "Publications", "", "/search/find/publications", false, ["publication"], ["/search/find/publications"], this.properties.environment != "development" ? {} : {communityId: community.communityId}), + new MenuItem("", "Research Data", "", "/search/find/datasets", false, ["dataset"], ["/search/find/datasets"], this.properties.environment != "development" ? {} : {communityId: community.communityId}), + new MenuItem("", "Software", "", "/search/find/software", false, ["software"], ["/search/find/software"], this.properties.environment != "development" ? {} : {communityId: community.communityId}), + new MenuItem("", "Other Research Products", "", "/search/find/other", false, ["orp"], ["/search/find/other"], this.properties.environment != "development" ? {} : {communityId: community.communityId}), + new MenuItem("", "Projects", "", "/search/find/projects/", false, ["project"], ["/search/find/projects"], this.properties.environment != "development" ? {} : {communityId: community.communityId}), + new MenuItem("", "Content Providers", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], this.properties.environment != "development" ? {} : {communityId: community.communityId}), + ] + }); + + 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}) + */ + ] + }); + this.menuItems.push( + { + rootItem: new MenuItem("link", "Link", "", "/participate/claim", false, [], ["/participate/claim"], this.properties.environment != "development" ? {} : {communityId: community.communityId}), + items: [ + new MenuItem("", "Start linking", "", "/participate/claim", false, [], ["/participate/claim"], this.properties.environment != "development" ? {} : {communityId: community.communityId}), + new MenuItem("", "Learn more", this.properties.claimsInformationLink, "", false, [], [], {}) + ] + }); + if (isCommunityManager) { + this.menuItems.push( + { + rootItem: new MenuItem("manage", "Manage", 'https://beta.admin.connect.openaire.eu/dashboard?communityId=' + community.communityId, "", false, [], [], {}), + items: [] + }); + } + + } + + } + if (community == null) { + this.menuItems = []; + this.menuItems.push({ + 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: [] + }); + this.menuItems.push({ + 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']}), + ]; + if (Session.isPortalAdministrator()) { + //((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 (Session.isLoggedIn()) { + 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) { + this.bottomMenuItems.push(new MenuItem("", "Content Policy", "", "/content", false, [], [], {})); + } + this.userMenuItems = [ /*new MenuItem("","My profile","","",false,[],[],{}),*/ + new MenuItem("", "My links", "", "/myclaims", false, [], ["/myclaims"], this.properties.environment != "development" ? {} : {communityId: community.communityId}), + new MenuItem("", "Invite users", "", "/invite", false, [], [], this.properties.environment != "development" ? {} : {communityId: community.communityId}), + ]; + if (this.managerOfCommunities) { + this.userMenuItems.push(new MenuItem("", "Support", "https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611", "", false, [], [], {})) + } + } + this.showMenu = true; + }); + } } diff --git a/src/app/communities/communities.component.html b/src/app/communities/communities.component.html index df1bd6b..c61d507 100644 --- a/src/app/communities/communities.component.html +++ b/src/app/communities/communities.component.html @@ -2,82 +2,7 @@ [logoURL]="properties.baseLink+'/assets/common-assets/logo-small-connect.png'" type="home" name="OpenAIRE Connect"> - -
diff --git a/src/app/communities/communities.component.ts b/src/app/communities/communities.component.ts index 12a5bb9..6fe3472 100644 --- a/src/app/communities/communities.component.ts +++ b/src/app/communities/communities.component.ts @@ -7,7 +7,6 @@ import {SubscribeService} from '../openaireLibrary/utils/subscribe/subscribe.ser import {CommunityInfo} from '../openaireLibrary/connect/community/communityInfo'; import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service'; -import {Session} from '../openaireLibrary/login/utils/helper.class'; import {StringUtils} from '../openaireLibrary/utils/string-utils.class'; import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes'; @@ -24,11 +23,7 @@ export class CommunitiesComponent { public piwiksub: any; public pageTitle = "OpenAIRE" - // TODO remove initiatives public researchCommunities = []; - public researchInitiatives = []; - public subscriberOfCommunities = []; - public managerOfCommunities = []; public gifs: { "gif": string, "header": string, "text" }[] = []; public pageContents = null; public divContents = null; @@ -102,9 +97,6 @@ export class CommunitiesComponent { this.subscriberErrorMessage = ""; this.researchCommunities = []; - this.researchInitiatives = []; - this.subscriberOfCommunities = []; - this.managerOfCommunities = []; this._communitiesService.getCommunitiesState().subscribe( communitiesResults => { @@ -115,83 +107,18 @@ export class CommunitiesComponent { this.status = this.errorCodes.DONE; return; } - //this.communitiesResults = communitiesResults; - //this.communitiesToShow = this.communitiesResults.slice(); - //console.log(communitiesResults); this.sort(communitiesResults); - - var subscribedLoading = communitiesResults.length; - var mail = Session.getUserEmail(); communitiesResults.forEach((community, index) => { let showCommunity: boolean = true; - let isManager: boolean = false; - let isSubscriber: boolean = false; - - if (community['status'] == "hidden") { + if (community['status'] == "hidden" || community['status'] == "manager") { showCommunity = false; - } else { - if (mail == null && community['status'] == "manager") { // no user - showCommunity = false; - } else if (Session.isCommunityCurator() || Session.isPortalAdministrator()) { - isManager = true; - } else if (community.managers.indexOf(mail) != -1) { - isManager = true; - } else if (community['status'] == "manager") { - showCommunity = false; - } } - if (showCommunity) { - // TODO remove - /*if(community.type == "community"){ - this.researchCommunities.push(community); - } else if(community.type == "ri") { - this.researchInitiatives.push(community); - }*/ this.researchCommunities.push(community); - if (isManager) { - community.isManager = true; - this.managerOfCommunities.push(community); - } } - this.status = this.errorCodes.DONE; - - if (mail != null && showCommunity) { - this._subscribeService.isSubscribedToCommunity(this.properties, community.communityId, mail).subscribe( - res => { - isSubscriber = res; - if (isSubscriber) { - community.isSubscribed = true; - if (isManager) { - this.subscriberOfCommunities.push(community); - } else { - this.subscriberOfCommunities.unshift(community); - } - } - - subscribedLoading--; - if (subscribedLoading == 0) { - this.loading = false; - } - }, - error => { - // if(this.properties.environment == "development") { - // this.subscriberErrorMessage = "Error fetching communities you are subscribed to"; - // } - this.handleError("Error getting response if email: " + mail + " is subscribed to community with id: " + community.communityId, error); - subscribedLoading--; - if (subscribedLoading == 0) { - this.loading = false; - } - }); - } else { - subscribedLoading--; - if (subscribedLoading == 0) { - this.loading = false; - } - } }); + this.loading = false; }, error => { this.status = this.handleError("Error getting communities", error); diff --git a/src/app/communities/communities.module.ts b/src/app/communities/communities.module.ts index 3b9fa6d..7874508 100644 --- a/src/app/communities/communities.module.ts +++ b/src/app/communities/communities.module.ts @@ -19,6 +19,7 @@ import {GifSliderModule} from "../openaireLibrary/utils/gif-slider/gif-slider.mo import {OtherPortalsModule} from "../openaireLibrary/sharedComponents/other-portals/other-portals.module"; import {Schema2jsonldModule} from "../openaireLibrary/sharedComponents/schema2jsonld/schema2jsonld.module"; import {SEOServiceModule} from "../openaireLibrary/sharedComponents/SEO/SEOService.module"; + @NgModule({ imports: [ CommonModule, FormsModule, RouterModule, diff --git a/src/app/my-communities/my-communities-routing.module.ts b/src/app/my-communities/my-communities-routing.module.ts new file mode 100644 index 0000000..e359a0d --- /dev/null +++ b/src/app/my-communities/my-communities-routing.module.ts @@ -0,0 +1,17 @@ +import {NgModule} from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {PreviousRouteRecorder} from '../openaireLibrary/utils/piwik/previousRouteRecorder.guard'; +import {MyCommunitiesComponent} from "./my-communities.component"; +import {LoginGuard} from "../openaireLibrary/login/loginGuard.guard"; +import {IsRouteEnabled} from "../openaireLibrary/error/isRouteEnabled.guard"; + +@NgModule({ + imports: [ + RouterModule.forChild([ + {path: '', component: MyCommunitiesComponent, canActivate: [LoginGuard, IsRouteEnabled], canDeactivate: [PreviousRouteRecorder]} + + ]) + ] +}) +export class MyCommunitiesRoutingModule { +} diff --git a/src/app/my-communities/my-communities.component.html b/src/app/my-communities/my-communities.component.html new file mode 100644 index 0000000..70e6b82 --- /dev/null +++ b/src/app/my-communities/my-communities.component.html @@ -0,0 +1,114 @@ + + + diff --git a/src/app/my-communities/my-communities.component.ts b/src/app/my-communities/my-communities.component.ts new file mode 100644 index 0000000..f4bcbc6 --- /dev/null +++ b/src/app/my-communities/my-communities.component.ts @@ -0,0 +1,226 @@ +import {Component} from '@angular/core'; +import {ActivatedRoute, Router} from '@angular/router'; +import {Meta, Title} from '@angular/platform-browser'; +import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties'; +import {CommunitiesService} from '../openaireLibrary/connect/communities/communities.service'; +import {SubscribeService} from '../openaireLibrary/utils/subscribe/subscribe.service'; +import {CommunityInfo} from '../openaireLibrary/connect/community/communityInfo'; + +import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service'; +import {Session} from '../openaireLibrary/login/utils/helper.class'; +import {StringUtils} from '../openaireLibrary/utils/string-utils.class'; + +import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes'; +import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component'; +import {HelperService} from "../openaireLibrary/utils/helper/helper.service"; +import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service"; + +@Component({ + selector: 'my-communities', + templateUrl: 'my-communities.component.html', +}) + +export class MyCommunitiesComponent { + public piwiksub: any; + + public pageTitle = "OpenAIRE" + public subscriberOfCommunities = []; + public managerOfCommunities = []; + public researchCommunities = []; + public pageContents = null; + public divContents = null; + // Message variables + public status: number; + public loading: boolean = true; + public subscriberErrorMessage: string = ""; + public errorCodes: ErrorCodes; + private errorMessages: ErrorMessagesComponent; + + properties: EnvProperties; + + constructor( + private route: ActivatedRoute, + private _router: Router, + private _meta: Meta, + private _title: Title, + private _piwikService: PiwikService, + private _communitiesService: CommunitiesService, + private _subscribeService: SubscribeService, + private helper: HelperService, + private seoService: SEOService) { + + var description = "OpenAIRE - Connect, Community Dashboard, research community " + + "| My managing and subscribed to Communities"; + var title = "OpenAIRE - Connect | My Communities"; + + this._meta.updateTag({content: description}, "name='description'"); + this._meta.updateTag({content: description}, "property='og:description'"); + this._meta.updateTag({content: title}, "property='og:title'"); + this._title.setTitle(title); + + this.errorCodes = new ErrorCodes(); + this.errorMessages = new ErrorMessagesComponent(); + this.status = this.errorCodes.LOADING; + } + + public ngOnInit() { + this.route.data + .subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + var url = data.envSpecific.baseLink + this._router.url; + this.seoService.createLinkForCanonicalURL(url, false); + this._meta.updateTag({content: url}, "property='og:url'"); + if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { + this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE Connect", this.properties.piwikSiteId).subscribe(); + } + this.getCommunities(); + //this.getDivContents(); + //this.getPageContents(); + }); + } + + private getPageContents() { + this.helper.getPageHelpContents(this._router.url, this.properties, 'connect').subscribe(contents => { + this.pageContents = contents; + }) + } + + private getDivContents() { + this.helper.getDivHelpContents(this._router.url, this.properties, 'connect').subscribe(contents => { + this.divContents = contents; + }) + } + + public getCommunities() { + this.loading = true; + this.status = this.errorCodes.LOADING; + this.subscriberErrorMessage = ""; + + this.subscriberOfCommunities = []; + this.managerOfCommunities = []; + this.researchCommunities = []; + + this._communitiesService.getCommunitiesState().subscribe( + communitiesResults => { + if(!communitiesResults){ + return; + } + if(communitiesResults.length == 0) { + this.status = this.errorCodes.DONE; + return; + }; + this.sort(communitiesResults); + + var subscribedLoading = communitiesResults.length; + var mail = Session.getUserEmail(); + communitiesResults.forEach((community, index) => { + let showCommunity: boolean = true; + let isManager: boolean = false; + let isSubscriber: boolean = false; + + if (community['status'] == "hidden") { + showCommunity = false; + } else { + if (mail == null && community['status'] == "manager") { // no user + showCommunity = false; + } else if (Session.isCommunityCurator() || Session.isPortalAdministrator()) { + isManager = true; + } else if (community.managers.indexOf(mail) != -1) { + isManager = true; + } else if (community['status'] == "manager") { + showCommunity = false; + } + } + + if (showCommunity) { + this.researchCommunities.push(community); + if (isManager) { + community.isManager = true; + this.managerOfCommunities.push(community); + } + } + + this.status = this.errorCodes.DONE; + + if (mail != null && showCommunity) { + this._subscribeService.isSubscribedToCommunity(this.properties, community.communityId, mail).subscribe( + res => { + isSubscriber = res; + if (isSubscriber) { + community.isSubscribed = true; + if (isManager) { + this.subscriberOfCommunities.push(community); + } else { + this.subscriberOfCommunities.unshift(community); + } + } + + subscribedLoading--; + if (subscribedLoading == 0) { + this.loading = false; + } + }, + error => { + this.handleError("Error getting response if email: " + mail + " is subscribed to community with id: " + community.communityId, error); + subscribedLoading--; + if (subscribedLoading == 0) { + this.loading = false; + } + }); + } else { + subscribedLoading--; + if (subscribedLoading == 0) { + this.loading = false; + } + } + }); + }, + error => { + this.status = this.handleError("Error getting communities", error); + this.loading = false; + } + ); + } + + private sort(results: CommunityInfo[]) { + results.sort((left, right): number => { + if (!right.date || left.date > right.date) { + return -1; + } else if (!left.date || left.date < right.date) { + return 1; + } else { + if (left.title > right.title) { + return 1; + } else if (left.title < right.title) { + return -1; + } else { + return 0; + } + } + }) + } + + public quote(param: string): string { + return StringUtils.quote(param); + } + + public ngOnDestroy() { + if (this.piwiksub) { + this.piwiksub.unsubscribe(); + } + } + + private handleError(message: string, error): number { + var code = ""; + if (!error.status) { + var error = error.json(); + code = error.code; + } else { + code = error.status; + } + + console.error("Communities (component): " + message, error); + + return this.errorMessages.getErrorCode(code); + } +} diff --git a/src/app/my-communities/my-communities.module.ts b/src/app/my-communities/my-communities.module.ts new file mode 100644 index 0000000..6672fcc --- /dev/null +++ b/src/app/my-communities/my-communities.module.ts @@ -0,0 +1,38 @@ +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {FormsModule} from '@angular/forms'; +import {RouterModule} from '@angular/router'; +import {ManageModule} from '../openaireLibrary/utils/manage/manage.module'; + +import {MyCommunitiesComponent} from './my-communities.component'; +import {PreviousRouteRecorder} from '../openaireLibrary/utils/piwik/previousRouteRecorder.guard'; + +import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service'; +import {ErrorMessagesModule} from '../openaireLibrary/utils/errorMessages.module'; +import {Schema2jsonldModule} from "../openaireLibrary/sharedComponents/schema2jsonld/schema2jsonld.module"; +import {SEOServiceModule} from "../openaireLibrary/sharedComponents/SEO/SEOService.module"; +import {LoginGuard} from "../openaireLibrary/login/loginGuard.guard"; +import {HelperModule} from "../openaireLibrary/utils/helper/helper.module"; +import {BrowseCommunityModule} from "../communities/browseCommunity/browse-community.module"; +import {MyCommunitiesRoutingModule} from "./my-communities-routing.module"; +import {IsRouteEnabled} from "../openaireLibrary/error/isRouteEnabled.guard"; + +@NgModule({ + imports: [ + CommonModule, FormsModule, RouterModule, HelperModule, + ManageModule, ErrorMessagesModule, BrowseCommunityModule, Schema2jsonldModule, SEOServiceModule, + MyCommunitiesRoutingModule + ], + declarations: [ + MyCommunitiesComponent + ], + providers: [ + LoginGuard, PreviousRouteRecorder, + PiwikService, IsRouteEnabled + ], + exports: [ + MyCommunitiesComponent + ] +}) +export class MyCommunitiesModule { +}