From 1ebad89c973f2818c212785ff346ca6692922861 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 14 Apr 2023 21:46:01 +0200 Subject: [PATCH 1/4] Improved members data loading #300 --- kdb-web/package.json | 2 +- kdb-web/src/app/models/data/user.model.ts | 11 ----- .../src/app/models/graphql/queries.model.ts | 35 ++++++++++++++- .../history-btn/history-btn.component.ts | 44 +++++++++++++++++-- .../auto-roles-rules.component.html | 2 +- .../auto-roles/auto-roles.component.html | 2 +- .../components/levels/levels.component.html | 2 +- .../server/members/members.component.html | 2 +- .../view/server/members/members.component.ts | 1 + .../view/server/profile/profile.component.ts | 6 +-- kdb-web/src/assets/config.json | 2 +- 11 files changed, 83 insertions(+), 26 deletions(-) diff --git a/kdb-web/package.json b/kdb-web/package.json index 4cff7843..44a55353 100644 --- a/kdb-web/package.json +++ b/kdb-web/package.json @@ -1,6 +1,6 @@ { "name": "kdb-web", - "version": "1.0.5", + "version": "1.0.dev307", "scripts": { "ng": "ng", "update-version": "ts-node-esm update-version.ts", diff --git a/kdb-web/src/app/models/data/user.model.ts b/kdb-web/src/app/models/data/user.model.ts index 671da870..fb36964e 100644 --- a/kdb-web/src/app/models/data/user.model.ts +++ b/kdb-web/src/app/models/data/user.model.ts @@ -23,17 +23,6 @@ export interface User extends DataWithHistory { userJoinedGameServerCount?: number; userJoinedGameServers?: UserJoinedGameServer[]; - - // history?: UserHistory[]; -} - -export interface UserHistory extends History { - id?: number; - discordId?: number; - xp?: number; - level?: number; - server?: number; - leftServer?: boolean; } export interface UserFilter { diff --git a/kdb-web/src/app/models/graphql/queries.model.ts b/kdb-web/src/app/models/graphql/queries.model.ts index 29b8dbcf..d55fef25 100644 --- a/kdb-web/src/app/models/graphql/queries.model.ts +++ b/kdb-web/src/app/models/graphql/queries.model.ts @@ -94,6 +94,29 @@ export class Queries { name } leftServer + + createdAt + modifiedAt + } + } + } + `; + + static userProfile = ` + query UserProfile($serverId: ID, $userId: ID, $page: Page, $sort: Sort) { + servers(filter: {id: $serverId}) { + userCount + users(filter: {id: $userId}, page: $page, sort: $sort) { + id + discordId + name + xp + ontime + level { + id + name + } + leftServer server { id name @@ -124,9 +147,17 @@ export class Queries { joinedOn leavedOn } + } + } + } + `; - createdAt - modifiedAt + static userQueryWithHistory = ` + query UsersWithHistory($serverId: ID, $userId: ID) { + servers(filter: {id: $serverId}) { + userCount + users(filter: {id: $userId}) { + id history { id diff --git a/kdb-web/src/app/modules/shared/components/history-btn/history-btn.component.ts b/kdb-web/src/app/modules/shared/components/history-btn/history-btn.component.ts index db89ea41..39c4cd45 100644 --- a/kdb-web/src/app/modules/shared/components/history-btn/history-btn.component.ts +++ b/kdb-web/src/app/modules/shared/components/history-btn/history-btn.component.ts @@ -1,5 +1,16 @@ import { Component, Input, OnInit } from "@angular/core"; import { History } from "../../../../models/data/data.model"; +import { UserListQuery } from "../../../../models/graphql/query.model"; +import { Server } from "../../../../models/data/server.model"; +import { DataService } from "../../../../services/data/data.service"; +import { AuthService } from "../../../../services/auth/auth.service"; +import { SpinnerService } from "../../../../services/spinner/spinner.service"; +import { ToastService } from "../../../../services/toast/toast.service"; +import { ConfirmationDialogService } from "../../../../services/confirmation-dialog/confirmation-dialog.service"; +import { FormBuilder } from "@angular/forms"; +import { TranslateService } from "@ngx-translate/core"; +import { ActivatedRoute } from "@angular/router"; +import { SidebarService } from "../../../../services/sidebar/sidebar.service"; @Component({ selector: "app-history-btn", @@ -8,19 +19,46 @@ import { History } from "../../../../models/data/data.model"; }) export class HistoryBtnComponent implements OnInit { - @Input() history: History[] = []; + @Input() id: number = 0; + @Input() query: string = ""; @Input() translationKey: string = ""; - public showSidebar: boolean = false; + public history: History[] = []; - public constructor() { + public showSidebar: boolean = false; + private server: Server = {}; + + public constructor( + private authService: AuthService, + private spinner: SpinnerService, + private toastService: ToastService, + private confirmDialog: ConfirmationDialogService, + private fb: FormBuilder, + private translate: TranslateService, + private data: DataService, + private route: ActivatedRoute, + private sidebar: SidebarService + ) { } public ngOnInit(): void { + this.server = this.sidebar.server$.value ?? {}; } public openHistory(): void { this.showSidebar = true; + this.data.query(this.query, { + serverId: this.server.id, userId: this.id + }, + (x: { servers: Server[] }) => { + return x.servers[0]; + } + ).subscribe(data => { + this.history = data.users[0].history ?? []; + this.spinner.hideSpinner(); + }); + + let oldHistory: Partial = {}; for (const history of this.history) { const attributes = Object.keys(history).map((key) => { diff --git a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.html b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.html index 3c389ab5..64154ee2 100644 --- a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.html +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.html @@ -160,7 +160,7 @@
- + diff --git a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html index a2677dc0..330b2016 100644 --- a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html @@ -193,7 +193,7 @@
- + diff --git a/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html b/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html index 97be32d8..4cb1859a 100644 --- a/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html +++ b/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html @@ -184,7 +184,7 @@
- + diff --git a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.ts b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.ts index 7f302851..5fab0523 100644 --- a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.ts +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.ts @@ -1,4 +1,4 @@ -import { Component, OnDestroy, OnInit } from "@angular/core"; +import { Component, OnDestroy, OnInit, Query } from "@angular/core"; import { DataService } from "../../../../../../services/data/data.service"; import { ActivatedRoute, Router } from "@angular/router"; import { AutoRoleRule, AutoRoleRuleFilter } from "../../../../../../models/data/auto_role.model"; @@ -66,6 +66,8 @@ export class AutoRolesRulesComponent implements OnInit, OnDestroy { private unsubscriber = new Subject(); private server: Server = {}; + query: string = Queries.autoRoleRulesHistoryQuery; + constructor( private authService: AuthService, private spinner: SpinnerService, diff --git a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html index 330b2016..b30ff372 100644 --- a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html @@ -126,7 +126,8 @@ - + {{autoRole.channelId}} @@ -191,9 +192,9 @@
- - - + + + diff --git a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.ts b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.ts index 12b070c0..77f249ad 100644 --- a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.ts +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.ts @@ -63,6 +63,8 @@ export class AutoRolesComponent implements OnInit, OnDestroy { private unsubscriber = new Subject(); private server: Server = {}; + query: string = Queries.autoRolesWithHistoryQuery; + constructor( private authService: AuthService, private spinner: SpinnerService, From 2b866b5ab1fc6266840d74c2af578d7c6cd5270d Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 14 Apr 2023 22:01:06 +0200 Subject: [PATCH 3/4] Improved level data loading #300 --- .../src/app/models/graphql/queries.model.ts | 21 ++++++++++--------- .../components/levels/levels.component.html | 2 +- .../components/levels/levels.component.ts | 2 ++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/kdb-web/src/app/models/graphql/queries.model.ts b/kdb-web/src/app/models/graphql/queries.model.ts index a8c0fd97..f3d68257 100644 --- a/kdb-web/src/app/models/graphql/queries.model.ts +++ b/kdb-web/src/app/models/graphql/queries.model.ts @@ -62,6 +62,17 @@ export class Queries { } createdAt modifiedAt + } + } + } + `; + + static levelWithHistoryQuery = ` + query LevelHistory($serverId: ID, $id: ID) { + servers(filter: {id: $serverId}) { + levelCount + levels(filter: {id: $id}) { + id history { id @@ -233,16 +244,6 @@ export class Queries { createdAt modifiedAt - - history { - id - emojiName - roleId - autoRole - deleted - dateFrom - dateTo - } } } } diff --git a/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html b/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html index 4cb1859a..0c8b1945 100644 --- a/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html +++ b/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html @@ -184,7 +184,7 @@
- +