From e0ca0573990b8fb1bd86fa0f096c3e49e920910e Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 19 Feb 2023 17:32:08 +0100 Subject: [PATCH 1/8] [WIP] Added auto roles list #134 --- .../bot_graphql/filter/auto_role_filter.py | 15 +- kdb-web/package.json | 2 +- .../src/app/models/data/auto_role.model.ts | 35 +++ .../src/app/models/graphql/queries.model.ts | 16 ++ kdb-web/src/app/models/graphql/query.model.ts | 6 + .../auth-user/auth-user.component.html | 2 +- .../auth-user/auth-user.component.ts | 37 ++- .../auto-role/auto-role-routing.module.ts | 18 ++ .../view/server/auto-role/auto-role.module.ts | 21 ++ .../auto-roles-rules.component.html | 1 + .../auto-roles-rules.component.scss | 0 .../auto-roles-rules.component.spec.ts | 23 ++ .../auto-roles-rules.component.ts | 10 + .../auto-roles/auto-roles.component.html | 219 +++++++++++++++++ .../auto-roles/auto-roles.component.scss | 0 .../auto-roles/auto-roles.component.spec.ts | 23 ++ .../auto-roles/auto-roles.component.ts | 221 ++++++++++++++++++ .../view/server/members/members.component.ts | 10 +- .../view/server/server-routing.module.ts | 1 + .../app/services/sidebar/sidebar.service.ts | 15 +- kdb-web/src/assets/config.json | 2 +- kdb-web/src/assets/i18n/de.json | 29 ++- 22 files changed, 669 insertions(+), 37 deletions(-) create mode 100644 kdb-web/src/app/models/data/auto_role.model.ts create mode 100644 kdb-web/src/app/modules/view/server/auto-role/auto-role-routing.module.ts create mode 100644 kdb-web/src/app/modules/view/server/auto-role/auto-role.module.ts create mode 100644 kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.html create mode 100644 kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.scss create mode 100644 kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.spec.ts create mode 100644 kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.ts create mode 100644 kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html create mode 100644 kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.scss create mode 100644 kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.spec.ts create mode 100644 kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.ts diff --git a/kdb-bot/src/bot_graphql/filter/auto_role_filter.py b/kdb-bot/src/bot_graphql/filter/auto_role_filter.py index 20d9d886..6f17dd59 100644 --- a/kdb-bot/src/bot_graphql/filter/auto_role_filter.py +++ b/kdb-bot/src/bot_graphql/filter/auto_role_filter.py @@ -45,16 +45,19 @@ class AutoRoleFilter(FilterABC): query = query.where(lambda x: x.id == self._id) if self._channel_id is not None: - query = query.where(lambda x: x.discord_channel_id == self._channel_id) - - if self._channel_name is not None and self._channel_id is not None: query = query.where( - lambda x: self._bot.get_channel(x.discord_channel_id).name == self._channel_name - or self._channel_name in self._bot.get_channel(x.discord_channel_id).name + lambda x: x.discord_channel_id == self._channel_id or str(self._channel_id) in str(x.discord_channel_id) + ) + + if self._channel_name is not None: + query = query.where( + lambda x: x.discord_channel_name == self._channel_name or self._channel_name in x.discord_channel_name ) if self._message_id is not None: - query = query.where(lambda x: x.discord_message_id == self._message_id) + query = query.where( + lambda x: x.discord_message_id == self._message_id or str(self._message_id) in str(x.discord_message_id) + ) if self._server is not None: servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.id) diff --git a/kdb-web/package.json b/kdb-web/package.json index 831fe41d..3f58bd6d 100644 --- a/kdb-web/package.json +++ b/kdb-web/package.json @@ -1,6 +1,6 @@ { "name": "kdb-web", - "version": "1.0.dev130", + "version": "1.0.dev134", "scripts": { "ng": "ng", "update-version": "ts-node-esm update-version.ts", diff --git a/kdb-web/src/app/models/data/auto_role.model.ts b/kdb-web/src/app/models/data/auto_role.model.ts new file mode 100644 index 00000000..c94e042f --- /dev/null +++ b/kdb-web/src/app/models/data/auto_role.model.ts @@ -0,0 +1,35 @@ +import { Data } from "./data.model"; +import { Server, ServerFilter } from "./server.model"; + +export interface AutoRole extends Data { + id?: number; + channelId?: string; + channelName?: string; + messageId?: string; + server?: Server; + + autoRoleRuleCount?: number; + autoRoleRules?: AutoRoleRule[]; +} + +export interface AutoRoleFilter { + id?: number; + channelId?: string; + channelName?: string; + messageId?: string; + server?: ServerFilter; +} + +export interface AutoRoleRule extends Data { + id?: number; + emojiName?: string; + roleId?: string; + autoRole?: AutoRole; +} + +export interface AutoRoleRuleFilter { + id?: number; + emojiName?: string; + roleId?: string; + autoRole?: AutoRoleFilter; +} diff --git a/kdb-web/src/app/models/graphql/queries.model.ts b/kdb-web/src/app/models/graphql/queries.model.ts index be97aec4..70866a8d 100644 --- a/kdb-web/src/app/models/graphql/queries.model.ts +++ b/kdb-web/src/app/models/graphql/queries.model.ts @@ -131,4 +131,20 @@ export class Queries { } } `; + + static autoRolesQuery = ` + query AutoRoleQuery($filter: AutoRoleFilter, $page: Page, $sort: Sort) { + autoRoleCount + autoRoles(filter: $filter, page: $page, sort: $sort) { + id + channelId + channelName + messageId + autoRoleRuleCount + + createdAt + modifiedAt + } + } + `; } diff --git a/kdb-web/src/app/models/graphql/query.model.ts b/kdb-web/src/app/models/graphql/query.model.ts index ed6eb037..235ad780 100644 --- a/kdb-web/src/app/models/graphql/query.model.ts +++ b/kdb-web/src/app/models/graphql/query.model.ts @@ -1,5 +1,6 @@ import { Server } from "../data/server.model"; import { User } from "../data/user.model"; +import { AutoRole } from "../data/auto_role.model"; export interface Query { serverCount: number; @@ -16,3 +17,8 @@ export interface LevelListQuery { levels: User[]; } +export interface AutoRoleQuery { + autoRoleCount: number; + autoRoles: AutoRole[]; +} + diff --git a/kdb-web/src/app/modules/admin/auth-users/components/auth-user/auth-user.component.html b/kdb-web/src/app/modules/admin/auth-users/components/auth-user/auth-user.component.html index 4aefe844..128fa909 100644 --- a/kdb-web/src/app/modules/admin/auth-users/components/auth-user/auth-user.component.html +++ b/kdb-web/src/app/modules/admin/auth-users/components/auth-user/auth-user.component.html @@ -21,7 +21,7 @@ icon="pi pi-user-plus" (click)="addUser(dt)" [disabled]="isEditingNew"> diff --git a/kdb-web/src/app/modules/admin/auth-users/components/auth-user/auth-user.component.ts b/kdb-web/src/app/modules/admin/auth-users/components/auth-user/auth-user.component.ts index a9243563..b4ac6706 100644 --- a/kdb-web/src/app/modules/admin/auth-users/components/auth-user/auth-user.component.ts +++ b/kdb-web/src/app/modules/admin/auth-users/components/auth-user/auth-user.component.ts @@ -1,20 +1,20 @@ -import { Component, OnInit } from '@angular/core'; -import { catchError, debounceTime, last } from 'rxjs/operators'; -import { AuthRoles } from 'src/app/models/auth/auth-roles.enum'; -import { AuthUserDTO } from 'src/app/models/auth/auth-user.dto'; -import { AuthService } from 'src/app/services/auth/auth.service'; -import { ConfirmationDialogService } from 'src/app/services/confirmation-dialog/confirmation-dialog.service'; -import { SpinnerService } from 'src/app/services/spinner/spinner.service'; -import { ToastService } from 'src/app/services/toast/toast.service'; -import { Table } from 'primeng/table'; -import { ServiceErrorCode } from 'src/app/models/error/service-error-code.enum'; -import { RegisterErrorMessages } from 'src/app/models/auth/register-error-messages.enum'; -import { ErrorDTO } from 'src/app/models/error/error-dto'; -import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; -import { AuthUserSelectCriterion } from 'src/app/models/selection/auth-user/auth-user-select-criterion.dto'; -import { LazyLoadEvent } from 'primeng/api'; -import { throwError } from 'rxjs'; -import { TranslateService } from '@ngx-translate/core'; +import { Component, OnInit } from "@angular/core"; +import { catchError, debounceTime } from "rxjs/operators"; +import { AuthRoles } from "src/app/models/auth/auth-roles.enum"; +import { AuthUserDTO } from "src/app/models/auth/auth-user.dto"; +import { AuthService } from "src/app/services/auth/auth.service"; +import { ConfirmationDialogService } from "src/app/services/confirmation-dialog/confirmation-dialog.service"; +import { SpinnerService } from "src/app/services/spinner/spinner.service"; +import { ToastService } from "src/app/services/toast/toast.service"; +import { Table } from "primeng/table"; +import { ServiceErrorCode } from "src/app/models/error/service-error-code.enum"; +import { RegisterErrorMessages } from "src/app/models/auth/register-error-messages.enum"; +import { ErrorDTO } from "src/app/models/error/error-dto"; +import { FormBuilder, FormControl, FormGroup } from "@angular/forms"; +import { AuthUserSelectCriterion } from "src/app/models/selection/auth-user/auth-user-select-criterion.dto"; +import { LazyLoadEvent } from "primeng/api"; +import { throwError } from "rxjs"; +import { TranslateService } from "@ngx-translate/core"; @Component({ @@ -162,7 +162,7 @@ export class AuthUserComponent implements OnInit { this.loadNextPage(); } - resetFilters(table: Table) { + resetFilters() { this.filterForm.reset(); } @@ -309,7 +309,6 @@ export class AuthUserComponent implements OnInit { addUser(table: Table) { const newUser = JSON.parse(JSON.stringify(this.newUserTemplate)); newUser.id = Math.max.apply(Math, this.users.map(u => { return u.id ?? 0; })) + 1; - console.log(newUser); this.users.push(newUser); this.triggerUserChangeDetection(); diff --git a/kdb-web/src/app/modules/view/server/auto-role/auto-role-routing.module.ts b/kdb-web/src/app/modules/view/server/auto-role/auto-role-routing.module.ts new file mode 100644 index 00000000..fa90d850 --- /dev/null +++ b/kdb-web/src/app/modules/view/server/auto-role/auto-role-routing.module.ts @@ -0,0 +1,18 @@ +import { NgModule } from "@angular/core"; +import { RouterModule, Routes } from "@angular/router"; +import { AutoRolesComponent } from "./components/auto-roles/auto-roles.component"; +import { AutoRolesRulesComponent } from "./components/auto-roles-rules/auto-roles-rules.component"; + +const routes: Routes = [ + + { path: "", component: AutoRolesComponent }, + { path: ":autoRoleId/rules", component: AutoRolesRulesComponent } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) +export class AutoRoleRoutingModule { + +} diff --git a/kdb-web/src/app/modules/view/server/auto-role/auto-role.module.ts b/kdb-web/src/app/modules/view/server/auto-role/auto-role.module.ts new file mode 100644 index 00000000..6d5b3248 --- /dev/null +++ b/kdb-web/src/app/modules/view/server/auto-role/auto-role.module.ts @@ -0,0 +1,21 @@ +import { NgModule } from "@angular/core"; +import { CommonModule } from "@angular/common"; + +import { AutoRoleRoutingModule } from "./auto-role-routing.module"; +import { AutoRolesComponent } from "./components/auto-roles/auto-roles.component"; +import { AutoRolesRulesComponent } from "./components/auto-roles-rules/auto-roles-rules.component"; +import { SharedModule } from "../../../shared/shared.module"; + + +@NgModule({ + declarations: [ + AutoRolesComponent, + AutoRolesRulesComponent + ], + imports: [ + CommonModule, + AutoRoleRoutingModule, + SharedModule, + ] +}) +export class AutoRoleModule { } 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 new file mode 100644 index 00000000..03f26bd4 --- /dev/null +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.html @@ -0,0 +1 @@ +

auto-roles-rules works!

diff --git a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.scss b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.spec.ts b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.spec.ts new file mode 100644 index 00000000..33059010 --- /dev/null +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AutoRolesRulesComponent } from './auto-roles-rules.component'; + +describe('AutoRolesRulesComponent', () => { + let component: AutoRolesRulesComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ AutoRolesRulesComponent ] + }) + .compileComponents(); + + fixture = TestBed.createComponent(AutoRolesRulesComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); 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 new file mode 100644 index 00000000..2440f09d --- /dev/null +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles-rules/auto-roles-rules.component.ts @@ -0,0 +1,10 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-auto-roles-rules', + templateUrl: './auto-roles-rules.component.html', + styleUrls: ['./auto-roles-rules.component.scss'] +}) +export class AutoRolesRulesComponent { + +} 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 new file mode 100644 index 00000000..ee1ac4af --- /dev/null +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.html @@ -0,0 +1,219 @@ +

+ {{'view.server.auto_roles.header' | translate}} +

