AutoRole #134 #222
@ -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)
|
||||
|
@ -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",
|
||||
|
35
kdb-web/src/app/models/data/auto_role.model.ts
Normal file
35
kdb-web/src/app/models/data/auto_role.model.ts
Normal file
@ -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;
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
@ -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[];
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
icon="pi pi-user-plus" (click)="addUser(dt)" [disabled]="isEditingNew">
|
||||
</button>
|
||||
<button pButton label="{{'admin.auth_users.reset_filters' | translate}}" icon="pi pi-undo"
|
||||
class="icon-btn btn" (click)="resetFilters(dt)">
|
||||
class="icon-btn btn" (click)="resetFilters()">
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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();
|
||||
|
@ -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 {
|
||||
|
||||
}
|
@ -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 { }
|
@ -0,0 +1 @@
|
||||
<p>auto-roles-rules works!</p>
|
@ -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<AutoRolesRulesComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ AutoRolesRulesComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(AutoRolesRulesComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -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 {
|
||||
|
||||
}
|
@ -0,0 +1,219 @@
|
||||
<h1>
|
||||
{{'view.server.auto_roles.header' | translate}}
|
||||
</h1>
|
||||
<div class="content-wrapper">
|
||||
<div class="content">
|
||||
<p-table #dt [value]="auto_roles" dataKey="id" editMode="row" [rowHover]="true" [rows]="10"
|
||||
[rowsPerPageOptions]="[10,25,50]" [paginator]="true" [loading]="loading" [totalRecords]="totalRecords"
|
||||
[lazy]="true" (onLazyLoad)="nextPage($event)">
|
||||
|
||||
<ng-template pTemplate="caption">
|
||||
<div class="table-caption">
|
||||
<div class="table-caption-text">
|
||||
<ng-container *ngIf="!loading">{{auto_roles.length}} {{'view.server.auto_roles.of' | translate}}
|
||||
{{dt.totalRecords}}
|
||||
</ng-container>
|
||||
{{'view.server.auto_roles.auto_roles' | translate}}
|
||||
</div>
|
||||
|
||||
<div class="table-caption-btn-wrapper btn-wrapper">
|
||||
<button pButton label="{{'admin.auth_users.add' | translate}}" class="icon-btn btn"
|
||||
icon="pi pi-user-plus" (click)="addUser(dt)" [disabled]="isEditingNew">
|
||||
</button>
|
||||
<button pButton label="{{'view.server.auto_roles.reset_filters' | translate}}" icon="pi pi-undo"
|
||||
class="icon-btn btn" (click)="resetFilters()">
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
<ng-template pTemplate="header">
|
||||
<tr>
|
||||
<th pSortableColumn="id">
|
||||
<div class="table-header-label">
|
||||
<div class="table-header-text">{{'view.server.auto_roles.headers.id' | translate}}</div>
|
||||
<p-sortIcon field="id" class="table-header-icon"></p-sortIcon>
|
||||
</div>
|
||||
</th>
|
||||
|
||||
<th pSortableColumn="discordChannelId">
|
||||
<div class="table-header-label">
|
||||
<div class="table-header-text">{{'view.server.auto_roles.headers.channel_id' | translate}}</div>
|
||||
<p-sortIcon field="discordChannelId" class="table-header-icon"></p-sortIcon>
|
||||
</div>
|
||||
</th>
|
||||
|
||||
<th pSortableColumn="discordChannelName">
|
||||
<div class="table-header-label">
|
||||
<div class="table-header-text">{{'view.server.auto_roles.headers.channel_name' | translate}}</div>
|
||||
<p-sortIcon field="discordChannelName" class="table-header-icon"></p-sortIcon>
|
||||
</div>
|
||||
</th>
|
||||
|
||||
<th pSortableColumn="discordMessageId">
|
||||
<div class="table-header-label">
|
||||
<div class="table-header-text">{{'view.server.auto_roles.headers.message_id' | translate}}</div>
|
||||
<p-sortIcon field="discordMessageId" class="table-header-icon"></p-sortIcon>
|
||||
</div>
|
||||
</th>
|
||||
|
||||
<th>
|
||||
<div class="table-header-label">
|
||||
<div class="table-header-text">{{'view.server.auto_roles.headers.role_count' | translate}}</div>
|
||||
</div>
|
||||
</th>
|
||||
|
||||
<th class="table-header-small-dropdown">
|
||||
<div class="table-header-label">
|
||||
<div class="table-header-text">{{'common.created_at' | translate}}</div>
|
||||
</div>
|
||||
</th>
|
||||
|
||||
<th class="table-header-small-dropdown">
|
||||
<div class="table-header-label">
|
||||
<div class="table-header-text">{{'common.modified_at' | translate}}</div>
|
||||
</div>
|
||||
</th>
|
||||
|
||||
<th>
|
||||
<div class="table-header-label">
|
||||
<div class="table-header-text">{{'view.server.auto_roles.headers.actions' | translate}}</div>
|
||||
</div>
|
||||
</th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th class="table-header-small">
|
||||
<form [formGroup]="filterForm">
|
||||
<input type="text" pInputText formControlName="id" placeholder="{{'view.server.auto_roles.headers.id' | translate}}">
|
||||
</form>
|
||||
</th>
|
||||
<th>
|
||||
<form [formGroup]="filterForm">
|
||||
<input type="text" pInputText formControlName="channelId" placeholder="{{'view.server.auto_roles.headers.channel_id' | translate}}">
|
||||
</form>
|
||||
</th>
|
||||
<th>
|
||||
<form [formGroup]="filterForm">
|
||||
<input type="text" pInputText formControlName="channelName" placeholder="{{'view.server.auto_roles.headers.channel_name' | translate}}">
|
||||
</form>
|
||||
</th>
|
||||
<th>
|
||||
<form [formGroup]="filterForm">
|
||||
<input type="text" pInputText formControlName="messageId" placeholder="{{'view.server.auto_roles.headers.message_id' | translate}}">
|
||||
</form>
|
||||
</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th class="table-header-actions"></th>
|
||||
</tr>
|
||||
</ng-template>
|
||||
|
||||
<ng-template pTemplate="body" let-autoRole let-editing="editing" let-ri="rowIndex">
|
||||
<tr [pEditableRow]="autoRole">
|
||||
<td>
|
||||
<p-cellEditor>
|
||||
<ng-template pTemplate="input">
|
||||
{{autoRole.id}}
|
||||
</ng-template>
|
||||
<ng-template pTemplate="output">
|
||||
{{autoRole.id}}
|
||||
</ng-template>
|
||||
</p-cellEditor>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<p-cellEditor>
|
||||
<ng-template pTemplate="input">
|
||||
{{autoRole.channelId}}
|
||||
</ng-template>
|
||||
<ng-template pTemplate="output">
|
||||
{{autoRole.channelId}}
|
||||
</ng-template>
|
||||
</p-cellEditor>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<p-cellEditor>
|
||||
<ng-template pTemplate="input">
|
||||
{{autoRole.channelName}}
|
||||
</ng-template>
|
||||
<ng-template pTemplate="output">
|
||||
{{autoRole.channelName}}
|
||||
</ng-template>
|
||||
</p-cellEditor>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<p-cellEditor>
|
||||
<ng-template pTemplate="input">
|
||||
{{autoRole.messageId}}
|
||||
</ng-template>
|
||||
<ng-template pTemplate="output">
|
||||
{{autoRole.messageId}}
|
||||
</ng-template>
|
||||
</p-cellEditor>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<p-cellEditor>
|
||||
<ng-template pTemplate="input">
|
||||
{{autoRole.autoRoleRuleCount}}
|
||||
</ng-template>
|
||||
<ng-template pTemplate="output">
|
||||
{{autoRole.autoRoleRuleCount}}
|
||||
</ng-template>
|
||||
</p-cellEditor>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<p-cellEditor>
|
||||
<ng-template pTemplate="input">
|
||||
{{autoRole.createdAt | date:'dd.MM.yy HH:mm'}}
|
||||
</ng-template>
|
||||
<ng-template pTemplate="output">
|
||||
{{autoRole.createdAt | date:'dd.MM.yy HH:mm'}}
|
||||
</ng-template>
|
||||
</p-cellEditor>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<p-cellEditor>
|
||||
<ng-template pTemplate="input">
|
||||
{{autoRole.modifiedAt | date:'dd.MM.yy HH:mm'}}
|
||||
</ng-template>
|
||||
<ng-template pTemplate="output">
|
||||
{{autoRole.modifiedAt | date:'dd.MM.yy HH:mm'}}
|
||||
</ng-template>
|
||||
</p-cellEditor>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<div class="btn-wrapper">
|
||||
<button *ngIf="!editing" pButton pInitEditableRow class="btn icon-btn" icon="pi pi-pencil"
|
||||
(click)="onRowEditInit(dt, autoRole, ri)"></button>
|
||||
<button *ngIf="!editing" pButton pInitEditableRow class="btn icon-btn" icon="pi pi-user" [routerLink]="[autoRole.id, 'rules']"></button>
|
||||
|
||||
<button *ngIf="editing" pButton pSaveEditableRow class="btn icon-btn"
|
||||
icon="pi pi-check-circle" (click)="onRowEditSave(dt, autoRole, ri)"></button>
|
||||
<button *ngIf="editing" pButton pCancelEditableRow class="btn icon-btn danger-icon-btn"
|
||||
icon="pi pi-times-circle" (click)="onRowEditCancel(autoRole, ri)"></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
|
||||
<ng-template pTemplate="emptymessage">
|
||||
<tr></tr>
|
||||
<tr>
|
||||
<td colspan="10">{{'view.server.auto_roles.no_entries_found' | translate}}</td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
</ng-template>
|
||||
|
||||
<ng-template pTemplate="paginatorleft">
|
||||
</ng-template>
|
||||
</p-table>
|
||||
</div>
|
||||
</div>
|
@ -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<AutoRolesComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ AutoRolesComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(AutoRolesComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -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<number | null>,
|
||||
channelId: FormControl<string | null>,
|
||||
channelName: FormControl<string | null>,
|
||||
messageId: FormControl<string | null>,
|
||||
}>;
|
||||
|
||||
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<AutoRoleQuery>(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<number | null>(null),
|
||||
channelId: new FormControl<string | null>(null),
|
||||
channelName: new FormControl<string | null>(null),
|
||||
messageId: new FormControl<string | null>(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<UpdateUserMutationResult>(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;
|
||||
}
|
||||
}
|
@ -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<number | null>(null),
|
||||
name: [""],
|
||||
leftServer: new FormControl<boolean | null>(null),
|
||||
level: new FormControl<number | null>(null),
|
||||
level: new FormControl<number | null>(null)
|
||||
});
|
||||
|
||||
this.filterForm.valueChanges.pipe(
|
||||
|
@ -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({
|
||||
|
@ -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<MenuItem[]>(new Array<MenuItem>());
|
||||
server$ = new BehaviorSubject<Server | null>(null);
|
||||
autoRole$ = new BehaviorSubject<AutoRole | null>(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;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
"WebVersion": {
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "dev130"
|
||||
"Micro": "dev134"
|
||||
},
|
||||
"Themes": [
|
||||
{
|
||||
|
@ -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": {},
|
||||
|
Loading…
Reference in New Issue
Block a user