diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts index b475db3..ab57d47 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts @@ -26,6 +26,7 @@ import { MatTableModule, MatSortModule, MatDialogModule, + MatTooltipModule, } from '@angular/material'; import { UserService } from '../services/user.service'; import { StoreModule } from '@ngrx/store'; @@ -39,6 +40,10 @@ import { GameMasterArmorsTableComponent } from './components/game-master-armors- import { GameMasterCharacterActionsDialogComponent } from './components/game-master-character-actions-dialog/game-master-character-actions-dialog.component'; import { GameMasterWeaponsTableComponent } from './components/game-master-weapons-table/game-master-weapons-table.component'; import { AbilitiesComponent } from './components/abilities/abilities.component'; +import { SpellService } from '../services/spell.service'; +import { WeaponService } from '../services/weapon.service'; +import { ArmorService } from '../services/armor.service'; +import { OtherEquipmentService } from '../services/other-equipment.service'; @NgModule({ declarations: [ @@ -81,8 +86,16 @@ import { AbilitiesComponent } from './components/abilities/abilities.component'; }), MatTableModule, MatSortModule, + MatTooltipModule, + ], + providers: [ + UserService, + CharacterService, + SpellService, + WeaponService, + ArmorService, + OtherEquipmentService, ], - providers: [UserService, CharacterService], bootstrap: [AppComponent], entryComponents: [ GameMasterSpellsTableComponent, diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-armors-table/game-master-armors-table.component.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-armors-table/game-master-armors-table.component.ts index 0af906c..139871c 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-armors-table/game-master-armors-table.component.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-armors-table/game-master-armors-table.component.ts @@ -3,6 +3,10 @@ import { MatTableDataSource } from '@angular/material/table'; import { ArmorViewModel } from '../../../types/viewmodels/armor-viewmodels/ArmorViewModel'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; +import { first } from 'rxjs/operators'; +import { ErrorResponse } from '../../../types/ErrorResponse'; +import { HttpErrorResponse } from '@angular/common/http'; +import { ArmorService } from '../../../services/armor.service'; @Component({ selector: 'app-game-master-armors-table', @@ -22,29 +26,27 @@ export class GameMasterArmorsTableComponent implements OnInit { @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator; @ViewChild(MatSort, { static: true }) sort: MatSort; - constructor() { - const armors = [ - { - id: 1, - name: 'Test', - category: 'Testowa', - minimumStrength: 12, - weight: 98, - cost: 123, - armorClassBase: 10, - haveDexterityBonus: false, - haveStealthDisadvantage: false, - currencyType: 1, - }, - ]; - - this.dataSource = new MatTableDataSource(armors); + constructor(private armorService: ArmorService) { + armorService + .GetAllArmors() + .pipe(first()) + .subscribe( + (result) => { + console.log(result); + this.dataSource = new MatTableDataSource(result); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + }, + (error: ErrorResponse | HttpErrorResponse) => { + if (error instanceof HttpErrorResponse) { + error = error.error as ErrorResponse; + } + console.log(error.message); + } + ); } - ngOnInit() { - this.dataSource.paginator = this.paginator; - this.dataSource.sort = this.sort; - } + ngOnInit() {} applyFilter(event: Event) { const filterValue = (event.target as HTMLInputElement).value; diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-spells-table/game-master-spells-table.component.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-spells-table/game-master-spells-table.component.ts index 8da89fa..7005445 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-spells-table/game-master-spells-table.component.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-spells-table/game-master-spells-table.component.ts @@ -2,13 +2,11 @@ import { Component, OnInit, ViewChild } from '@angular/core'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; import { MatTableDataSource } from '@angular/material/table'; - -export interface SpellData { - name: string; - range: string; - level: number; - school: string; -} +import { SpellViewModel } from '../../../types/viewmodels/spell-viewmodels/SpellViewModel'; +import { SpellService } from '../../../services/spell.service'; +import { first } from 'rxjs/operators'; +import { ErrorResponse } from '../../../types/ErrorResponse'; +import { HttpErrorResponse } from '@angular/common/http'; @Component({ selector: 'app-game-master-spells-table', @@ -17,25 +15,31 @@ export interface SpellData { }) export class GameMasterSpellsTableComponent implements OnInit { displayedColumns: string[] = ['Name', 'Range', 'Level', 'School']; - dataSource: MatTableDataSource; + dataSource: MatTableDataSource; @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator; @ViewChild(MatSort, { static: true }) sort: MatSort; - constructor() { - const users = Array.from({ length: 100 }, (_, k) => this.createSepll()); - - this.dataSource = new MatTableDataSource(users); + constructor(private spellService: SpellService) { + spellService + .GetAllSpells() + .pipe(first()) + .subscribe( + (result) => { + this.dataSource = new MatTableDataSource(result); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + }, + (error: ErrorResponse | HttpErrorResponse) => { + if (error instanceof HttpErrorResponse) { + error = error.error as ErrorResponse; + } + console.log(error.message); + } + ); } - createSepll(): SpellData { - return { name: 'test', range: 'asd', level: 2, school: 'UAM!!!!' }; - } - - ngOnInit() { - this.dataSource.paginator = this.paginator; - this.dataSource.sort = this.sort; - } + ngOnInit() {} applyFilter(event: Event) { const filterValue = (event.target as HTMLInputElement).value; diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.css b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.css index 83e5e96..c83a0ea 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.css +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.css @@ -1,11 +1,11 @@ -.description-weapon-column { +.text-cut { + max-width: 60px; /* feel free to include any other value */ white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } table { - width: 100%; background-color: initial; } @@ -34,5 +34,4 @@ mat-paginator { td, th { color: whitesmoke; - width: 25%; } diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.html b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.html index 966d65d..ab3bbf1 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.html +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.html @@ -3,8 +3,8 @@ -
- +
+
@@ -28,7 +28,9 @@ - + diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.ts index 4a17e31..24bdcbf 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.ts @@ -3,6 +3,10 @@ import { MatTableDataSource } from '@angular/material/table'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; import { WeaponViewModel } from '../../../types/viewmodels/weapon-viewmodels/WeaponViewModel'; +import { WeaponService } from '../../../services/weapon.service'; +import { first } from 'rxjs/operators'; +import { ErrorResponse } from '../../../types/ErrorResponse'; +import { HttpErrorResponse } from '@angular/common/http'; @Component({ selector: 'app-game-master-weapons-table', @@ -22,30 +26,27 @@ export class GameMasterWeaponsTableComponent implements OnInit { @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator; @ViewChild(MatSort, { static: true }) sort: MatSort; - constructor() { - const weapons = [ - { - id: 1, - name: 'Test', - cost: 123, - weight: 98, - diceCount: 2, - diceValue: 20, - twoHandDamageType: 'Toxic', - description: - 'A japanase battleaxe with a spike on the opposite side of the blade.', - weaponType: 'Two-Handed Melee Weapons', - rangeMeele: 50, - }, - ]; - - this.dataSource = new MatTableDataSource(weapons); + constructor(private weaponService: WeaponService) { + weaponService + .GetAllWeapons() + .pipe(first()) + .subscribe( + (result) => { + console.log(result); + this.dataSource = new MatTableDataSource(result); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + }, + (error: ErrorResponse | HttpErrorResponse) => { + if (error instanceof HttpErrorResponse) { + error = error.error as ErrorResponse; + } + console.log(error.message); + } + ); } - ngOnInit() { - this.dataSource.paginator = this.paginator; - this.dataSource.sort = this.sort; - } + ngOnInit() {} applyFilter(event: Event) { const filterValue = (event.target as HTMLInputElement).value; diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/services/armor.service.ts b/SessionCompanion/SessionCompanion/ClientApp/src/services/armor.service.ts new file mode 100644 index 0000000..9651317 --- /dev/null +++ b/SessionCompanion/SessionCompanion/ClientApp/src/services/armor.service.ts @@ -0,0 +1,34 @@ +import { Inject, Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { Observable, of, throwError } from 'rxjs'; +import { WeaponViewModel } from '../types/viewmodels/weapon-viewmodels/WeaponViewModel'; +import { Either } from '../types/Either'; +import { ErrorResponse } from '../types/ErrorResponse'; +import { switchMap } from 'rxjs/operators'; +import { ArmorViewModel } from '../types/viewmodels/armor-viewmodels/ArmorViewModel'; + +Injectable({ + providedIn: 'root', +}); +export class ArmorService { + private baseUrl = 'api/armor/'; + constructor(private http: HttpClient, @Inject('BASE_URL') baseUrl: string) { + this.baseUrl = baseUrl + this.baseUrl; + } + + GetAllArmors(): Observable { + return this.http + .get>( + this.baseUrl + 'getAllArmor' + ) + .pipe( + switchMap((response) => { + if (response.isLeft) { + return of(response.left); + } else { + return throwError(response.right); + } + }) + ); + } +} diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/services/other-equipment.service.ts b/SessionCompanion/SessionCompanion/ClientApp/src/services/other-equipment.service.ts new file mode 100644 index 0000000..3799e0b --- /dev/null +++ b/SessionCompanion/SessionCompanion/ClientApp/src/services/other-equipment.service.ts @@ -0,0 +1,12 @@ +import { Inject, Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; + +Injectable({ + providedIn: 'root', +}); +export class OtherEquipmentService { + private baseUrl = 'api/otherEquipment/'; + constructor(private http: HttpClient, @Inject('BASE_URL') baseUrl: string) { + this.baseUrl = baseUrl + this.baseUrl; + } +} diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/services/spell.service.ts b/SessionCompanion/SessionCompanion/ClientApp/src/services/spell.service.ts new file mode 100644 index 0000000..bdbcaa0 --- /dev/null +++ b/SessionCompanion/SessionCompanion/ClientApp/src/services/spell.service.ts @@ -0,0 +1,33 @@ +import { Inject, Injectable } from '@angular/core'; +import { HttpClient, HttpParams } from '@angular/common/http'; +import { Observable, of, throwError } from 'rxjs'; +import { SpellViewModel } from '../types/viewmodels/spell-viewmodels/SpellViewModel'; +import { Either } from '../types/Either'; +import { ErrorResponse } from '../types/ErrorResponse'; +import { switchMap } from 'rxjs/operators'; + +Injectable({ + providedIn: 'root', +}); +export class SpellService { + private baseUrl = 'api/spell/'; + constructor(private http: HttpClient, @Inject('BASE_URL') baseUrl: string) { + this.baseUrl = baseUrl + this.baseUrl; + } + + GetAllSpells(): Observable { + return this.http + .get>( + this.baseUrl + 'getAllSpells' + ) + .pipe( + switchMap((response) => { + if (response.isLeft) { + return of(response.left); + } else { + return throwError(response.right); + } + }) + ); + } +} diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/services/weapon.service.ts b/SessionCompanion/SessionCompanion/ClientApp/src/services/weapon.service.ts new file mode 100644 index 0000000..480d1bd --- /dev/null +++ b/SessionCompanion/SessionCompanion/ClientApp/src/services/weapon.service.ts @@ -0,0 +1,34 @@ +import { Inject, Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { Observable, of, throwError } from 'rxjs'; +import { SpellViewModel } from '../types/viewmodels/spell-viewmodels/SpellViewModel'; +import { Either } from '../types/Either'; +import { ErrorResponse } from '../types/ErrorResponse'; +import { switchMap } from 'rxjs/operators'; +import { WeaponViewModel } from '../types/viewmodels/weapon-viewmodels/WeaponViewModel'; + +Injectable({ + providedIn: 'root', +}); +export class WeaponService { + private baseUrl = 'api/weapon/'; + constructor(private http: HttpClient, @Inject('BASE_URL') baseUrl: string) { + this.baseUrl = baseUrl + this.baseUrl; + } + + GetAllWeapons(): Observable { + return this.http + .get>( + this.baseUrl + 'getAllWeapons' + ) + .pipe( + switchMap((response) => { + if (response.isLeft) { + return of(response.left); + } else { + return throwError(response.right); + } + }) + ); + } +} diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/types/viewmodels/spell-viewmodels/SpellViewModel.ts b/SessionCompanion/SessionCompanion/ClientApp/src/types/viewmodels/spell-viewmodels/SpellViewModel.ts new file mode 100644 index 0000000..93c6936 --- /dev/null +++ b/SessionCompanion/SessionCompanion/ClientApp/src/types/viewmodels/spell-viewmodels/SpellViewModel.ts @@ -0,0 +1,17 @@ +export interface SpellViewModel { + id: number; + name: string; + descriptions: string[]; + higherLevel: string[]; + range: string; + components: string; + material: string; + ritual: boolean; + duration: string; + concentration: boolean; + castingTime: string; + level: number; + school: string; + classes: string; + subclasses: string; +}
Name Description {{row.description}} + {{row.description}} +