update character screen
This commit is contained in:
@@ -30,7 +30,13 @@ implements FrontworkComponent<CharacterManagerIfc, RPCInterface>, ICharacterMana
|
||||
this.getHeadCount
|
||||
]
|
||||
|
||||
RPCFeatures = () => []
|
||||
RPCFeatures = () => [{
|
||||
name: 'manageCharacter' as 'manageCharacter',
|
||||
RPCs: [
|
||||
this.updateCharacter
|
||||
]
|
||||
}]
|
||||
|
||||
|
||||
getTableDefinitions = (): TableDefiniton[] => [
|
||||
{
|
||||
@@ -66,6 +72,22 @@ implements FrontworkComponent<CharacterManagerIfc, RPCInterface>, ICharacterMana
|
||||
})
|
||||
}
|
||||
|
||||
updateCharacter = async (character: Character) : Promise<Character> => {
|
||||
await this.admin
|
||||
.knex('characters')
|
||||
.update(<Character>{
|
||||
race: character.race,
|
||||
specid: character.specid,
|
||||
charactername: character.charactername.toLowerCase(),
|
||||
userid: character.userid
|
||||
})
|
||||
.where({
|
||||
id: character.id
|
||||
})
|
||||
|
||||
return await this.getCharacterByName(character.charactername) as Character
|
||||
}
|
||||
|
||||
createCharacter = async (userToken: string, character : Character) : Promise<Character> => {
|
||||
try{
|
||||
character.charactername = character.charactername.toLowerCase()
|
||||
|
||||
@@ -10,4 +10,6 @@ export class ICharacterManager{
|
||||
getCharactersOfUser: (username: string) => Promise<(Character & Spec)[]>
|
||||
getUserOfCharacter: (character:Character) => Promise<User>
|
||||
getHeadCount: (clazz: Class) => Promise<number>
|
||||
updateCharacter: (character: Character) => Promise<Character>
|
||||
|
||||
}
|
||||
@@ -14,5 +14,7 @@ export type CharacterManagerIfc = {
|
||||
}
|
||||
|
||||
export type CharacterManagerFeatureIfc = {
|
||||
|
||||
manageCharacter: {
|
||||
updateCharacter: ICharacterManager['updateCharacter']
|
||||
}
|
||||
}
|
||||
@@ -136,6 +136,8 @@ export class UserManager
|
||||
//set up permissions
|
||||
getLogger('UserManager#initialize').debug('setting up permissions')
|
||||
|
||||
console.log(this.character.RPCFeatures())
|
||||
|
||||
await Promise.all(
|
||||
[this, ...this.exporters].flatMap(exp => exp.RPCFeatures().map(async (feature) => {
|
||||
try {
|
||||
|
||||
@@ -21,12 +21,12 @@ export class RegisterComponent implements OnInit{
|
||||
race: "Night Elf"
|
||||
}
|
||||
|
||||
ranks = _Rank.splice(5) //remove admin, gm, officer
|
||||
ranks = ["Trial"] //remove admin, gm, officer
|
||||
classes = _Class
|
||||
races = _Race
|
||||
selectedClass : Class = "Warrior"
|
||||
selectedSpec = specs[this.selectedClass][0]
|
||||
specs = specs[this.selectedClass]
|
||||
selectedSpec = specs[this.selectedClass][0]
|
||||
showApplication = false
|
||||
submitted = false
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<nb-card
|
||||
class = "col-12 col-xl-9">
|
||||
<nb-card class="col-12 col-xl-9">
|
||||
<nb-card-header style="text-transform: capitalize;">
|
||||
<h4>
|
||||
<a *ngIf="link === 'character'" [ngStyle]="{'color': color}" [routerLink]="'/frontcraft/character/'+char.charactername">
|
||||
<a *ngIf="link === 'character'" [ngStyle]="{'color': color}"
|
||||
[routerLink]="'/frontcraft/character/'+char.charactername">
|
||||
{{char.charactername}}
|
||||
</a>
|
||||
</h4>
|
||||
@@ -14,12 +14,33 @@ class = "col-12 col-xl-9">
|
||||
</nb-card-header>
|
||||
|
||||
<nb-card-body>
|
||||
<img style="width:20px; height:20px" [src]="'../../../../assets/images/'+char.race.toLowerCase()+'_xs.gif'" />
|
||||
{{char.race}}<br />
|
||||
<img style="width:20px; height:20px" [src]="'../../../../assets/images/'+char.class.toLowerCase()+'.png'" />
|
||||
{{char.specname}} {{char.class}}<br />
|
||||
<span *ngIf="!canManage">
|
||||
<img style="width:20px; height:20px" [src]="'../../../../assets/images/'+char.race.toLowerCase()+'_xs.gif'" />
|
||||
{{char.race}}<br />
|
||||
<img style="width:20px; height:20px" [src]="'../../../../assets/images/'+char.class.toLowerCase()+'.png'" />
|
||||
|
||||
{{char.specname}} {{char.class}}<br />
|
||||
</span>
|
||||
<span *ngIf="canManage">
|
||||
<input nbInput [required]="true" name="preMember" [(ngModel)]="char.charactername"><br />
|
||||
<nb-select [(selected)]="char.race" placeholder="Race">
|
||||
<nb-option *ngFor="let race of races" [value]="race">{{race}}</nb-option>
|
||||
</nb-select>
|
||||
<nb-select [(selected)]="char.specname" placeholder="Spec">
|
||||
<nb-option *ngFor="let spec of specs" [value]="spec">{{spec}}</nb-option>
|
||||
</nb-select>
|
||||
<nb-select [(selected)]="char.class" placeholder="Class" (selectedChange)="onSelectClass()">
|
||||
<nb-option *ngFor="let class of classes" [value]="class">{{class}}</nb-option>
|
||||
</nb-select>
|
||||
<button nbButton
|
||||
status="primary"
|
||||
[class.btn-pulse]="submitted"
|
||||
(click)="updateCharacter()">
|
||||
Update
|
||||
</button>
|
||||
</span>
|
||||
<span *ngIf="link === 'owner'">
|
||||
Owned by <a [routerLink]="'/frontcraft/user/'+char.username"> {{char.username}} ({{char.rank}})</a>
|
||||
</span>
|
||||
</nb-card-body>
|
||||
</nb-card>
|
||||
</nb-card>
|
||||
@@ -1,9 +1,10 @@
|
||||
import { Component, OnInit, Input } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Spec, User, Character, Item } from '../../../../../../backend/Types/Types';
|
||||
import { getClassColor } from '../../../../../../backend/Types/PlayerSpecs';
|
||||
import { Spec, User, Character, Item, _Class, _Race, Class } from '../../../../../../backend/Types/Types';
|
||||
import { getClassColor, specs } from '../../../../../../backend/Types/PlayerSpecs';
|
||||
import { _Tiers } from '../../../../../../backend/Types/Items';
|
||||
import { IApiService } from '../../services/ApiService/ApiService';
|
||||
import { NbToastrService } from '@nebular/theme';
|
||||
|
||||
@Component({
|
||||
selector: 'character',
|
||||
@@ -13,11 +14,17 @@ export class FrontcraftCharacterComponent implements OnInit {
|
||||
|
||||
@Input() name?: string
|
||||
@Input() link?: "owner" | "character" = 'owner'
|
||||
|
||||
char: (Character & User & Spec) = {
|
||||
charactername: "Loading",
|
||||
race: 'Human',
|
||||
class: 'Warrior'
|
||||
class: 'Warrior',
|
||||
spec: 'Arms'
|
||||
} as any
|
||||
|
||||
classes = _Class
|
||||
races = _Race
|
||||
specs = specs[this.char.class]
|
||||
|
||||
color: string
|
||||
tokens
|
||||
dataLink = ""
|
||||
@@ -27,23 +34,32 @@ export class FrontcraftCharacterComponent implements OnInit {
|
||||
boss2 = { name: undefined, date: undefined }
|
||||
gear2: Item[] = []
|
||||
|
||||
canManage: boolean = false
|
||||
|
||||
constructor(
|
||||
private api: IApiService,
|
||||
private route: ActivatedRoute,
|
||||
private toast: NbToastrService,
|
||||
) { }
|
||||
|
||||
async ngOnInit() {
|
||||
const param = this.name || this.route.snapshot.paramMap.get('name');
|
||||
if (!param) return
|
||||
|
||||
const manageChar = this.api.get('manageCharacter')
|
||||
|
||||
if (manageChar) this.canManage = true
|
||||
|
||||
const char = await this.api.get('CharacterManager').getCharacterByName(param)
|
||||
if (char) {
|
||||
this.color = getClassColor(char.class)
|
||||
this.char = char
|
||||
this.specs = specs[this.char.class]
|
||||
this.api.get('ItemManager').getTokens(this.char, _Tiers, true).then(tokens => {
|
||||
this.tokens = tokens
|
||||
})
|
||||
|
||||
/*
|
||||
this.dataLink = "https://classic.warcraftlogs.com:443/v1/parses/character/" + this.char.charactername.replace(/^\w/, c => c.toUpperCase()) + "/Gandling/EU?api_key=c698515ab4f592cdb848d80b3abe616c&metric=dps"
|
||||
|
||||
const json: any[] = await fetch(this.dataLink).then(raw => raw.json())
|
||||
@@ -68,6 +84,24 @@ export class FrontcraftCharacterComponent implements OnInit {
|
||||
const maybeItems: (Item | undefined)[] = await Promise.all(data.gear.filter(item => item.name != "Unknown Item").map(async item => await this.api.get('ItemManager').getItem(item.name)))
|
||||
const geardata = maybeItems.filter(maybeItem => maybeItem != null)
|
||||
this.gear2 = geardata
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
updateCharacter = async () => {
|
||||
const manager = this.api.get('manageCharacter')
|
||||
if (manager) {
|
||||
const specid = await this.api.get('CharacterManager').getSpecId(this.char['class'], this.char['specname'] as any)
|
||||
this.char.specid = specid
|
||||
manager.updateCharacter(this.char).then(() => {
|
||||
this.toast.show('Update', 'Success', { status: 'success' })
|
||||
})
|
||||
}
|
||||
}
|
||||
onSelectClass() {
|
||||
this.specs = specs[this.char.class]
|
||||
setTimeout(() => {
|
||||
this.char.specname = this.specs[0]
|
||||
}, 25)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user