connect/src/app/app.component.ts

354 lines
18 KiB
TypeScript
Raw Normal View History

import {Component} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
import {MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu';
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
import {CommunitiesService} from "./openaireLibrary/connect/communities/communities.service";
import {Session, User} from './openaireLibrary/login/utils/helper.class';
import {ConnectHelper} from './openaireLibrary/connect/connectHelper';
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
import {ConfigurationService} from "./openaireLibrary/utils/configuration/configuration.service";
import {properties} from '../environments/environment';
import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component";
import {Subscriber} from "rxjs";
import {CommunityService} from "./openaireLibrary/connect/community/community.service";
import {StringUtils} from "./openaireLibrary/utils/string-utils.class";
import {LoginErrorCodes} from "./openaireLibrary/login/utils/guardHelper.class";
import {CustomizationOptions} from "./openaireLibrary/connect/community/CustomizationOptions";
import {LayoutService} from "./openaireLibrary/services/layout.service";
import {SmoothScroll} from "./openaireLibrary/utils/smooth-scroll";
import {Meta} from "@angular/platform-browser";
import {CommunityInfo} from "./openaireLibrary/connect/community/communityInfo";
import {SEOService} from "./openaireLibrary/sharedComponents/SEO/SEO.service";
@Component({
selector: 'app-root',
styles: [`
`],
template: `
<div [class]="(community)?(community.communityId +'App communityApp'):'connectApp'">
<navbar *ngIf="properties && showMenu && !community && header" [portal]="properties.dashboard" [onlyTop]=false
[userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user" [header]="header"
[showMenu]=showMenu [properties]="properties" [showHomeMenuItem]="false" communityId="connect"></navbar>
<navbar *ngIf="properties && showMenu && community && header" [portal]="community.communityId" [onlyTop]=false
[communityId]="community.communityId" [header]="header"
[userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
[showMenu]=showMenu [properties]="properties" [enableSearch]="false"
searchRoute="/search/find/research-outcomes"
[showHomeMenuItem]="false"></navbar>
<customization *ngIf="properties && showMenu && communityId && communityId.length > 0 && layout" [properties]="properties"
[communityId]="communityId" [layout]="layout" ></customization>
<schema2jsonld *ngIf="properties && showMenu && !community" [URL]="properties.domain + properties.baseLink"
[logoURL]="properties.domain + properties.baseLink+'/assets/common-assets/logo-small-connect.png'"
type="home"
[searchActionRoute]="properties.searchLinkToCommunities" [searchAction]="true"
name="OpenAIRE Connect"
description="Build a Gateway for your Community: Turn Open Science into Practice. It takes your open and linked research outcomes.">
</schema2jsonld>
<schema2jsonld *ngIf="properties && showMenu && communityId && communityId.length > 0 && community"
[URL]="properties.domain + properties.baseLink"
[logoURL]="community.logoUrl" type="home" [searchActionRoute]="properties.searchLinkToResults"
[name]="(community.shortTitle) ? community.shortTitle : community.title" [description]="community.description">
</schema2jsonld>
<div class="custom-main-content">
<main>
<router-outlet></router-outlet>
</main>
</div>
<div id="subscribeAndInviteBtn" *ngIf="isClient && communityId && community">
<subscribe [communityId]="community.communityId"></subscribe>
<invite *ngIf="isManager" [longView]="false"></invite>
[Trunk | Connect]: 1. app-routing.module.ts: Add route '/subjects'. 2. app.component.ts: Group subscribe and invite buttons under id="subscribeAndInviteBtn" (keep distance between them alwayes the same) | uncomment menu item 'Subjects' in About. 3. app.module.ts: import 'SubscribeService' (singleton service to update everywhere subscriber status). 4. libUser.module.ts & subscribe.module.ts: remove import of 'SubscribeService' (singleton service to update everywhere subscriber status). 5. community.component.html: a. Improve some checks b. In main tabs of the page (class main-tabs) add class 'uk-text-truncate' and remove class 'uk-width-3-4' (each tab has max-width) c. Add icon in 'Analytics' tab d. [Bug fix] In description, fix overflow and max height of box 6. community.component.ts: Add field '@ViewChild(SubscribeComponent) subscribeComponent: SubscribeComponent' to add some checks in html. 7. curators.component.html: Remove div with class 'image-front-topbar' | Update css for title | Add <breadcrumbs> | Add user icon for each curator. 8. curators.component.ts: Initialize breadcrumb | [Bug fix] In methods 'getPageContents()' and 'getDivContents()' use communityId (instead of 'connect'). 9. curators.module.ts & organizationsPage.module.ts & inviteBasic.module.ts: import 'BreadcrumbsModule'. 10. organizationsPage.component.ts: Update css for title | Add <breadcrumbs> | Initialize breadcrumb. 11. subjects.component.ts, subjects.module.ts, subjects-routing.module.ts: Add page for Subjects. 12. invite.component.html: Add <breadcrumbs> in longView | Add icon in button 'Invite users'. 13. invite.component.ts: Initialize breadcrumb. 14. subscribe.component.ts: a. Add icon in button "Subscribe"/ "Subscribed" b. Add class 'uk-display-inline-block' in showNumbers (members) c. Initialize and get subscriber status with new methods of service (initIsSubscribedToCommunity() & isSubscribed - BehaviorSubject instead of isSubscribedToCommunity()) 15. connect-custom.css: Group css for #subscribeBtn, #inviteBtn into #subscribeAndInviteBtn | Add css for class 'user-circle-background' (background of user icon in curators). git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@58574 d315682c-612b-4755-9ff5-7f18f6832af3
2020-04-28 13:07:36 +02:00
</div>
<!--feedback *ngIf= "isClient && properties" portalName="Connect" [feedbackQuestionaire]=properties.feedbackQuestionaire></feedback-->
<cookie-law *ngIf="isClient" position="bottom">
OpenAIRE uses cookies in order to function properly.<br>
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. <a
href="//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target="_blank"> Read more <span class="uk-icon">
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03"
points="7 4 13 10 7 16"></polyline></svg>
</span></a>
</cookie-law>
<bottom *ngIf="properties && isClient && showMenu && !community" [grantAdvance]="false"
[properties]="properties"></bottom>
<bottom *ngIf="properties && isClient && showMenu && community" class=" communityPanelBackground "
[showSocialButtons]="true" [showMenuItems]="true" [grantAdvance]="false" [showOpenaire]="true"
[communityId]="community.communityId" [menuItems]=bottomMenuItems [properties]="properties"
[darkBackground]="true" [centered]="true"></bottom>
<role-verification *ngIf="community" service="connect"
[id]="community.communityId" [name]="community.title" [type]="'community'"></role-verification>
</div>
`
})
export class AppComponent {
isClient: boolean = false;
userMenuItems: MenuItem[] = [];
menuItems: RootMenuItem [] = [];
bottomMenuItems: MenuItem[] = [];
public community:CommunityInfo = null;
properties: EnvProperties = properties;
showMenu: boolean = false;
communities = null;
user: User;
[Trunk | Connect]: Connect redesing 1. app.component.ts: <subscribe> and <invite> components added (floating buttons on the right side of each page for communities). 2. community.component.html: 3. community.component.ts: a. 'projectsCalculated' and 'contentProvidersCalculated' fields added, to calculate tootlip after both requests complete b. added methods for building tootips c. 'activeTab' set to 'summary'. 4. affiliations.component.html: minor phrasing changes (e.g. title). 5. curators.component.html: shortview changed. 6. results.component.ts: Title changed | 'View all' moved to the bottom. 7. customization.component.ts: Changed '--portal-main-color' from '#4C9CD5' to '#4687E6' | Changed '--portal-dark-color' from '#24857F' to '#2D72D6'. 8. invite.component.html: shortview changed. 9. invite.component.ts: 'properties' field as input (get it is called from app.component). 10. invite.module.ts & inviteBasic.module.ts: InviteBasicModule created to declare InviteComponent without routing and login guard | InviteModule imports InviteBasicModule and adds routing and login guar$ 11. subscribe.component.ts: Changes for subscribe button and members | 'properties' field as input (get it is called from app.component). 12. connect-custom.css: css for subscribe and invite buttons and for tooltip with 'community-page-tooltip' class. 13. customization.css: class 'communityBackground' added and css for 'subtitle' class inside 'communityBackground'. git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@58549 d315682c-612b-4755-9ff5-7f18f6832af3
2020-04-24 18:38:35 +02:00
communityId: string = "";
header: Header;
logoPath: string = 'assets/common-assets/';
subscriptions = [];
layout: CustomizationOptions = null;
constructor(private route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
private _communitiesService: CommunitiesService, private smoothScroll: SmoothScroll,
private router: Router, private userManagementService: UserManagementService,
private configurationService: ConfigurationService, private _communityService: CommunityService, private _layoutService: LayoutService, private _meta: Meta, private seoService: SEOService) {
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => {
if (subscription instanceof Subscriber) {
subscription.unsubscribe();
}
});
this._communitiesService.clearSubscriptions();
this.userManagementService.clearSubscriptions();
this.configurationService.clearSubscriptions();
this._communityService.clearSubscriptions();
this.smoothScroll.clearSubscriptions();
}
ngOnInit() {
if (this.properties.environment == "production" || this.properties.environment == "development") {
this.subscriptions.push(this.route.queryParams.subscribe(data => {
this._meta.updateTag({content: 'all', name: 'robots'});
this.seoService.removeLinkForPrevURL();
this.seoService.removeLinkForNextURL();
}));
}
this._communitiesService.updateCommunities(this.properties, this.properties.communitiesAPI);
if (typeof document !== 'undefined') {
try {
this.isClient = true;
} catch (e) {
}
}
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
this.user = user;
this.init();
}, error => {
this.init()}));
}
get isManager() {
return Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user) || (this.communityId && Session.isManager('community', this.communityId, this.user))
}
get isPrivate() {
return this.community && !ConnectHelper.isPrivate(this.community, this.user)
}
private init() {
let communityId: string = ConnectHelper.getCommunityFromDomain(this.properties.domain);
this.showMenu = false;
this.initAdminToolCommunity(communityId);
this.buildMenu(communityId);
// this.communityId = communityId;
if (this.communityId === null) {
this.userManagementService.fixRedirectURL = properties.afterLoginRedirectLink;
} else {
this.userManagementService.fixRedirectURL = null;
}
}
initAdminToolCommunity(communityId) {
if (communityId) {
this.properties.adminToolsPortalType = "community";
this.initLayout(communityId);
}
this.configurationService.initCommunityInformation(this.properties, (communityId) ? communityId : this.properties.adminToolsPortalType);
}
initLayout(communityId){
if(!this.layout) {
this._layoutService.getLayout(this.properties, communityId).subscribe(
layout => {
if (layout) {
this.layout = CustomizationOptions.checkForObsoleteVersion(layout.layoutOptions,this.communityId);
} else {
this.layout = new CustomizationOptions(CustomizationOptions.getIdentity(communityId).mainColor, CustomizationOptions.getIdentity(communityId).secondaryColor);
}
},
error => {
this.layout = new CustomizationOptions(CustomizationOptions.getIdentity(communityId).mainColor, CustomizationOptions.getIdentity(communityId).secondaryColor);
}
);
}
}
public buildMenu(communityId: string) {
if (communityId) {
if (!this.community || this.communityId !== communityId) {
this.subscriptions.push(this._communityService.getCommunity(communityId).subscribe(community => {
if (community) {
this.community = community;
}else{
this.community = null;
this.communityId = null;
}
this.buildCommunityMenu();
}));
} else {
this.buildCommunityMenu();
}
} else {
this.buildConnectMenu();
}
}
buildCommunityMenu(){
if (this.community && !ConnectHelper.isPrivate(this.community, this.user)) {
this.communityId = this.community.communityId;
this.header = {
// url: 'https://' + (this.properties.environment == 'beta' ? 'beta.' : '') + this.community.id + '.openaire.eu',
route: "/",
title: (this.community.shortTitle) ? this.community.shortTitle : this.community.title,
logoUrl: (this.community.isUpload) ? (properties.utilsService + '/download/' + this.community.logoUrl) : (StringUtils.urlPrefix(this.community.logoUrl) + this.community.logoUrl),
logoSmallUrl: (this.community.isUpload) ? (properties.utilsService + '/download/' + this.community.logoUrl) : (StringUtils.urlPrefix(this.community.logoUrl) + this.community.logoUrl),
position: 'left',
badge: true
};
this.menuItems = [];
this.menuItems.push({
rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], {}),
items: []
});
this.menuItems.push(
{
rootItem: new MenuItem("link", "Link", "", "/participate/claim", false, [], ["/participate/claim"], {}),
items: [
new MenuItem("", "Start linking", "", "/participate/claim", false, [], ["/participate/claim"], {}),
new MenuItem("", "Learn more", this.properties.claimsInformationLink, "", false, [], [], {})
]
});
this.menuItems.push(
{
rootItem: new MenuItem("search", "Search", "", "/search/find", false, [], ["/search/find"], {}),
items: [
new MenuItem("", "Research outcomes", "", "/search/find/research-outcomes", false, [], ["/search/find/research-outcomes"], {resultbestaccessright: '"' + encodeURIComponent("Open Access") + '"'}),
new MenuItem("", "Projects", "", "/search/find/projects/", false, ["project"], ["/search/find/projects"], {}),
new MenuItem("", "Content Providers", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], {}),
]
});
this.menuItems.push(
{
rootItem: new MenuItem("about", "About", "", "", false, [], [], {}),
items: [
new MenuItem("", "Supporting organizations", "", "/organizations", false, [], ["/organizations"], {}),
new MenuItem("", "Curators", "", "/curators", false, [], ["/curators"], {}),
new MenuItem("", "Sources and methodology", "", "/content", false, [], ["/content"], {}),
new MenuItem("", "National Bulletins", "", "/national-bulletins", false, [], ["/national-bulletins"], {}),
new MenuItem("", "Subjects", "", "/subjects", false, [], ["/subjects"], {}),
new MenuItem("", "Projects and funding Opportunities", "", "/projects", false, [], ["/projects"], {}),
]
});
if (this.isManager) {
this.menuItems.push(
{
rootItem: new MenuItem("manage", "Manage", this.properties.adminPortalURL + '/' + this.community.communityId, "", false, [], [], {}),
items: []
});
}
this.bottomMenuItems = [
new MenuItem("", "Supporting organizations", "", "/organizations", false, [], ["/organizations"], {})
];
if (this.properties.showContent) {
this.bottomMenuItems.push(new MenuItem("", "Sources and methodology", "", "/content", false, [], [], {}));
}
if (this.user) {
this.userMenuItems = [ /*new MenuItem("","My profile","","",false,[],[],{}),*/
new MenuItem("", "My ORCID links", "", "/my-orcid-links", false, [], [], {}),
new MenuItem("", "My links", "", "/myclaims", false, [], ["/myclaims"], {}),
new MenuItem("", "Invite users", "", "/invite", false, [], [], {}),
];
if (this.isManager) {
this.userMenuItems.push(new MenuItem("", "Support", "https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611", "", false, [], [], {}))
}
}
this.showMenu = true;
} else {
this.communityId = null;
this.properties.adminToolsPortalType = "connect";
this.configurationService.initCommunityInformation(this.properties, "connect");
this.initAdminToolCommunity(null);
this.buildConnectMenu(true);
if (this.community && this.community.status == "manager") {
if (!this.user ) {
if(typeof location !== 'undefined' && location.pathname.indexOf("user-info") == -1) {
this.router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_LOGIN,
"redirectUrl": location.pathname + location.search + location.hash
}
});
}
} else {
if(typeof location !== 'undefined' && location.pathname.indexOf("user-info") == -1) {
this.router.navigate(['/'], {queryParamsHandling: "merge"});
}
}
}else if (this.community && this.community.status == "hidden") {
this.router.navigate(['/error']);
}else{
this.router.navigate(['/'], this.community && this.community.status ? { queryParamsHandling: "merge" } : {});
}
}
}
buildConnectMenu(restrictedData: boolean = false) {
let url = "https://" + (properties.environment != "production" ? "beta." : "") + "connect.openaire.eu";
this.header = {
route: restrictedData ? "" : "/",
url: restrictedData ? url : "",
title: 'connect',
logoUrl: this.logoPath + 'logo-large-connect.png',
logoSmallUrl: this.logoPath + 'logo-small-connect.png',
position: 'left',
badge: true
};
this.menuItems = [];
this.menuItems.push({
rootItem: new MenuItem("about", "About", restrictedData ? url + "/about/learn-how" : "", restrictedData ? "" : "/about/learn-how", false, [], ["/about/learn-how"], {}),
items: [
new MenuItem("", "Learn the process", restrictedData ? url + "/about/learn-how" : "", restrictedData ? "" : "/about/learn-how", false, [], ["/about/learn-in-depth"], {}),
new MenuItem("", "Publications", restrictedData ? url + "/publications" : "", restrictedData ? "" : "/publications", false, [], ["/publications"], {}),
new MenuItem("", "Roadmap", "https://trello.com/b/yfzUz0kp/openaire-connect-dashboard", "", false, [], [], {}),
new MenuItem("", "FAQs", restrictedData ? url + "/about/faq" : "", restrictedData ? "" : "/about/faq", false, [], ["/about/faq"], {})
]
});
this.menuItems.push({
rootItem: new MenuItem("communities", "Communities", restrictedData ? url + "/search/find/communities" : "", restrictedData ? "" : "/search/find/communities", false, [], ['/search/find/communities'], {}),
items: []
});
this.menuItems.push({
rootItem: new MenuItem("contact-us", "Contact us", restrictedData ? url + "/contact-us" : "", restrictedData ? "" : "/contact-us", false, [], ['/contact-us'], {}),
items: []
});
this.bottomMenuItems = [
new MenuItem("", "About", "https://openaire.eu/project-factsheets", "", false, [], [], {}),
new MenuItem("", "News - Events", "https://openaire.eu/news-events", "", false, [], [], {}),
new MenuItem("", "Blog", "https://blogs.openaire.eu/", "", false, [], [], {}),
new MenuItem("", "Contact us", restrictedData ? url + "/contact-us" : "", restrictedData ? "" : "/contact-us", false, [], [], {})
];
this.userMenuItems = [];
if (Session.isPortalAdministrator(this.user)) {
this.userMenuItems.push(new MenuItem("", "Manage Helptexts",
properties.adminPortalURL + "/connect/admin-tools/pages", "", false, [], [], {}))
}
if (this.user) {
this.userMenuItems.push(new MenuItem("my-communities", "My Communities", restrictedData ? url + "/myCommunities" : "",
restrictedData ? "" : "/myCommunities", false, [], [], {}));
}
this.showMenu = true;
}
}