mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-20 03:48:47 +00:00
feat: rehauled console (#3525)
* new console * move npm ci to angular build * rel path for assets * local grpc copy * login policy, rm clear views, features rel path * lock Co-authored-by: Livio Amstutz <[email protected]>
This commit is contained in:
co-authored by
Livio Amstutz
parent
00f7dbe875
commit
08ae39ae19
@@ -0,0 +1,9 @@
|
||||
import { OverlayRef } from '@angular/cdk/overlay';
|
||||
|
||||
export class CnslOverlayRef {
|
||||
constructor(private overlayRef: OverlayRef) {}
|
||||
|
||||
close(): void {
|
||||
this.overlayRef.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
import { MediaMatcher } from '@angular/cdk/layout';
|
||||
import { Injectable, OnDestroy } from '@angular/core';
|
||||
import { BehaviorSubject, Observable, of, Subject, switchMap, take, takeUntil, zip } from 'rxjs';
|
||||
|
||||
import { GrpcAuthService } from '../grpc-auth.service';
|
||||
import { CnslOverlayRef } from './overlay-ref';
|
||||
import { OverlayService } from './overlay.service';
|
||||
|
||||
export interface OverlayWorkflow {
|
||||
currentIndex: number;
|
||||
currentRef?: CnslOverlayRef;
|
||||
overlays: CnslOverlay[];
|
||||
}
|
||||
|
||||
export interface CnslOverlay {
|
||||
id: string;
|
||||
origin: string;
|
||||
toHighlight: string[];
|
||||
content: {
|
||||
count?: number;
|
||||
number?: number;
|
||||
i18nText: string;
|
||||
};
|
||||
requirements?: {
|
||||
media?: string;
|
||||
permission?: string[];
|
||||
feature?: string[];
|
||||
};
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class OverlayWorkflowService implements OnDestroy {
|
||||
public readonly currentWorkflow$: BehaviorSubject<OverlayWorkflow | null> = new BehaviorSubject<OverlayWorkflow | null>(
|
||||
null,
|
||||
);
|
||||
public destroy$: Subject<void> = new Subject();
|
||||
|
||||
public openRef: CnslOverlayRef | null = null;
|
||||
public highlightedIds: { [id: string]: number } = {};
|
||||
public callback: Function | null = null;
|
||||
constructor(private mediaMatcher: MediaMatcher, overlayService: OverlayService, private authService: GrpcAuthService) {
|
||||
this.currentWorkflow$.pipe(takeUntil(this.destroy$)).subscribe((workflow) => {
|
||||
if (this.openRef) {
|
||||
this.openRef.close();
|
||||
this.openRef = null;
|
||||
}
|
||||
|
||||
Object.keys(this.highlightedIds).forEach((id) => {
|
||||
const element = document.getElementById(id);
|
||||
if (element) {
|
||||
element.style.removeProperty('z-index');
|
||||
delete this.highlightedIds[id];
|
||||
}
|
||||
});
|
||||
|
||||
const overlay = workflow?.overlays[workflow.currentIndex];
|
||||
if (overlay) {
|
||||
this.meetsRequirements(overlay)
|
||||
.pipe(take(1))
|
||||
.subscribe((can) => {
|
||||
if (can) {
|
||||
this.openRef = overlayService.open(overlay);
|
||||
|
||||
overlay.toHighlight.forEach((id) => {
|
||||
const element = document.getElementById(id);
|
||||
if (element) {
|
||||
const oldZ = element.style.zIndex;
|
||||
this.highlightedIds[id] = Number(oldZ);
|
||||
element.style.zIndex = '1001';
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.nextStep();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public meetsRequirements(overlay: CnslOverlay): Observable<boolean> {
|
||||
return zip([
|
||||
this.meetsMediaRequirements(overlay),
|
||||
this.meetsPermissionRequirements(overlay),
|
||||
this.meetsFeatureRequirements(overlay),
|
||||
] as Observable<boolean>[]).pipe(
|
||||
switchMap(([media, permission, feature]) => {
|
||||
return of(media && permission && feature);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public meetsMediaRequirements(overlay: CnslOverlay): Observable<boolean> {
|
||||
const media = overlay.requirements?.media;
|
||||
if (media) {
|
||||
const matches = this.mediaMatcher.matchMedia(media).matches;
|
||||
if (!matches) {
|
||||
return of(false);
|
||||
} else {
|
||||
return of(true);
|
||||
}
|
||||
} else {
|
||||
return of(true);
|
||||
}
|
||||
}
|
||||
|
||||
public meetsPermissionRequirements(overlay: CnslOverlay): Observable<boolean> {
|
||||
const regexArray = overlay.requirements?.permission;
|
||||
if (regexArray && regexArray.length) {
|
||||
return this.authService.isAllowed(regexArray);
|
||||
} else {
|
||||
return of(true);
|
||||
}
|
||||
}
|
||||
|
||||
public meetsFeatureRequirements(overlay: CnslOverlay): Observable<boolean> {
|
||||
const regexArray = overlay.requirements?.feature;
|
||||
if (regexArray && regexArray.length) {
|
||||
return this.authService.canUseFeature(regexArray);
|
||||
} else {
|
||||
return of(true);
|
||||
}
|
||||
}
|
||||
|
||||
public reset(): void {
|
||||
this.currentWorkflow$.next(null);
|
||||
if (this.callback) {
|
||||
this.callback();
|
||||
}
|
||||
}
|
||||
|
||||
public ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
public startWorkflow(overlays: CnslOverlay[], cb: Function | null): void {
|
||||
if (cb) {
|
||||
this.callback = cb;
|
||||
}
|
||||
this.currentWorkflow$.next({ overlays, currentIndex: 0 });
|
||||
}
|
||||
|
||||
public nextStep(): void {
|
||||
const currentWorkflow = this.currentWorkflow$.value;
|
||||
if (this.nextPossible && currentWorkflow) {
|
||||
const nextIndex = currentWorkflow?.currentIndex + 1;
|
||||
this.currentWorkflow$.next({ ...currentWorkflow, currentIndex: nextIndex });
|
||||
} else {
|
||||
this.currentWorkflow$.next(null);
|
||||
if (this.callback) {
|
||||
this.callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public previousStep(): void {
|
||||
const currentWorkflow = this.currentWorkflow$.value;
|
||||
if (this.previousPossible && currentWorkflow) {
|
||||
const nextIndex = currentWorkflow?.currentIndex - 1;
|
||||
this.currentWorkflow$.next({ ...currentWorkflow, currentIndex: nextIndex });
|
||||
}
|
||||
}
|
||||
|
||||
public get nextPossible(): boolean {
|
||||
const currentWorkflow = this.currentWorkflow$.value;
|
||||
|
||||
if (currentWorkflow) {
|
||||
const nextIndex = currentWorkflow?.currentIndex + 1;
|
||||
if (nextIndex < currentWorkflow?.overlays.length) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public get isLast(): boolean {
|
||||
const currentWorkflow = this.currentWorkflow$.value;
|
||||
|
||||
if (currentWorkflow) {
|
||||
const currentIndex = currentWorkflow?.currentIndex;
|
||||
|
||||
if (currentIndex == currentWorkflow?.overlays.length - 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public get previousPossible(): boolean {
|
||||
const currentWorkflow = this.currentWorkflow$.value;
|
||||
|
||||
if (currentWorkflow && currentWorkflow.currentIndex > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import { ConnectedPosition, ConnectionPositionPair, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay';
|
||||
import { ComponentPortal, PortalInjector } from '@angular/cdk/portal';
|
||||
import { ComponentRef, Injectable, Injector } from '@angular/core';
|
||||
|
||||
import { InfoOverlayComponent, OVERLAY_DATA } from '../../modules/info-overlay/info-overlay.component';
|
||||
import { CnslOverlayRef } from './overlay-ref';
|
||||
import { CnslOverlay } from './overlay-workflow.service';
|
||||
|
||||
interface InfoOverlayConfig extends CnslOverlay {
|
||||
backdropClass?: string;
|
||||
panelClass?: string;
|
||||
}
|
||||
|
||||
const DEFAULT_CONFIG: Partial<InfoOverlayConfig> = {
|
||||
backdropClass: 'cnsl-overlay-backdrop',
|
||||
panelClass: 'cnsl-overlay-panel',
|
||||
};
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class OverlayService {
|
||||
constructor(private overlay: Overlay, private injector: Injector) {}
|
||||
|
||||
public open(overlay: CnslOverlay) {
|
||||
const dialogConfig: InfoOverlayConfig = { ...DEFAULT_CONFIG, ...overlay };
|
||||
const overlayRef = this.createOverlay(dialogConfig);
|
||||
|
||||
const dialogRef = new CnslOverlayRef(overlayRef);
|
||||
|
||||
const overlayComponent = this.attachOverlayContainer(overlayRef, dialogConfig, overlayRef);
|
||||
|
||||
overlayRef.backdropClick().subscribe((_) => dialogRef.close());
|
||||
|
||||
return dialogRef;
|
||||
}
|
||||
|
||||
private attachOverlayContainer(overlayRef: OverlayRef, config: InfoOverlayConfig, dialogRef: OverlayRef) {
|
||||
const injector = this.createInjector(config, dialogRef);
|
||||
|
||||
const containerPortal = new ComponentPortal(InfoOverlayComponent, null, injector);
|
||||
const containerRef: ComponentRef<InfoOverlayComponent> = overlayRef.attach(containerPortal);
|
||||
|
||||
return containerRef.instance;
|
||||
}
|
||||
|
||||
private createInjector(config: InfoOverlayConfig, dialogRef: OverlayRef): PortalInjector {
|
||||
const injectionTokens = new WeakMap();
|
||||
|
||||
injectionTokens.set(OverlayRef, dialogRef);
|
||||
injectionTokens.set(OVERLAY_DATA, config.content);
|
||||
|
||||
return new PortalInjector(this.injector, injectionTokens);
|
||||
}
|
||||
|
||||
private createOverlay(config: InfoOverlayConfig): OverlayRef {
|
||||
const overlayConfig = this.getOverlayConfig(config);
|
||||
return this.overlay.create(overlayConfig);
|
||||
}
|
||||
|
||||
private getOverlayConfig(config: InfoOverlayConfig): OverlayConfig {
|
||||
// const positionStrategy = this.overlay.position().global().centerHorizontally().centerVertically();
|
||||
|
||||
const htmlOrigin: HTMLElement | null = document.getElementById(config.origin);
|
||||
|
||||
const positions: ConnectedPosition[] = [
|
||||
new ConnectionPositionPair({ originX: 'start', originY: 'bottom' }, { overlayX: 'start', overlayY: 'top' }, 0, 10),
|
||||
new ConnectionPositionPair({ originX: 'end', originY: 'bottom' }, { overlayX: 'end', overlayY: 'top' }, 0, 10),
|
||||
];
|
||||
|
||||
let positionStrategy;
|
||||
if (htmlOrigin) {
|
||||
positionStrategy = this.overlay
|
||||
.position()
|
||||
.flexibleConnectedTo(htmlOrigin)
|
||||
.withPositions(positions)
|
||||
.withFlexibleDimensions(true)
|
||||
.withPush(false);
|
||||
} else {
|
||||
positionStrategy = this.overlay.position().global().centerHorizontally().centerVertically();
|
||||
}
|
||||
|
||||
const overlayConfig = new OverlayConfig({
|
||||
hasBackdrop: true,
|
||||
backdropClass: config.backdropClass,
|
||||
panelClass: config.panelClass,
|
||||
scrollStrategy: this.overlay.scrollStrategies.block(),
|
||||
positionStrategy,
|
||||
});
|
||||
|
||||
return overlayConfig;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { CnslOverlay } from './overlay-workflow.service';
|
||||
|
||||
export const IntroWorkflowOverlays: CnslOverlay[] = [
|
||||
{
|
||||
id: 'orgswitcher',
|
||||
origin: 'orgswitchbutton',
|
||||
toHighlight: ['orgswitchbutton', 'orglink'],
|
||||
content: {
|
||||
number: 1,
|
||||
count: 4,
|
||||
i18nText: 'OVERLAYS.ORGSWITCHER.TEXT',
|
||||
},
|
||||
requirements: {
|
||||
permission: ['org.read'],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'systembutton',
|
||||
origin: 'systembutton',
|
||||
toHighlight: ['systembutton'],
|
||||
content: {
|
||||
number: 2,
|
||||
count: 4,
|
||||
i18nText: 'OVERLAYS.SYSTEM.TEXT',
|
||||
},
|
||||
requirements: {
|
||||
media: '(min-width: 600px)',
|
||||
permission: ['iam.read'],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'profilebutton',
|
||||
origin: 'avatartoggle',
|
||||
toHighlight: ['avatartoggle'],
|
||||
content: {
|
||||
number: 3,
|
||||
count: 4,
|
||||
i18nText: 'OVERLAYS.PROFILE.TEXT',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'mainnav',
|
||||
origin: 'mainnav',
|
||||
toHighlight: ['mainnav'],
|
||||
content: {
|
||||
number: 4,
|
||||
count: 4,
|
||||
i18nText: 'OVERLAYS.NAV.TEXT',
|
||||
},
|
||||
requirements: {
|
||||
permission: ['org.read'],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const OrgContextChangedWorkflowOverlays: CnslOverlay[] = [
|
||||
{
|
||||
id: 'orgswitcher',
|
||||
origin: 'orgswitchbutton',
|
||||
toHighlight: ['orgswitchbutton', 'orglink'],
|
||||
content: {
|
||||
i18nText: 'OVERLAYS.CONTEXTCHANGED.TEXT',
|
||||
},
|
||||
requirements: {
|
||||
permission: ['org.read'],
|
||||
},
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user