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",
"version": "1.0.dev217",
"version": "1.0.0",
"scripts": {
"ng": "ng",
"update-version": "ts-node-esm update-version.ts",

View File

@ -84,36 +84,38 @@ export class AutoRolesRulesComponent implements OnInit {
}
public ngOnInit(): void {
this.data.getServerFromRoute(this.route);
this.spinner.showSpinner();
if (!this.route.snapshot.params["autoRoleId"]) {
this.spinner.hideSpinner();
this.router.navigate(["../"]);
return;
}
this.autoRoleId = +this.route.snapshot.params["autoRoleId"];
this.spinner.showSpinner();
this.data.query<SingleDiscordQuery>(Queries.guildsQuery, {
filter: {
id: this.sidebar.server$.value?.discordId
}
}
).subscribe(data => {
this.guild = data.guilds[0];
this.emojis = this.guild.emojis
.map(x => {
return { label: x.name, value: x };
});
this.roles = this.guild.roles
.map(x => {
return { label: x.name, value: x };
});
this.spinner.hideSpinner();
});
this.setFilterForm();
this.loadNextPage();
this.data.getServerFromRoute(this.route).then(server => {
this.spinner.showSpinner();
if (!this.route.snapshot.params["autoRoleId"]) {
this.spinner.hideSpinner();
this.router.navigate(["../"]);
return;
}
this.autoRoleId = +this.route.snapshot.params["autoRoleId"];
this.spinner.showSpinner();
this.data.query<SingleDiscordQuery>(Queries.guildsQuery, {
filter: {
id: server.discordId
}
}
).subscribe(data => {
this.guild = data.guilds[0];
this.emojis = this.guild.emojis
.map(x => {
return { label: x.name, value: x };
});
this.roles = this.guild.roles
.map(x => {
return { label: x.name, value: x };
});
this.spinner.hideSpinner();
});
this.loadNextPage();
});
}
public loadNextPage(): void {

View File

@ -76,26 +76,26 @@ export class AutoRolesComponent implements OnInit {
}
public ngOnInit(): void {
this.data.getServerFromRoute(this.route);
this.spinner.showSpinner();
this.data.query<SingleDiscordQuery>(Queries.guildsQuery, {
filter: {
id: this.sidebar.server$.value?.discordId
}
}
).subscribe(data => {
this.guild = data.guilds[0];
this.channels = this.guild.channels
.filter(x => x.type === ChannelType.text)
.map(x => {
return { label: x.name, value: x };
});
this.spinner.hideSpinner();
});
this.setFilterForm();
this.loadNextPage();
this.data.getServerFromRoute(this.route).then(server => {
this.spinner.showSpinner();
this.data.query<SingleDiscordQuery>(Queries.guildsQuery, {
filter: {
id: server?.discordId
}
}
).subscribe(data => {
this.guild = data.guilds[0];
this.channels = this.guild.channels
.filter(x => x.type === ChannelType.text)
.map(x => {
return { label: x.name, value: x };
});
this.spinner.hideSpinner();
});
this.loadNextPage();
});
}
public loadNextPage(): void {

View File

@ -14,7 +14,6 @@ import { LevelListQuery, UserListQuery } from "../../../../models/graphql/query.
import { DataService } from "../../../../services/data/data.service";
import { Page } from "../../../../models/graphql/filter/page.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 { throwError } from "rxjs";
import { UpdateUserMutationResult } from "../../../../models/graphql/result.model";
@ -88,32 +87,31 @@ export class MembersComponent implements OnInit {
private fb: FormBuilder,
private translate: TranslateService,
private data: DataService,
private sidebar: SidebarService,
private route: ActivatedRoute
) {
}
ngOnInit(): void {
this.data.getServerFromRoute(this.route);
this.spinner.showSpinner();
this.data.query<LevelListQuery>(Queries.levelQuery, {
filter: {
server: { id: this.sidebar.server$.value?.id }
}
}
).subscribe(data => {
this.levels = data.levels.map(level => {
return { label: level.name, value: level };
});
this.spinner.hideSpinner();
});
this.setFilterForm();
this.loadNextPage();
this.data.getServerFromRoute(this.route).then(server => {
this.spinner.showSpinner();
this.data.query<LevelListQuery>(Queries.levelQuery, {
filter: {
server: { id: server.id }
}
}
).subscribe(data => {
this.levels = data.levels.map(level => {
return { label: level.name, value: level };
});
});
this.loadNextPage();
});
}
loadNextPage() {
this.spinner.showSpinner();
this.loading = true;
this.data.query<UserListQuery>(Queries.usersQuery, {
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 { UserDTO } from "../../../../models/auth/auth-user.dto";
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 { TranslateService } from "@ngx-translate/core";
@ -18,13 +17,12 @@ import { TranslateService } from "@ngx-translate/core";
})
export class ProfileComponent implements OnInit {
user!: User;
user: User = { createdAt: "", modifiedAt: "" };
constructor(
private route: ActivatedRoute,
private router: Router,
private spinner: SpinnerService,
private sidebar: SidebarService,
private data: DataService,
private auth: AuthService,
private toast: ToastService,
@ -32,35 +30,37 @@ export class ProfileComponent implements OnInit {
) {
}
async ngOnInit() {
this.data.getServerFromRoute(this.route);
if (!this.route.snapshot.params["memberId"]) {
this.router.navigate(["/dashboard"]);
return;
}
let authUser = await this.auth.getLoggedInUser();
this.spinner.showSpinner();
let user: UserDTO | null = authUser?.users?.find(u => u.server == this.sidebar.server$.value?.id) ?? null;
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.spinner.hideSpinner();
this.router.navigate(["/server", this.sidebar.server$.value?.id]);
return;
}
this.data.query<User>(Queries.singleUserQuery, {
filter: {
id: this.route.snapshot.params["memberId"]
}
},
function(data: UserListQuery) {
return data.users.length > 0 ? data.users[0] : null;
ngOnInit() {
this.data.getServerFromRoute(this.route).then(async (server) => {
if (!this.route.snapshot.params["memberId"] || this.route.snapshot.params["memberId"] == "undefined") {
this.router.navigate([`/server/${server.id}`]);
return;
}
).subscribe(user => {
this.user = user;
this.spinner.hideSpinner();
let authUser = await this.auth.getLoggedInUser();
this.spinner.showSpinner();
let user: UserDTO | null = authUser?.users?.find(u => u.server == server.id) ?? null;
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.spinner.hideSpinner();
this.router.navigate(["/server", server.id]);
return;
}
this.data.query<User>(Queries.singleUserQuery, {
filter: {
id: this.route.snapshot.params["memberId"]
}
},
function(data: UserListQuery) {
return data.users.length > 0 ? data.users[0] : null;
}
).subscribe(user => {
this.user = user;
this.spinner.hideSpinner();
});
});
}
}

View File

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

View File

@ -25,24 +25,28 @@ export class DataService {
) {
}
public getServerFromRoute(route: ActivatedRoute) {
this.spinner.showSpinner();
if (!route.snapshot.params["serverId"]) {
this.spinner.hideSpinner();
this.router.navigate(["/dashboard"]);
return;
}
this.query<Server>(Queries.serversQuery, {
filter: { id: route.snapshot.params["serverId"] }
},
function(data: Query) {
return data.servers.length > 0 ? data.servers[0] : null;
public getServerFromRoute(route: ActivatedRoute): Promise<Server> {
return new Promise((resolve, reject) => {
this.spinner.showSpinner();
if (!route.snapshot.params["serverId"]) {
this.spinner.hideSpinner();
this.router.navigate(["/dashboard"]);
reject();
}
).subscribe(server => {
this.sidebar.setServer(server);
this.spinner.hideSpinner();
this.query<Server>(Queries.serversQuery, {
filter: { id: route.snapshot.params["serverId"] }
},
function(data: Query) {
return data.servers.length > 0 ? data.servers[0] : null;
}
).subscribe(server => {
this.sidebar.setServer(server);
this.spinner.hideSpinner();
resolve(server);
});
});
}
public query<T>(query: string, variables?: Variables, f?: Function): Observable<T> {
@ -53,7 +57,7 @@ export class DataService {
})
.pipe(map(d => {
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;
}))

View File

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