mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-29 07:28:52 +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,147 @@
|
||||
import { Injectable, OnDestroy, Renderer2, RendererFactory2 } from '@angular/core';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { Router } from '@angular/router';
|
||||
import { BehaviorSubject, Observable, of, pairwise, Subject, takeUntil } from 'rxjs';
|
||||
|
||||
import { KeyboardShortcutsComponent } from '../../modules/keyboard-shortcuts/keyboard-shortcuts.component';
|
||||
import { GrpcAuthService } from '../grpc-auth.service';
|
||||
import {
|
||||
ACTIONS,
|
||||
DOMAINS,
|
||||
HOME,
|
||||
KeyboardShortcut,
|
||||
ME,
|
||||
ORG,
|
||||
PROJECTS,
|
||||
SYSTEM,
|
||||
USERGRANTS,
|
||||
USERS,
|
||||
} from './keyboard-shortcuts';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class KeyboardShortcutsService implements OnDestroy {
|
||||
private renderer: Renderer2;
|
||||
private keyPressed: BehaviorSubject<any> = new BehaviorSubject<any>(null);
|
||||
private destroy$: Subject<void> = new Subject();
|
||||
|
||||
constructor(
|
||||
private rendererFactory2: RendererFactory2,
|
||||
private dialog: MatDialog,
|
||||
private router: Router,
|
||||
private authService: GrpcAuthService,
|
||||
) {
|
||||
this.renderer = this.rendererFactory2.createRenderer(null, null);
|
||||
this.renderer.listen('document', 'keydown', (event) => {
|
||||
this.keyPressed.next(event);
|
||||
});
|
||||
|
||||
this.keyPressed.pipe(pairwise(), takeUntil(this.destroy$)).subscribe(([firstKey, secondKey]) => {
|
||||
const firstTagname = firstKey?.target?.tagName;
|
||||
const secondTagname = secondKey?.target?.tagName;
|
||||
|
||||
const exclude = ['input', 'textarea'];
|
||||
|
||||
if (
|
||||
firstKey &&
|
||||
secondKey &&
|
||||
exclude.indexOf(firstTagname?.toLowerCase()) === -1 &&
|
||||
exclude.indexOf(secondTagname?.toLowerCase()) === -1
|
||||
) {
|
||||
if (secondKey.key === '?') {
|
||||
this.openOverviewDialog();
|
||||
}
|
||||
|
||||
if (firstKey.code === 'KeyG' && secondKey.code === 'KeyH') {
|
||||
if (this.hasPermission(HOME) && this.hasFeature(HOME)) {
|
||||
this.router.navigate(HOME.link);
|
||||
}
|
||||
}
|
||||
if (firstKey.code === 'KeyG' && secondKey.code === 'KeyS') {
|
||||
if (this.hasPermission(SYSTEM) && this.hasFeature(SYSTEM)) {
|
||||
this.router.navigate(SYSTEM.link);
|
||||
}
|
||||
}
|
||||
if (firstKey.code === 'KeyG' && secondKey.code === 'KeyO') {
|
||||
if (this.hasPermission(ORG) && this.hasFeature(ORG)) {
|
||||
this.router.navigate(ORG.link);
|
||||
}
|
||||
}
|
||||
if (firstKey.code === 'KeyM' && secondKey.code === 'KeyE') {
|
||||
if (this.hasPermission(ME) && this.hasFeature(ME)) {
|
||||
this.router.navigate(ME.link);
|
||||
}
|
||||
}
|
||||
if (firstKey.code === 'KeyG' && secondKey.code === 'KeyP') {
|
||||
if (this.hasPermission(PROJECTS) && this.hasFeature(PROJECTS)) {
|
||||
this.router.navigate(PROJECTS.link);
|
||||
}
|
||||
}
|
||||
if (firstKey.code === 'KeyG' && secondKey.code === 'KeyU') {
|
||||
if (this.hasPermission(USERS) && this.hasFeature(USERS)) {
|
||||
this.router.navigate(USERS.link);
|
||||
}
|
||||
}
|
||||
if (firstKey.code === 'KeyG' && secondKey.code === 'KeyA') {
|
||||
if (this.hasPermission(USERGRANTS) && this.hasFeature(USERGRANTS)) {
|
||||
this.router.navigate(USERGRANTS.link);
|
||||
}
|
||||
}
|
||||
if (firstKey.code === 'KeyG' && secondKey.code === 'KeyF') {
|
||||
if (this.hasPermission(ACTIONS) && this.hasFeature(ACTIONS)) {
|
||||
this.router.navigate(ACTIONS.link);
|
||||
}
|
||||
}
|
||||
if (firstKey.code === 'KeyG' && secondKey.code === 'KeyD') {
|
||||
if (this.hasPermission(DOMAINS) && this.hasFeature(DOMAINS)) {
|
||||
this.router.navigate(DOMAINS.link);
|
||||
}
|
||||
}
|
||||
|
||||
// if (secondKey.shiftKey && (secondKey.code === 'Digit7' || secondKey.key==='/')) {
|
||||
|
||||
// }
|
||||
|
||||
// SIDEWIDESHORTCUTS.f
|
||||
} else if (secondKey && exclude.indexOf(secondTagname?.toLowerCase()) === -1) {
|
||||
if (secondKey.key === '?') {
|
||||
this.openOverviewDialog();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
public openOverviewDialog(): void {
|
||||
const dialogRef = this.dialog.open(KeyboardShortcutsComponent, {
|
||||
data: {},
|
||||
width: '400px',
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((resp) => {
|
||||
if (resp) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private hasPermission(shortcut: KeyboardShortcut): Observable<boolean> {
|
||||
if (shortcut.permissions) {
|
||||
return this.authService.isAllowed(shortcut.permissions);
|
||||
} else {
|
||||
return of(true);
|
||||
}
|
||||
}
|
||||
|
||||
private hasFeature(shortcut: KeyboardShortcut): Observable<boolean> {
|
||||
if (shortcut.features) {
|
||||
return this.authService.canUseFeature(shortcut.features);
|
||||
} else {
|
||||
return of(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
export interface KeyboardShortcut {
|
||||
keyboardKeys: string[];
|
||||
link: any[];
|
||||
i18nKey: string;
|
||||
features?: string[] | RegExp[];
|
||||
permissions?: string[] | RegExp[];
|
||||
}
|
||||
|
||||
export const HOME: KeyboardShortcut = {
|
||||
i18nKey: 'KEYBOARDSHORTCUTS.SHORTCUTS.HOME',
|
||||
link: ['/'],
|
||||
keyboardKeys: ['g', 'h'],
|
||||
};
|
||||
|
||||
export const SYSTEM: KeyboardShortcut = {
|
||||
i18nKey: 'KEYBOARDSHORTCUTS.SHORTCUTS.SYSTEM',
|
||||
link: ['/system'],
|
||||
keyboardKeys: ['g', 's'],
|
||||
permissions: ['iam.read'],
|
||||
};
|
||||
|
||||
export const ORG: KeyboardShortcut = {
|
||||
i18nKey: 'KEYBOARDSHORTCUTS.SHORTCUTS.ORG',
|
||||
link: ['/org'],
|
||||
keyboardKeys: ['g', 'o'],
|
||||
permissions: ['org.read'],
|
||||
};
|
||||
|
||||
export const ME: KeyboardShortcut = {
|
||||
i18nKey: 'KEYBOARDSHORTCUTS.SHORTCUTS.ME',
|
||||
link: ['/users/me'],
|
||||
keyboardKeys: ['m', 'e'],
|
||||
};
|
||||
|
||||
export const PROJECTS: KeyboardShortcut = {
|
||||
i18nKey: 'KEYBOARDSHORTCUTS.SHORTCUTS.PROJECTS',
|
||||
link: ['/projects'],
|
||||
keyboardKeys: ['g', 'p'],
|
||||
permissions: ['project.read'],
|
||||
};
|
||||
|
||||
export const USERS: KeyboardShortcut = {
|
||||
i18nKey: 'KEYBOARDSHORTCUTS.SHORTCUTS.USERS',
|
||||
link: ['/users'],
|
||||
keyboardKeys: ['g', 'u'],
|
||||
permissions: ['user.read'],
|
||||
};
|
||||
|
||||
export const USERGRANTS: KeyboardShortcut = {
|
||||
i18nKey: 'KEYBOARDSHORTCUTS.SHORTCUTS.USERGRANTS',
|
||||
link: ['/grants'],
|
||||
keyboardKeys: ['g', 'a'],
|
||||
permissions: ['usergrant.read'],
|
||||
};
|
||||
|
||||
export const ACTIONS: KeyboardShortcut = {
|
||||
i18nKey: 'KEYBOARDSHORTCUTS.SHORTCUTS.ACTIONS',
|
||||
link: ['/actions'],
|
||||
keyboardKeys: ['g', 'f'],
|
||||
features: ['actions'],
|
||||
permissions: ['org.action.read'],
|
||||
};
|
||||
|
||||
export const DOMAINS: KeyboardShortcut = {
|
||||
i18nKey: 'KEYBOARDSHORTCUTS.SHORTCUTS.DOMAINS',
|
||||
link: ['/domains'],
|
||||
keyboardKeys: ['g', 'd'],
|
||||
permissions: ['org.read'],
|
||||
};
|
||||
|
||||
export const SIDEWIDESHORTCUTS = [ME, HOME, SYSTEM, ORG, PROJECTS, USERS, USERGRANTS, ACTIONS, DOMAINS];
|
||||
|
||||
export const ORGSWITCHER: KeyboardShortcut = {
|
||||
i18nKey: 'KEYBOARDSHORTCUTS.SHORTCUTS.ORGSWITCHER',
|
||||
link: ['/org'],
|
||||
keyboardKeys: ['/'],
|
||||
};
|
||||
|
||||
export const ORGSHORTCUTS = [ORGSWITCHER];
|
||||
Reference in New Issue
Block a user