SES-160 shop on gm and player screen #85
@ -53,6 +53,7 @@ import { GameMasterShopkeepersTableComponent } from './components/game-master-sh
|
|||||||
import { GameMasterTurntrackerComponent } from './components/game-master-turntracker/game-master-turntracker.component';
|
import { GameMasterTurntrackerComponent } from './components/game-master-turntracker/game-master-turntracker.component';
|
||||||
import { DragDropModule } from '@angular/cdk/drag-drop';
|
import { DragDropModule } from '@angular/cdk/drag-drop';
|
||||||
import { ChooseMonsterDialogComponent } from './components/choose-monster-dialog/choose-monster-dialog.component';
|
import { ChooseMonsterDialogComponent } from './components/choose-monster-dialog/choose-monster-dialog.component';
|
||||||
|
import { ShopkeeperService } from '../services/shopkeeper.service';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
@ -113,6 +114,7 @@ import { ChooseMonsterDialogComponent } from './components/choose-monster-dialog
|
|||||||
ArmorService,
|
ArmorService,
|
||||||
OtherEquipmentService,
|
OtherEquipmentService,
|
||||||
MonsterService,
|
MonsterService,
|
||||||
|
ShopkeeperService,
|
||||||
],
|
],
|
||||||
bootstrap: [AppComponent],
|
bootstrap: [AppComponent],
|
||||||
entryComponents: [
|
entryComponents: [
|
||||||
|
@ -97,6 +97,7 @@ export class GameMasterDashboardComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.signalRService.Login();
|
this.signalRService.Login();
|
||||||
|
this.UpdateCharactersList();
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateSidenavStatus(sidenav: string, newValue: boolean) {
|
UpdateSidenavStatus(sidenav: string, newValue: boolean) {
|
||||||
|
@ -11,20 +11,16 @@
|
|||||||
<td mat-cell *matCellDef="let row"> {{row.name}} </td>
|
<td mat-cell *matCellDef="let row"> {{row.name}} </td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<ng-container matColumnDef="itemsCount">
|
|
||||||
<th mat-header-cell *matHeaderCellDef mat-sort-header> Items Count </th>
|
|
||||||
<td mat-cell *matCellDef="let row"> {{row.itemsCount}} </td>
|
|
||||||
</ng-container>
|
|
||||||
|
|
||||||
<ng-container matColumnDef="actions">
|
<ng-container matColumnDef="actions">
|
||||||
<th mat-header-cell *matHeaderCellDef> Actions </th>
|
<th mat-header-cell *matHeaderCellDef> Actions </th>
|
||||||
<td mat-cell *matCellDef="let row">
|
<td mat-cell *matCellDef="let row">
|
||||||
<button mat-flat-button
|
<button mat-flat-button
|
||||||
*ngIf="row.isAvailable"
|
*ngIf="row.isAvailable"
|
||||||
color="red">
|
color="red"
|
||||||
|
(click)="DeactivateShopkeeper(row.id)">
|
||||||
Deactivate
|
Deactivate
|
||||||
</button>
|
</button>
|
||||||
<button mat-flat-button *ngIf="!row.isAvailable" color="green">
|
<button mat-flat-button *ngIf="!row.isAvailable" color="green" (click)="ActivateShopkeeper(row.id)">
|
||||||
Activate
|
Activate
|
||||||
</button>
|
</button>
|
||||||
<button mat-flat-button color="warn" >
|
<button mat-flat-button color="warn" >
|
||||||
|
@ -3,6 +3,11 @@ import { MatPaginator } from '@angular/material/paginator';
|
|||||||
import { MatSort } from '@angular/material/sort';
|
import { MatSort } from '@angular/material/sort';
|
||||||
import { MatTableDataSource } from '@angular/material/table';
|
import { MatTableDataSource } from '@angular/material/table';
|
||||||
import { MonsterViewModel } from '../../../types/viewmodels/monster-viewmodels/MonsterViewModel';
|
import { MonsterViewModel } from '../../../types/viewmodels/monster-viewmodels/MonsterViewModel';
|
||||||
|
import { ShopkeeperViewModel } from '../../../types/viewmodels/shopkeeper-viewmodels/ShopkeeperViewModel';
|
||||||
|
import { ShopkeeperService } from '../../../services/shopkeeper.service';
|
||||||
|
import { first } from 'rxjs/operators';
|
||||||
|
import { ErrorResponse } from '../../../types/ErrorResponse';
|
||||||
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-game-master-shopkeepers-table',
|
selector: 'app-game-master-shopkeepers-table',
|
||||||
@ -10,35 +15,44 @@ import { MonsterViewModel } from '../../../types/viewmodels/monster-viewmodels/M
|
|||||||
styleUrls: ['./game-master-shopkeepers-table.component.css'],
|
styleUrls: ['./game-master-shopkeepers-table.component.css'],
|
||||||
})
|
})
|
||||||
export class GameMasterShopkeepersTableComponent implements OnInit {
|
export class GameMasterShopkeepersTableComponent implements OnInit {
|
||||||
displayedColumns: string[] = ['name', 'itemsCount', 'actions'];
|
displayedColumns: string[] = ['name', 'actions'];
|
||||||
dataSource: MatTableDataSource<{
|
dataSource: MatTableDataSource<ShopkeeperViewModel>;
|
||||||
name: string;
|
|
||||||
itemsCount: number;
|
|
||||||
isAvailable: boolean;
|
|
||||||
}>; //TODO zmienić na skopkeeper view model
|
|
||||||
|
|
||||||
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
||||||
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
||||||
|
|
||||||
constructor() {}
|
constructor(private shopkeeperService: ShopkeeperService) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.dataSource = new MatTableDataSource<{
|
this.shopkeeperService
|
||||||
name: string;
|
.GetAllShopkeepers()
|
||||||
itemsCount: number;
|
.pipe(first())
|
||||||
isAvailable: boolean;
|
.subscribe(
|
||||||
}>([
|
(result) => {
|
||||||
{
|
this.dataSource = new MatTableDataSource(result);
|
||||||
name: 'Test',
|
this.dataSource.sort = this.sort;
|
||||||
itemsCount: 12,
|
this.dataSource.paginator = this.paginator;
|
||||||
isAvailable: true,
|
},
|
||||||
},
|
(error: ErrorResponse | HttpErrorResponse) => {
|
||||||
{
|
console.error(error);
|
||||||
name: 'Test2',
|
if (error instanceof HttpErrorResponse) {
|
||||||
itemsCount: 12,
|
error = error.error as ErrorResponse;
|
||||||
isAvailable: false,
|
}
|
||||||
},
|
console.error(error.message);
|
||||||
]);
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ActivateShopkeeper(shopkeeperId: number) {
|
||||||
|
if (this.dataSource.data.find((e) => e.isAvailable) != null) {
|
||||||
|
this.dataSource.data.find((e) => e.id == shopkeeperId).isAvailable = true;
|
||||||
|
//TODO podpięcie pod backend zmianę
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DeactivateShopkeeper(shopkeeperId: number) {
|
||||||
|
this.dataSource.data.find((e) => e.id == shopkeeperId).isAvailable = true;
|
||||||
|
//TODO podpięcie pod backend zmianę
|
||||||
}
|
}
|
||||||
|
|
||||||
applyFilter(event: Event) {
|
applyFilter(event: Event) {
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
import { Inject, Injectable } from '@angular/core';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Observable, of, throwError } from 'rxjs';
|
||||||
|
import { ShopkeeperViewModel } from '../types/viewmodels/shopkeeper-viewmodels/ShopkeeperViewModel';
|
||||||
|
import { Either } from '../types/Either';
|
||||||
|
import { ErrorResponse } from '../types/ErrorResponse';
|
||||||
|
import { switchMap } from 'rxjs/operators';
|
||||||
|
|
||||||
|
Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
});
|
||||||
|
export class ShopkeeperService {
|
||||||
|
private baseUrl = 'api/shopkeeper/';
|
||||||
|
constructor(private http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
|
||||||
|
this.baseUrl = baseUrl + this.baseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetAllShopkeepers(): Observable<ShopkeeperViewModel[]> {
|
||||||
|
return this.http
|
||||||
|
.get<Either<ShopkeeperViewModel[], ErrorResponse>>(
|
||||||
|
this.baseUrl + 'getShopkeepers'
|
||||||
|
)
|
||||||
|
.pipe(
|
||||||
|
switchMap((response) => {
|
||||||
|
debugger;
|
||||||
|
if (response.isLeft) {
|
||||||
|
return of(response.left);
|
||||||
|
} else {
|
||||||
|
return throwError(response.right);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
export interface ShopkeeperViewModel {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
isAvailable: boolean;
|
||||||
|
}
|
@ -26,7 +26,7 @@ namespace SessionCompanion.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Lista sklepikarzy</returns>
|
/// <returns>Lista sklepikarzy</returns>
|
||||||
[HttpGet("getShopkeepers")]
|
[HttpGet("getShopkeepers")]
|
||||||
public async Task<List<ShopkeeperViewModel>> GetShopkeepers()
|
public async Task<Either<List<ShopkeeperViewModel>, ErrorResponse>> GetShopkeepers()
|
||||||
{
|
{
|
||||||
return _service.Get().ToList();
|
return _service.Get().ToList();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user