Improved way to load server for server dashboard #131

This commit is contained in:
Sven Heidemann 2023-02-10 19:33:44 +01:00
parent a6df06f13a
commit 4822348e01
13 changed files with 26088 additions and 19815 deletions

39460
kdb-web/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "kdb-web", "name": "kdb-web",
"version": "0.3.dev162-2", "version": "0.3.dev162-3",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"update-version": "ts-node-esm update-version.ts", "update-version": "ts-node-esm update-version.ts",

View File

@ -7,7 +7,7 @@ import { AuthGuard } from './modules/shared/guards/auth/auth.guard';
const routes: Routes = [ const routes: Routes = [
{ path: '', redirectTo: 'dashboard', pathMatch: 'full' }, { path: '', redirectTo: 'dashboard', pathMatch: 'full' },
{ path: 'dashboard', loadChildren: () => import('./modules/view/dashboard/dashboard.module').then(m => m.DashboardModule), canActivate: [AuthGuard] }, { path: 'dashboard', loadChildren: () => import('./modules/view/dashboard/dashboard.module').then(m => m.DashboardModule), canActivate: [AuthGuard] },
{ path: 'server', loadChildren: () => import('./modules/view/server/server.module').then(m => m.ServerModule), canActivate: [AuthGuard] }, { path: 'server/:id', loadChildren: () => import('./modules/view/server/server.module').then(m => m.ServerModule), canActivate: [AuthGuard] },
{ path: 'change-password', loadChildren: () => import('./modules/view/change-password/change-password.module').then(m => m.ChangePasswordModule), canActivate: [AuthGuard] }, { path: 'change-password', loadChildren: () => import('./modules/view/change-password/change-password.module').then(m => m.ChangePasswordModule), canActivate: [AuthGuard] },
{ path: 'user-settings', loadChildren: () => import('./modules/view/user-settings/user-settings.module').then(m => m.UserSettingsModule), canActivate: [AuthGuard] }, { path: 'user-settings', loadChildren: () => import('./modules/view/user-settings/user-settings.module').then(m => m.UserSettingsModule), canActivate: [AuthGuard] },
{ path: 'auth', loadChildren: () => import('./modules/auth/auth.module').then(m => m.AuthModule) }, { path: 'auth', loadChildren: () => import('./modules/auth/auth.module').then(m => m.AuthModule) },

View File

@ -1,11 +1,10 @@
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'; import { Component, OnInit } from "@angular/core";
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from "@angular/router";
import { LangChangeEvent, TranslateService } from '@ngx-translate/core'; import { LangChangeEvent, TranslateService } from "@ngx-translate/core";
import { MenuItem } from 'primeng/api'; import { MenuItem } from "primeng/api";
import { AuthRoles } from 'src/app/models/auth/auth-roles.enum'; import { AuthRoles } from "src/app/models/auth/auth-roles.enum";
import { AuthService } from 'src/app/services/auth/auth.service'; import { AuthService } from "src/app/services/auth/auth.service";
import { ServerService } from 'src/app/services/data/server.service'; import { ThemeService } from "src/app/services/theme/theme.service";
import { ThemeService } from 'src/app/services/theme/theme.service';
@Component({ @Component({
selector: 'app-sidebar', selector: 'app-sidebar',
@ -24,7 +23,6 @@ export class SidebarComponent implements OnInit {
private translateService: TranslateService, private translateService: TranslateService,
private themeService: ThemeService, private themeService: ThemeService,
private route: ActivatedRoute, private route: ActivatedRoute,
private serverService: ServerService
) { ) {
this.themeService.isSidebarOpen$.subscribe(value => { this.themeService.isSidebarOpen$.subscribe(value => {
this.isSidebarOpen = value; this.isSidebarOpen = value;
@ -35,14 +33,14 @@ export class SidebarComponent implements OnInit {
this.setMenu(); this.setMenu();
}); });
this.serverService.server$.subscribe(server => { // this.serverService.server$.subscribe(server => {
if (!server) { // if (!server) {
return; // return;
} // }
//
this.serverId = server.id; // this.serverId = server.id;
this.setMenu(); // this.setMenu();
}); // });
} }
ngOnInit(): void { ngOnInit(): void {
@ -56,9 +54,9 @@ export class SidebarComponent implements OnInit {
{ label: this.isSidebarOpen ? this.translateService.instant('sidebar.dashboard') : '', icon: 'pi pi-th-large', routerLink: 'dashboard' } { label: this.isSidebarOpen ? this.translateService.instant('sidebar.dashboard') : '', icon: 'pi pi-th-large', routerLink: 'dashboard' }
]; ];
if (this.serverId) { // if (this.serverId) {
this.addServerMenu(); // this.addServerMenu();
} // }
if (hasPermission) { if (hasPermission) {
this.addAdminMenu(); this.addAdminMenu();

View File

@ -1,5 +1,5 @@
export class Queries { export class Queries {
static serverInfoQuery = ` static serversListQuery = `
query ServerInfo($filter: ServerFilter, $page: Page, $sort: Sort) { query ServerInfo($filter: ServerFilter, $page: Page, $sort: Sort) {
serverCount serverCount
servers(filter: $filter, page: $page, sort: $sort) { servers(filter: $filter, page: $page, sort: $sort) {
@ -10,4 +10,15 @@ export class Queries {
} }
} }
`; `;
static serversQuery = `
query ServerInfo($filter: ServerFilter, $page: Page, $sort: Sort) {
servers(filter: $filter, page: $page, sort: $sort) {
id
name
iconURL
userCount
}
}
`;
} }

View File

@ -6,7 +6,6 @@ import { LazyLoadEvent } from "primeng/api";
import { debounceTime, throwError } from "rxjs"; import { debounceTime, throwError } from "rxjs";
import { ConfirmationDialogService } from "src/app/services/confirmation-dialog/confirmation-dialog.service"; import { ConfirmationDialogService } from "src/app/services/confirmation-dialog/confirmation-dialog.service";
import { DataService } from "src/app/services/data/data.service"; import { DataService } from "src/app/services/data/data.service";
import { ServerService } from "src/app/services/data/server.service";
import { SpinnerService } from "src/app/services/spinner/spinner.service"; import { SpinnerService } from "src/app/services/spinner/spinner.service";
import { ToastService } from "src/app/services/toast/toast.service"; import { ToastService } from "src/app/services/toast/toast.service";
import { Server } from "../../../../../models/data/server.model"; import { Server } from "../../../../../models/data/server.model";
@ -50,7 +49,7 @@ export class DashboardComponent implements OnInit {
private fb: FormBuilder, private fb: FormBuilder,
private translate: TranslateService, private translate: TranslateService,
private router: Router, private router: Router,
private serverService: ServerService // private serverService: ServerService
) { ) {
} }
@ -85,7 +84,7 @@ export class DashboardComponent implements OnInit {
loadNextPage() { loadNextPage() {
this.spinnerService.showSpinner(); this.spinnerService.showSpinner();
this.data.query<Query>(Queries.serverInfoQuery,{ this.data.query<Query>(Queries.serversListQuery,{
filter: this.filter, filter: this.filter,
page: this.page, page: this.page,
sort: this.sort, sort: this.sort,
@ -122,8 +121,8 @@ export class DashboardComponent implements OnInit {
} }
selectServer(server: Server) { selectServer(server: Server) {
this.serverService.server$.next(server); // this.serverService.server$.next(server);
this.router.navigate(["/server"]); this.router.navigate(["/server", server.id]);
} }
} }

View File

@ -1,5 +1,5 @@
<h1> <h1>
{{'view.dashboard.header' | translate}} {{'view.server.dashboard.header' | translate}}
</h1> </h1>
<div class="content-wrapper"> <div class="content-wrapper">
<div class="content-header"> <div class="content-header">

View File

@ -2,13 +2,14 @@ import { Component, OnInit } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router"; import { ActivatedRoute, Router } from "@angular/router";
import { Server } from "src/app/models/data/server.model"; import { Server } from "src/app/models/data/server.model";
import { DataService } from "src/app/services/data/data.service"; import { DataService } from "src/app/services/data/data.service";
import { ServerService } from "src/app/services/data/server.service";
import { SpinnerService } from "src/app/services/spinner/spinner.service"; import { SpinnerService } from "src/app/services/spinner/spinner.service";
import { Queries } from "../../../../models/graphql/queries.model";
import { Query } from "../../../../models/graphql/query.model";
@Component({ @Component({
selector: 'app-server-dashboard', selector: "app-server-dashboard",
templateUrl: './server-dashboard.component.html', templateUrl: "./server-dashboard.component.html",
styleUrls: ['./server-dashboard.component.scss'] styleUrls: ["./server-dashboard.component.scss"]
}) })
export class ServerDashboardComponent implements OnInit { export class ServerDashboardComponent implements OnInit {
@ -19,20 +20,22 @@ export class ServerDashboardComponent implements OnInit {
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router, private router: Router,
private data: DataService, private data: DataService,
private spinner: SpinnerService, private spinner: SpinnerService
private serverService: ServerService ) {
) { } }
ngOnInit(): void { ngOnInit(): void {
this.spinner.showSpinner(); this.spinner.showSpinner();
if (!this.serverService.server$.value) { this.data.query<Server>(Queries.serversQuery, {
filter: { id: this.route.snapshot.params["id"] }
},
function(data: Query) {
return data.servers.length > 0 ? data.servers[0] : null;
}
).subscribe(server => {
this.server = server;
this.spinner.hideSpinner(); this.spinner.hideSpinner();
this.router.navigate(['/dashboard']); });
return;
}
this.server = this.serverService.server$.value;
this.spinner.hideSpinner();
} }
} }

View File

@ -27,13 +27,14 @@ export class DataService {
// ); // );
// } // }
public query<T>(query: string, variables?: Variables): Observable<T> { public query<T>(query: string, variables?: Variables, f?: Function): Observable<T> {
return this.http return this.http
.post<{ data: T }>(`${this.appsettings.getApiURL()}/api/graphql`, { .post<{ data: T }>(`${this.appsettings.getApiURL()}/api/graphql`, {
query: query, query: query,
variables: variables variables: variables
}) })
.pipe(map((d) => d.data)); .pipe(map((d) => d.data))
.pipe(map((d) => f ? f(d) : d));
} }
} }

View File

@ -1,16 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { ServerService } from './server.service';
describe('ServerService', () => {
let service: ServerService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ServerService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { Injectable } from "@angular/core";
import { BehaviorSubject } from "rxjs";
import { Server } from "src/app/models/data/server.model";
@Injectable({
providedIn: 'root'
})
export class ServerService {
private server!: Server;
server$ = new BehaviorSubject<Server | null>(null);
constructor() {
this.server$.subscribe(server => {
if (!server) {
return;
}
this.server = server;
});
}
}

View File

@ -151,7 +151,10 @@
} }
}, },
"server": { "server": {
"header": "Server" "header": "Server",
"dashboard": {
"header": "Server dashboard"
}
}, },
"user-list": {}, "user-list": {},
"change-password": { "change-password": {

File diff suppressed because it is too large Load Diff