update character screen
This commit is contained in:
@@ -30,7 +30,13 @@ implements FrontworkComponent<CharacterManagerIfc, RPCInterface>, ICharacterMana
|
|||||||
this.getHeadCount
|
this.getHeadCount
|
||||||
]
|
]
|
||||||
|
|
||||||
RPCFeatures = () => []
|
RPCFeatures = () => [{
|
||||||
|
name: 'manageCharacter' as 'manageCharacter',
|
||||||
|
RPCs: [
|
||||||
|
this.updateCharacter
|
||||||
|
]
|
||||||
|
}]
|
||||||
|
|
||||||
|
|
||||||
getTableDefinitions = (): TableDefiniton[] => [
|
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> => {
|
createCharacter = async (userToken: string, character : Character) : Promise<Character> => {
|
||||||
try{
|
try{
|
||||||
character.charactername = character.charactername.toLowerCase()
|
character.charactername = character.charactername.toLowerCase()
|
||||||
|
|||||||
@@ -10,4 +10,6 @@ export class ICharacterManager{
|
|||||||
getCharactersOfUser: (username: string) => Promise<(Character & Spec)[]>
|
getCharactersOfUser: (username: string) => Promise<(Character & Spec)[]>
|
||||||
getUserOfCharacter: (character:Character) => Promise<User>
|
getUserOfCharacter: (character:Character) => Promise<User>
|
||||||
getHeadCount: (clazz: Class) => Promise<number>
|
getHeadCount: (clazz: Class) => Promise<number>
|
||||||
|
updateCharacter: (character: Character) => Promise<Character>
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -14,5 +14,7 @@ export type CharacterManagerIfc = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type CharacterManagerFeatureIfc = {
|
export type CharacterManagerFeatureIfc = {
|
||||||
|
manageCharacter: {
|
||||||
|
updateCharacter: ICharacterManager['updateCharacter']
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -136,6 +136,8 @@ export class UserManager
|
|||||||
//set up permissions
|
//set up permissions
|
||||||
getLogger('UserManager#initialize').debug('setting up permissions')
|
getLogger('UserManager#initialize').debug('setting up permissions')
|
||||||
|
|
||||||
|
console.log(this.character.RPCFeatures())
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
[this, ...this.exporters].flatMap(exp => exp.RPCFeatures().map(async (feature) => {
|
[this, ...this.exporters].flatMap(exp => exp.RPCFeatures().map(async (feature) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ export class RegisterComponent implements OnInit{
|
|||||||
race: "Night Elf"
|
race: "Night Elf"
|
||||||
}
|
}
|
||||||
|
|
||||||
ranks = _Rank.splice(5) //remove admin, gm, officer
|
ranks = ["Trial"] //remove admin, gm, officer
|
||||||
classes = _Class
|
classes = _Class
|
||||||
races = _Race
|
races = _Race
|
||||||
selectedClass : Class = "Warrior"
|
selectedClass : Class = "Warrior"
|
||||||
selectedSpec = specs[this.selectedClass][0]
|
|
||||||
specs = specs[this.selectedClass]
|
specs = specs[this.selectedClass]
|
||||||
|
selectedSpec = specs[this.selectedClass][0]
|
||||||
showApplication = false
|
showApplication = false
|
||||||
submitted = false
|
submitted = false
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<nb-card
|
<nb-card class="col-12 col-xl-9">
|
||||||
class = "col-12 col-xl-9">
|
|
||||||
<nb-card-header style="text-transform: capitalize;">
|
<nb-card-header style="text-transform: capitalize;">
|
||||||
<h4>
|
<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}}
|
{{char.charactername}}
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
@@ -14,10 +14,31 @@ class = "col-12 col-xl-9">
|
|||||||
</nb-card-header>
|
</nb-card-header>
|
||||||
|
|
||||||
<nb-card-body>
|
<nb-card-body>
|
||||||
|
<span *ngIf="!canManage">
|
||||||
<img style="width:20px; height:20px" [src]="'../../../../assets/images/'+char.race.toLowerCase()+'_xs.gif'" />
|
<img style="width:20px; height:20px" [src]="'../../../../assets/images/'+char.race.toLowerCase()+'_xs.gif'" />
|
||||||
{{char.race}}<br />
|
{{char.race}}<br />
|
||||||
<img style="width:20px; height:20px" [src]="'../../../../assets/images/'+char.class.toLowerCase()+'.png'" />
|
<img style="width:20px; height:20px" [src]="'../../../../assets/images/'+char.class.toLowerCase()+'.png'" />
|
||||||
|
|
||||||
{{char.specname}} {{char.class}}<br />
|
{{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'">
|
<span *ngIf="link === 'owner'">
|
||||||
Owned by <a [routerLink]="'/frontcraft/user/'+char.username"> {{char.username}} ({{char.rank}})</a>
|
Owned by <a [routerLink]="'/frontcraft/user/'+char.username"> {{char.username}} ({{char.rank}})</a>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { Component, OnInit, Input } from '@angular/core';
|
import { Component, OnInit, Input } from '@angular/core';
|
||||||
import { ActivatedRoute } from '@angular/router';
|
import { ActivatedRoute } from '@angular/router';
|
||||||
import { Spec, User, Character, Item } from '../../../../../../backend/Types/Types';
|
import { Spec, User, Character, Item, _Class, _Race, Class } from '../../../../../../backend/Types/Types';
|
||||||
import { getClassColor } from '../../../../../../backend/Types/PlayerSpecs';
|
import { getClassColor, specs } from '../../../../../../backend/Types/PlayerSpecs';
|
||||||
import { _Tiers } from '../../../../../../backend/Types/Items';
|
import { _Tiers } from '../../../../../../backend/Types/Items';
|
||||||
import { IApiService } from '../../services/ApiService/ApiService';
|
import { IApiService } from '../../services/ApiService/ApiService';
|
||||||
|
import { NbToastrService } from '@nebular/theme';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'character',
|
selector: 'character',
|
||||||
@@ -13,11 +14,17 @@ export class FrontcraftCharacterComponent implements OnInit {
|
|||||||
|
|
||||||
@Input() name?: string
|
@Input() name?: string
|
||||||
@Input() link?: "owner" | "character" = 'owner'
|
@Input() link?: "owner" | "character" = 'owner'
|
||||||
|
|
||||||
char: (Character & User & Spec) = {
|
char: (Character & User & Spec) = {
|
||||||
|
charactername: "Loading",
|
||||||
race: 'Human',
|
race: 'Human',
|
||||||
class: 'Warrior'
|
class: 'Warrior',
|
||||||
|
spec: 'Arms'
|
||||||
} as any
|
} as any
|
||||||
|
|
||||||
|
classes = _Class
|
||||||
|
races = _Race
|
||||||
|
specs = specs[this.char.class]
|
||||||
|
|
||||||
color: string
|
color: string
|
||||||
tokens
|
tokens
|
||||||
dataLink = ""
|
dataLink = ""
|
||||||
@@ -27,23 +34,32 @@ export class FrontcraftCharacterComponent implements OnInit {
|
|||||||
boss2 = { name: undefined, date: undefined }
|
boss2 = { name: undefined, date: undefined }
|
||||||
gear2: Item[] = []
|
gear2: Item[] = []
|
||||||
|
|
||||||
|
canManage: boolean = false
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private api: IApiService,
|
private api: IApiService,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
|
private toast: NbToastrService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
const param = this.name || this.route.snapshot.paramMap.get('name');
|
const param = this.name || this.route.snapshot.paramMap.get('name');
|
||||||
if (!param) return
|
if (!param) return
|
||||||
|
|
||||||
|
const manageChar = this.api.get('manageCharacter')
|
||||||
|
|
||||||
|
if (manageChar) this.canManage = true
|
||||||
|
|
||||||
const char = await this.api.get('CharacterManager').getCharacterByName(param)
|
const char = await this.api.get('CharacterManager').getCharacterByName(param)
|
||||||
if (char) {
|
if (char) {
|
||||||
this.color = getClassColor(char.class)
|
this.color = getClassColor(char.class)
|
||||||
this.char = char
|
this.char = char
|
||||||
|
this.specs = specs[this.char.class]
|
||||||
this.api.get('ItemManager').getTokens(this.char, _Tiers, true).then(tokens => {
|
this.api.get('ItemManager').getTokens(this.char, _Tiers, true).then(tokens => {
|
||||||
this.tokens = 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"
|
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())
|
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 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)
|
const geardata = maybeItems.filter(maybeItem => maybeItem != null)
|
||||||
this.gear2 = geardata
|
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