Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hide app when globalLoading is true to avoid unwanted behavior when switching apps #218

Merged
merged 10 commits into from
Apr 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ export class UserService implements OnDestroy {
.subscribe(this.lang$)

this.profile$.pipe(map((profile) => this.extractPermissions(profile))).subscribe(this.permissions$)
this.permissionsTopic$.subscribe(this.permissions$)
}

ngOnDestroy(): void {
this.profile$.destroy()
}

hasPermission(permissionKey: string): boolean {
const result = this.permissions$.getValue() ? this.permissions$.getValue()?.includes(permissionKey) : false
const oldConceptResult = this.permissions$.getValue()
? this.permissions$.getValue()?.includes(permissionKey)
: false
const result = this.permissionsTopic$.getValue()
? this.permissionsTopic$.getValue()?.includes(permissionKey)
: oldConceptResult

if (!result) {
console.log(`👮‍♀️ No permission for: ${permissionKey}`)
}
Expand Down Expand Up @@ -79,4 +84,9 @@ export class UserService implements OnDestroy {
}
return permissions
}

get isInitialized(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-empty-function
return Promise.all([this.permissionsTopic$.isInitialized, this.profile$.isInitialized]).then(() => {})
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Topic } from "@onecx/accelerator";
import { SyncableTopic } from "@onecx/accelerator";

export class PermissionsTopic extends Topic<string[]> {
export class PermissionsTopic extends SyncableTopic<string[]> {
constructor() {
super('permissions', 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class InitializeModuleGuard implements CanActivate {
return zip([
this.loadTranslations(),
from(this.configService.isInitialized),
from(this.userService.isInitialized),
from(this.appStateService.currentWorkspace$.isInitialized),
this.appStateService.globalLoading$.pipe(filter((g) => !g)),
]).pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
<div class="layout-main">
<div class="layout-content relative">
<ocx-slot name="subHeader"></ocx-slot>

<ng-content></ng-content>
<router-outlet></router-outlet>
<ng-container *ngIf="(appStateService.globalLoading$ | async) === false">
<ng-content></ng-content>
<router-outlet></router-outlet>
</ng-container>
</div>

<ocx-shell-footer></ocx-shell-footer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class PortalViewportComponent implements OnInit, AfterViewInit, OnDestroy
private renderer: Renderer2,
private primengConfig: PrimeNGConfig,
private messageService: MessageService,
private appStateService: AppStateService,
public appStateService: AppStateService,
private portalMessageService: PortalMessageService,
private userService: UserService,
private themeService: ThemeService,
Expand Down
Loading