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,
ChangeDetectorRef,
Component,
ElementRef,
ElementRef, Inject,
Input,
OnDestroy,
OnInit,
OnInit, PLATFORM_ID,
ViewChild
} from "@angular/core";
import {LayoutService} from "../sidebar/layout.service";
@ -18,7 +18,7 @@ declare var ResizeObserver;
selector: '[page-content]',
template: `
<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">
<div class="uk-container uk-container-large">
<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;
subscriptions = [];
constructor(private layoutService: LayoutService, private cdr: ChangeDetectorRef) {
constructor(private layoutService: LayoutService, private cdr: ChangeDetectorRef,
@Inject(PLATFORM_ID) private platformId) {
}
ngOnInit() {
@ -83,6 +84,10 @@ export class PageContentComponent implements OnInit, AfterViewInit, OnDestroy {
}
}
get isBrowser() {
return this.platformId === 'browser';
}
get isStickyActive() {
if (this.header && this.actions && this.shouldSticky) {
let sticky = this.headerSticky ? this.header.nativeElement : this.actions.nativeElement;

View File

@ -15,7 +15,7 @@
<span *ngIf="item.items?.length > 0"></span>
</div>
</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"
[class.uk-active]="isTheActiveMenuItem(item, subItem)">
<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 {ActivatedRoute, Router} from "@angular/router";
import {DomSanitizer} from "@angular/platform-browser";
@ -20,10 +20,12 @@ export class SideBarComponent implements AfterViewInit {
@ViewChild("nav") nav: ElementRef
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() {
if(this.nav) {
if(this.nav && typeof UIkit !== "undefined") {
setTimeout(() => {
if(this.items[this.activeIndex]?.items?.length > 0) {
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() {
return {
route: this.router.url.split('?')[0].split('#')[0],

View File

@ -1,19 +1,23 @@
import { Injectable, Inject, PLATFORM_ID } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent, HttpResponse } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { tap } from 'rxjs/operators';
import { TransferState, makeStateKey, StateKey } from '@angular/platform-browser';
import { isPlatformServer } from '@angular/common';
import {Injectable, Inject, PLATFORM_ID, Optional} from '@angular/core';
import {HttpInterceptor, HttpRequest, HttpHandler, HttpEvent, HttpResponse, HttpHeaders} from '@angular/common/http';
import {Observable, of} from 'rxjs';
import {tap} from 'rxjs/operators';
import {TransferState, makeStateKey, StateKey} from '@angular/platform-browser';
import {isPlatformServer} from '@angular/common';
import {properties} from "../../environments/environment";
import {REQUEST} from "./utils/tokens";
import * as Xhr2 from 'xhr2';
Xhr2.prototype._restrictedHeaders = {};
@Injectable()
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>> {
if (request.method !== 'GET' || this.isService(request, HttpInterceptorService.HTTP_WHITELIST)) {
return next.handle(request);
}
@ -31,7 +35,12 @@ export class HttpInterceptorService implements HttpInterceptor {
return of(response);
} else {
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);
this.transferState.set(key, (<HttpResponse<any>>event).body);
}));
@ -41,8 +50,8 @@ export class HttpInterceptorService implements HttpInterceptor {
}
}
isService(req: HttpRequest<any>, service: string | string[]):boolean {
if(Array.isArray(service)) {
isService(req: HttpRequest<any>, service: string | string[]): boolean {
if (Array.isArray(service)) {
return !!service.find(element => req.url.indexOf(element) !== -1);
} else {
return req.url.indexOf(service) !== -1;

View File

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