From 2a974384172e127f835afc1daa2ac013c0297c02 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 17 Oct 2022 19:44:28 +0200 Subject: [PATCH] [WIP] Added server dashboard #72 --- .../controller/discord/server_controller.py | 6 +++ .../src/bot_api/service/discord_service.py | 7 +++ kdb-web/src/app/app-routing.module.ts | 1 + .../dashboard/dashboard.component.html | 2 +- .../dashboard/dashboard.component.ts | 17 ++++--- .../dashboard/dashboard-routing.module.ts | 2 +- .../view/dashboard/dashboard.module.ts | 6 +-- .../server-dashboard.component.html | 36 +++++++++++++++ .../server-dashboard.component.scss | 0 .../server-dashboard.component.spec.ts | 23 ++++++++++ .../server-dashboard.component.ts | 45 +++++++++++++++++++ .../view/server/server-routing.module.ts | 14 ++++++ .../app/modules/view/server/server.module.ts | 19 ++++++++ kdb-web/src/app/services/data/data.service.ts | 8 ++++ kdb-web/src/assets/i18n/de.json | 9 ++-- 15 files changed, 181 insertions(+), 14 deletions(-) create mode 100644 kdb-web/src/app/modules/view/server/server-dashboard/server-dashboard.component.html create mode 100644 kdb-web/src/app/modules/view/server/server-dashboard/server-dashboard.component.scss create mode 100644 kdb-web/src/app/modules/view/server/server-dashboard/server-dashboard.component.spec.ts create mode 100644 kdb-web/src/app/modules/view/server/server-dashboard/server-dashboard.component.ts create mode 100644 kdb-web/src/app/modules/view/server/server-routing.module.ts create mode 100644 kdb-web/src/app/modules/view/server/server.module.ts diff --git a/kdb-bot/src/bot_api/controller/discord/server_controller.py b/kdb-bot/src/bot_api/controller/discord/server_controller.py index d2c89b1049..1c362ab957 100644 --- a/kdb-bot/src/bot_api/controller/discord/server_controller.py +++ b/kdb-bot/src/bot_api/controller/discord/server_controller.py @@ -57,3 +57,9 @@ class ServerController: result = await self._discord_service.get_filtered_servers_async(dto) result.result = result.result.select(lambda x: x.to_dict()) return jsonify(result.to_dict()) + + @Route.get(f'{BasePath}/get/') + @Route.authorize + async def get_server_by_id(self, id: int) -> Response: + result = await self._discord_service.get_server_by_id_async(id) + return jsonify(result.to_dict()) diff --git a/kdb-bot/src/bot_api/service/discord_service.py b/kdb-bot/src/bot_api/service/discord_service.py index a0163dcc9e..7266e1bd4a 100644 --- a/kdb-bot/src/bot_api/service/discord_service.py +++ b/kdb-bot/src/bot_api/service/discord_service.py @@ -89,3 +89,10 @@ class DiscordService: List(ServerDTO, result), filtered_result.total_count ) + + async def get_server_by_id_async(self, id: int) -> ServerDTO: + server = self._servers.get_server_by_id(id) + guild = self._bot.get_guild(server.discord_server_id) + + server_dto = ServerTransformer.to_dto(server, guild.name, guild.member_count, guild.icon) + return server_dto diff --git a/kdb-web/src/app/app-routing.module.ts b/kdb-web/src/app/app-routing.module.ts index 803deb705b..1a1c9c3b46 100644 --- a/kdb-web/src/app/app-routing.module.ts +++ b/kdb-web/src/app/app-routing.module.ts @@ -7,6 +7,7 @@ import { AuthGuard } from './modules/shared/guards/auth/auth.guard'; const routes: Routes = [ { path: '', redirectTo: 'dashboard', pathMatch: 'full' }, { path: 'dashboard', loadChildren: () => import('./modules/view/dashboard/dashboard.module').then(m => m.DashboardModule), canActivate: [AuthGuard] }, + { path: 'server', loadChildren: () => import('./modules/view/server/server.module').then(m => m.ServerModule), canActivate: [AuthGuard] }, { path: 'change-password', loadChildren: () => import('./modules/view/change-password/change-password.module').then(m => m.ChangePasswordModule), canActivate: [AuthGuard] }, { path: 'user-settings', loadChildren: () => import('./modules/view/user-settings/user-settings.module').then(m => m.UserSettingsModule), canActivate: [AuthGuard] }, { path: 'auth', loadChildren: () => import('./modules/auth/auth.module').then(m => m.AuthModule) }, diff --git a/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.html b/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.html index c7dd5fdfbe..ded533101a 100644 --- a/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.html +++ b/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.html @@ -26,7 +26,7 @@
-
+
diff --git a/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.ts b/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.ts index 0fb3ff19a4..d149298e49 100644 --- a/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.ts +++ b/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.ts @@ -1,5 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { FormGroup, FormControl, FormBuilder } from '@angular/forms'; +import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; +import { Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; import { LazyLoadEvent } from 'primeng/api'; import { catchError, debounceTime, throwError } from 'rxjs'; @@ -17,7 +18,6 @@ import { ToastService } from 'src/app/services/toast/toast.service'; }) export class DashboardComponent implements OnInit { - loading = true; servers: ServerDTO[] = []; searchCriterions: ServerSelectCriterion = { @@ -40,10 +40,12 @@ export class DashboardComponent implements OnInit { private toastService: ToastService, private confirmDialog: ConfirmationDialogService, private fb: FormBuilder, - private translate: TranslateService + private translate: TranslateService, + private router: Router ) { } ngOnInit(): void { + this.spinnerService.showSpinner(); this.setFilterForm(); this.loadNextPage(); } @@ -73,13 +75,14 @@ export class DashboardComponent implements OnInit { } loadNextPage() { + this.spinnerService.showSpinner(); this.data.getFilteredServers(this.searchCriterions).pipe(catchError(err => { - this.loading = false; + this.spinnerService.hideSpinner(); return throwError(() => err); })).subscribe(list => { this.totalRecords = list.totalCount; this.servers = list.servers; - this.loading = false; + this.spinnerService.hideSpinner(); }); } @@ -102,4 +105,8 @@ export class DashboardComponent implements OnInit { this.filterForm.reset(); } + selectServer(server: ServerDTO) { + this.router.navigate(['/server', server.serverId]); + } + } diff --git a/kdb-web/src/app/modules/view/dashboard/dashboard-routing.module.ts b/kdb-web/src/app/modules/view/dashboard/dashboard-routing.module.ts index 27f772462c..37add74128 100644 --- a/kdb-web/src/app/modules/view/dashboard/dashboard-routing.module.ts +++ b/kdb-web/src/app/modules/view/dashboard/dashboard-routing.module.ts @@ -3,7 +3,7 @@ import { RouterModule, Routes } from '@angular/router'; import { DashboardComponent } from './components/dashboard/dashboard.component'; const routes: Routes = [ - {path: '', component: DashboardComponent} + { path: '', component: DashboardComponent } ]; @NgModule({ diff --git a/kdb-web/src/app/modules/view/dashboard/dashboard.module.ts b/kdb-web/src/app/modules/view/dashboard/dashboard.module.ts index 0b3abe11d6..80438b6ee9 100644 --- a/kdb-web/src/app/modules/view/dashboard/dashboard.module.ts +++ b/kdb-web/src/app/modules/view/dashboard/dashboard.module.ts @@ -1,9 +1,9 @@ -import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; +import { NgModule } from '@angular/core'; -import { DashboardRoutingModule } from './dashboard-routing.module'; -import { DashboardComponent } from './components/dashboard/dashboard.component'; import { SharedModule } from '../../shared/shared.module'; +import { DashboardComponent } from './components/dashboard/dashboard.component'; +import { DashboardRoutingModule } from './dashboard-routing.module'; @NgModule({ diff --git a/kdb-web/src/app/modules/view/server/server-dashboard/server-dashboard.component.html b/kdb-web/src/app/modules/view/server/server-dashboard/server-dashboard.component.html new file mode 100644 index 0000000000..1fbf61d3c5 --- /dev/null +++ b/kdb-web/src/app/modules/view/server/server-dashboard/server-dashboard.component.html @@ -0,0 +1,36 @@ +

+ {{'view.dashboard.header' | translate}} +

+
+
+

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

+
+ +
+
+
+
+ + +
+

+ {{server.name}} +

+ +
+ + {{server.memberCount}} + {{'view.dashboard.server.member_count' | translate}} +
+
+ +
+
+
+
+
\ No newline at end of file diff --git a/kdb-web/src/app/modules/view/server/server-dashboard/server-dashboard.component.scss b/kdb-web/src/app/modules/view/server/server-dashboard/server-dashboard.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/kdb-web/src/app/modules/view/server/server-dashboard/server-dashboard.component.spec.ts b/kdb-web/src/app/modules/view/server/server-dashboard/server-dashboard.component.spec.ts new file mode 100644 index 0000000000..9f49b43a16 --- /dev/null +++ b/kdb-web/src/app/modules/view/server/server-dashboard/server-dashboard.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ServerDashboardComponent } from './server-dashboard.component'; + +describe('ServerDashboardComponent', () => { + let component: ServerDashboardComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ ServerDashboardComponent ] + }) + .compileComponents(); + + fixture = TestBed.createComponent(ServerDashboardComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/kdb-web/src/app/modules/view/server/server-dashboard/server-dashboard.component.ts b/kdb-web/src/app/modules/view/server/server-dashboard/server-dashboard.component.ts new file mode 100644 index 0000000000..540ac8b639 --- /dev/null +++ b/kdb-web/src/app/modules/view/server/server-dashboard/server-dashboard.component.ts @@ -0,0 +1,45 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { catchError, throwError } from 'rxjs'; +import { ServerDTO } from 'src/app/models/discord/server.dto'; +import { DataService } from 'src/app/services/data/data.service'; +import { SpinnerService } from 'src/app/services/spinner/spinner.service'; + +@Component({ + selector: 'app-server-dashboard', + templateUrl: './server-dashboard.component.html', + styleUrls: ['./server-dashboard.component.scss'] +}) +export class ServerDashboardComponent implements OnInit { + + id!: number; + server!: ServerDTO; + + constructor( + private route: ActivatedRoute, + private router: Router, + private data: DataService, + private spinner: SpinnerService + ) { } + + ngOnInit(): void { + this.route.params.subscribe(params => { + this.id = +params['id']; + + if (!this.id) { + this.router.navigate(['/dashboard']); + return; + } + + this.spinner.showSpinner(); + this.data.getServerByID(this.id).pipe(catchError(err => { + this.spinner.hideSpinner(); + return throwError(() => err); + })).subscribe(server => { + this.server = server; + this.spinner.hideSpinner(); + }); + }); + } + +} 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 new file mode 100644 index 0000000000..063beab12c --- /dev/null +++ b/kdb-web/src/app/modules/view/server/server-routing.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import { RouterModule, Routes } from '@angular/router'; +import { ServerDashboardComponent } from './server-dashboard/server-dashboard.component'; + +const routes: Routes = [ + { path: '', component: ServerDashboardComponent }, + { path: ':id', component: ServerDashboardComponent } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) +export class ServerRoutingModule { } diff --git a/kdb-web/src/app/modules/view/server/server.module.ts b/kdb-web/src/app/modules/view/server/server.module.ts new file mode 100644 index 0000000000..824e2412df --- /dev/null +++ b/kdb-web/src/app/modules/view/server/server.module.ts @@ -0,0 +1,19 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { ServerDashboardComponent } from './server-dashboard/server-dashboard.component'; +import { ServerRoutingModule } from './server-routing.module'; +import { SharedModule } from '../../shared/shared.module'; + + + +@NgModule({ + declarations: [ + ServerDashboardComponent + ], + imports: [ + CommonModule, + ServerRoutingModule, + SharedModule + ] +}) +export class ServerModule { } diff --git a/kdb-web/src/app/services/data/data.service.ts b/kdb-web/src/app/services/data/data.service.ts index 80a6060082..6b1a0f76a7 100644 --- a/kdb-web/src/app/services/data/data.service.ts +++ b/kdb-web/src/app/services/data/data.service.ts @@ -42,4 +42,12 @@ export class DataService { }) }); } + + getServerByID(id: number): Observable { + return this.http.get(`${this.appsettings.getApiURL()}/api/discord/server/get/${id}`, { + headers: new HttpHeaders({ + 'Content-Type': 'application/json' + }) + }); + } } diff --git a/kdb-web/src/assets/i18n/de.json b/kdb-web/src/assets/i18n/de.json index 83fd1ae359..96fa7213ee 100644 --- a/kdb-web/src/assets/i18n/de.json +++ b/kdb-web/src/assets/i18n/de.json @@ -7,10 +7,8 @@ }, "sidebar": { "dashboard": "Dashboard", - "domain_list": "Domänen", - "host_list": "Rechner", - "user_list": "Benutzer", - "login_list": "Logins", + "server": "Server", + "server_empty": "Kein Server ausgewählt", "config": "Konfiguration", "auth_user_list": "Benutzer" }, @@ -118,6 +116,9 @@ "name": "Name" } }, + "server": { + "header": "Server" + }, "user-list": {}, "change-password": { "header": "Passwort ändern",