diff --git a/kdb-bot/src/bot_data/service/auth_user_repository_service.py b/kdb-bot/src/bot_data/service/auth_user_repository_service.py index 295e3c2f..87b39169 100644 --- a/kdb-bot/src/bot_data/service/auth_user_repository_service.py +++ b/kdb-bot/src/bot_data/service/auth_user_repository_service.py @@ -1,3 +1,4 @@ +from enum import Enum from typing import Optional from cpl_core.database.context import DatabaseContextABC @@ -100,9 +101,17 @@ class AuthUserRepositoryService(AuthUserRepositoryABC): ): crit_sort_direction = criteria.sort_direction.lower() if crit_sort_direction == "desc" or crit_sort_direction == "descending": - query = query.order_by_descending(lambda x: getattr(x, criteria.sort_column)) + query = query.order_by_descending( + lambda x: getattr(x, criteria.sort_column) + if not isinstance(getattr(x, criteria.sort_column), Enum) + else getattr(x, criteria.sort_column).value + ) else: - query = query.order_by(lambda x: getattr(x, criteria.sort_column)) + query = query.order_by( + lambda x: getattr(x, criteria.sort_column) + if not isinstance(getattr(x, criteria.sort_column), Enum) + else getattr(x, criteria.sort_column).value + ) result = FilteredResult() result.total_count = query.count() diff --git a/kdb-web/package.json b/kdb-web/package.json index fc35367e..998a4411 100644 --- a/kdb-web/package.json +++ b/kdb-web/package.json @@ -1,6 +1,6 @@ { "name": "kdb-web", - "version": "1.1.0", + "version": "1.1.dev79_hide_table_columns", "scripts": { "ng": "ng", "update-version": "ts-node-esm update-version.ts", diff --git a/kdb-web/src/app/base/component-with-table.spec.ts b/kdb-web/src/app/base/component-with-table.spec.ts new file mode 100644 index 00000000..5b08b905 --- /dev/null +++ b/kdb-web/src/app/base/component-with-table.spec.ts @@ -0,0 +1,7 @@ +import { ComponentWithTable } from './component-with-table'; + +describe('ComponentWithTable', () => { + it('should create an instance', () => { + expect(new ComponentWithTable()).toBeTruthy(); + }); +}); diff --git a/kdb-web/src/app/base/component-with-table.ts b/kdb-web/src/app/base/component-with-table.ts new file mode 100644 index 00000000..ae39c2b3 --- /dev/null +++ b/kdb-web/src/app/base/component-with-table.ts @@ -0,0 +1,39 @@ +export interface Column { + key: string; + name: string; +} + +export class ComponentWithTable { + + private _hiddenColumns: Column[] = []; + set hiddenColumns(value: Column[]) { + this._hiddenColumns = value; + localStorage.setItem("hiddenColumns", JSON.stringify(value)); + } + + get hiddenColumns(): Column[] { + return this._hiddenColumns; + } + + private name: string = ""; + public columns: Column[] = []; + + constructor( + name: string, + columns: string[] + ) { + this.name = name; + this.columns = columns.map(column => { + return { key: this.getKey(column), name: column }; + }); + this._hiddenColumns = JSON.parse(localStorage.getItem("hiddenColumns") ?? ""); + } + + private getKey(column: string): string { + return `${this.name}_${column}`; + } + + public isColumnVisible(column: string): boolean { + return !this._hiddenColumns.map(column => column.key).includes(this.getKey(column)); + } +} 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 58f5eb9d..6699495b 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 @@ -9,11 +9,14 @@
-
- {{users.length}} {{'common.of' | translate}} - {{dt.totalRecords}} - - {{'admin.auth_users.users' | translate}} +
+
+ {{users.length}} {{'common.of' | translate}} + {{dt.totalRecords}} + + {{'admin.auth_users.users' | translate}} +
+
@@ -29,44 +32,44 @@ - +
-
{{'admin.auth_users.headers.first_name' | translate}}
+
{{'common.first_name' | translate}}
- +
-
{{'admin.auth_users.headers.last_name' | translate}}
+
{{'common.last_name' | translate}}
- +
{{'common.email' | translate}}
- +
-
{{'admin.auth_users.headers.active' | translate}}
+
{{'common.active' | translate}}
- +
-
{{'admin.auth_users.headers.role' | translate}}
+
{{'common.role' | translate}}
- +
-
{{'admin.auth_users.headers.password' | translate}}
+
{{'common.password' | translate}}
@@ -89,28 +92,28 @@ - +
- +
- +
- +
- +
- - + +
- +
- + @@ -119,7 +122,7 @@ - + - + - + - + - + - + { + it('should create an instance', () => { + expect(new HideableComponent()).toBeTruthy(); + }); +}); diff --git a/kdb-web/src/app/modules/shared/base/hideable-component.ts b/kdb-web/src/app/modules/shared/base/hideable-component.ts new file mode 100644 index 00000000..4421ff91 --- /dev/null +++ b/kdb-web/src/app/modules/shared/base/hideable-component.ts @@ -0,0 +1,13 @@ +import { Directive, HostBinding, Input } from "@angular/core"; +import { ComponentWithTable } from "../../../base/component-with-table"; + +@Directive() +export class HideableComponent { + @HostBinding("class.hidden-column") + get hidden() { + return !(this.parent?.isColumnVisible(this.column) ?? true); + }; + + @Input() column!: string; + @Input() parent!: ComponentWithTable; +} diff --git a/kdb-web/src/app/modules/shared/base/multi-select-columns/multi-select-columns.component.html b/kdb-web/src/app/modules/shared/base/multi-select-columns/multi-select-columns.component.html new file mode 100644 index 00000000..d26b948b --- /dev/null +++ b/kdb-web/src/app/modules/shared/base/multi-select-columns/multi-select-columns.component.html @@ -0,0 +1,16 @@ +
+ + +
+
+ {{'common.' + item.name | translate}}, +
+
+
{{'common.hidden_columns' | translate}}
+
+ + +
{{'common.' + item.name | translate}}
+
+
+
diff --git a/kdb-web/src/app/modules/shared/base/multi-select-columns/multi-select-columns.component.scss b/kdb-web/src/app/modules/shared/base/multi-select-columns/multi-select-columns.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/kdb-web/src/app/modules/shared/base/multi-select-columns/multi-select-columns.component.spec.ts b/kdb-web/src/app/modules/shared/base/multi-select-columns/multi-select-columns.component.spec.ts new file mode 100644 index 00000000..fd671a32 --- /dev/null +++ b/kdb-web/src/app/modules/shared/base/multi-select-columns/multi-select-columns.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { MultiSelectColumnsComponent } from './multi-select-columns.component'; + +describe('MultiSelectColumnsComponent', () => { + let component: MultiSelectColumnsComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ MultiSelectColumnsComponent ] + }) + .compileComponents(); + + fixture = TestBed.createComponent(MultiSelectColumnsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/kdb-web/src/app/modules/shared/base/multi-select-columns/multi-select-columns.component.ts b/kdb-web/src/app/modules/shared/base/multi-select-columns/multi-select-columns.component.ts new file mode 100644 index 00000000..db458e39 --- /dev/null +++ b/kdb-web/src/app/modules/shared/base/multi-select-columns/multi-select-columns.component.ts @@ -0,0 +1,24 @@ +import { Component, EventEmitter, Input, Output } from "@angular/core"; +import { Column } from "../../../../base/component-with-table"; + +@Component({ + selector: "app-multi-select-columns", + templateUrl: "./multi-select-columns.component.html", + styleUrls: ["./multi-select-columns.component.scss"] +}) +export class MultiSelectColumnsComponent { + @Input() columns: Column[] = []; + + private _hiddenColumns: Column[] = []; + @Input() + set hiddenColumns(columns: Column[]) { + this._hiddenColumns = columns; + this.hiddenColumnsChange.emit(columns); + } + + get hiddenColumns(): Column[] { + return this._hiddenColumns; + } + + @Output() hiddenColumnsChange: EventEmitter = new EventEmitter(); +} diff --git a/kdb-web/src/app/modules/shared/components/hideable-column/hideable-column.component.html b/kdb-web/src/app/modules/shared/components/hideable-column/hideable-column.component.html new file mode 100644 index 00000000..6dbc7430 --- /dev/null +++ b/kdb-web/src/app/modules/shared/components/hideable-column/hideable-column.component.html @@ -0,0 +1 @@ + diff --git a/kdb-web/src/app/modules/shared/components/hideable-column/hideable-column.component.scss b/kdb-web/src/app/modules/shared/components/hideable-column/hideable-column.component.scss new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/kdb-web/src/app/modules/shared/components/hideable-column/hideable-column.component.scss @@ -0,0 +1 @@ + diff --git a/kdb-web/src/app/modules/shared/components/hideable-column/hideable-column.component.spec.ts b/kdb-web/src/app/modules/shared/components/hideable-column/hideable-column.component.spec.ts new file mode 100644 index 00000000..dfa08452 --- /dev/null +++ b/kdb-web/src/app/modules/shared/components/hideable-column/hideable-column.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { HideableColumnComponent } from './hideable-column.component'; + +describe('HideableColumnComponent', () => { + let component: HideableColumnComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ HideableColumnComponent ] + }) + .compileComponents(); + + fixture = TestBed.createComponent(HideableColumnComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/kdb-web/src/app/modules/shared/components/hideable-column/hideable-column.component.ts b/kdb-web/src/app/modules/shared/components/hideable-column/hideable-column.component.ts new file mode 100644 index 00000000..4cba495c --- /dev/null +++ b/kdb-web/src/app/modules/shared/components/hideable-column/hideable-column.component.ts @@ -0,0 +1,16 @@ +import { Component, Input } from "@angular/core"; +import { HideableComponent } from "../../base/hideable-component"; + +@Component({ + selector: "[hideable-td]", + templateUrl: "./hideable-column.component.html", + styleUrls: ["./hideable-column.component.scss"] +}) +export class HideableColumnComponent extends HideableComponent { + @Input("hideable-td") override column!: string; + + constructor() { + super(); + } + +} diff --git a/kdb-web/src/app/modules/shared/components/hideable-header/hideable-header.component.html b/kdb-web/src/app/modules/shared/components/hideable-header/hideable-header.component.html new file mode 100644 index 00000000..f35a2a42 --- /dev/null +++ b/kdb-web/src/app/modules/shared/components/hideable-header/hideable-header.component.html @@ -0,0 +1,11 @@ + + + + +
+ +
+ + + + diff --git a/kdb-web/src/app/modules/shared/components/hideable-header/hideable-header.component.scss b/kdb-web/src/app/modules/shared/components/hideable-header/hideable-header.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/kdb-web/src/app/modules/shared/components/hideable-header/hideable-header.component.spec.ts b/kdb-web/src/app/modules/shared/components/hideable-header/hideable-header.component.spec.ts new file mode 100644 index 00000000..27570e8b --- /dev/null +++ b/kdb-web/src/app/modules/shared/components/hideable-header/hideable-header.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { HideableHeaderComponent } from './hideable-header.component'; + +describe('HideableHeaderComponent', () => { + let component: HideableHeaderComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ HideableHeaderComponent ] + }) + .compileComponents(); + + fixture = TestBed.createComponent(HideableHeaderComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/kdb-web/src/app/modules/shared/components/hideable-header/hideable-header.component.ts b/kdb-web/src/app/modules/shared/components/hideable-header/hideable-header.component.ts new file mode 100644 index 00000000..bd7f5597 --- /dev/null +++ b/kdb-web/src/app/modules/shared/components/hideable-header/hideable-header.component.ts @@ -0,0 +1,16 @@ +import { Component, Input } from "@angular/core"; +import { HideableComponent } from "../../base/hideable-component"; + +@Component({ + selector: "[hideable-th]", + templateUrl: "./hideable-header.component.html", + styleUrls: ["./hideable-header.component.scss"] +}) +export class HideableHeaderComponent extends HideableComponent { + @Input("hideable-th") override column!: string; + @Input() sortable: boolean = false; + constructor() { + super(); + } + +} diff --git a/kdb-web/src/app/modules/shared/shared.module.ts b/kdb-web/src/app/modules/shared/shared.module.ts index b92aa75b..ae7d2ebd 100644 --- a/kdb-web/src/app/modules/shared/shared.module.ts +++ b/kdb-web/src/app/modules/shared/shared.module.ts @@ -13,7 +13,7 @@ import { InputTextModule } from "primeng/inputtext"; import { MenuModule } from "primeng/menu"; import { PasswordModule } from "primeng/password"; import { ProgressSpinnerModule } from "primeng/progressspinner"; -import { TableModule } from "primeng/table"; +import { SortableColumn, TableModule } from "primeng/table"; import { ToastModule } from "primeng/toast"; import { AuthRolePipe } from "./pipes/auth-role.pipe"; import { IpAddressPipe } from "./pipes/ip-address.pipe"; @@ -23,9 +23,13 @@ import { PanelModule } from "primeng/panel"; import { InputNumberModule } from "primeng/inputnumber"; import { ImageModule } from "primeng/image"; import { SidebarModule } from "primeng/sidebar"; -import { HistoryBtnComponent } from './components/history-btn/history-btn.component'; -import { DataViewModule, DataViewLayoutOptions } from 'primeng/dataview'; -import { ConfigListComponent } from './components/config-list/config-list.component'; +import { HistoryBtnComponent } from "./components/history-btn/history-btn.component"; +import { DataViewModule, DataViewLayoutOptions } from "primeng/dataview"; +import { ConfigListComponent } from "./components/config-list/config-list.component"; +import { MultiSelectModule } from "primeng/multiselect"; +import { HideableColumnComponent } from './components/hideable-column/hideable-column.component'; +import { HideableHeaderComponent } from './components/hideable-header/hideable-header.component'; +import { MultiSelectColumnsComponent } from './base/multi-select-columns/multi-select-columns.component'; @NgModule({ @@ -35,6 +39,9 @@ import { ConfigListComponent } from './components/config-list/config-list.compon BoolPipe, HistoryBtnComponent, ConfigListComponent, + HideableColumnComponent, + HideableHeaderComponent, + MultiSelectColumnsComponent, ], imports: [ CommonModule, @@ -60,36 +67,42 @@ import { ConfigListComponent } from './components/config-list/config-list.compon ImageModule, SidebarModule, DataViewModule, + MultiSelectModule, ], - exports: [ - ButtonModule, - PasswordModule, - MenuModule, - DialogModule, - ProgressSpinnerModule, - HttpClientModule, - FormsModule, - ReactiveFormsModule, - ToastModule, - ConfirmDialogModule, - TableModule, - InputTextModule, - CheckboxModule, - DropdownModule, - TranslateModule, - DynamicDialogModule, - PanelMenuModule, - PanelModule, - AuthRolePipe, - IpAddressPipe, - BoolPipe, - InputNumberModule, - ImageModule, - SidebarModule, - HistoryBtnComponent, - DataViewModule, - DataViewLayoutOptions, - ConfigListComponent - ] + exports: [ + ButtonModule, + PasswordModule, + MenuModule, + DialogModule, + ProgressSpinnerModule, + HttpClientModule, + FormsModule, + ReactiveFormsModule, + ToastModule, + ConfirmDialogModule, + TableModule, + InputTextModule, + CheckboxModule, + DropdownModule, + TranslateModule, + DynamicDialogModule, + PanelMenuModule, + PanelModule, + AuthRolePipe, + IpAddressPipe, + BoolPipe, + InputNumberModule, + ImageModule, + SidebarModule, + HistoryBtnComponent, + DataViewModule, + DataViewLayoutOptions, + ConfigListComponent, + MultiSelectModule, + HideableColumnComponent, + HideableHeaderComponent, + MultiSelectColumnsComponent, + ] }) -export class SharedModule { } +export class SharedModule { +} diff --git a/kdb-web/src/app/modules/view/server/achievements/components/achievement/achievement.component.html b/kdb-web/src/app/modules/view/server/achievements/components/achievement/achievement.component.html index 44f88ad5..23ea6dd2 100644 --- a/kdb-web/src/app/modules/view/server/achievements/components/achievement/achievement.component.html +++ b/kdb-web/src/app/modules/view/server/achievements/components/achievement/achievement.component.html @@ -9,11 +9,15 @@
-
- {{achievements.length}} {{'common.of' | translate}} - {{dt.totalRecords}} - - {{'view.server.achievements.achievements' | translate}} +
+
+ {{achievements.length}} {{'common.of' | translate}} + {{dt.totalRecords}} + + {{'view.server.achievements.achievements' | translate}} +
+ +
@@ -29,44 +33,44 @@ - +
{{'common.id' | translate}}
- +
-
{{'view.server.achievements.headers.name' | translate}}
+
{{'common.name' | translate}}
- +
-
{{'view.server.achievements.headers.description' | translate}}
+
{{'common.description' | translate}}
- +
-
{{'view.server.achievements.headers.attribute' | translate}}
+
{{'common.attribute' | translate}}
- +
-
{{'view.server.achievements.headers.operator' | translate}}
+
{{'common.operator' | translate}}
- +
-
{{'view.server.achievements.headers.value' | translate}}
+
{{'common.value' | translate}}
@@ -91,27 +95,27 @@ - +
- +
+ placeholder="{{'common.name' | translate}}">
- +
- +
- - - + + + @@ -120,7 +124,7 @@ - + {{achievement.id}} @@ -131,7 +135,7 @@ - + @@ -142,7 +146,7 @@ - + @@ -153,11 +157,11 @@ - + + placeholder="{{'common.attribute' | translate}}"> {{achievement.attribute}} @@ -165,10 +169,10 @@ - + - + {{achievement.operator}} @@ -176,7 +180,7 @@ - + diff --git a/kdb-web/src/app/modules/view/server/achievements/components/achievement/achievement.component.ts b/kdb-web/src/app/modules/view/server/achievements/components/achievement/achievement.component.ts index 6a65d21c..a96d24ac 100644 --- a/kdb-web/src/app/modules/view/server/achievements/components/achievement/achievement.component.ts +++ b/kdb-web/src/app/modules/view/server/achievements/components/achievement/achievement.component.ts @@ -22,13 +22,14 @@ import { Table } from "primeng/table"; import { User } from "../../../../../../models/data/user.model"; import { AchievementMutationResult } from "../../../../../../models/graphql/result.model"; import { Mutations } from "../../../../../../models/graphql/mutations.model"; +import { ComponentWithTable } from "../../../../../../base/component-with-table"; @Component({ selector: "app-achievement", templateUrl: "./achievement.component.html", styleUrls: ["./achievement.component.scss"] }) -export class AchievementComponent implements OnInit, OnDestroy { +export class AchievementComponent extends ComponentWithTable implements OnInit, OnDestroy { public achievements: Achievement[] = []; public loading = true; @@ -37,6 +38,7 @@ export class AchievementComponent implements OnInit, OnDestroy { public filterForm!: FormGroup<{ id: FormControl, name: FormControl, + description: FormControl, color: FormControl, min_xp: FormControl, permissions: FormControl, @@ -79,6 +81,7 @@ export class AchievementComponent implements OnInit, OnDestroy { private data: DataService, private sidebar: SidebarService, private route: ActivatedRoute) { + super("achievement", ["id", "name", "description", "attribute", "operator", "value"]); } public ngOnInit(): void { @@ -157,6 +160,7 @@ export class AchievementComponent implements OnInit, OnDestroy { this.filterForm = this.fb.group({ id: new FormControl(null), name: new FormControl(null), + description: new FormControl(null), color: new FormControl(null), min_xp: new FormControl(null), permissions: new FormControl(null) 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 c44d7208..3b2c6864 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 @@ -9,11 +9,14 @@
-
- {{rules.length}} {{'common.of' | translate}} - {{dt.totalRecords}} - - {{'view.server.auto_roles.rules.auto_roles' | translate}} +
+
+ {{rules.length}} {{'common.of' | translate}} + {{dt.totalRecords}} + + {{'view.server.auto_roles.rules.auto_roles' | translate}} +
+
@@ -29,23 +32,23 @@ - +
{{'common.id' | translate}}
- +
-
{{'view.server.auto_roles.rules.headers.role' | translate}}
+
{{'common.role' | translate}}
- +
-
{{'view.server.auto_roles.rules.headers.emoji' | translate}}
+
{{'common.emoji' | translate}}
@@ -69,17 +72,17 @@ - +
- +
- +
- + @@ -88,7 +91,7 @@ - + {{autoRoleRule.id}} @@ -99,11 +102,11 @@ - + + placeholder="{{'common.role' | translate}}"> {{autoRoleRule.roleName}} @@ -111,11 +114,11 @@ - + + placeholder="{{'common.emoji' | translate}}">