Add cookie in server side requests. Remove sticky footer from page-content in server. Hide subitems in sidebar on server

This commit is contained in:
Konstantinos Triantafyllou 2022-12-23 17:36:35 +02:00
parent 88b0987ba3
commit 789a0225fa
5 changed files with 48 additions and 29 deletions

View File

@ -2,10 +2,10 @@ import {
AfterViewInit, AfterViewInit,
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
ElementRef, ElementRef, Inject,
Input, Input,
OnDestroy, OnDestroy,
OnInit, OnInit, PLATFORM_ID,
ViewChild ViewChild
} from "@angular/core"; } from "@angular/core";
import {LayoutService} from "../sidebar/layout.service"; import {LayoutService} from "../sidebar/layout.service";
@ -18,7 +18,7 @@ declare var ResizeObserver;
selector: '[page-content]', selector: '[page-content]',
template: ` template: `
<div id="page_content"> <div id="page_content">
<div id="page_content_sticky_footer" #sticky_footer class="uk-tile-default uk-blur-background" <div [class.uk-hidden]="!isBrowser" id="page_content_sticky_footer" #sticky_footer class="uk-tile-default uk-blur-background"
[attr.uk-sticky]="'bottom: true'" [attr.offset]="footer_offset"> [attr.uk-sticky]="'bottom: true'" [attr.offset]="footer_offset">
<div class="uk-container uk-container-large"> <div class="uk-container uk-container-large">
<div class="uk-padding-small uk-padding-remove-vertical"> <div class="uk-padding-small uk-padding-remove-vertical">
@ -74,7 +74,8 @@ export class PageContentComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild("sticky_footer") sticky_footer; @ViewChild("sticky_footer") sticky_footer;
subscriptions = []; subscriptions = [];
constructor(private layoutService: LayoutService, private cdr: ChangeDetectorRef) { constructor(private layoutService: LayoutService, private cdr: ChangeDetectorRef,
@Inject(PLATFORM_ID) private platformId) {
} }
ngOnInit() { ngOnInit() {
@ -83,6 +84,10 @@ export class PageContentComponent implements OnInit, AfterViewInit, OnDestroy {
} }
} }
get isBrowser() {
return this.platformId === 'browser';
}
get isStickyActive() { get isStickyActive() {
if (this.header && this.actions && this.shouldSticky) { if (this.header && this.actions && this.shouldSticky) {
let sticky = this.headerSticky ? this.header.nativeElement : this.actions.nativeElement; let sticky = this.headerSticky ? this.header.nativeElement : this.actions.nativeElement;

View File

@ -15,7 +15,7 @@
<span *ngIf="item.items?.length > 0"></span> <span *ngIf="item.items?.length > 0"></span>
</div> </div>
</a> </a>
<ul *ngIf="item.items?.length > 0" class="uk-nav-sub"> <ul *ngIf="item.items?.length > 0 && (isBrowser || isTheActiveMenuItem(item))" class="uk-nav-sub">
<li *ngFor="let subItem of item.items" <li *ngFor="let subItem of item.items"
[class.uk-active]="isTheActiveMenuItem(item, subItem)"> [class.uk-active]="isTheActiveMenuItem(item, subItem)">
<a [routerLink]="subItem.route?subItem.route:null" [queryParams]="subItem.route?subItem.params:null" <a [routerLink]="subItem.route?subItem.route:null" [queryParams]="subItem.route?subItem.params:null"

View File

@ -1,4 +1,4 @@
import {AfterViewInit, Component, ElementRef, Input, ViewChild} from '@angular/core'; import {AfterViewInit, Component, ElementRef, Inject, Input, PLATFORM_ID, ViewChild} from '@angular/core';
import {MenuItem} from "../../../sharedComponents/menu"; import {MenuItem} from "../../../sharedComponents/menu";
import {ActivatedRoute, Router} from "@angular/router"; import {ActivatedRoute, Router} from "@angular/router";
import {DomSanitizer} from "@angular/platform-browser"; import {DomSanitizer} from "@angular/platform-browser";
@ -20,10 +20,12 @@ export class SideBarComponent implements AfterViewInit {
@ViewChild("nav") nav: ElementRef @ViewChild("nav") nav: ElementRef
public properties = properties; public properties = properties;
constructor(private route: ActivatedRoute, private router: Router, private sanitizer: DomSanitizer, private layoutService: LayoutService) {} constructor(private route: ActivatedRoute, private router: Router,
private sanitizer: DomSanitizer, private layoutService: LayoutService,
@Inject(PLATFORM_ID) private platformId) {}
ngAfterViewInit() { ngAfterViewInit() {
if(this.nav) { if(this.nav && typeof UIkit !== "undefined") {
setTimeout(() => { setTimeout(() => {
if(this.items[this.activeIndex]?.items?.length > 0) { if(this.items[this.activeIndex]?.items?.length > 0) {
UIkit.nav(this.nav.nativeElement).toggle(this.activeIndex, true); UIkit.nav(this.nav.nativeElement).toggle(this.activeIndex, true);
@ -32,6 +34,10 @@ export class SideBarComponent implements AfterViewInit {
} }
} }
get isBrowser() {
return this.platformId === 'browser';
}
get currentRoute() { get currentRoute() {
return { return {
route: this.router.url.split('?')[0].split('#')[0], route: this.router.url.split('?')[0].split('#')[0],

View File

@ -1,25 +1,29 @@
import { Injectable, Inject, PLATFORM_ID } from '@angular/core'; import {Injectable, Inject, PLATFORM_ID, Optional} from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent, HttpResponse } from '@angular/common/http'; import {HttpInterceptor, HttpRequest, HttpHandler, HttpEvent, HttpResponse, HttpHeaders} from '@angular/common/http';
import { Observable, of } from 'rxjs'; import {Observable, of} from 'rxjs';
import { tap } from 'rxjs/operators'; import {tap} from 'rxjs/operators';
import { TransferState, makeStateKey, StateKey } from '@angular/platform-browser'; import {TransferState, makeStateKey, StateKey} from '@angular/platform-browser';
import { isPlatformServer } from '@angular/common'; import {isPlatformServer} from '@angular/common';
import {properties} from "../../environments/environment"; import {properties} from "../../environments/environment";
import {REQUEST} from "./utils/tokens";
import * as Xhr2 from 'xhr2';
Xhr2.prototype._restrictedHeaders = {};
@Injectable() @Injectable()
export class HttpInterceptorService implements HttpInterceptor { export class HttpInterceptorService implements HttpInterceptor {
private static HTTP_WHITELIST = [ properties.monitorServiceAPIURL + '/stakeholder' ]; private static HTTP_WHITELIST = [];
constructor(private transferState: TransferState, @Inject(PLATFORM_ID) private platformId: any) {} constructor(private transferState: TransferState, @Inject(PLATFORM_ID) private platformId: any, @Optional() @Inject(REQUEST) protected req: any) {
}
public intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { public intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (request.method !== 'GET' || this.isService(request, HttpInterceptorService.HTTP_WHITELIST)) { if (request.method !== 'GET' || this.isService(request, HttpInterceptorService.HTTP_WHITELIST)) {
return next.handle(request); return next.handle(request);
} }
const key: StateKey<string> = makeStateKey<string>(request.url); const key: StateKey<string> = makeStateKey<string>(request.url);
const storedResponse = this.transferState.get<any>(key, null); const storedResponse = this.transferState.get<any>(key, null);
//console.info(key, storedResponse); //console.info(key, storedResponse);
if (storedResponse) { if (storedResponse) {
@ -31,7 +35,12 @@ export class HttpInterceptorService implements HttpInterceptor {
return of(response); return of(response);
} else { } else {
if (isPlatformServer(this.platformId)) { if (isPlatformServer(this.platformId)) {
return next.handle(request).pipe(tap((event) => { let headers = new HttpHeaders();
headers = headers.set('Cookie', this.req.get('Cookie'));
const authReq = request.clone({
headers: headers
});
return next.handle(authReq).pipe(tap((event) => {
//console.info("server add: ", key); //console.info("server add: ", key);
this.transferState.set(key, (<HttpResponse<any>>event).body); this.transferState.set(key, (<HttpResponse<any>>event).body);
})); }));
@ -40,15 +49,15 @@ export class HttpInterceptorService implements HttpInterceptor {
} }
} }
} }
isService(req: HttpRequest<any>, service: string | string[]):boolean { isService(req: HttpRequest<any>, service: string | string[]): boolean {
if(Array.isArray(service)) { if (Array.isArray(service)) {
return !!service.find(element => req.url.indexOf(element) !== -1); return !!service.find(element => req.url.indexOf(element) !== -1);
} else { } else {
return req.url.indexOf(service) !== -1; return req.url.indexOf(service) !== -1;
} }
} }
// public cleanRequest(requestUrl: string) { // public cleanRequest(requestUrl: string) {
// console.log("cleaned"); // console.log("cleaned");
// const key: StateKey<string> = makeStateKey<string>(requestUrl); // const key: StateKey<string> = makeStateKey<string>(requestUrl);

View File

@ -1,9 +1,8 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http'; import {HttpClient} from '@angular/common/http';
import {BehaviorSubject, from, Observable} from "rxjs"; import {Observable} from "rxjs";
import {COOKIE, Session, User} from "../login/utils/helper.class"; import {Session, User} from "../login/utils/helper.class";
import {map} from "rxjs/operators"; import {map} from "rxjs/operators";
import {NavigationEnd, Router} from "@angular/router";
import {properties} from "../../../environments/environment"; import {properties} from "../../../environments/environment";
import {StringUtils} from "../utils/string-utils.class"; import {StringUtils} from "../utils/string-utils.class";
import {CustomOptions} from "./servicesUtils/customOptions.class"; import {CustomOptions} from "./servicesUtils/customOptions.class";