Various improvements to game management interface

This commit is contained in:
grimsi
2022-08-05 18:34:24 +02:00
parent 22c8e99f38
commit 98197fc4a6
23 changed files with 446 additions and 170 deletions
+8 -4
View File
@@ -4,6 +4,7 @@ import {ErrorDialogComponent} from '../components/error-dialog/error-dialog.comp
import {DetectedGameDto} from "../models/dtos/DetectedGameDto";
import {MapGameDialogComponent} from "../components/map-game-dialog/map-game-dialog.component";
import {UnmappedFileDto} from "../models/dtos/UnmappedFileDto";
import {Observable} from "rxjs";
@Injectable({
providedIn: 'root'
@@ -19,6 +20,7 @@ export class DialogService {
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
dialogConfig.closeOnNavigation = true;
dialogConfig.minWidth = '25vw';
dialogConfig.data = {
message
@@ -27,33 +29,35 @@ export class DialogService {
this.dialog.open(ErrorDialogComponent, dialogConfig);
}
public correctGameMappingDialog(game: DetectedGameDto): void {
public correctGameMappingDialog(game: DetectedGameDto): Observable<any> {
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
dialogConfig.closeOnNavigation = true;
dialogConfig.minWidth = '25vw';
dialogConfig.data = {
path: game.path,
slug: game.slug
};
this.dialog.open(MapGameDialogComponent, dialogConfig);
return this.dialog.open(MapGameDialogComponent, dialogConfig).afterClosed();
}
public mapUnmappedGameDialog(unmappedFile: UnmappedFileDto): void {
public mapUnmappedGameDialog(unmappedFile: UnmappedFileDto): Observable<any> {
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
dialogConfig.closeOnNavigation = true;
dialogConfig.minWidth = '25vw';
dialogConfig.data = {
path: unmappedFile.path
};
this.dialog.open(MapGameDialogComponent, dialogConfig);
return this.dialog.open(MapGameDialogComponent, dialogConfig).afterClosed();
}
}
@@ -54,6 +54,10 @@ export class GamesService implements GamesApi {
return this.http.get<Map<string, string>>(`${this.apiPath}/game-mappings`);
}
removeGameFromCache(slug: string): void {
this.cache.delete(slug);
}
private cacheGames(gameList: DetectedGameDto[]): void {
this.cache.clear();
gameList.forEach(game => this.cache.set(game.slug, game));
@@ -1,10 +1,11 @@
import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {HttpClient, HttpParams} from "@angular/common/http";
import {Observable} from "rxjs";
import {DetectedGameDto} from "../models/dtos/DetectedGameDto";
import {PathToSlugDto} from "../models/dtos/PathToSlugDto";
import {UnmappedFileDto} from "../models/dtos/UnmappedFileDto";
import {LibraryManagementApi} from "../api/LibraryManagementApi";
import {GamesService} from "./games.service";
@Injectable({
providedIn: 'root'
@@ -13,7 +14,8 @@ export class LibraryManagementService implements LibraryManagementApi {
private readonly apiPath = '/library-management';
constructor(private http: HttpClient) {
constructor(private http: HttpClient,
private gamesService: GamesService) {
}
mapGame(pathToSlugDto: PathToSlugDto): Observable<DetectedGameDto> {
@@ -24,11 +26,15 @@ export class LibraryManagementService implements LibraryManagementApi {
return this.http.get<UnmappedFileDto[]>(`${this.apiPath}/unmapped-files`);
}
confirmGameMapping(slug: string): Observable<DetectedGameDto> {
return this.http.get<DetectedGameDto>(`${this.apiPath}/confirm-game/${slug}`);
confirmGameMapping(slug: string, confirm: boolean): Observable<DetectedGameDto> {
let queryParams = new HttpParams();
queryParams = queryParams.append("confirm", confirm);
return this.http.get<DetectedGameDto>(`${this.apiPath}/confirm-game/${slug}`, {params:queryParams});
}
deleteGame(slug: string): Observable<Response> {
this.gamesService.removeGameFromCache(slug);
return this.http.delete<Response>(`${this.apiPath}/delete-game/${slug}`);
}