feat(console): v2 feature cleanup, fix styling issues, instance naming (#3530)

* new console

* move npm ci to angular build

* rel path for assets

* local grpc copy

* login policy, rm clear views, features rel path

* login_hint param

* edit default color values

* remove features, zitadel-tier, contact styles

* html formatter

* rm feature restrictions, fix theming issues

* instance naming

* statehandler

* rm class

* rm class

* update footer links

* statehandler

* stroked color

Co-authored-by: Livio Amstutz <[email protected]>
This commit is contained in:
Max Peintner
2022-04-29 10:25:12 +02:00
committed by GitHub
co-authored by Livio Amstutz
parent f9e79ef8fe
commit 41e60b3d8a
93 changed files with 5256 additions and 13100 deletions
@@ -4,34 +4,36 @@ import { Observable, of } from 'rxjs';
import { v4 as uuidv4 } from 'uuid';
export abstract class StatehandlerProcessorService {
public abstract createState(url: string): Observable<string | undefined>;
public abstract restoreState(state?: string): void;
public abstract createState(url: string): Observable<string | undefined>;
public abstract restoreState(state?: string): void;
}
@Injectable()
export class StatehandlerProcessorServiceImpl
implements StatehandlerProcessorService {
constructor(private location: Location) { }
export class StatehandlerProcessorServiceImpl implements StatehandlerProcessorService {
constructor(private location: Location) {}
public createState(url: string): Observable<string> {
const externalUrl = this.location.prepareExternalUrl(url);
const urlId = uuidv4();
public createState(url: string): Observable<string> {
const externalUrl = this.location.prepareExternalUrl(url);
const urlId = uuidv4();
sessionStorage.setItem(urlId, externalUrl);
return of(urlId);
if (externalUrl.includes('login_hint=')) {
sessionStorage.setItem(urlId, externalUrl);
}
public restoreState(state?: string): void {
if (state === undefined) {
return;
}
return of(urlId);
}
const url = sessionStorage.getItem(state);
if (url === null) {
return;
}
window.location.href = window.location.origin + url;
public restoreState(state?: string): void {
if (state === undefined) {
return;
}
const url = sessionStorage.getItem(state);
if (url === null) {
return;
}
sessionStorage.removeItem(state);
window.location.href = window.location.origin + url;
}
}
@@ -1,59 +1,79 @@
import { Injectable, Injector, OnDestroy, Type } from '@angular/core';
import { GuardsCheckStart, Router, RouterEvent } from '@angular/router';
import { OAuthService } from 'angular-oauth2-oidc';
import { Observable, Subject, throwError } from 'rxjs';
import { Observable, of, Subject, throwError } from 'rxjs';
import { filter, map, shareReplay, switchMap, take, takeUntil } from 'rxjs/operators';
import { StatehandlerProcessorService } from './statehandler-processor.service';
export abstract class StatehandlerService {
public abstract createState(): Observable<string | undefined>;
public abstract initStateHandler(): void;
public abstract createState(): Observable<string | undefined>;
public abstract initStateHandler(): void;
}
@Injectable()
export class StatehandlerServiceImpl
implements StatehandlerService, OnDestroy {
private events?: Observable<string>;
private unsubscribe$: Subject<void> = new Subject();
export class StatehandlerServiceImpl implements StatehandlerService, OnDestroy {
private events?: Observable<string>;
private unsubscribe$: Subject<void> = new Subject();
constructor(
oauthService: OAuthService,
private injector: Injector,
private processor: StatehandlerProcessorService,
) {
oauthService.events
.pipe(
filter(event => event.type === 'token_received'),
map(() => oauthService.state),
takeUntil(this.unsubscribe$),
)
.subscribe(state => processor.restoreState(state));
constructor(oauthService: OAuthService, private injector: Injector, private processor: StatehandlerProcessorService) {
oauthService.events
.pipe(
filter((event) => event.type === 'token_received'),
map(() => oauthService.state),
takeUntil(this.unsubscribe$),
)
.subscribe((state) => processor.restoreState(state));
}
public initStateHandler(): void {
const router = this.injector.get(Router as Type<Router>);
this.events = (router.events as Observable<RouterEvent>).pipe(
filter((event) => event instanceof GuardsCheckStart),
map((event) => event.url),
shareReplay(1),
);
this.events.pipe(takeUntil(this.unsubscribe$)).subscribe();
}
public createState(): Observable<string | undefined> {
if (this.events === undefined) {
return throwError(() => new Error('no router events'));
}
public initStateHandler(): void {
const router = this.injector.get(Router as Type<Router>);
this.events = (router.events as Observable<RouterEvent>).pipe(
filter(event => event instanceof GuardsCheckStart),
map(event => event.url),
shareReplay(1),
);
this.events.pipe(takeUntil(this.unsubscribe$)).subscribe();
}
public createState(): Observable<string | undefined> {
if (this.events === undefined) {
return throwError('no router events');
return this.events.pipe(
take(1),
switchMap((url: string) => {
if (url.includes('?login_hint=')) {
const newUrl = this.removeParam('login_hint', url);
return of(newUrl);
} else {
return this.processor.createState(url);
}
}),
);
}
return this.events.pipe(
take(1),
switchMap(url => this.processor.createState(url)),
);
}
public ngOnDestroy(): void {
this.unsubscribe$.next();
}
public ngOnDestroy(): void {
this.unsubscribe$.next();
removeParam(key: string, sourceURL: string) {
var rtn = sourceURL.split('?')[0],
param,
params_arr = [],
queryString = sourceURL.indexOf('?') !== -1 ? sourceURL.split('?')[1] : '';
if (queryString !== '') {
params_arr = queryString.split('&');
for (var i = params_arr.length - 1; i >= 0; i -= 1) {
param = params_arr[i].split('=')[0];
if (param === key) {
params_arr.splice(i, 1);
}
}
if (params_arr.length) rtn = rtn + '?' + params_arr.join('&');
}
return rtn;
}
}