[WIP] Switched to gql #162-2

This commit is contained in:
2023-02-09 15:19:31 +01:00
parent 79837afdfb
commit 667b9fa87e
18 changed files with 21903 additions and 21567 deletions

View File

@@ -38,7 +38,7 @@
<div class="data">
<i class="pi pi-users"></i>
{{server.memberCount}}
{{server.userCount}}
{{'view.dashboard.server.member_count' | translate}}
</div>
</div>
@@ -47,4 +47,4 @@
</div>
</div>
</div>
</div>
</div>

View File

@@ -1,16 +1,16 @@
import { Component, OnInit } from '@angular/core';
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';
import { ServerDTO } from 'src/app/models/discord/server.dto';
import { ServerSelectCriterion } from 'src/app/models/selection/server/server-select-criterion.dto';
import { ConfirmationDialogService } from 'src/app/services/confirmation-dialog/confirmation-dialog.service';
import { DataService } from 'src/app/services/data/data.service';
import { ServerService } from 'src/app/services/data/server.service';
import { SpinnerService } from 'src/app/services/spinner/spinner.service';
import { ToastService } from 'src/app/services/toast/toast.service';
import { Component, OnInit } from "@angular/core";
import { FormBuilder, FormControl, FormGroup } from "@angular/forms";
import { Router } from "@angular/router";
import { TranslateService } from "@ngx-translate/core";
import { Apollo } from "apollo-angular";
import { LazyLoadEvent } from "primeng/api";
import { debounceTime } from "rxjs";
import { ConfirmationDialogService } from "src/app/services/confirmation-dialog/confirmation-dialog.service";
import { DataService } from "src/app/services/data/data.service";
import { ServerService } from "src/app/services/data/server.service";
import { SpinnerService } from "src/app/services/spinner/spinner.service";
import { ToastService } from "src/app/services/toast/toast.service";
import { Server } from "../../../../../models/data/server.model";
@Component({
selector: 'app-dashboard',
@@ -19,15 +19,8 @@ import { ToastService } from 'src/app/services/toast/toast.service';
})
export class DashboardComponent implements OnInit {
servers: ServerDTO[] = [];
servers: Server[] = [];
searchCriterions: ServerSelectCriterion = {
name: null,
pageIndex: 0,
pageSize: 10,
sortColumn: null,
sortDirection: null
};
totalRecords!: number;
@@ -43,13 +36,15 @@ export class DashboardComponent implements OnInit {
private fb: FormBuilder,
private translate: TranslateService,
private router: Router,
private serverService: ServerService
private serverService: ServerService,
private apollo: Apollo
) { }
ngOnInit(): void {
async ngOnInit(): Promise<void> {
this.spinnerService.showSpinner();
this.setFilterForm();
this.loadNextPage();
await this.loadNextPage();
}
setFilterForm() {
@@ -59,46 +54,46 @@ export class DashboardComponent implements OnInit {
this.filterForm.valueChanges.pipe(
debounceTime(600)
).subscribe(changes => {
if (changes.name) {
this.searchCriterions.name = changes.name;
} else {
this.searchCriterions.name = null;
}
).subscribe(async changes => {
// if (changes.name) {
// this.searchCriterions.name = changes.name;
// } else {
// this.searchCriterions.name = null;
// }
//
// if (this.searchCriterions.pageSize)
// this.searchCriterions.pageSize = 10;
//
// if (this.searchCriterions.pageSize)
// this.searchCriterions.pageIndex = 0;
if (this.searchCriterions.pageSize)
this.searchCriterions.pageSize = 10;
if (this.searchCriterions.pageSize)
this.searchCriterions.pageIndex = 0;
this.loadNextPage();
await this.loadNextPage();
});
}
loadNextPage() {
async loadNextPage() {
this.spinnerService.showSpinner();
this.data.getFilteredServers(this.searchCriterions).pipe(catchError(err => {
this.spinnerService.hideSpinner();
return throwError(() => err);
})).subscribe(list => {
this.totalRecords = list.totalCount;
this.servers = list.servers;
this.spinnerService.hideSpinner();
});
// this.data.getFilteredServers(this.searchCriterions).pipe(catchError(err => {
// this.spinnerService.hideSpinner();
// return throwError(() => err);
// })).subscribe(list => {
// this.totalRecords = list.totalCount;
// this.servers = list.servers;
// this.spinnerService.hideSpinner();
// });
}
nextPage(event: LazyLoadEvent) {
this.searchCriterions.pageSize = event.rows ?? 0;
if (event.first != null && event.rows != null)
this.searchCriterions.pageIndex = event.first / event.rows;
this.searchCriterions.sortColumn = event.sortField ?? null;
this.searchCriterions.sortDirection = event.sortOrder === 1 ? 'asc' : event.sortOrder === -1 ? 'desc' : 'asc';
if (event.filters) {
// + "" => convert to string
this.searchCriterions.name = event.filters['name'] ? event.filters['name'] + "" : null;
}
// this.searchCriterions.pageSize = event.rows ?? 0;
// if (event.first != null && event.rows != null)
// this.searchCriterions.pageIndex = event.first / event.rows;
// this.searchCriterions.sortColumn = event.sortField ?? null;
// this.searchCriterions.sortDirection = event.sortOrder === 1 ? 'asc' : event.sortOrder === -1 ? 'desc' : 'asc';
//
// if (event.filters) {
// // + "" => convert to string
// this.searchCriterions.name = event.filters['name'] ? event.filters['name'] + "" : null;
// }
this.loadNextPage();
}
@@ -107,7 +102,7 @@ export class DashboardComponent implements OnInit {
this.filterForm.reset();
}
selectServer(server: ServerDTO) {
selectServer(server: Server) {
this.serverService.server$.next(server);
this.router.navigate(['/server']);
}

View File

@@ -24,7 +24,7 @@
<div class="data">
<i class="pi pi-users"></i>
{{server.memberCount}}
{{server.userCount}}
{{'view.dashboard.server.member_count' | translate}}
</div>
</div>
@@ -33,4 +33,4 @@
</div>
</div>
</div>
</div>
</div>

View File

@@ -1,9 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ServerDTO } from 'src/app/models/discord/server.dto';
import { DataService } from 'src/app/services/data/data.service';
import { ServerService } from 'src/app/services/data/server.service';
import { SpinnerService } from 'src/app/services/spinner/spinner.service';
import { Component, OnInit } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import { Server } from "src/app/models/data/server.model";
import { DataService } from "src/app/services/data/data.service";
import { ServerService } from "src/app/services/data/server.service";
import { SpinnerService } from "src/app/services/spinner/spinner.service";
@Component({
selector: 'app-server-dashboard',
@@ -13,7 +13,7 @@ import { SpinnerService } from 'src/app/services/spinner/spinner.service';
export class ServerDashboardComponent implements OnInit {
id!: number;
server!: ServerDTO;
server!: Server;
constructor(
private route: ActivatedRoute,