Add hasMachineCache: true in production. Fix css loading bug when a community is restricted.

This commit is contained in:
Konstantinos Triantafyllou 2023-05-25 16:38:18 +03:00
parent a855a7491d
commit 59b6d14342
3 changed files with 113 additions and 92 deletions

View File

@ -1,4 +1,13 @@
import {Component, ElementRef, Inject, OnDestroy, OnInit, RendererFactory2, ViewChild, ViewEncapsulation} from '@angular/core';
import {
Component,
ElementRef,
Inject,
OnDestroy,
OnInit, PLATFORM_ID,
RendererFactory2,
ViewChild,
ViewEncapsulation
} from '@angular/core';
import {ActivatedRoute, NavigationEnd, Router} from '@angular/router';
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
@ -11,14 +20,14 @@ import {UserManagementService} from "./openaireLibrary/services/user-management.
import {ConfigurationService} from "./openaireLibrary/utils/configuration/configuration.service";
import {properties} from '../environments/environment';
import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component";
import {AsyncSubject, Subscriber} from "rxjs";
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, Layout} from "./openaireLibrary/connect/community/CustomizationOptions";
import {Layout} from "./openaireLibrary/connect/community/CustomizationOptions";
import {CustomizationService} from "./openaireLibrary/services/customization.service";
import {SmoothScroll} from "./openaireLibrary/utils/smooth-scroll";
import {Meta} from "@angular/platform-browser";
import {makeStateKey, Meta, StateKey, TransferState} from "@angular/platform-browser";
import {CommunityInfo} from "./openaireLibrary/connect/community/communityInfo";
import {SEOService} from "./openaireLibrary/sharedComponents/SEO/SEO.service";
import {UntypedFormBuilder, UntypedFormGroup, Validators} from "@angular/forms";
@ -29,7 +38,8 @@ import {QuickContactComponent} from "./openaireLibrary/sharedComponents/quick-co
import {Composer} from "./openaireLibrary/utils/email/composer";
import {NotificationHandler} from "./openaireLibrary/utils/notification-handler";
import {OpenaireEntities} from "./openaireLibrary/utils/properties/searchFields";
import {DOCUMENT} from "@angular/common";
import {DOCUMENT, isPlatformServer} from "@angular/common";
import {AdvancedAsyncSubject} from "./openaireLibrary/utils/AdvancedAsyncSubject";
@Component({
selector: 'app-root',
@ -44,7 +54,9 @@ import {DOCUMENT} from "@angular/common";
<a routerLink="/get-started">Get Started</a>
</li>
</ul>
<a *ngIf="showGetStarted" extra-m class="uk-button uk-button-small uk-button-primary uk-text-uppercase uk-margin-left" routerLink="/get-started">Get Started</a>
<a *ngIf="showGetStarted" extra-m
class="uk-button uk-button-small uk-button-primary uk-text-uppercase uk-margin-left"
routerLink="/get-started">Get Started</a>
</navbar>
<navbar *ngIf="properties && showMenu && community && header" [portal]="community.communityId" [onlyTop]=false
[communityId]="community.communityId" [header]="header"
@ -65,7 +77,8 @@ import {DOCUMENT} from "@angular/common";
<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">
[name]="(community.shortTitle) ? community.shortTitle : community.title"
[description]="community.description">
</schema2jsonld>
<div class="custom-main-content">
<main>
@ -89,17 +102,17 @@ import {DOCUMENT} from "@angular/common";
</span></a>
</cookie-law>
<bottom #bottom *ngIf="properties && isClient && showMenu && !community" [grantAdvance]="false"
[properties]="properties"></bottom>
[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>
<quick-contact #quickContact *ngIf="showQuickContact && contactForm" (sendEmitter)="send($event)"
[contact]="'Help'" [images]="images" [background]="{class: 'uk-background-primary', dark: false}"
[contactForm]="contactForm" [sending]="sending"></quick-contact>
[showSocialButtons]="true" [showMenuItems]="true" [grantAdvance]="false" [showOpenaire]="true"
[communityId]="community.communityId" [menuItems]=bottomMenuItems [properties]="properties" [centered]="true"></bottom>
<quick-contact #quickContact *ngIf="showQuickContact && contactForm" (sendEmitter)="send($event)"
[contact]="'Help'" [images]="images" [background]="{class: 'uk-background-primary', dark: false}"
[contactForm]="contactForm" [sending]="sending"></quick-contact>
<modal-alert #modal [overflowBody]="false"></modal-alert>
<role-verification *ngIf="community" service="connect"
[id]="community.communityId" [name]="community.title" [type]="community.type"></role-verification>
[id]="community.communityId" [name]="community.title"
[type]="community.type"></role-verification>
</div>
`
@ -109,7 +122,7 @@ export class AppComponent implements OnInit, OnDestroy {
userMenuItems: MenuItem[] = [];
menuItems: MenuItem [] = [];
bottomMenuItems: MenuItem[] = [];
public community:CommunityInfo = null;
public community: CommunityInfo = null;
properties: EnvProperties = properties;
showMenu: boolean = false;
communities = null;
@ -125,15 +138,20 @@ export class AppComponent implements OnInit, OnDestroy {
public images: string[] = [];
@ViewChild('modal') modal: AlertModal;
@ViewChild('quickContact') quickContact: QuickContactComponent;
@ViewChild('bottom', {read: ElementRef}) bottom: ElementRef;
@ViewChild('bottom', {read: ElementRef}) bottom: ElementRef;
private subscriptions = [];
layout: Layout = null;
layouts: Layout[] = null;
layoutDefault: Layout = null;
layoutConnect: Layout = null;
layoutSub = new AsyncSubject();
layoutSub = new AdvancedAsyncSubject<Layout[]>();
previewLayout = null;
constructor(private route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
/**
* key for portal identity check (client - server: using transfer state
* */
key: StateKey<string> = makeStateKey<string>('portal');
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,
@ -141,8 +159,11 @@ export class AppComponent implements OnInit, OnDestroy {
private quickContactService: QuickContactService,
private fb: UntypedFormBuilder,
private emailService: EmailService,
@Inject(DOCUMENT) private document, private rendererFactory: RendererFactory2
) {
@Inject(DOCUMENT) private document,
private transferState: TransferState,
@Inject(PLATFORM_ID) private platformId: any,
private rendererFactory: RendererFactory2
) {
this.subscriptions.push(router.events.forEach((event) => {
if (event instanceof NavigationEnd) {
if (event.url === '/contact-us') {
@ -157,15 +178,14 @@ export class AppComponent implements OnInit, OnDestroy {
}
ngOnInit() {
this.subscriptions.push(this.route.queryParams.subscribe(data => {
this.previewLayout = (data['previewLayout'] && data['previewLayout'].length >0 ? data['previewLayout']: null);
if (this.properties.environment == "production" || this.properties.environment == "development") {
this._meta.updateTag({content: 'all', name: 'robots'});
this.seoService.removeLinkForPrevURL();
this.seoService.removeLinkForNextURL();
}
}));
this.subscriptions.push(this.route.queryParams.subscribe(data => {
this.previewLayout = (data['previewLayout'] && data['previewLayout'].length > 0 ? data['previewLayout'] : null);
if (this.properties.environment == "production" || this.properties.environment == "development") {
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 {
@ -177,7 +197,8 @@ export class AppComponent implements OnInit, OnDestroy {
this.user = user;
this.init();
}, error => {
this.init()}));
this.init();
}));
this.subscriptions.push(this.quickContactService.isDisplayed.subscribe(display => {
this.showQuickContact = display;
}));
@ -195,15 +216,15 @@ export class AppComponent implements OnInit, OnDestroy {
this._communityService.clearSubscriptions();
this.smoothScroll.clearSubscriptions();
}
createObservers() {
let options = {
root: null,
rootMargin: '0px',
threshold: 0.1
};
let intersectionObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
createObservers() {
let options = {
root: null,
rootMargin: '0px',
threshold: 0.1
};
let intersectionObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting && this.showQuickContact) {
this.showQuickContact = false;
this.quickContactService.setDisplay(this.showQuickContact);
@ -212,15 +233,15 @@ export class AppComponent implements OnInit, OnDestroy {
this.quickContactService.setDisplay(this.showQuickContact);
}
});
}, options);
intersectionObserver.observe(this.bottom.nativeElement);
this.subscriptions.push(intersectionObserver);
}
}, options);
intersectionObserver.observe(this.bottom.nativeElement);
this.subscriptions.push(intersectionObserver);
}
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)
}
@ -238,9 +259,9 @@ export class AppComponent implements OnInit, OnDestroy {
this.userManagementService.fixRedirectURL = null;
}
}
initCss(communityId, suffix=null) {
initCss(communityId, suffix = null) {
try {
const renderer = this.rendererFactory.createRenderer(this.document, {
id: '-1',
encapsulation: ViewEncapsulation.None,
@ -251,21 +272,18 @@ export class AppComponent implements OnInit, OnDestroy {
if (head === null) {
throw new Error('<head> not found within DOCUMENT.');
}
if(!this.document.getElementById("dashboardStyle")) {
if (!this.document.getElementById("dashboardStyle")) {
const script = renderer.createElement('link');
renderer.setAttribute(script, "id", "dashboardStyle");
renderer.setAttribute(script, "href", ((communityId) ? communityId : this.properties.adminToolsPortalType) + (suffix?"-"+suffix:"") + ".css");
renderer.setAttribute(script, "href", ((communityId) ? communityId : this.properties.adminToolsPortalType) + (suffix ? "-" + suffix : "") + ".css");
renderer.setAttribute(script, "rel", "stylesheet");
renderer.appendChild(head, script);
}else if(!this.previewLayout){
this.document.getElementById("dashboardStyle").href = ((communityId) ? communityId : this.properties.adminToolsPortalType)+ (suffix?"-"+suffix:"") + ".css";
// console.log(this.document.getElementById("dashboardStyle"));
} else if (!this.previewLayout) {
this.document.getElementById("dashboardStyle").href = ((communityId) ? communityId : this.properties.adminToolsPortalType) + (suffix ? "-" + suffix : "") + ".css";
}
} catch (e) {
console.error('Renderrer Error to append style ', e);
}
}
initAdminToolCommunity(communityId) {
@ -274,48 +292,54 @@ export class AppComponent implements OnInit, OnDestroy {
if (this.document) {
this.initLayout(communityId);
}
}else{
} else {
this.properties.adminToolsPortalType = "connect";
if (this.document) {
this.initLayout('connect');
}
}
this.configurationService.initCommunityInformation(this.properties, (communityId) ? communityId : this.properties.adminToolsPortalType);
}
getLayouts(){
getLayouts() {
this.customizationService.getLayouts(this.properties).subscribe(
layouts => {
this.layouts = layouts;
this.layoutDefault = layouts.filter(layout => layout.portalPid == 'default')[0];
this.layoutConnect = layouts.filter(layout => layout.portalPid == 'connect')[0];
this.layoutSub.next(this.layouts);
this.layoutSub.complete();
},
error => {
}
);
layouts => {
this.layouts = layouts;
this.layoutDefault = layouts.filter(layout => layout.portalPid == 'default')[0];
this.layoutConnect = layouts.filter(layout => layout.portalPid == 'connect')[0];
this.layoutSub.next(this.layouts);
},
error => {
this.layoutSub.next([]);
}
);
}
initLayout(communityId){
if(!this.layout && (typeof location == 'undefined') && !this.previewLayout) {
initLayout(communityId) {
let portal = this.transferState.get<string>(this.key, null);
if(isPlatformServer(this.platformId)) {
this.transferState.set(this.key, communityId);
}
if (!this.layout && (portal !== communityId) && !this.previewLayout) {
// if((typeof location == 'undefined') && !this.previewLayout) {
this.subscriptions.push(this.layoutSub.subscribe(value => {
this.layout = this.layouts.filter(layout => layout.portalPid == communityId)[0]?this.layouts.filter(layout => layout.portalPid == communityId)[0]:this.layouts.filter(layout => layout.portalPid == 'default')[0];
this.initCss(this.layout.portalPid, this.layout.date?this.layout.date:null)
this.layouts = value;
this.layout = this.layouts.filter(layout => layout.portalPid == communityId)[0] ? this.layouts.filter(layout => layout.portalPid == communityId)[0] : this.layouts.filter(layout => layout.portalPid == 'default')[0];
this.initCss(this.layout.portalPid, this.layout.date ? this.layout.date : null)
}));
}else if(this.previewLayout && this.previewLayout.split("-preview-")[0] == communityId){
} else if (this.previewLayout && this.previewLayout.split("-preview-")[0] == communityId) {
this.initCss(communityId, this.previewLayout.split(communityId)[1]);
}
}
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 = community;
} else {
this.community = null;
this.communityId = null;
}
@ -328,12 +352,11 @@ export class AppComponent implements OnInit, OnDestroy {
this.buildConnectMenu();
}
}
buildCommunityMenu(){
buildCommunityMenu() {
if (this.community && !ConnectHelper.isPrivate(this.community, this.user)) {
this.communityId = this.community.communityId;
this.initAdminToolCommunity(this.communityId);
this.header = {
// url: 'https://' + (this.properties.environment == 'beta' ? 'beta.' : '') + this.community.id + '.openaire.eu',
route: "/",
@ -382,8 +405,8 @@ export class AppComponent implements OnInit, OnDestroy {
new MenuItem("", "Projects and funding Opportunities", "", "/projects", false, [], ["/projects"], {}),
]
));
this.menuItems.push(
new MenuItem("develop", "Develop", "", "/develop", false, [], ["/develop"], {}),
this.menuItems.push(
new MenuItem("develop", "Develop", "", "/develop", false, [], ["/develop"], {}),
);
if (this.isManager) {
this.menuItems.push(
@ -408,10 +431,7 @@ export class AppComponent implements OnInit, OnDestroy {
}
this.showMenu = true;
} else {
this.initAdminToolCommunity(this.communityId);
this.communityId = null;
this.properties.adminToolsPortalType = "connect";
this.configurationService.initCommunityInformation(this.properties, "connect");
// this.initAdminToolCommunity(null);
this.buildConnectMenu(true);
@ -425,21 +445,21 @@ export class AppComponent implements OnInit, OnDestroy {
}
});
}
} else {
if(typeof location !== 'undefined' && location.pathname.indexOf("user-info") == -1) {
} else {
if (typeof location !== 'undefined' && location.pathname.indexOf("user-info") == -1) {
this.router.navigate(['/'], {queryParamsHandling: "merge"});
}
}
}else if (this.community && this.community.status == "hidden") {
} else if (this.community && this.community.status == "hidden") {
this.router.navigate([this.properties.errorLink]);
}else{
this.router.navigate(['/'], this.community && this.community.status ? { queryParamsHandling: "merge" } : {});
} else {
this.router.navigate(['/'], this.community && this.community.status ? {queryParamsHandling: "merge"} : {});
}
}
}
buildConnectMenu(restrictedData: boolean = false) {
this.initAdminToolCommunity(null);
let url = "https://" + (properties.environment != "production" ? "beta." : "") + "connect.openaire.eu";
this.header = {
route: restrictedData ? "" : "/",

@ -1 +1 @@
Subproject commit 95a3cc3ff62983d593730827a8d07fd43887627b
Subproject commit 39a7ed58be27513c05598edc18cf095eb5b044c5

View File

@ -114,5 +114,6 @@ export let properties: EnvProperties = {
altMetricsAPIURL: "https://api.altmetric.com/v1/doi/",
b2noteAPIURL: 'https://b2note.eudat.eu/',
adminPortalURL: "https://admin.connect.openaire.eu",
myOrcidLinksPage: "/my-orcid-links"
myOrcidLinksPage: "/my-orcid-links",
hasMachineCache: true
};