Merge pull request 'Improved server loading by route #216' (#227) from #216 into 1.0.0

Reviewed-on: sh-edraft.de/kd_discord_bot#227
Reviewed-by: edraft-dev <dev.sven.heidemann@sh-edraft.de>
Closes #216
This commit is contained in:
Sven Heidemann 2023-02-21 12:12:20 +01:00
commit a3fa7cb7b9
8 changed files with 122 additions and 116 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "kdb-web", "name": "kdb-web",
"version": "1.0.dev217", "version": "1.0.0",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"update-version": "ts-node-esm update-version.ts", "update-version": "ts-node-esm update-version.ts",

View File

@ -84,7 +84,10 @@ export class AutoRolesRulesComponent implements OnInit {
} }
public ngOnInit(): void { public ngOnInit(): void {
this.data.getServerFromRoute(this.route);
this.setFilterForm();
this.data.getServerFromRoute(this.route).then(server => {
this.spinner.showSpinner(); this.spinner.showSpinner();
if (!this.route.snapshot.params["autoRoleId"]) { if (!this.route.snapshot.params["autoRoleId"]) {
this.spinner.hideSpinner(); this.spinner.hideSpinner();
@ -96,7 +99,7 @@ export class AutoRolesRulesComponent implements OnInit {
this.spinner.showSpinner(); this.spinner.showSpinner();
this.data.query<SingleDiscordQuery>(Queries.guildsQuery, { this.data.query<SingleDiscordQuery>(Queries.guildsQuery, {
filter: { filter: {
id: this.sidebar.server$.value?.discordId id: server.discordId
} }
} }
).subscribe(data => { ).subscribe(data => {
@ -111,9 +114,8 @@ export class AutoRolesRulesComponent implements OnInit {
}); });
this.spinner.hideSpinner(); this.spinner.hideSpinner();
}); });
this.setFilterForm();
this.loadNextPage(); this.loadNextPage();
});
} }
public loadNextPage(): void { public loadNextPage(): void {

View File

@ -76,12 +76,13 @@ export class AutoRolesComponent implements OnInit {
} }
public ngOnInit(): void { public ngOnInit(): void {
this.data.getServerFromRoute(this.route);
this.setFilterForm();
this.data.getServerFromRoute(this.route).then(server => {
this.spinner.showSpinner(); this.spinner.showSpinner();
this.data.query<SingleDiscordQuery>(Queries.guildsQuery, { this.data.query<SingleDiscordQuery>(Queries.guildsQuery, {
filter: { filter: {
id: this.sidebar.server$.value?.discordId id: server?.discordId
} }
} }
).subscribe(data => { ).subscribe(data => {
@ -93,9 +94,8 @@ export class AutoRolesComponent implements OnInit {
}); });
this.spinner.hideSpinner(); this.spinner.hideSpinner();
}); });
this.setFilterForm();
this.loadNextPage(); this.loadNextPage();
});
} }
public loadNextPage(): void { public loadNextPage(): void {

View File

@ -14,7 +14,6 @@ import { LevelListQuery, UserListQuery } from "../../../../models/graphql/query.
import { DataService } from "../../../../services/data/data.service"; import { DataService } from "../../../../services/data/data.service";
import { Page } from "../../../../models/graphql/filter/page.model"; import { Page } from "../../../../models/graphql/filter/page.model";
import { Sort, SortDirection } from "../../../../models/graphql/filter/sort.model"; import { Sort, SortDirection } from "../../../../models/graphql/filter/sort.model";
import { SidebarService } from "../../../../services/sidebar/sidebar.service";
import { Mutations } from "../../../../models/graphql/mutations.model"; import { Mutations } from "../../../../models/graphql/mutations.model";
import { throwError } from "rxjs"; import { throwError } from "rxjs";
import { UpdateUserMutationResult } from "../../../../models/graphql/result.model"; import { UpdateUserMutationResult } from "../../../../models/graphql/result.model";
@ -88,32 +87,31 @@ export class MembersComponent implements OnInit {
private fb: FormBuilder, private fb: FormBuilder,
private translate: TranslateService, private translate: TranslateService,
private data: DataService, private data: DataService,
private sidebar: SidebarService,
private route: ActivatedRoute private route: ActivatedRoute
) { ) {
} }
ngOnInit(): void { ngOnInit(): void {
this.data.getServerFromRoute(this.route); this.setFilterForm();
this.data.getServerFromRoute(this.route).then(server => {
this.spinner.showSpinner(); this.spinner.showSpinner();
this.data.query<LevelListQuery>(Queries.levelQuery, { this.data.query<LevelListQuery>(Queries.levelQuery, {
filter: { filter: {
server: { id: this.sidebar.server$.value?.id } server: { id: server.id }
} }
} }
).subscribe(data => { ).subscribe(data => {
this.levels = data.levels.map(level => { this.levels = data.levels.map(level => {
return { label: level.name, value: level }; return { label: level.name, value: level };
}); });
this.spinner.hideSpinner();
}); });
this.setFilterForm();
this.loadNextPage(); this.loadNextPage();
});
} }
loadNextPage() { loadNextPage() {
this.spinner.showSpinner();
this.loading = true; this.loading = true;
this.data.query<UserListQuery>(Queries.usersQuery, { this.data.query<UserListQuery>(Queries.usersQuery, {
filter: this.filter, page: this.page, sort: this.sort filter: this.filter, page: this.page, sort: this.sort

View File

@ -7,7 +7,6 @@ import { DataService } from "../../../../services/data/data.service";
import { User } from "../../../../models/data/user.model"; import { User } from "../../../../models/data/user.model";
import { UserDTO } from "../../../../models/auth/auth-user.dto"; import { UserDTO } from "../../../../models/auth/auth-user.dto";
import { AuthService } from "src/app/services/auth/auth.service"; import { AuthService } from "src/app/services/auth/auth.service";
import { SidebarService } from "../../../../services/sidebar/sidebar.service";
import { ToastService } from "src/app/services/toast/toast.service"; import { ToastService } from "src/app/services/toast/toast.service";
import { TranslateService } from "@ngx-translate/core"; import { TranslateService } from "@ngx-translate/core";
@ -18,13 +17,12 @@ import { TranslateService } from "@ngx-translate/core";
}) })
export class ProfileComponent implements OnInit { export class ProfileComponent implements OnInit {
user!: User; user: User = { createdAt: "", modifiedAt: "" };
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router, private router: Router,
private spinner: SpinnerService, private spinner: SpinnerService,
private sidebar: SidebarService,
private data: DataService, private data: DataService,
private auth: AuthService, private auth: AuthService,
private toast: ToastService, private toast: ToastService,
@ -32,21 +30,20 @@ export class ProfileComponent implements OnInit {
) { ) {
} }
async ngOnInit() { ngOnInit() {
this.data.getServerFromRoute(this.route); this.data.getServerFromRoute(this.route).then(async (server) => {
if (!this.route.snapshot.params["memberId"] || this.route.snapshot.params["memberId"] == "undefined") {
if (!this.route.snapshot.params["memberId"]) { this.router.navigate([`/server/${server.id}`]);
this.router.navigate(["/dashboard"]);
return; return;
} }
let authUser = await this.auth.getLoggedInUser(); let authUser = await this.auth.getLoggedInUser();
this.spinner.showSpinner(); this.spinner.showSpinner();
let user: UserDTO | null = authUser?.users?.find(u => u.server == this.sidebar.server$.value?.id) ?? null; let user: UserDTO | null = authUser?.users?.find(u => u.server == server.id) ?? null;
if (!user || user?.id != this.route.snapshot.params["memberId"] && !user?.isModerator) { if (!user || user?.id != this.route.snapshot.params["memberId"] && !user?.isModerator) {
this.toast.error(this.translate.instant("view.server.profile.permission_denied"), this.translate.instant("view.server.profile.permission_denied_d")); this.toast.error(this.translate.instant("view.server.profile.permission_denied"), this.translate.instant("view.server.profile.permission_denied_d"));
this.spinner.hideSpinner(); this.spinner.hideSpinner();
this.router.navigate(["/server", this.sidebar.server$.value?.id]); this.router.navigate(["/server", server.id]);
return; return;
} }
@ -62,5 +59,8 @@ export class ProfileComponent implements OnInit {
this.user = user; this.user = user;
this.spinner.hideSpinner(); this.spinner.hideSpinner();
}); });
});
} }
} }