+
+
+ + + +
+
+ {{auto_roles.length}} {{'view.server.auto_roles.of' | translate}} + {{dt.totalRecords}} + + {{'view.server.auto_roles.auto_roles' | translate}} +
+ +
+ + +
+
+
+ + + + +
+
{{'view.server.auto_roles.headers.id' | translate}}
+ +
+ + + +
+
{{'view.server.auto_roles.headers.channel_id' | translate}}
+ +
+ + + +
+
{{'view.server.auto_roles.headers.channel_name' | translate}}
+ +
+ + + +
+
{{'view.server.auto_roles.headers.message_id' | translate}}
+ +
+ + + +
+
{{'view.server.auto_roles.headers.role_count' | translate}}
+
+ + + +
+
{{'common.created_at' | translate}}
+
+ + + +
+
{{'common.modified_at' | translate}}
+
+ + + +
+
{{'view.server.auto_roles.headers.actions' | translate}}
+
+ + + + + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + + + + + +
+ + + + + + + {{autoRole.id}} + + + {{autoRole.id}} + + + + + + + + {{autoRole.channelId}} + + + {{autoRole.channelId}} + + + + + + + + {{autoRole.channelName}} + + + {{autoRole.channelName}} + + + + + + + + {{autoRole.messageId}} + + + {{autoRole.messageId}} + + + + + + + + {{autoRole.autoRoleRuleCount}} + + + {{autoRole.autoRoleRuleCount}} + + + + + + + + {{autoRole.createdAt | date:'dd.MM.yy HH:mm'}} + + + {{autoRole.createdAt | date:'dd.MM.yy HH:mm'}} + + + + + + + + {{autoRole.modifiedAt | date:'dd.MM.yy HH:mm'}} + + + {{autoRole.modifiedAt | date:'dd.MM.yy HH:mm'}} + + + + + +
+ + + + + +
+ + +
+ + + + + {{'view.server.auto_roles.no_entries_found' | translate}} + + + + + + +
+
+
diff --git a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.scss b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.spec.ts b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.spec.ts new file mode 100644 index 00000000..88577828 --- /dev/null +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AutoRolesComponent } from './auto-roles.component'; + +describe('AutoRolesComponent', () => { + let component: AutoRolesComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ AutoRolesComponent ] + }) + .compileComponents(); + + fixture = TestBed.createComponent(AutoRolesComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); 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 new file mode 100644 index 00000000..a995cd83 --- /dev/null +++ b/kdb-web/src/app/modules/view/server/auto-role/components/auto-roles/auto-roles.component.ts @@ -0,0 +1,221 @@ +import { Component, OnInit } from "@angular/core"; +import { User } from "../../../../../../models/data/user.model"; +import { LazyLoadEvent } from "primeng/api"; +import { FormBuilder, FormControl, FormGroup } from "@angular/forms"; +import { Page } from "../../../../../../models/graphql/filter/page.model"; +import { Sort, SortDirection } from "../../../../../../models/graphql/filter/sort.model"; +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 { TranslateService } from "@ngx-translate/core"; +import { DataService } from "../../../../../../services/data/data.service"; +import { SidebarService } from "../../../../../../services/sidebar/sidebar.service"; +import { ActivatedRoute } from "@angular/router"; +import { AutoRoleQuery } from "../../../../../../models/graphql/query.model"; +import { Queries } from "../../../../../../models/graphql/queries.model"; +import { catchError, debounceTime } from "rxjs/operators"; +import { Table } from "primeng/table"; +import { UpdateUserMutationResult } from "../../../../../../models/graphql/result.model"; +import { Mutations } from "../../../../../../models/graphql/mutations.model"; +import { throwError } from "rxjs"; +import { AutoRole, AutoRoleFilter } from "../../../../../../models/data/auto_role.model"; + +@Component({ + selector: "app-auto-roles", + templateUrl: "./auto-roles.component.html", + styleUrls: ["./auto-roles.component.scss"] +}) +export class AutoRolesComponent implements OnInit { + auto_roles!: AutoRole[]; + loading = true; + + clonedUsers: { [s: string]: User; } = {}; + isEditingNew: boolean = false; + + newAutoRoleTemplate: AutoRole = { + id: 0, + createdAt: "", + modifiedAt: "" + }; + + filterForm!: FormGroup<{ + id: FormControl, + channelId: FormControl, + channelName: FormControl, + messageId: FormControl, + }>; + + filter: AutoRoleFilter = {}; + page: Page = { + pageSize: undefined, + pageIndex: undefined + }; + sort: Sort = { + sortColumn: undefined, + sortDirection: undefined + }; + + totalRecords!: number; + + constructor( + private authService: AuthService, + private spinner: SpinnerService, + private toastService: ToastService, + private confirmDialog: ConfirmationDialogService, + private fb: FormBuilder, + private translate: TranslateService, + private data: DataService, + private sidebar: SidebarService, + private route: ActivatedRoute + ) { + } + + ngOnInit(): void { + this.data.getServerFromRoute(this.route); + + this.setFilterForm(); + this.loadNextPage(); + } + + loadNextPage() { + this.loading = true; + this.data.query(Queries.autoRolesQuery, { + filter: this.filter, page: this.page, sort: this.sort + } + ).subscribe(data => { + this.totalRecords = data.autoRoleCount; + this.auto_roles = data.autoRoles; + this.spinner.hideSpinner(); + this.loading = false; + }); + } + + setFilterForm() { + this.filterForm = this.fb.group({ + id: new FormControl(null), + channelId: new FormControl(null), + channelName: new FormControl(null), + messageId: new FormControl(null), + }); + + this.filterForm.valueChanges.pipe( + debounceTime(600) + ).subscribe(changes => { + if (changes.id) { + this.filter.id = changes.id; + } else { + this.filter.id = undefined; + } + + if (changes.channelId) { + this.filter.channelId = changes.channelId; + } else { + this.filter.channelId = undefined; + } + + if (changes.channelName) { + this.filter.channelName = changes.channelName; + } else { + this.filter.channelName = undefined; + } + + if (changes.messageId) { + this.filter.messageId = changes.messageId; + } else { + this.filter.messageId = undefined; + } + + if (this.page.pageSize) + this.page.pageSize = 10; + + if (this.page.pageIndex) + this.page.pageIndex = 0; + + this.loadNextPage(); + }); + } + + nextPage(event: LazyLoadEvent) { + this.page.pageSize = event.rows ?? 0; + if (event.first != null && event.rows != null) + this.page.pageIndex = event.first / event.rows; + this.sort.sortColumn = event.sortField ?? undefined; + this.sort.sortDirection = event.sortOrder === 1 ? SortDirection.ASC : event.sortOrder === -1 ? SortDirection.DESC : SortDirection.ASC; + + this.loadNextPage(); + } + + resetFilters() { + this.filterForm.reset(); + } + + onRowEditInit(table: Table, user: User, index: number) { + this.clonedUsers[index] = { ...user }; + } + + onRowEditSave(table: Table, newUser: User, index: number) { + // const oldUser = this.clonedUsers[index]; + // delete this.clonedUsers[index]; + + // if (JSON.stringify(oldUser) === JSON.stringify(newUser) && !this.isEditingNew) { + // console.log(1, oldUser, newUser, JSON.stringify(oldUser) === JSON.stringify(newUser), !this.isEditingNew); + // return; + // } + + if (this.isEditingNew && JSON.stringify(newUser) === JSON.stringify(this.newAutoRoleTemplate)) { + this.isEditingNew = false; + this.auto_roles.splice(index, 1); + return; + } + + if (!newUser.id || !newUser.xp && !newUser.level?.id) { + return; + } + + this.spinner.showSpinner(); + this.data.mutation(Mutations.updateUser, { + id: newUser.id, + xp: newUser.xp, + levelId: newUser.level?.id + } + ).pipe(catchError(err => { + this.spinner.hideSpinner(); + this.toastService.error(this.translate.instant("view.server.members.message.user_change_failed"), this.translate.instant("view.server.members.message.user_change_failed_d", { name: newUser.name })); + return throwError(err); + })).subscribe(_ => { + this.spinner.hideSpinner(); + this.toastService.success(this.translate.instant("view.server.members.message.user_changed"), this.translate.instant("view.server.members.message.user_changed_d", { name: newUser.name })); + this.loadNextPage(); + }); + + } + + onRowEditCancel(user: User, index: number) { + if (this.isEditingNew) { + this.auto_roles.splice(index, 1); + delete this.clonedUsers[index]; + this.isEditingNew = false; + return; + } + + this.auto_roles[index] = this.clonedUsers[index]; + delete this.clonedUsers[index]; + } + + addUser(table: Table) { + const newAutoRole = JSON.parse(JSON.stringify(this.newAutoRoleTemplate)); + newAutoRole.id = Math.max.apply(Math, this.auto_roles.map(u => { + return u.id ?? 0; + })) + 1; + + this.auto_roles.push(newAutoRole); + + table.initRowEdit(newAutoRole); + + const index = this.auto_roles.findIndex(u => u.id == newAutoRole.id); + this.onRowEditInit(table, newAutoRole, index); + + this.isEditingNew = true; + } +} diff --git a/kdb-web/src/app/modules/view/server/members/members.component.ts b/kdb-web/src/app/modules/view/server/members/members.component.ts index bc98e1ee..51bf7cba 100644 --- a/kdb-web/src/app/modules/view/server/members/members.component.ts +++ b/kdb-web/src/app/modules/view/server/members/members.component.ts @@ -1,4 +1,4 @@ -import { Component } from "@angular/core"; +import { Component, OnInit } from "@angular/core"; import { FormBuilder, FormControl, FormGroup } from "@angular/forms"; import { AuthService } from "../../../../services/auth/auth.service"; import { SpinnerService } from "../../../../services/spinner/spinner.service"; @@ -25,13 +25,13 @@ import { ActivatedRoute } from "@angular/router"; templateUrl: "./members.component.html", styleUrls: ["./members.component.scss"] }) -export class MembersComponent { +export class MembersComponent implements OnInit { members!: User[]; // levelsFilter!: MenuItem[]; levels!: MenuItem[]; leftServerOptions = [ - {label: this.translate.instant('common.bool_as_string.true'), value: false}, - {label: this.translate.instant('common.bool_as_string.false'), value: true}, + { label: this.translate.instant("common.bool_as_string.true"), value: false }, + { label: this.translate.instant("common.bool_as_string.false"), value: true } ]; loading = true; @@ -132,7 +132,7 @@ export class MembersComponent { discordId: new FormControl(null), name: [""], leftServer: new FormControl(null), - level: new FormControl(null), + level: new FormControl(null) }); this.filterForm.valueChanges.pipe( diff --git a/kdb-web/src/app/modules/view/server/server-routing.module.ts b/kdb-web/src/app/modules/view/server/server-routing.module.ts index d4de8413..b390b0b8 100644 --- a/kdb-web/src/app/modules/view/server/server-routing.module.ts +++ b/kdb-web/src/app/modules/view/server/server-routing.module.ts @@ -8,6 +8,7 @@ const routes: Routes = [ { path: '', component: ServerDashboardComponent }, { path: 'members', component: MembersComponent }, { path: 'members/:memberId', component: ProfileComponent }, + { path: 'auto-roles', loadChildren: () => import('./auto-role/auto-role.module').then(m => m.AutoRoleModule)}, ]; @NgModule({ diff --git a/kdb-web/src/app/services/sidebar/sidebar.service.ts b/kdb-web/src/app/services/sidebar/sidebar.service.ts index 5a7a23a6..601a8ad0 100644 --- a/kdb-web/src/app/services/sidebar/sidebar.service.ts +++ b/kdb-web/src/app/services/sidebar/sidebar.service.ts @@ -8,6 +8,7 @@ import { NavigationEnd, Router } from "@angular/router"; import { ThemeService } from "../theme/theme.service"; import { Server } from "../../models/data/server.model"; import { UserDTO } from "../../models/auth/auth-user.dto"; +import { AutoRole } from "../../models/data/auto_role.model"; @Injectable({ providedIn: "root" @@ -17,11 +18,14 @@ export class SidebarService { isSidebarOpen: boolean = true; menuItems$ = new BehaviorSubject(new Array()); server$ = new BehaviorSubject(null); + autoRole$ = new BehaviorSubject(null); dashboard!: MenuItem; serverDashboard!: MenuItem; serverProfile!: MenuItem; serverMembers!: MenuItem; + serverAutoRoles!: MenuItem; + serverAutoRoleRules!: MenuItem; serverMenu!: MenuItem; adminConfig!: MenuItem; adminUsers!: MenuItem; @@ -81,12 +85,20 @@ export class SidebarService { visible: true, routerLink: `server/${this.server$.value?.id}/members` }; + + this.serverAutoRoles = { + label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.auto_roles") : "", + icon: "pi pi-sitemap", + visible: true, + routerLink: `server/${this.server$.value?.id}/auto-roles` + }; + this.serverMenu = { label: this.isSidebarOpen ? this.server$.value?.name : "", icon: "pi pi-server", visible: false, expanded: true, - items: [this.serverDashboard, this.serverProfile, this.serverMembers] + items: [this.serverDashboard, this.serverProfile, this.serverMembers, this.serverAutoRoles] }; this.adminConfig = { label: this.isSidebarOpen ? this.translateService.instant("sidebar.config") : "", icon: "pi pi-cog", routerLink: "/admin/settings" }; this.adminUsers = { @@ -115,6 +127,7 @@ export class SidebarService { if (this.server$.value) { this.serverMenu.visible = true; this.serverMembers.visible = !!user?.isModerator; + this.serverAutoRoles.visible = !!user?.isAdmin; } else { this.serverMenu.visible = false; } diff --git a/kdb-web/src/assets/config.json b/kdb-web/src/assets/config.json index cac3944d..d4110a8a 100644 --- a/kdb-web/src/assets/config.json +++ b/kdb-web/src/assets/config.json @@ -3,7 +3,7 @@ "WebVersion": { "Major": "1", "Minor": "0", - "Micro": "dev130" + "Micro": "dev134" }, "Themes": [ { diff --git a/kdb-web/src/assets/i18n/de.json b/kdb-web/src/assets/i18n/de.json index 7a26d75b..eefd653d 100644 --- a/kdb-web/src/assets/i18n/de.json +++ b/kdb-web/src/assets/i18n/de.json @@ -10,7 +10,8 @@ "server": { "dashboard": "Dashboard", "profile": "Dein Profil", - "members": "Mitglieder" + "members": "Mitglieder", + "auto_roles": "Auto Rollen" }, "server_empty": "Kein Server ausgewählt", "members": "Mitglieder", @@ -202,8 +203,8 @@ "reset_filters": "Filter zurücksetzen", "members": "Mitgliedern", "headers": { - "id": "ID", - "discord_id": "Discord ID", + "id": "Id", + "discord_id": "Discord Id", "name": "Name", "xp": "XP", "ontime": "Ontime", @@ -218,6 +219,28 @@ "user_change_failed": "Benutzer änderung fehlgeschlagen", "user_change_failed_d": "Benutzer {{name}} konnte nicht geändert werden!" } + }, + "auto_roles": { + "header": "Auto Rollen", + "of": "von", + "add": "Hinzufügen", + "reset_filters": "Filter zurücksetzen", + "auto_roles": "Auto Rollen", + "headers": { + "id": "Id", + "channel_id": "Kanal Id", + "channel_name": "Kanal", + "message_id": "Nachricht Id", + "role_count": "Regeln", + "actions": "Aktionen" + }, + "no_entries_found": "Keine Einträge gefunden", + "message": { + "user_changed": "Benutzer geändert", + "user_changed_d": "Benutzer {{name}} erfolgreich geändert", + "user_change_failed": "Benutzer änderung fehlgeschlagen", + "user_change_failed_d": "Benutzer {{name}} konnte nicht geändert werden!" + } } }, "user-list": {}, -- 2.45.2 From ed5564dc7cd149f2d8f4cb140e19164cf0785ab5 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 19 Feb 2023 19:45:24 +0100 Subject: [PATCH 2/8] [WIP] Improved auto roles #134 --- kdb-bot/src/bot/config | 2 +- kdb-bot/src/bot_api/config | 2 +- kdb-bot/src/bot_graphql/model/discord.gql | 29 ++++++++++++ kdb-bot/src/bot_graphql/model/query.gql | 2 + .../bot_graphql/queries/discord/__init__.py | 0 .../queries/discord/channel_query.py | 10 +++++ .../queries/discord/emoji_query.py | 10 +++++ .../queries/discord/guild_query.py | 12 +++++ .../bot_graphql/queries/discord/role_query.py | 9 ++++ kdb-bot/src/bot_graphql/query.py | 44 ++++++++++--------- kdb-web/src/app/models/data/discord.model.ts | 31 +++++++++++++ .../src/app/models/graphql/queries.model.ts | 24 ++++++++++ kdb-web/src/app/models/graphql/query.model.ts | 5 +++ .../auto-roles/auto-roles.component.html | 9 ++-- .../auto-roles/auto-roles.component.ts | 23 ++++++++-- 15 files changed, 183 insertions(+), 29 deletions(-) create mode 100644 kdb-bot/src/bot_graphql/model/discord.gql create mode 100644 kdb-bot/src/bot_graphql/queries/discord/__init__.py create mode 100644 kdb-bot/src/bot_graphql/queries/discord/channel_query.py create mode 100644 kdb-bot/src/bot_graphql/queries/discord/emoji_query.py create mode 100644 kdb-bot/src/bot_graphql/queries/discord/guild_query.py create mode 100644 kdb-bot/src/bot_graphql/queries/discord/role_query.py create mode 100644 kdb-web/src/app/models/data/discord.model.ts diff --git a/kdb-bot/src/bot/config b/kdb-bot/src/bot/config index eff27f42..84d05a9c 160000 --- a/kdb-bot/src/bot/config +++ b/kdb-bot/src/bot/config @@ -1 +1 @@ -Subproject commit eff27f42808909a816c37f31d81f085d59d4728c +Subproject commit 84d05a9c7825ada185c4c0819555fa6b3b0de662 diff --git a/kdb-bot/src/bot_api/config b/kdb-bot/src/bot_api/config index c712f856..81021418 160000 --- a/kdb-bot/src/bot_api/config +++ b/kdb-bot/src/bot_api/config @@ -1 +1 @@ -Subproject commit c712f856ebe30c71ac0b144045599ed2f91a1cba +Subproject commit 81021418c21d45cee54478ab5fd69f9ce7261644 diff --git a/kdb-bot/src/bot_graphql/model/discord.gql b/kdb-bot/src/bot_graphql/model/discord.gql new file mode 100644 index 00000000..1218b790 --- /dev/null +++ b/kdb-bot/src/bot_graphql/model/discord.gql @@ -0,0 +1,29 @@ +type Guild { + id: ID + name: String + + channels: [Channel] + roles: [Role] + emojis: [Emoji] +} + +input GuildFilter { + id: ID +} + +type Channel { + id: String + name: String + type: String +} + +type Role { + id: String + name: String +} + +type Emoji { + id: String + name: String + url: String +} \ No newline at end of file diff --git a/kdb-bot/src/bot_graphql/model/query.gql b/kdb-bot/src/bot_graphql/model/query.gql index 2f597800..69b5a74a 100644 --- a/kdb-bot/src/bot_graphql/model/query.gql +++ b/kdb-bot/src/bot_graphql/model/query.gql @@ -28,4 +28,6 @@ type Query { userCount: Int users(filter: UserFilter, page: Page, sort: Sort): [User] + + guilds(filter: GuildFilter): [Guild] } \ No newline at end of file diff --git a/kdb-bot/src/bot_graphql/queries/discord/__init__.py b/kdb-bot/src/bot_graphql/queries/discord/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/kdb-bot/src/bot_graphql/queries/discord/channel_query.py b/kdb-bot/src/bot_graphql/queries/discord/channel_query.py new file mode 100644 index 00000000..56807d5e --- /dev/null +++ b/kdb-bot/src/bot_graphql/queries/discord/channel_query.py @@ -0,0 +1,10 @@ +from bot_graphql.abc.data_query_abc import DataQueryABC + + +class ChannelQuery(DataQueryABC): + def __init__(self): + DataQueryABC.__init__(self, "Channel") + + self.set_field("id", lambda c, *_: c.id) + self.set_field("name", lambda c, *_: c.name) + self.set_field("type", lambda c, *_: type(c)) diff --git a/kdb-bot/src/bot_graphql/queries/discord/emoji_query.py b/kdb-bot/src/bot_graphql/queries/discord/emoji_query.py new file mode 100644 index 00000000..3c776a9d --- /dev/null +++ b/kdb-bot/src/bot_graphql/queries/discord/emoji_query.py @@ -0,0 +1,10 @@ +from bot_graphql.abc.data_query_abc import DataQueryABC + + +class RoleQuery(DataQueryABC): + def __init__(self): + DataQueryABC.__init__(self, "Emoji") + + self.set_field("id", lambda e, *_: e.id) + self.set_field("name", lambda e, *_: e.name) + self.set_field("url", lambda e, *_: e.url) diff --git a/kdb-bot/src/bot_graphql/queries/discord/guild_query.py b/kdb-bot/src/bot_graphql/queries/discord/guild_query.py new file mode 100644 index 00000000..f963e999 --- /dev/null +++ b/kdb-bot/src/bot_graphql/queries/discord/guild_query.py @@ -0,0 +1,12 @@ +from bot_graphql.abc.data_query_abc import DataQueryABC + + +class GuildQuery(DataQueryABC): + def __init__(self): + DataQueryABC.__init__(self, "Guild") + + self.set_field("id", lambda g, *_: g.id) + self.set_field("name", lambda g, *_: g.name) + self.set_field("channels", lambda g, *_: g.channels) + self.set_field("roles", lambda g, *_: g.roles) + self.set_field("emojis", lambda g, *_: g.emojis) diff --git a/kdb-bot/src/bot_graphql/queries/discord/role_query.py b/kdb-bot/src/bot_graphql/queries/discord/role_query.py new file mode 100644 index 00000000..6880ed4f --- /dev/null +++ b/kdb-bot/src/bot_graphql/queries/discord/role_query.py @@ -0,0 +1,9 @@ +from bot_graphql.abc.data_query_abc import DataQueryABC + + +class RoleQuery(DataQueryABC): + def __init__(self): + DataQueryABC.__init__(self, "Role") + + self.set_field("id", lambda r, *_: r.id) + self.set_field("name", lambda r, *_: r.name) diff --git a/kdb-bot/src/bot_graphql/query.py b/kdb-bot/src/bot_graphql/query.py index 252a416b..f8e7853a 100644 --- a/kdb-bot/src/bot_graphql/query.py +++ b/kdb-bot/src/bot_graphql/query.py @@ -1,3 +1,5 @@ +from cpl_discord.service import DiscordBotServiceABC + from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC from bot_data.abc.client_repository_abc import ClientRepositoryABC from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC @@ -22,44 +24,46 @@ from bot_graphql.filter.user_joined_voice_channel_filter import UserJoinedVoiceC class Query(QueryABC): def __init__( self, + bot: DiscordBotServiceABC, auto_roles: AutoRoleRepositoryABC, clients: ClientRepositoryABC, known_users: KnownUserRepositoryABC, levels: LevelRepositoryABC, servers: ServerRepositoryABC, user_joined_servers: UserJoinedServerRepositoryABC, - user_joined_voice_channel: UserJoinedVoiceChannelRepositoryABC, + user_joined_voice_channels: UserJoinedVoiceChannelRepositoryABC, user_joined_game_server: UserJoinedGameServerRepositoryABC, users: UserRepositoryABC, ): QueryABC.__init__(self, "Query") - self._auto_roles = auto_roles - self._clients = clients - self._known_users = known_users - self._levels = levels - self._servers = servers - self._user_joined_servers = user_joined_servers - self._user_joined_voice_channels = user_joined_voice_channel - self._user_joined_game_server = user_joined_game_server - self._users = users - self.add_collection("autoRole", lambda *_: self._auto_roles.get_auto_roles(), AutoRoleFilter) - self.add_collection("autoRoleRule", lambda *_: self._auto_roles.get_auto_role_rules(), AutoRoleRuleFilter) - self.add_collection("client", lambda *_: self._clients.get_clients(), ClientFilter) - self.add_collection("knownUser", lambda *_: self._known_users.get_users()) - self.add_collection("level", lambda *_: self._levels.get_levels(), LevelFilter) - self.add_collection("server", lambda *_: self._servers.get_servers(), ServerFilter) + self._bot = bot + + self.add_collection("autoRole", lambda *_: auto_roles.get_auto_roles(), AutoRoleFilter) + self.add_collection("autoRoleRule", lambda *_: auto_roles.get_auto_role_rules(), AutoRoleRuleFilter) + self.add_collection("client", lambda *_: clients.get_clients(), ClientFilter) + self.add_collection("knownUser", lambda *_: known_users.get_users()) + self.add_collection("level", lambda *_: levels.get_levels(), LevelFilter) + self.add_collection("server", lambda *_: servers.get_servers(), ServerFilter) self.add_collection( - "userJoinedServer", lambda *_: self._user_joined_servers.get_user_joined_servers(), UserJoinedServerFilter + "userJoinedServer", lambda *_: user_joined_servers.get_user_joined_servers(), UserJoinedServerFilter ) self.add_collection( "userJoinedVoiceChannel", - lambda *_: self._user_joined_voice_channels.get_user_joined_voice_channels(), + lambda *_: user_joined_voice_channels.get_user_joined_voice_channels(), UserJoinedVoiceChannelFilter, ) self.add_collection( "userJoinedGameServer", - lambda *_: self._user_joined_game_server.get_user_joined_game_servers(), + lambda *_: user_joined_game_server.get_user_joined_game_servers(), UserJoinedGameServerFilter, ) - self.add_collection("user", lambda *_: self._users.get_users(), UserFilter) + self.add_collection("user", lambda *_: users.get_users(), UserFilter) + + self.set_field("guilds", self._resolve_guilds) + + def _resolve_guilds(self, *_, filter=None): + if filter is None and "id" not in filter: + return self._bot.guilds + + return self._bot.guilds.where(lambda g: g.id == int(filter["id"])) diff --git a/kdb-web/src/app/models/data/discord.model.ts b/kdb-web/src/app/models/data/discord.model.ts new file mode 100644 index 00000000..9f9ac6ba --- /dev/null +++ b/kdb-web/src/app/models/data/discord.model.ts @@ -0,0 +1,31 @@ +export interface Guild { + id?: string; + name?: string; + + channels: [Channel] + role: [Role] + emojis: [Emoji] +} + +export interface Channel { + id?: string; + name?: string; + type?: ChannelType; +} + +export enum ChannelType { + category = "category", + text = "text", + voice = "voice" +} + +export interface Role { + id?: string; + name?: string; +} + +export interface Emoji { + id?: string; + name?: string; + url?: string; +} diff --git a/kdb-web/src/app/models/graphql/queries.model.ts b/kdb-web/src/app/models/graphql/queries.model.ts index 70866a8d..bd93162b 100644 --- a/kdb-web/src/app/models/graphql/queries.model.ts +++ b/kdb-web/src/app/models/graphql/queries.model.ts @@ -1,5 +1,29 @@ export class Queries { + static guildsQuery = ` + query GuildsQuery($id: ID) { + guilds(filter: {id: $id}) { + id + name + + channels { + id + name + type + } + roles { + id + name + } + emojis { + id + name + url + } + } + } + `; + static serversQuery = ` query ServerInfo($filter: ServerFilter, $page: Page, $sort: Sort) { servers(filter: $filter, page: $page, sort: $sort) { diff --git a/kdb-web/src/app/models/graphql/query.model.ts b/kdb-web/src/app/models/graphql/query.model.ts index 235ad780..904cbf41 100644 --- a/kdb-web/src/app/models/graphql/query.model.ts +++ b/kdb-web/src/app/models/graphql/query.model.ts @@ -1,12 +1,17 @@ import { Server } from "../data/server.model"; import { User } from "../data/user.model"; import { AutoRole } from "../data/auto_role.model"; +import { Guild } from "../data/discord.model"; export interface Query { serverCount: number; servers: Server[]; } +export interface SingleDiscordQuery { + guilds: Guild[]; +} + export interface UserListQuery { userCount: number; users: User[]; 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 ee1ac4af..dc5bd7a8 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 @@ -63,13 +63,13 @@ - +
{{'common.created_at' | translate}}
- +
{{'common.modified_at' | translate}}
@@ -104,8 +104,8 @@ - - + + @@ -127,6 +127,7 @@ {{autoRole.channelId}} + {{autoRole.channelId}} 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 a995cd83..844a9c04 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 @@ -1,6 +1,6 @@ import { Component, OnInit } from "@angular/core"; import { User } from "../../../../../../models/data/user.model"; -import { LazyLoadEvent } from "primeng/api"; +import { LazyLoadEvent, MenuItem } from "primeng/api"; import { FormBuilder, FormControl, FormGroup } from "@angular/forms"; import { Page } from "../../../../../../models/graphql/filter/page.model"; import { Sort, SortDirection } from "../../../../../../models/graphql/filter/sort.model"; @@ -12,7 +12,7 @@ import { TranslateService } from "@ngx-translate/core"; import { DataService } from "../../../../../../services/data/data.service"; import { SidebarService } from "../../../../../../services/sidebar/sidebar.service"; import { ActivatedRoute } from "@angular/router"; -import { AutoRoleQuery } from "../../../../../../models/graphql/query.model"; +import { AutoRoleQuery, SingleDiscordQuery } from "../../../../../../models/graphql/query.model"; import { Queries } from "../../../../../../models/graphql/queries.model"; import { catchError, debounceTime } from "rxjs/operators"; import { Table } from "primeng/table"; @@ -20,6 +20,7 @@ import { UpdateUserMutationResult } from "../../../../../../models/graphql/resul import { Mutations } from "../../../../../../models/graphql/mutations.model"; import { throwError } from "rxjs"; import { AutoRole, AutoRoleFilter } from "../../../../../../models/data/auto_role.model"; +import { ChannelType, Guild } from "../../../../../../models/data/discord.model"; @Component({ selector: "app-auto-roles", @@ -28,6 +29,8 @@ import { AutoRole, AutoRoleFilter } from "../../../../../../models/data/auto_rol }) export class AutoRolesComponent implements OnInit { auto_roles!: AutoRole[]; + guild!: Guild; + channels!: MenuItem[]; loading = true; clonedUsers: { [s: string]: User; } = {}; @@ -74,6 +77,20 @@ export class AutoRolesComponent implements OnInit { ngOnInit(): void { this.data.getServerFromRoute(this.route); + this.spinner.showSpinner(); + this.data.query(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 {value: x.name, label: x.id}}); + this.spinner.hideSpinner(); + }); + this.setFilterForm(); this.loadNextPage(); } @@ -96,7 +113,7 @@ export class AutoRolesComponent implements OnInit { id: new FormControl(null), channelId: new FormControl(null), channelName: new FormControl(null), - messageId: new FormControl(null), + messageId: new FormControl(null) }); this.filterForm.valueChanges.pipe( -- 2.45.2 From 81fe7433bd4ad874672d6852da5fd04d02cced8f Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 20 Feb 2023 08:22:08 +0100 Subject: [PATCH 3/8] Improved settings #134 --- kdb-bot/src/bot/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdb-bot/src/bot/config b/kdb-bot/src/bot/config index 84d05a9c..e3019156 160000 --- a/kdb-bot/src/bot/config +++ b/kdb-bot/src/bot/config @@ -1 +1 @@ -Subproject commit 84d05a9c7825ada185c4c0819555fa6b3b0de662 +Subproject commit e3019156c058a93c092932dad75db39576bc55a7 -- 2.45.2 From a2dcbbc4658bd4ac781ba0db75e4bef44be64cde Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 20 Feb 2023 18:30:45 +0100 Subject: [PATCH 4/8] Finished auto role list #134 --- kdb-bot/src/bot/bot.json | 3 +- kdb-bot/src/bot/config | 2 +- kdb-bot/src/bot_api/config | 2 +- kdb-bot/src/bot_graphql/query.py | 2 +- .../src/app/models/graphql/mutations.model.ts | 26 ++++++++ .../src/app/models/graphql/queries.model.ts | 4 ++ kdb-web/src/app/models/graphql/query.model.ts | 3 +- .../src/app/models/graphql/result.model.ts | 13 ++++ .../src/app/modules/shared/shared.module.ts | 3 + .../auto-roles-rules.component.ts | 22 +++++-- .../auto-roles/auto-roles.component.html | 17 ++--- .../auto-roles/auto-roles.component.ts | 65 ++++++++++++------- .../server/members/members.component.html | 3 +- kdb-web/src/app/services/data/data.service.ts | 23 +++++-- kdb-web/src/assets/i18n/de.json | 14 ++-- kdb-web/src/styles/primeng-fixes.scss | 5 ++ .../src/styles/themes/default-dark-theme.scss | 14 ++++ .../styles/themes/default-light-theme.scss | 14 ++++ .../styles/themes/sh-edraft-dark-theme.scss | 14 ++++ .../styles/themes/sh-edraft-light-theme.scss | 14 ++++ 20 files changed, 209 insertions(+), 54 deletions(-) diff --git a/kdb-bot/src/bot/bot.json b/kdb-bot/src/bot/bot.json index d7d6a2d7..66f56772 100644 --- a/kdb-bot/src/bot/bot.json +++ b/kdb-bot/src/bot/bot.json @@ -32,7 +32,8 @@ "cpl-discord==2022.12.2" ], "DevDependencies": [ - "cpl-cli==2022.12.1.post3" + "cpl-cli==2022.12.1.post3", + "pygount==1.5.1" ], "PythonVersion": ">=3.10.4", "PythonPath": {}, diff --git a/kdb-bot/src/bot/config b/kdb-bot/src/bot/config index e3019156..79861447 160000 --- a/kdb-bot/src/bot/config +++ b/kdb-bot/src/bot/config @@ -1 +1 @@ -Subproject commit e3019156c058a93c092932dad75db39576bc55a7 +Subproject commit 7986144705052ff38472a5d3f0776cb6c1752a55 diff --git a/kdb-bot/src/bot_api/config b/kdb-bot/src/bot_api/config index 81021418..c712f856 160000 --- a/kdb-bot/src/bot_api/config +++ b/kdb-bot/src/bot_api/config @@ -1 +1 @@ -Subproject commit 81021418c21d45cee54478ab5fd69f9ce7261644 +Subproject commit c712f856ebe30c71ac0b144045599ed2f91a1cba diff --git a/kdb-bot/src/bot_graphql/query.py b/kdb-bot/src/bot_graphql/query.py index f8e7853a..8133e4dc 100644 --- a/kdb-bot/src/bot_graphql/query.py +++ b/kdb-bot/src/bot_graphql/query.py @@ -63,7 +63,7 @@ class Query(QueryABC): self.set_field("guilds", self._resolve_guilds) def _resolve_guilds(self, *_, filter=None): - if filter is None and "id" not in filter: + if filter is None or "id" not in filter: return self._bot.guilds return self._bot.guilds.where(lambda g: g.id == int(filter["id"])) diff --git a/kdb-web/src/app/models/graphql/mutations.model.ts b/kdb-web/src/app/models/graphql/mutations.model.ts index f7be1c11..db06c8f8 100644 --- a/kdb-web/src/app/models/graphql/mutations.model.ts +++ b/kdb-web/src/app/models/graphql/mutations.model.ts @@ -14,4 +14,30 @@ export class Mutations { } } `; + + static createAutoRole = ` + mutation updateAutoRole($serverId: ID, $channelId: String, $messageId: String) { + autoRole { + createAutoRole(input: { serverId: $serverId, channelId: $channelId, messageId: $messageId }) { + id + channelId + channelName + messageId + } + } + } + `; + + static deleteAutoRole = ` + mutation updateAutoRole($id: ID) { + autoRole { + deleteAutoRole(id: $id) { + id + channelId + channelName + messageId + } + } + } + `; } diff --git a/kdb-web/src/app/models/graphql/queries.model.ts b/kdb-web/src/app/models/graphql/queries.model.ts index bd93162b..c71733eb 100644 --- a/kdb-web/src/app/models/graphql/queries.model.ts +++ b/kdb-web/src/app/models/graphql/queries.model.ts @@ -166,6 +166,10 @@ export class Queries { messageId autoRoleRuleCount + server { + id + } + createdAt modifiedAt } diff --git a/kdb-web/src/app/models/graphql/query.model.ts b/kdb-web/src/app/models/graphql/query.model.ts index 904cbf41..a6c1090f 100644 --- a/kdb-web/src/app/models/graphql/query.model.ts +++ b/kdb-web/src/app/models/graphql/query.model.ts @@ -2,6 +2,7 @@ import { Server } from "../data/server.model"; import { User } from "../data/user.model"; import { AutoRole } from "../data/auto_role.model"; import { Guild } from "../data/discord.model"; +import { Level } from "../data/level.model"; export interface Query { serverCount: number; @@ -19,7 +20,7 @@ export interface UserListQuery { export interface LevelListQuery { levelCount: number; - levels: User[]; + levels: Level[]; } export interface AutoRoleQuery { diff --git a/kdb-web/src/app/models/graphql/result.model.ts b/kdb-web/src/app/models/graphql/result.model.ts index bc28521d..8198fda2 100644 --- a/kdb-web/src/app/models/graphql/result.model.ts +++ b/kdb-web/src/app/models/graphql/result.model.ts @@ -1,4 +1,10 @@ import { User } from "../data/user.model"; +import { AutoRole } from "../data/auto_role.model"; + +export interface GraphQLResult { + data: any; + errors?: []; +} export interface QueryResult { data: any; @@ -9,3 +15,10 @@ export interface UpdateUserMutationResult { updateUser: User }; } +export interface AutoRoleMutationResult { + autoRole: { + createAutoRole?: AutoRole + updateAutoRole?: AutoRole + deleteAutoRole?: AutoRole + }; +} diff --git a/kdb-web/src/app/modules/shared/shared.module.ts b/kdb-web/src/app/modules/shared/shared.module.ts index bf719ea6..1402c6ef 100644 --- a/kdb-web/src/app/modules/shared/shared.module.ts +++ b/kdb-web/src/app/modules/shared/shared.module.ts @@ -20,6 +20,7 @@ import { IpAddressPipe } from './pipes/ip-address.pipe'; import { BoolPipe } from './pipes/bool.pipe'; import { PanelMenuModule } from 'primeng/panelmenu'; import { PanelModule } from "primeng/panel"; +import { InputNumberModule } from 'primeng/inputnumber'; @@ -49,6 +50,7 @@ import { PanelModule } from "primeng/panel"; DynamicDialogModule, PanelMenuModule, PanelModule, + InputNumberModule, ], exports: [ ButtonModule, @@ -72,6 +74,7 @@ import { PanelModule } from "primeng/panel"; AuthRolePipe, IpAddressPipe, BoolPipe, + InputNumberModule, ] }) export class SharedModule { } 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 2440f09d..538afde3 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,10 +1,22 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from "@angular/core"; +import { DataService } from "../../../../../../services/data/data.service"; +import { ActivatedRoute } from "@angular/router"; @Component({ - selector: 'app-auto-roles-rules', - templateUrl: './auto-roles-rules.component.html', - styleUrls: ['./auto-roles-rules.component.scss'] + selector: "app-auto-roles-rules", + templateUrl: "./auto-roles-rules.component.html", + styleUrls: ["./auto-roles-rules.component.scss"] }) -export class AutoRolesRulesComponent { +export class AutoRolesRulesComponent implements OnInit { + + constructor( + private data: DataService, + private route: ActivatedRoute, + ) { + } + + ngOnInit(): void { + this.data.getServerFromRoute(this.route); + } } 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 dc5bd7a8..16cb0710 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 @@ -18,7 +18,7 @@
- + + + + + icon="pi pi-times-circle" (click)="onRowEditCancel(ri)">
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 844a9c04..6659fc68 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 @@ -16,7 +16,7 @@ import { AutoRoleQuery, SingleDiscordQuery } from "../../../../../../models/grap import { Queries } from "../../../../../../models/graphql/queries.model"; import { catchError, debounceTime } from "rxjs/operators"; import { Table } from "primeng/table"; -import { UpdateUserMutationResult } from "../../../../../../models/graphql/result.model"; +import { AutoRoleMutationResult } from "../../../../../../models/graphql/result.model"; import { Mutations } from "../../../../../../models/graphql/mutations.model"; import { throwError } from "rxjs"; import { AutoRole, AutoRoleFilter } from "../../../../../../models/data/auto_role.model"; @@ -87,7 +87,9 @@ export class AutoRolesComponent implements OnInit { this.guild = data.guilds[0]; this.channels = this.guild.channels .filter(x => x.type === ChannelType.text) - .map(x => {return {value: x.name, label: x.id}}); + .map(x => { + return { label: x.name, value: x }; + }); this.spinner.hideSpinner(); }); @@ -167,48 +169,39 @@ export class AutoRolesComponent implements OnInit { this.filterForm.reset(); } - onRowEditInit(table: Table, user: User, index: number) { - this.clonedUsers[index] = { ...user }; + onRowEditInit(table: Table, autoRole: AutoRole, index: number) { + this.clonedUsers[index] = { ...autoRole }; } - onRowEditSave(table: Table, newUser: User, index: number) { - // const oldUser = this.clonedUsers[index]; - // delete this.clonedUsers[index]; - - // if (JSON.stringify(oldUser) === JSON.stringify(newUser) && !this.isEditingNew) { - // console.log(1, oldUser, newUser, JSON.stringify(oldUser) === JSON.stringify(newUser), !this.isEditingNew); - // return; - // } - - if (this.isEditingNew && JSON.stringify(newUser) === JSON.stringify(this.newAutoRoleTemplate)) { + onRowEditSave(table: Table, newAutoRole: AutoRole, index: number) { + if (this.isEditingNew && JSON.stringify(newAutoRole) === JSON.stringify(this.newAutoRoleTemplate)) { this.isEditingNew = false; this.auto_roles.splice(index, 1); return; } - if (!newUser.id || !newUser.xp && !newUser.level?.id) { + if (!newAutoRole.id || !newAutoRole.channelId && !newAutoRole.messageId) { return; } this.spinner.showSpinner(); - this.data.mutation(Mutations.updateUser, { - id: newUser.id, - xp: newUser.xp, - levelId: newUser.level?.id + this.data.mutation(Mutations.createAutoRole, { + serverId: this.sidebar.server$.value?.id, + channelId: newAutoRole.channelId, + messageId: newAutoRole.messageId } ).pipe(catchError(err => { this.spinner.hideSpinner(); - this.toastService.error(this.translate.instant("view.server.members.message.user_change_failed"), this.translate.instant("view.server.members.message.user_change_failed_d", { name: newUser.name })); + this.toastService.error(this.translate.instant("view.server.auto_roles.message.auto_role_create_failed"), this.translate.instant("view.server.auto_roles.message.auto_role_create_failed_d")); return throwError(err); - })).subscribe(_ => { + })).subscribe(result => { this.spinner.hideSpinner(); - this.toastService.success(this.translate.instant("view.server.members.message.user_changed"), this.translate.instant("view.server.members.message.user_changed_d", { name: newUser.name })); + this.toastService.success(this.translate.instant("view.server.auto_roles.message.auto_role_created"), this.translate.instant("view.server.auto_roles.message.auto_role_create_d", { id: result.autoRole.createAutoRole?.id })); this.loadNextPage(); }); - } - onRowEditCancel(user: User, index: number) { + onRowEditCancel(index: number) { if (this.isEditingNew) { this.auto_roles.splice(index, 1); delete this.clonedUsers[index]; @@ -220,7 +213,29 @@ export class AutoRolesComponent implements OnInit { delete this.clonedUsers[index]; } - addUser(table: Table) { + deleteAutoRole(autoRole: AutoRole) { + this.confirmDialog.confirmDialog( + this.translate.instant("view.server.auto_roles.message.auto_role_delete"), this.translate.instant("view.server.auto_roles.message.auto_role_delete_q", { id: autoRole.id }), + () => { + this.spinner.showSpinner(); + this.data.mutation(Mutations.deleteAutoRole, { + id: autoRole.id + } + ).pipe(catchError(err => { + this.spinner.hideSpinner(); + this.toastService.error(this.translate.instant("view.server.auto_roles.message.auto_role_delete_failed"), this.translate.instant("view.server.auto_roles.message.auto_role_delete_failed_d", { id: autoRole.id })); + return throwError(err); + })).subscribe(_ => { + this.spinner.hideSpinner(); + this.toastService.success(this.translate.instant("view.server.auto_roles.message.auto_role_deleted"), this.translate.instant("view.server.auto_roles.message.auto_role_deleted_d", { id: autoRole.id })); + this.loadNextPage(); + }); + }); + + + } + + addAutoRole(table: Table) { const newAutoRole = JSON.parse(JSON.stringify(this.newAutoRoleTemplate)); newAutoRole.id = Math.max.apply(Math, this.auto_roles.map(u => { return u.id ?? 0; diff --git a/kdb-web/src/app/modules/view/server/members/members.component.html b/kdb-web/src/app/modules/view/server/members/members.component.html index 7170c8f5..1c120f02 100644 --- a/kdb-web/src/app/modules/view/server/members/members.component.html +++ b/kdb-web/src/app/modules/view/server/members/members.component.html @@ -163,7 +163,8 @@ - + {{member.xp}} diff --git a/kdb-web/src/app/services/data/data.service.ts b/kdb-web/src/app/services/data/data.service.ts index e0c36ef1..5a6b37ed 100644 --- a/kdb-web/src/app/services/data/data.service.ts +++ b/kdb-web/src/app/services/data/data.service.ts @@ -9,6 +9,7 @@ import { Queries } from "../../models/graphql/queries.model"; import { Query } from "../../models/graphql/query.model"; import { SidebarService } from "../sidebar/sidebar.service"; import { SpinnerService } from "../spinner/spinner.service"; +import { GraphQLResult } from "../../models/graphql/result.model"; @Injectable({ providedIn: "root" @@ -20,7 +21,7 @@ export class DataService { private http: HttpClient, private sidebar: SidebarService, private spinner: SpinnerService, - private router: Router, + private router: Router ) { } @@ -28,7 +29,7 @@ export class DataService { this.spinner.showSpinner(); if (!route.snapshot.params["serverId"]) { this.spinner.hideSpinner(); - this.router.navigate(['/dashboard']); + this.router.navigate(["/dashboard"]); return; } @@ -46,21 +47,31 @@ export class DataService { public query(query: string, variables?: Variables, f?: Function): Observable { return this.http - .post<{ data: T }>(`${this.appsettings.getApiURL()}/api/graphql`, { + .post(`${this.appsettings.getApiURL()}/api/graphql`, { query: query, variables: variables }) - .pipe(map((d) => d.data)) + .pipe(map(d => { + if (d.errors && d.errors.length > 0) { + throw new Error(d.errors.toString()); + } + return d.data; + })) .pipe(map((d) => f ? f(d) : d)); } public mutation(query: string, variables?: object, f?: Function): Observable { return this.http - .post<{ data: T }>(`${this.appsettings.getApiURL()}/api/graphql`, { + .post(`${this.appsettings.getApiURL()}/api/graphql`, { query: query, variables: variables }) - .pipe(map((d) => d.data)) + .pipe(map(d => { + if (d.errors && d.errors.length > 0) { + throw new Error(d.errors.toString()); + } + return d.data; + })) .pipe(map((d) => f ? f(d) : d)); } diff --git a/kdb-web/src/assets/i18n/de.json b/kdb-web/src/assets/i18n/de.json index eefd653d..9af9fa47 100644 --- a/kdb-web/src/assets/i18n/de.json +++ b/kdb-web/src/assets/i18n/de.json @@ -236,10 +236,16 @@ }, "no_entries_found": "Keine Einträge gefunden", "message": { - "user_changed": "Benutzer geändert", - "user_changed_d": "Benutzer {{name}} erfolgreich geändert", - "user_change_failed": "Benutzer änderung fehlgeschlagen", - "user_change_failed_d": "Benutzer {{name}} konnte nicht geändert werden!" + "auto_role_create": "Auto Rolle erstellt", + "auto_role_create_d": "Auto Rolle {{id}} erfolgreich erstellt", + "auto_role_create_failed": "Auto Rolle Erstellung fehlgeschlagen", + "auto_role_create_failed_d": "Die Erstellung der Auto Rolle ist fehlgeschlagen!", + "auto_role_delete": "Auto Rolle löschen", + "auto_role_delete_q": "Sind Sie sich sicher, dass Sie die Auto Rolle {{id}} löschen möchten?", + "auto_role_deleted": "Auto Rolle gelöscht", + "auto_role_deleted_d": "Auto Rolle {{id}} erfolgreich gelöscht", + "auto_role_delete_failed": "Auto Rolle Löschung fehlgeschlagen", + "auto_role_delete_failed_d": "Die Löschung der Auto Rolle {{id}} ist fehlgeschlagen!" } } }, diff --git a/kdb-web/src/styles/primeng-fixes.scss b/kdb-web/src/styles/primeng-fixes.scss index dccf88d9..506f1fee 100644 --- a/kdb-web/src/styles/primeng-fixes.scss +++ b/kdb-web/src/styles/primeng-fixes.scss @@ -97,6 +97,11 @@ p-table { } } +.p-dropdown, +.p-inputnumber { + width: 100% !important; +} + .pi-sort-alt:before { content: "\e915" !important; } diff --git a/kdb-web/src/styles/themes/default-dark-theme.scss b/kdb-web/src/styles/themes/default-dark-theme.scss index f0a7658b..c3b52930 100644 --- a/kdb-web/src/styles/themes/default-dark-theme.scss +++ b/kdb-web/src/styles/themes/default-dark-theme.scss @@ -580,4 +580,18 @@ background-color: $primaryBackgroundColor !important; color: $primaryHeaderColor !important; } + + .input-number { + span { + .p-button { + background-color: $primaryHeaderColor !important; + border: 1px solid $primaryHeaderColor !important; + + &:hover { + background-color: $secondaryHeaderColor !important; + border: 1px solid $secondaryHeaderColor !important; + } + } + } + } } diff --git a/kdb-web/src/styles/themes/default-light-theme.scss b/kdb-web/src/styles/themes/default-light-theme.scss index 4c37c304..2ae2814e 100644 --- a/kdb-web/src/styles/themes/default-light-theme.scss +++ b/kdb-web/src/styles/themes/default-light-theme.scss @@ -580,4 +580,18 @@ background-color: $primaryBackgroundColor !important; color: $primaryHeaderColor !important; } + + .input-number { + span { + .p-button { + background-color: $primaryHeaderColor !important; + border: 1px solid $primaryHeaderColor !important; + + &:hover { + background-color: $secondaryHeaderColor !important; + border: 1px solid $secondaryHeaderColor !important; + } + } + } + } } diff --git a/kdb-web/src/styles/themes/sh-edraft-dark-theme.scss b/kdb-web/src/styles/themes/sh-edraft-dark-theme.scss index d05d920f..3a3d6013 100644 --- a/kdb-web/src/styles/themes/sh-edraft-dark-theme.scss +++ b/kdb-web/src/styles/themes/sh-edraft-dark-theme.scss @@ -582,4 +582,18 @@ background-color: $primaryBackgroundColor !important; color: $primaryHeaderColor !important; } + + .input-number { + span { + .p-button { + background-color: $primaryHeaderColor !important; + border: 1px solid $primaryHeaderColor !important; + + &:hover { + background-color: $secondaryHeaderColor !important; + border: 1px solid $secondaryHeaderColor !important; + } + } + } + } } diff --git a/kdb-web/src/styles/themes/sh-edraft-light-theme.scss b/kdb-web/src/styles/themes/sh-edraft-light-theme.scss index 6d3e5f42..f6d389ea 100644 --- a/kdb-web/src/styles/themes/sh-edraft-light-theme.scss +++ b/kdb-web/src/styles/themes/sh-edraft-light-theme.scss @@ -580,4 +580,18 @@ background-color: $primaryBackgroundColor !important; color: $primaryHeaderColor !important; } + + .input-number { + span { + .p-button { + background-color: $primaryHeaderColor !important; + border: 1px solid $primaryHeaderColor !important; + + &:hover { + background-color: $secondaryHeaderColor !important; + border: 1px solid $secondaryHeaderColor !important; + } + } + } + } } -- 2.45.2 From 10d79f8c2c66bec90febf2a045d087b21d399808 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 20 Feb 2023 18:53:02 +0100 Subject: [PATCH 5/8] Prepared auto role rules #134 --- .../src/app/models/data/auto_role.model.ts | 1 + .../src/app/models/graphql/mutations.model.ts | 30 +++++++++++++++++-- .../src/app/models/graphql/queries.model.ts | 23 ++++++++++++++ kdb-web/src/app/models/graphql/query.model.ts | 7 ++++- 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/kdb-web/src/app/models/data/auto_role.model.ts b/kdb-web/src/app/models/data/auto_role.model.ts index c94e042f..2d9c35c5 100644 --- a/kdb-web/src/app/models/data/auto_role.model.ts +++ b/kdb-web/src/app/models/data/auto_role.model.ts @@ -24,6 +24,7 @@ export interface AutoRoleRule extends Data { id?: number; emojiName?: string; roleId?: string; + roleName?: string; autoRole?: AutoRole; } diff --git a/kdb-web/src/app/models/graphql/mutations.model.ts b/kdb-web/src/app/models/graphql/mutations.model.ts index db06c8f8..310f300f 100644 --- a/kdb-web/src/app/models/graphql/mutations.model.ts +++ b/kdb-web/src/app/models/graphql/mutations.model.ts @@ -16,7 +16,7 @@ export class Mutations { `; static createAutoRole = ` - mutation updateAutoRole($serverId: ID, $channelId: String, $messageId: String) { + mutation createAutoRole($serverId: ID, $channelId: String, $messageId: String) { autoRole { createAutoRole(input: { serverId: $serverId, channelId: $channelId, messageId: $messageId }) { id @@ -29,7 +29,7 @@ export class Mutations { `; static deleteAutoRole = ` - mutation updateAutoRole($id: ID) { + mutation deleteAutoRole($id: ID) { autoRole { deleteAutoRole(id: $id) { id @@ -40,4 +40,30 @@ export class Mutations { } } `; + + static createAutoRoleRule = ` + mutation createAutoRoleRule($autoRoleId: ID, $emojiName: String, roleId: String) { + autoRoleRule { + createAutoRoleRule(input: { autoRoleId: $autoRoleId, emojiName: $emojiName, roleId: $roleId }) { + id + emojiName + roleId + roleName + } + } + } + `; + + static deleteAutoRoleRule = ` + mutation deleteAutoRoleRule($id: ID) { + autoRoleRule { + deleteAutoRoleRule(id: $id) { + id + emojiName + roleId + roleName + } + } + } + `; } diff --git a/kdb-web/src/app/models/graphql/queries.model.ts b/kdb-web/src/app/models/graphql/queries.model.ts index c71733eb..1824c577 100644 --- a/kdb-web/src/app/models/graphql/queries.model.ts +++ b/kdb-web/src/app/models/graphql/queries.model.ts @@ -175,4 +175,27 @@ export class Queries { } } `; + + static autoRoleRulesQuery = ` + query AutoRoleRuleQuery($serverId: ID, $autoRoleId: ID, $filter: AutoRoleFilter, $page: Page, $sort: Sort) { + servers(filter: {id: $serverId} { + autoRoles(filter: {id: $autoRoleId}) { + autoRoleRuleCount + autoRoleRules(filter: $filter, page: $page, sort: $sort) { + id + emojiName + roleId + roleName + + autoRole { + id + } + + createdAt + modifiedAt + } + } + } + } + `; } diff --git a/kdb-web/src/app/models/graphql/query.model.ts b/kdb-web/src/app/models/graphql/query.model.ts index a6c1090f..3f7e85a1 100644 --- a/kdb-web/src/app/models/graphql/query.model.ts +++ b/kdb-web/src/app/models/graphql/query.model.ts @@ -1,6 +1,6 @@ import { Server } from "../data/server.model"; import { User } from "../data/user.model"; -import { AutoRole } from "../data/auto_role.model"; +import { AutoRole, AutoRoleRule } from "../data/auto_role.model"; import { Guild } from "../data/discord.model"; import { Level } from "../data/level.model"; @@ -28,3 +28,8 @@ export interface AutoRoleQuery { autoRoles: AutoRole[]; } +export interface AutoRoleRuleQuery { + autoRoleRuleCount: number; + autoRoleRules: AutoRoleRule[]; +} + -- 2.45.2 From 02d04725bdac70efbf9582ee8e91984cb70bcfda Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 20 Feb 2023 21:22:33 +0100 Subject: [PATCH 6/8] Added auto role rule list logic #134 --- .../app/components/footer/footer.component.ts | 4 +- kdb-web/src/app/models/data/discord.model.ts | 2 +- kdb-web/src/app/models/data/server.model.ts | 3 +- .../src/app/models/graphql/queries.model.ts | 32 +-- .../src/app/models/graphql/variables.model.ts | 1 + .../src/app/modules/shared/shared.module.ts | 3 + .../auto-roles-rules.component.html | 189 ++++++++++++- .../auto-roles-rules.component.ts | 252 +++++++++++++++++- .../auto-roles/auto-roles.component.ts | 6 +- kdb-web/src/app/services/data/data.service.ts | 2 +- .../error-handler/error-handler.service.ts | 25 +- .../app/services/sidebar/sidebar.service.ts | 2 - .../src/app/services/theme/theme.service.ts | 15 +- kdb-web/src/assets/i18n/de.json | 26 ++ kdb-web/src/styles.scss | 6 + 15 files changed, 524 insertions(+), 44 deletions(-) diff --git a/kdb-web/src/app/components/footer/footer.component.ts b/kdb-web/src/app/components/footer/footer.component.ts index bd4f1e61..47f24b99 100644 --- a/kdb-web/src/app/components/footer/footer.component.ts +++ b/kdb-web/src/app/components/footer/footer.component.ts @@ -13,8 +13,8 @@ import { SpinnerService } from "src/app/services/spinner/spinner.service"; export class FooterComponent implements OnInit { - frontendVersion!: SoftwareVersion; - backendVersion!: SoftwareVersion; + frontendVersion: SoftwareVersion = new SoftwareVersion("0", "0", "0"); + backendVersion: SoftwareVersion = new SoftwareVersion("0", "0", "0"); constructor( private settings: SettingsService, diff --git a/kdb-web/src/app/models/data/discord.model.ts b/kdb-web/src/app/models/data/discord.model.ts index 9f9ac6ba..6e8bc0b0 100644 --- a/kdb-web/src/app/models/data/discord.model.ts +++ b/kdb-web/src/app/models/data/discord.model.ts @@ -3,7 +3,7 @@ export interface Guild { name?: string; channels: [Channel] - role: [Role] + roles: [Role] emojis: [Emoji] } diff --git a/kdb-web/src/app/models/data/server.model.ts b/kdb-web/src/app/models/data/server.model.ts index 8df91d13..cc160e68 100644 --- a/kdb-web/src/app/models/data/server.model.ts +++ b/kdb-web/src/app/models/data/server.model.ts @@ -2,6 +2,7 @@ import {Data} from "./data.model"; import {User} from "./user.model"; import {Level} from "./level.model"; import {Client} from "./client.model"; +import { AutoRole } from "./auto_role.model"; export interface Server extends Data { id?: number; @@ -9,7 +10,7 @@ export interface Server extends Data { name?: string; iconURL?: string; autoRoleCount?: number; - autoRoles?: []; + autoRoles?: AutoRole[]; clientCount?: number; clients?: Client[]; levelCount?: number; diff --git a/kdb-web/src/app/models/graphql/queries.model.ts b/kdb-web/src/app/models/graphql/queries.model.ts index 1824c577..82bb40af 100644 --- a/kdb-web/src/app/models/graphql/queries.model.ts +++ b/kdb-web/src/app/models/graphql/queries.model.ts @@ -157,28 +157,30 @@ export class Queries { `; static autoRolesQuery = ` - query AutoRoleQuery($filter: AutoRoleFilter, $page: Page, $sort: Sort) { - autoRoleCount - autoRoles(filter: $filter, page: $page, sort: $sort) { - id - channelId - channelName - messageId - autoRoleRuleCount - - server { + query AutoRoleQuery($serverId: ID, $filter: AutoRoleFilter, $page: Page, $sort: Sort) { + servers(filter: {id: $serverId}) { + autoRoleCount + autoRoles(filter: $filter, page: $page, sort: $sort) { id - } + channelId + channelName + messageId + autoRoleRuleCount - createdAt - modifiedAt + server { + id + } + + createdAt + modifiedAt + } } } `; static autoRoleRulesQuery = ` - query AutoRoleRuleQuery($serverId: ID, $autoRoleId: ID, $filter: AutoRoleFilter, $page: Page, $sort: Sort) { - servers(filter: {id: $serverId} { + query AutoRoleRuleQuery($serverId: ID, $autoRoleId: ID, $filter: AutoRoleRuleFilter, $page: Page, $sort: Sort) { + servers(filter: {id: $serverId}) { autoRoles(filter: {id: $autoRoleId}) { autoRoleRuleCount autoRoleRules(filter: $filter, page: $page, sort: $sort) { diff --git a/kdb-web/src/app/models/graphql/variables.model.ts b/kdb-web/src/app/models/graphql/variables.model.ts index fdc5d93f..8acb41a6 100644 --- a/kdb-web/src/app/models/graphql/variables.model.ts +++ b/kdb-web/src/app/models/graphql/variables.model.ts @@ -5,4 +5,5 @@ export interface Variables { filter?: object; page?: Page; sort?: Sort; + [x: string | number | symbol]: unknown; } diff --git a/kdb-web/src/app/modules/shared/shared.module.ts b/kdb-web/src/app/modules/shared/shared.module.ts index 1402c6ef..986ddd26 100644 --- a/kdb-web/src/app/modules/shared/shared.module.ts +++ b/kdb-web/src/app/modules/shared/shared.module.ts @@ -21,6 +21,7 @@ import { BoolPipe } from './pipes/bool.pipe'; import { PanelMenuModule } from 'primeng/panelmenu'; import { PanelModule } from "primeng/panel"; import { InputNumberModule } from 'primeng/inputnumber'; +import { ImageModule } from "primeng/image"; @@ -51,6 +52,7 @@ import { InputNumberModule } from 'primeng/inputnumber'; PanelMenuModule, PanelModule, InputNumberModule, + ImageModule ], exports: [ ButtonModule, @@ -75,6 +77,7 @@ import { InputNumberModule } from 'primeng/inputnumber'; IpAddressPipe, BoolPipe, InputNumberModule, + ImageModule ] }) export class SharedModule { } 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 03f26bd4..fd1a4536 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 @@ -1 +1,188 @@ -

auto-roles-rules works!

+

+ {{'view.server.auto_roles.rules.header' | translate}} +

+
+
+ + + +
+
+ {{rules.length}} {{'view.server.auto_roles.rules.of' | translate}} + {{dt.totalRecords}} + + {{'view.server.auto_roles.rules.auto_roles' | translate}} +
+ +
+ + +
+
+
+ + + + +
+
{{'view.server.auto_roles.rules.headers.id' | translate}}
+ +
+ + + +
+
{{'view.server.auto_roles.rules.headers.role' | translate}}
+ +
+ + + +
+
{{'view.server.auto_roles.rules.headers.emoji' | translate}}
+
+ + + +
+
{{'common.created_at' | translate}}
+
+ + + +
+
{{'common.modified_at' | translate}}
+
+ + + +
+
{{'view.server.auto_roles.rules.headers.actions' | translate}}
+
+ + + + + +
+ +
+ + +
+ +
+ + + + + + +
+ + + + + + + {{autoRoleRule.id}} + + + {{autoRoleRule.id}} + + + + + + + + + + + {{autoRoleRule.roleName}} + + + + + + + + + + + + + + + + + + + + + + + + + + {{autoRoleRule.createdAt | date:'dd.MM.yy HH:mm'}} + + + {{autoRoleRule.createdAt | date:'dd.MM.yy HH:mm'}} + + + + + + + + {{autoRoleRule.modifiedAt | date:'dd.MM.yy HH:mm'}} + + + {{autoRoleRule.modifiedAt | date:'dd.MM.yy HH:mm'}} + + + + + +
+ + + + + +
+ + +
+ + + + + {{'view.server.auto_roles.rules.no_entries_found' | translate}} + + + + + + +
+
+
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 538afde3..cca972a0 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,6 +1,27 @@ import { Component, OnInit } from "@angular/core"; import { DataService } from "../../../../../../services/data/data.service"; -import { ActivatedRoute } from "@angular/router"; +import { ActivatedRoute, Router } from "@angular/router"; +import { AutoRoleRule, AutoRoleRuleFilter } from "../../../../../../models/data/auto_role.model"; +import { Guild } from "../../../../../../models/data/discord.model"; +import { LazyLoadEvent, MenuItem } from "primeng/api"; +import { User } from "../../../../../../models/data/user.model"; +import { FormBuilder, FormControl, FormGroup } from "@angular/forms"; +import { Page } from "../../../../../../models/graphql/filter/page.model"; +import { Sort, SortDirection } from "../../../../../../models/graphql/filter/sort.model"; +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 { TranslateService } from "@ngx-translate/core"; +import { SidebarService } from "../../../../../../services/sidebar/sidebar.service"; +import { AutoRoleRuleQuery, SingleDiscordQuery } from "../../../../../../models/graphql/query.model"; +import { Queries } from "../../../../../../models/graphql/queries.model"; +import { Server } from "../../../../../../models/data/server.model"; +import { catchError, debounceTime } from "rxjs/operators"; +import { Table } from "primeng/table"; +import { AutoRoleMutationResult } from "../../../../../../models/graphql/result.model"; +import { Mutations } from "../../../../../../models/graphql/mutations.model"; +import { throwError } from "rxjs"; @Component({ selector: "app-auto-roles-rules", @@ -9,14 +30,243 @@ import { ActivatedRoute } from "@angular/router"; }) export class AutoRolesRulesComponent implements OnInit { + rules!: AutoRoleRule[]; + guild!: Guild; + emojis!: MenuItem[]; + roles!: MenuItem[]; + loading = true; + + autoRoleId!: number; + + clonedUsers: { [s: string]: User; } = {}; + isEditingNew: boolean = false; + + newAutoRoleTemplate: AutoRoleRule = { + id: 0, + createdAt: "", + modifiedAt: "" + }; + + filterForm!: FormGroup<{ + id: FormControl, + emojiName: FormControl, + roleId: FormControl, + }>; + + filter: AutoRoleRuleFilter = {}; + page: Page = { + pageSize: undefined, + pageIndex: undefined + }; + sort: Sort = { + sortColumn: undefined, + sortDirection: undefined + }; + + totalRecords!: number; + constructor( + private authService: AuthService, + private spinner: SpinnerService, + private toastService: ToastService, + private confirmDialog: ConfirmationDialogService, + private fb: FormBuilder, + private translate: TranslateService, private data: DataService, + private sidebar: SidebarService, private route: ActivatedRoute, + private router: Router ) { } + getEmojiUrl(name: string): string { + return this.guild.emojis.filter(x => x.name == name)[0].url ?? ""; + } + 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(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(); + } + + loadNextPage() { + this.loading = true; + this.data.query(Queries.autoRoleRulesQuery, { + id: this.sidebar.server$.value?.id, filter: this.filter, page: this.page, sort: this.sort + }, + (x: { servers: Server[] }) => { + if (!x.servers[0].autoRoles || x.servers[0].autoRoles?.length == 0) { + return undefined; + } + return x.servers[0].autoRoles[0]; + } + ).subscribe(data => { + this.totalRecords = data.autoRoleRuleCount; + this.rules = data.autoRoleRules; + this.spinner.hideSpinner(); + this.loading = false; + }); + } + + setFilterForm() { + this.filterForm = this.fb.group({ + id: new FormControl(null), + emojiName: new FormControl(null), + roleId: new FormControl(null) + }); + + this.filterForm.valueChanges.pipe( + debounceTime(600) + ).subscribe(changes => { + if (changes.id) { + this.filter.id = changes.id; + } else { + this.filter.id = undefined; + } + + if (changes.emojiName) { + this.filter.emojiName = changes.emojiName; + } else { + this.filter.emojiName = undefined; + } + + if (changes.roleId) { + this.filter.roleId = changes.roleId; + } else { + this.filter.roleId = undefined; + } + + if (this.page.pageSize) + this.page.pageSize = 10; + + if (this.page.pageIndex) + this.page.pageIndex = 0; + + this.loadNextPage(); + }); + } + + nextPage(event: LazyLoadEvent) { + this.page.pageSize = event.rows ?? 0; + if (event.first != null && event.rows != null) + this.page.pageIndex = event.first / event.rows; + this.sort.sortColumn = event.sortField ?? undefined; + this.sort.sortDirection = event.sortOrder === 1 ? SortDirection.ASC : event.sortOrder === -1 ? SortDirection.DESC : SortDirection.ASC; + + this.loadNextPage(); + } + + resetFilters() { + this.filterForm.reset(); + } + + onRowEditInit(table: Table, autoRoleRule: AutoRoleRule, index: number) { + this.clonedUsers[index] = { ...autoRoleRule }; + } + + onRowEditSave(table: Table, newAutoRole: AutoRoleRule, index: number) { + if (this.isEditingNew && JSON.stringify(newAutoRole) === JSON.stringify(this.newAutoRoleTemplate)) { + this.isEditingNew = false; + this.rules.splice(index, 1); + return; + } + + if (!newAutoRole.id || !newAutoRole.emojiName && !newAutoRole.roleId) { + return; + } + + this.spinner.showSpinner(); + this.data.mutation(Mutations.createAutoRoleRule, { + serverId: this.sidebar.server$.value?.id, + emojiName: newAutoRole.emojiName, + roleId: newAutoRole.roleId + } + ).pipe(catchError(err => { + this.spinner.hideSpinner(); + this.toastService.error(this.translate.instant("view.server.auto_roles.message.auto_role_create_failed"), this.translate.instant("view.server.auto_roles.message.auto_role_create_failed_d")); + return throwError(err); + })).subscribe(result => { + this.spinner.hideSpinner(); + this.toastService.success(this.translate.instant("view.server.auto_roles.message.auto_role_created"), this.translate.instant("view.server.auto_roles.message.auto_role_create_d", { id: result.autoRole.createAutoRole?.id })); + this.loadNextPage(); + }); + } + + onRowEditCancel(index: number) { + if (this.isEditingNew) { + this.rules.splice(index, 1); + delete this.clonedUsers[index]; + this.isEditingNew = false; + return; + } + + this.rules[index] = this.clonedUsers[index]; + delete this.clonedUsers[index]; + } + + deleteAutoRoleRule(autoRoleRule: AutoRoleRule) { + this.confirmDialog.confirmDialog( + this.translate.instant("view.server.auto_roles.message.auto_role_delete"), this.translate.instant("view.server.auto_roles.message.auto_role_delete_q", { id: autoRoleRule.id }), + () => { + this.spinner.showSpinner(); + this.data.mutation(Mutations.deleteAutoRole, { + id: autoRoleRule.id + } + ).pipe(catchError(err => { + this.spinner.hideSpinner(); + this.toastService.error(this.translate.instant("view.server.auto_roles.message.auto_role_delete_failed"), this.translate.instant("view.server.auto_roles.message.auto_role_delete_failed_d", { id: autoRoleRule.id })); + return throwError(err); + })).subscribe(_ => { + this.spinner.hideSpinner(); + this.toastService.success(this.translate.instant("view.server.auto_roles.message.auto_role_deleted"), this.translate.instant("view.server.auto_roles.message.auto_role_deleted_d", { id: autoRoleRule.id })); + this.loadNextPage(); + }); + }); + + + } + + addAutoRoleRule(table: Table) { + const newAutoRole = JSON.parse(JSON.stringify(this.newAutoRoleTemplate)); + newAutoRole.id = Math.max.apply(Math, this.rules.map(u => { + return u.id ?? 0; + })) + 1; + + this.rules.push(newAutoRole); + + table.initRowEdit(newAutoRole); + + const index = this.rules.findIndex(u => u.id == newAutoRole.id); + this.onRowEditInit(table, newAutoRole, index); + + this.isEditingNew = true; } } 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 6659fc68..e7718ca7 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 @@ -21,6 +21,7 @@ import { Mutations } from "../../../../../../models/graphql/mutations.model"; import { throwError } from "rxjs"; import { AutoRole, AutoRoleFilter } from "../../../../../../models/data/auto_role.model"; import { ChannelType, Guild } from "../../../../../../models/data/discord.model"; +import { Server } from "../../../../../../models/data/server.model"; @Component({ selector: "app-auto-roles", @@ -100,7 +101,10 @@ export class AutoRolesComponent implements OnInit { loadNextPage() { this.loading = true; this.data.query(Queries.autoRolesQuery, { - filter: this.filter, page: this.page, sort: this.sort + id: this.sidebar.server$.value?.id, filter: this.filter, page: this.page, sort: this.sort + }, + (x: { servers: Server[] }) => { + return x.servers[0]; } ).subscribe(data => { this.totalRecords = data.autoRoleCount; diff --git a/kdb-web/src/app/services/data/data.service.ts b/kdb-web/src/app/services/data/data.service.ts index 5a6b37ed..fbcb7c45 100644 --- a/kdb-web/src/app/services/data/data.service.ts +++ b/kdb-web/src/app/services/data/data.service.ts @@ -53,7 +53,7 @@ export class DataService { }) .pipe(map(d => { if (d.errors && d.errors.length > 0) { - throw new Error(d.errors.toString()); + throw new Error(d.errors.map((x: {message: String}) => x.message).toString()); } return d.data; })) diff --git a/kdb-web/src/app/services/error-handler/error-handler.service.ts b/kdb-web/src/app/services/error-handler/error-handler.service.ts index b2ed4f6d..89786ef2 100644 --- a/kdb-web/src/app/services/error-handler/error-handler.service.ts +++ b/kdb-web/src/app/services/error-handler/error-handler.service.ts @@ -1,16 +1,17 @@ -import { HttpErrorResponse } from '@angular/common/http'; -import { ErrorHandler, Injectable, Injector } from '@angular/core'; -import { Observable, throwError } from 'rxjs'; -import { ErrorDTO } from 'src/app/models/error/error-dto'; -import { ServiceErrorCode } from 'src/app/models/error/service-error-code.enum'; -import { AuthService } from '../auth/auth.service'; -import { ToastService } from '../toast/toast.service'; +import { HttpErrorResponse } from "@angular/common/http"; +import { ErrorHandler, Injectable } from "@angular/core"; +import { Observable, throwError } from "rxjs"; +import { ErrorDTO } from "src/app/models/error/error-dto"; +import { ServiceErrorCode } from "src/app/models/error/service-error-code.enum"; +import { AuthService } from "../auth/auth.service"; +import { ToastService } from "../toast/toast.service"; @Injectable() export class ErrorHandlerService implements ErrorHandler { constructor( - private injector: Injector + private auth: AuthService, + private toast: ToastService, ) { } handleError(error: HttpErrorResponse): Observable { @@ -20,7 +21,7 @@ export class ErrorHandlerService implements ErrorHandler { const errorDto: ErrorDTO = error.error; if (errorDto.errorCode === ServiceErrorCode.Unauthorized) { - this.injector.get(AuthService).logout(); + this.auth.logout(); return throwError(() => error); } @@ -34,11 +35,13 @@ export class ErrorHandlerService implements ErrorHandler { message = error.message; } - this.injector.get(ToastService).error(header, message); + this.toast.error(header, message); + } else { + console.error(error.message); } if (error.status === 401) { - this.injector.get(AuthService).logout(); + this.auth.logout(); } return throwError(() => error); } diff --git a/kdb-web/src/app/services/sidebar/sidebar.service.ts b/kdb-web/src/app/services/sidebar/sidebar.service.ts index 601a8ad0..021f434f 100644 --- a/kdb-web/src/app/services/sidebar/sidebar.service.ts +++ b/kdb-web/src/app/services/sidebar/sidebar.service.ts @@ -8,7 +8,6 @@ import { NavigationEnd, Router } from "@angular/router"; import { ThemeService } from "../theme/theme.service"; import { Server } from "../../models/data/server.model"; import { UserDTO } from "../../models/auth/auth-user.dto"; -import { AutoRole } from "../../models/data/auto_role.model"; @Injectable({ providedIn: "root" @@ -18,7 +17,6 @@ export class SidebarService { isSidebarOpen: boolean = true; menuItems$ = new BehaviorSubject(new Array()); server$ = new BehaviorSubject(null); - autoRole$ = new BehaviorSubject(null); dashboard!: MenuItem; serverDashboard!: MenuItem; diff --git a/kdb-web/src/app/services/theme/theme.service.ts b/kdb-web/src/app/services/theme/theme.service.ts index 6abe0955..32d56f4c 100644 --- a/kdb-web/src/app/services/theme/theme.service.ts +++ b/kdb-web/src/app/services/theme/theme.service.ts @@ -1,8 +1,7 @@ -import { Injectable } from '@angular/core'; -import { LangChangeEvent, TranslateService } from '@ngx-translate/core'; -import { Subject } from 'rxjs'; -import { Themes } from 'src/app/models/view/themes.enum'; -import { AuthService } from '../auth/auth.service'; +import { Injectable } from "@angular/core"; +import { BehaviorSubject } from "rxjs"; +import { Themes } from "src/app/models/view/themes.enum"; +import { AuthService } from "../auth/auth.service"; @Injectable({ providedIn: 'root' @@ -15,9 +14,9 @@ export class ThemeService { isSidebarOpen = false; hasLangChanged = false; - themeName$ = new Subject(); - isSidebarOpen$ = new Subject(); - sidebarWidth$ = new Subject(); + themeName$ = new BehaviorSubject(Themes.Default); + isSidebarOpen$ = new BehaviorSubject(true); + sidebarWidth$ = new BehaviorSubject('175px'); constructor( private authService: AuthService diff --git a/kdb-web/src/assets/i18n/de.json b/kdb-web/src/assets/i18n/de.json index 9af9fa47..2e8e2ea5 100644 --- a/kdb-web/src/assets/i18n/de.json +++ b/kdb-web/src/assets/i18n/de.json @@ -246,6 +246,32 @@ "auto_role_deleted_d": "Auto Rolle {{id}} erfolgreich gelöscht", "auto_role_delete_failed": "Auto Rolle Löschung fehlgeschlagen", "auto_role_delete_failed_d": "Die Löschung der Auto Rolle {{id}} ist fehlgeschlagen!" + }, + "rules": { + "header": "Auto Rollen Regeln", + "of": "von", + "add": "Hinzufügen", + "reset_filters": "Filter zurücksetzen", + "auto_roles": "Auto Rollen Regeln", + "headers": { + "id": "Id", + "emoji": "Emoji", + "role": "Rolle", + "actions": "Aktionen" + }, + "no_entries_found": "Keine Einträge gefunden", + "message": { + "auto_role_create": "Auto Rolle erstellt", + "auto_role_create_d": "Auto Rolle {{id}} erfolgreich erstellt", + "auto_role_create_failed": "Auto Rolle Erstellung fehlgeschlagen", + "auto_role_create_failed_d": "Die Erstellung der Auto Rolle ist fehlgeschlagen!", + "auto_role_delete": "Auto Rolle löschen", + "auto_role_delete_q": "Sind Sie sich sicher, dass Sie die Auto Rolle {{id}} löschen möchten?", + "auto_role_deleted": "Auto Rolle gelöscht", + "auto_role_deleted_d": "Auto Rolle {{id}} erfolgreich gelöscht", + "auto_role_delete_failed": "Auto Rolle Löschung fehlgeschlagen", + "auto_role_delete_failed_d": "Die Löschung der Auto Rolle {{id}} ist fehlgeschlagen!" + } } } }, diff --git a/kdb-web/src/styles.scss b/kdb-web/src/styles.scss index 6af8ef9f..d55386b7 100644 --- a/kdb-web/src/styles.scss +++ b/kdb-web/src/styles.scss @@ -156,6 +156,12 @@ header { margin: 5px 0; } + .dropdown-icon-label-wrapper { + display: flex; + flex-direction: row; + gap: 10px; + } + .content-input-field { width: 50% !important; margin: 0 !important; -- 2.45.2 From ec9bc803921edd6b52a0b892f5eb9db52687f351 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 20 Feb 2023 22:30:18 +0100 Subject: [PATCH 7/8] Finished auto role rules #134 --- kdb-bot/src/bot_data/model/auto_role_rule.py | 6 +- .../mutations/auto_role_rule_mutation.py | 4 +- .../src/app/models/graphql/mutations.model.ts | 15 ++++- .../src/app/models/graphql/result.model.ts | 11 +++- .../auto-roles-rules.component.html | 2 +- .../auto-roles-rules.component.ts | 56 ++++++++++++------- kdb-web/src/assets/i18n/de.json | 24 ++++---- 7 files changed, 81 insertions(+), 37 deletions(-) diff --git a/kdb-bot/src/bot_data/model/auto_role_rule.py b/kdb-bot/src/bot_data/model/auto_role_rule.py index 3630f134..34188caa 100644 --- a/kdb-bot/src/bot_data/model/auto_role_rule.py +++ b/kdb-bot/src/bot_data/model/auto_role_rule.py @@ -89,7 +89,7 @@ class AutoRoleRule(TableABC): INSERT INTO `AutoRoleRules` ( `AutoRoleId`, `DiscordEmojiName`, `DiscordRoleId`, `CreatedAt`, `LastModifiedAt` ) VALUES ( - {self._auto_role}, + {self._auto_role.id}, '{self._discord_emoji_name}', {self._discord_role_id}, '{self._created_at}', @@ -103,8 +103,8 @@ class AutoRoleRule(TableABC): return str( f""" UPDATE `AutoRoleRules` - SET `AutoRoleId` = {self._auto_role}, - `DiscordEmojiName` = {self._discord_emoji_name}, + SET `AutoRoleId` = {self._auto_role.id}, + `DiscordEmojiName` = '{self._discord_emoji_name}', `DiscordRoleId` = {self._discord_role_id}, `LastModifiedAt` = '{self._modified_at}' WHERE `AutoRoleRuleId` = {self._auto_role_rule_id}; diff --git a/kdb-bot/src/bot_graphql/mutations/auto_role_rule_mutation.py b/kdb-bot/src/bot_graphql/mutations/auto_role_rule_mutation.py index b6b6a943..76dce97c 100644 --- a/kdb-bot/src/bot_graphql/mutations/auto_role_rule_mutation.py +++ b/kdb-bot/src/bot_graphql/mutations/auto_role_rule_mutation.py @@ -35,9 +35,9 @@ class AutoRoleRuleMutation(QueryABC): def get_new(x: AutoRoleRule): return ( - x.auto_role.id == input["autoRoleId"] + x.auto_role.id == int(input["autoRoleId"]) and x.emoji_name == input["emojiName"] - and x.role_id == input["roleId"] + and x.role_id == int(input["roleId"]) ) return self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role_rule.auto_role.id).where(get_new).last() diff --git a/kdb-web/src/app/models/graphql/mutations.model.ts b/kdb-web/src/app/models/graphql/mutations.model.ts index 310f300f..4d10e87d 100644 --- a/kdb-web/src/app/models/graphql/mutations.model.ts +++ b/kdb-web/src/app/models/graphql/mutations.model.ts @@ -42,7 +42,7 @@ export class Mutations { `; static createAutoRoleRule = ` - mutation createAutoRoleRule($autoRoleId: ID, $emojiName: String, roleId: String) { + mutation createAutoRoleRule($autoRoleId: ID, $emojiName: String, $roleId: String) { autoRoleRule { createAutoRoleRule(input: { autoRoleId: $autoRoleId, emojiName: $emojiName, roleId: $roleId }) { id @@ -54,6 +54,19 @@ export class Mutations { } `; + static updateAutoRoleRule = ` + mutation updateAutoRoleRule($id: ID, $emojiName: String, $roleId: String) { + autoRoleRule { + updateAutoRoleRule(input: { id: $id, emojiName: $emojiName, roleId: $roleId }) { + id + emojiName + roleId + roleName + } + } + } + `; + static deleteAutoRoleRule = ` mutation deleteAutoRoleRule($id: ID) { autoRoleRule { diff --git a/kdb-web/src/app/models/graphql/result.model.ts b/kdb-web/src/app/models/graphql/result.model.ts index 8198fda2..5ad5cd8a 100644 --- a/kdb-web/src/app/models/graphql/result.model.ts +++ b/kdb-web/src/app/models/graphql/result.model.ts @@ -1,5 +1,5 @@ import { User } from "../data/user.model"; -import { AutoRole } from "../data/auto_role.model"; +import { AutoRole, AutoRoleRule } from "../data/auto_role.model"; export interface GraphQLResult { data: any; @@ -15,6 +15,7 @@ export interface UpdateUserMutationResult { updateUser: User }; } + export interface AutoRoleMutationResult { autoRole: { createAutoRole?: AutoRole @@ -22,3 +23,11 @@ export interface AutoRoleMutationResult { deleteAutoRole?: AutoRole }; } + +export interface AutoRoleRuleMutationResult { + autoRoleRule: { + createAutoRoleRule?: AutoRoleRule + updateAutoRoleRule?: AutoRoleRule + deleteAutoRoleRule?: AutoRoleRule + }; +} 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 fd1a4536..12176fec 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 @@ -102,7 +102,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 cca972a0..48aa83f4 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 @@ -19,7 +19,7 @@ import { Queries } from "../../../../../../models/graphql/queries.model"; import { Server } from "../../../../../../models/data/server.model"; import { catchError, debounceTime } from "rxjs/operators"; import { Table } from "primeng/table"; -import { AutoRoleMutationResult } from "../../../../../../models/graphql/result.model"; +import { AutoRoleMutationResult, AutoRoleRuleMutationResult } from "../../../../../../models/graphql/result.model"; import { Mutations } from "../../../../../../models/graphql/mutations.model"; import { throwError } from "rxjs"; @@ -32,8 +32,8 @@ export class AutoRolesRulesComponent implements OnInit { rules!: AutoRoleRule[]; guild!: Guild; - emojis!: MenuItem[]; - roles!: MenuItem[]; + emojis: MenuItem[] = []; + roles: MenuItem[] = []; loading = true; autoRoleId!: number; @@ -80,7 +80,7 @@ export class AutoRolesRulesComponent implements OnInit { } getEmojiUrl(name: string): string { - return this.guild.emojis.filter(x => x.name == name)[0].url ?? ""; + return this.guild?.emojis.filter(x => x.name == name)[0].url ?? ""; } ngOnInit(): void { @@ -191,30 +191,50 @@ export class AutoRolesRulesComponent implements OnInit { this.clonedUsers[index] = { ...autoRoleRule }; } - onRowEditSave(table: Table, newAutoRole: AutoRoleRule, index: number) { - if (this.isEditingNew && JSON.stringify(newAutoRole) === JSON.stringify(this.newAutoRoleTemplate)) { + onRowEditSave(table: Table, newAutoRoleRule: AutoRoleRule, index: number) { + if (this.isEditingNew && JSON.stringify(newAutoRoleRule) === JSON.stringify(this.newAutoRoleTemplate)) { this.isEditingNew = false; this.rules.splice(index, 1); return; } - if (!newAutoRole.id || !newAutoRole.emojiName && !newAutoRole.roleId) { + if (!newAutoRoleRule.id && !this.isEditingNew || !newAutoRoleRule.emojiName && !newAutoRoleRule.roleId) { + return; + } + + if (this.isEditingNew) { + this.spinner.showSpinner(); + this.data.mutation(Mutations.createAutoRoleRule, { + autoRoleId: this.autoRoleId, + emojiName: newAutoRoleRule.emojiName, + roleId: newAutoRoleRule.roleId + } + ).pipe(catchError(err => { + this.spinner.hideSpinner(); + this.toastService.error(this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_create_failed"), this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_create_failed_d")); + return throwError(err); + })).subscribe(result => { + this.spinner.hideSpinner(); + this.toastService.success(this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_created"), this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_create_d", { id: result.autoRoleRule.createAutoRoleRule?.id })); + this.isEditingNew = false; + this.loadNextPage(); + }); return; } this.spinner.showSpinner(); - this.data.mutation(Mutations.createAutoRoleRule, { - serverId: this.sidebar.server$.value?.id, - emojiName: newAutoRole.emojiName, - roleId: newAutoRole.roleId + this.data.mutation(Mutations.updateAutoRoleRule, { + id: newAutoRoleRule.id, + emojiName: newAutoRoleRule.emojiName, + roleId: newAutoRoleRule.roleId } ).pipe(catchError(err => { this.spinner.hideSpinner(); - this.toastService.error(this.translate.instant("view.server.auto_roles.message.auto_role_create_failed"), this.translate.instant("view.server.auto_roles.message.auto_role_create_failed_d")); + this.toastService.error(this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_update_failed"), this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_update_failed_d")); return throwError(err); })).subscribe(result => { this.spinner.hideSpinner(); - this.toastService.success(this.translate.instant("view.server.auto_roles.message.auto_role_created"), this.translate.instant("view.server.auto_roles.message.auto_role_create_d", { id: result.autoRole.createAutoRole?.id })); + this.toastService.success(this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_updated"), this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_update_d", { id: result.autoRole.createAutoRole?.id })); this.loadNextPage(); }); } @@ -233,24 +253,22 @@ export class AutoRolesRulesComponent implements OnInit { deleteAutoRoleRule(autoRoleRule: AutoRoleRule) { this.confirmDialog.confirmDialog( - this.translate.instant("view.server.auto_roles.message.auto_role_delete"), this.translate.instant("view.server.auto_roles.message.auto_role_delete_q", { id: autoRoleRule.id }), + this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_delete"), this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_delete_q", { id: autoRoleRule.id }), () => { this.spinner.showSpinner(); - this.data.mutation(Mutations.deleteAutoRole, { + this.data.mutation(Mutations.deleteAutoRoleRule, { id: autoRoleRule.id } ).pipe(catchError(err => { this.spinner.hideSpinner(); - this.toastService.error(this.translate.instant("view.server.auto_roles.message.auto_role_delete_failed"), this.translate.instant("view.server.auto_roles.message.auto_role_delete_failed_d", { id: autoRoleRule.id })); + this.toastService.error(this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_delete_failed"), this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_delete_failed_d", { id: autoRoleRule.id })); return throwError(err); })).subscribe(_ => { this.spinner.hideSpinner(); - this.toastService.success(this.translate.instant("view.server.auto_roles.message.auto_role_deleted"), this.translate.instant("view.server.auto_roles.message.auto_role_deleted_d", { id: autoRoleRule.id })); + this.toastService.success(this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_deleted"), this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_deleted_d", { id: autoRoleRule.id })); this.loadNextPage(); }); }); - - } addAutoRoleRule(table: Table) { diff --git a/kdb-web/src/assets/i18n/de.json b/kdb-web/src/assets/i18n/de.json index 2e8e2ea5..8a7b7eaf 100644 --- a/kdb-web/src/assets/i18n/de.json +++ b/kdb-web/src/assets/i18n/de.json @@ -261,16 +261,20 @@ }, "no_entries_found": "Keine Einträge gefunden", "message": { - "auto_role_create": "Auto Rolle erstellt", - "auto_role_create_d": "Auto Rolle {{id}} erfolgreich erstellt", - "auto_role_create_failed": "Auto Rolle Erstellung fehlgeschlagen", - "auto_role_create_failed_d": "Die Erstellung der Auto Rolle ist fehlgeschlagen!", - "auto_role_delete": "Auto Rolle löschen", - "auto_role_delete_q": "Sind Sie sich sicher, dass Sie die Auto Rolle {{id}} löschen möchten?", - "auto_role_deleted": "Auto Rolle gelöscht", - "auto_role_deleted_d": "Auto Rolle {{id}} erfolgreich gelöscht", - "auto_role_delete_failed": "Auto Rolle Löschung fehlgeschlagen", - "auto_role_delete_failed_d": "Die Löschung der Auto Rolle {{id}} ist fehlgeschlagen!" + "auto_role_rule_create": "Auto Rollen Regel erstellt", + "auto_role_rule_create_d": "Auto Rollen Regel {{id}} erfolgreich erstellt", + "auto_role_rule_create_failed": "Auto Rollen Regel Erstellung fehlgeschlagen", + "auto_role_rule_create_failed_d": "Die Erstellung der Auto Rollen Regel ist fehlgeschlagen!", + "auto_role_rule_update": "Auto Rollen Regel bearbeitet", + "auto_role_rule_update_d": "Auto Rollen Regel {{id}} erfolgreich bearbeitet", + "auto_role_rule_update_failed": "Auto Rollen Regel Bearbeitung fehlgeschlagen", + "auto_role_rule_update_failed_d": "Die Bearbeitung der Auto Rollen Regel ist fehlgeschlagen!", + "auto_role_rule_delete": "Auto Rollen Regel löschen", + "auto_role_rule_delete_q": "Sind Sie sich sicher, dass Sie die Auto Rollen Regel {{id}} löschen möchten?", + "auto_role_rule_deleted": "Auto Rollen Regel gelöscht", + "auto_role_rule_deleted_d": "Auto Rollen Regel {{id}} erfolgreich gelöscht", + "auto_role_rule_delete_failed": "Auto Rollen Regel Löschung fehlgeschlagen", + "auto_role_rule_delete_failed_d": "Die Löschung der Auto Rollen Regel {{id}} ist fehlgeschlagen!" } } } -- 2.45.2 From 75ab1595396b545d26c381bfc40fc817d65b09f6 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 20 Feb 2023 22:46:18 +0100 Subject: [PATCH 8/8] Added typing #134 --- .../auto-roles-rules.component.ts | 22 +++++++++---------- .../auto-roles/auto-roles.component.ts | 20 ++++++++--------- 2 files changed, 21 insertions(+), 21 deletions(-) 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 48aa83f4..383586a2 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 @@ -79,11 +79,11 @@ export class AutoRolesRulesComponent implements OnInit { ) { } - getEmojiUrl(name: string): string { + public getEmojiUrl(name: string): string { return this.guild?.emojis.filter(x => x.name == name)[0].url ?? ""; } - ngOnInit(): void { + public ngOnInit(): void { this.data.getServerFromRoute(this.route); this.spinner.showSpinner(); if (!this.route.snapshot.params["autoRoleId"]) { @@ -116,7 +116,7 @@ export class AutoRolesRulesComponent implements OnInit { this.loadNextPage(); } - loadNextPage() { + public loadNextPage(): void { this.loading = true; this.data.query(Queries.autoRoleRulesQuery, { id: this.sidebar.server$.value?.id, filter: this.filter, page: this.page, sort: this.sort @@ -135,7 +135,7 @@ export class AutoRolesRulesComponent implements OnInit { }); } - setFilterForm() { + public setFilterForm(): void { this.filterForm = this.fb.group({ id: new FormControl(null), emojiName: new FormControl(null), @@ -173,7 +173,7 @@ export class AutoRolesRulesComponent implements OnInit { }); } - nextPage(event: LazyLoadEvent) { + public nextPage(event: LazyLoadEvent): void { this.page.pageSize = event.rows ?? 0; if (event.first != null && event.rows != null) this.page.pageIndex = event.first / event.rows; @@ -183,15 +183,15 @@ export class AutoRolesRulesComponent implements OnInit { this.loadNextPage(); } - resetFilters() { + public resetFilters(): void { this.filterForm.reset(); } - onRowEditInit(table: Table, autoRoleRule: AutoRoleRule, index: number) { + public onRowEditInit(table: Table, autoRoleRule: AutoRoleRule, index: number): void { this.clonedUsers[index] = { ...autoRoleRule }; } - onRowEditSave(table: Table, newAutoRoleRule: AutoRoleRule, index: number) { + public onRowEditSave(table: Table, newAutoRoleRule: AutoRoleRule, index: number): void { if (this.isEditingNew && JSON.stringify(newAutoRoleRule) === JSON.stringify(this.newAutoRoleTemplate)) { this.isEditingNew = false; this.rules.splice(index, 1); @@ -239,7 +239,7 @@ export class AutoRolesRulesComponent implements OnInit { }); } - onRowEditCancel(index: number) { + public onRowEditCancel(index: number): void { if (this.isEditingNew) { this.rules.splice(index, 1); delete this.clonedUsers[index]; @@ -251,7 +251,7 @@ export class AutoRolesRulesComponent implements OnInit { delete this.clonedUsers[index]; } - deleteAutoRoleRule(autoRoleRule: AutoRoleRule) { + public deleteAutoRoleRule(autoRoleRule: AutoRoleRule): void { this.confirmDialog.confirmDialog( this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_delete"), this.translate.instant("view.server.auto_roles.rules.message.auto_role_rule_delete_q", { id: autoRoleRule.id }), () => { @@ -271,7 +271,7 @@ export class AutoRolesRulesComponent implements OnInit { }); } - addAutoRoleRule(table: Table) { + public addAutoRoleRule(table: Table): void { const newAutoRole = JSON.parse(JSON.stringify(this.newAutoRoleTemplate)); newAutoRole.id = Math.max.apply(Math, this.rules.map(u => { return u.id ?? 0; 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 e7718ca7..78b27de9 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 @@ -75,7 +75,7 @@ export class AutoRolesComponent implements OnInit { ) { } - ngOnInit(): void { + public ngOnInit(): void { this.data.getServerFromRoute(this.route); this.spinner.showSpinner(); @@ -98,7 +98,7 @@ export class AutoRolesComponent implements OnInit { this.loadNextPage(); } - loadNextPage() { + public loadNextPage(): void { this.loading = true; this.data.query(Queries.autoRolesQuery, { id: this.sidebar.server$.value?.id, filter: this.filter, page: this.page, sort: this.sort @@ -114,7 +114,7 @@ export class AutoRolesComponent implements OnInit { }); } - setFilterForm() { + public setFilterForm(): void { this.filterForm = this.fb.group({ id: new FormControl(null), channelId: new FormControl(null), @@ -159,7 +159,7 @@ export class AutoRolesComponent implements OnInit { }); } - nextPage(event: LazyLoadEvent) { + public nextPage(event: LazyLoadEvent): void { this.page.pageSize = event.rows ?? 0; if (event.first != null && event.rows != null) this.page.pageIndex = event.first / event.rows; @@ -169,15 +169,15 @@ export class AutoRolesComponent implements OnInit { this.loadNextPage(); } - resetFilters() { + public resetFilters(): void { this.filterForm.reset(); } - onRowEditInit(table: Table, autoRole: AutoRole, index: number) { + public onRowEditInit(table: Table, autoRole: AutoRole, index: number): void { this.clonedUsers[index] = { ...autoRole }; } - onRowEditSave(table: Table, newAutoRole: AutoRole, index: number) { + public onRowEditSave(table: Table, newAutoRole: AutoRole, index: number): void { if (this.isEditingNew && JSON.stringify(newAutoRole) === JSON.stringify(this.newAutoRoleTemplate)) { this.isEditingNew = false; this.auto_roles.splice(index, 1); @@ -205,7 +205,7 @@ export class AutoRolesComponent implements OnInit { }); } - onRowEditCancel(index: number) { + public onRowEditCancel(index: number): void { if (this.isEditingNew) { this.auto_roles.splice(index, 1); delete this.clonedUsers[index]; @@ -217,7 +217,7 @@ export class AutoRolesComponent implements OnInit { delete this.clonedUsers[index]; } - deleteAutoRole(autoRole: AutoRole) { + public deleteAutoRole(autoRole: AutoRole): void { this.confirmDialog.confirmDialog( this.translate.instant("view.server.auto_roles.message.auto_role_delete"), this.translate.instant("view.server.auto_roles.message.auto_role_delete_q", { id: autoRole.id }), () => { @@ -239,7 +239,7 @@ export class AutoRolesComponent implements OnInit { } - addAutoRole(table: Table) { + public addAutoRole(table: Table): void { const newAutoRole = JSON.parse(JSON.stringify(this.newAutoRoleTemplate)); newAutoRole.id = Math.max.apply(Math, this.auto_roles.map(u => { return u.id ?? 0; -- 2.45.2