View File

@ -25,7 +25,9 @@ export class ServerDashboardComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.data.getServerFromRoute(this.route); this.data.getServerFromRoute(this.route).then(server => {
this.server = server;
});
this.sidebar.server$.subscribe(server => { this.sidebar.server$.subscribe(server => {
if (!server) { if (!server) {

View File

@ -25,12 +25,13 @@ export class DataService {
) { ) {
} }
public getServerFromRoute(route: ActivatedRoute) { public getServerFromRoute(route: ActivatedRoute): Promise<Server> {
return new Promise((resolve, reject) => {
this.spinner.showSpinner(); this.spinner.showSpinner();
if (!route.snapshot.params["serverId"]) { if (!route.snapshot.params["serverId"]) {
this.spinner.hideSpinner(); this.spinner.hideSpinner();
this.router.navigate(["/dashboard"]); this.router.navigate(["/dashboard"]);
return; reject();
} }
this.query<Server>(Queries.serversQuery, { this.query<Server>(Queries.serversQuery, {
@ -42,7 +43,10 @@ export class DataService {
).subscribe(server => { ).subscribe(server => {
this.sidebar.setServer(server); this.sidebar.setServer(server);
this.spinner.hideSpinner(); this.spinner.hideSpinner();
resolve(server);
}); });
});
} }
public query<T>(query: string, variables?: Variables, f?: Function): Observable<T> { public query<T>(query: string, variables?: Variables, f?: Function): Observable<T> {
@ -53,7 +57,7 @@ export class DataService {
}) })
.pipe(map(d => { .pipe(map(d => {
if (d.errors && d.errors.length > 0) { if (d.errors && d.errors.length > 0) {
throw new Error(d.errors.map((x: {message: String}) => x.message).toString()); throw new Error(d.errors.map((x: { message: String }) => x.message).toString());
} }
return d.data; return d.data;
})) }))

View File

@ -3,7 +3,7 @@
"WebVersion": { "WebVersion": {
"Major": "1", "Major": "1",
"Minor": "0", "Minor": "0",
"Micro": "dev217" "Micro": "0"
}, },
"Themes": [ "Themes": [
{ {