Selaa lähdekoodia

fix warcraftlogs api calls unknown item

master
peter 5 vuotta sitten
vanhempi
commit
f3979befa2

+ 1
- 1
src/backend/Components/PubSub/Interface.ts Näytä tiedosto

@@ -2,6 +2,6 @@ import { SubscriptionResponse } from "rpclibrary"
2 2
 
3 3
 export class IPubSub<UpdateType>{
4 4
     publish: (topic: string, p: UpdateType) => Promise<void>
5
-    subscribe: (topic:string, callback: (p:UpdateType)=>any) => Promise<SubscriptionResponse>
5
+    subscribe: (topic:string, callback: (p:UpdateType)=>any) => Promise<SubscriptionResponse&{data:any}>
6 6
     unsubscribe: (uuid: string) => Promise<void>
7 7
 }

+ 2
- 1
src/frontend/src/app/frontcraft/pages/armory/armory.component.html Näytä tiedosto

@@ -9,7 +9,8 @@ status="control">
9 9
 
10 10
     <nb-card-body>
11 11
         <div>
12
-            <input name="Character" [(ngModel)]="charactername"  placeholder="Character Name" nbInput>
12
+            
13
+            <input name="Character" [(ngModel)]="charactername" (keydown.enter)="submit()" placeholder="Character Name" nbInput>
13 14
             <nb-select [(selected)]="server" placeholder="Spec">
14 15
                 <nb-option *ngFor="let sv of servers" [value]="sv">{{sv}}</nb-option>
15 16
             </nb-select>

+ 15
- 9
src/frontend/src/app/frontcraft/pages/armory/armory.component.ts Näytä tiedosto

@@ -1,5 +1,6 @@
1 1
 import { Component, OnInit } from '@angular/core';
2 2
 import { Item } from '../../../../../../backend/Types/Types';
3
+import { NbToastrService } from '@nebular/theme';
3 4
 
4 5
 @Component({
5 6
   selector: 'armory',
@@ -14,6 +15,7 @@ export class FrontcraftArmoryComponent implements OnInit{
14 15
   gear:string[] = []
15 16
 
16 17
   constructor(
18
+    private toastr: NbToastrService
17 19
   ){}
18 20
 
19 21
   async submit(){
@@ -22,23 +24,27 @@ export class FrontcraftArmoryComponent implements OnInit{
22 24
     fetch(dataLink).then(raw => raw.json().then((json:any[]) => {
23 25
       if(json.length < 1) return
24 26
       let min = -1
25
-      let data = null
27
+      let data
26 28
 
27
-      json.forEach(item => {
28
-        if(item.startTime > min){
29
-          if(item.gear[0].name != "Unknown Item"){
30
-            min = item.startTime
31
-            data = item
32
-          }
29
+      for(let i = json.length-1; i > 0; i--){
30
+        if(json[i].startTime > min && json[i].gear[0].name != "Unknown Item"){
31
+          data = json[i]
32
+          break
33 33
         }
34
-      })
34
+      }
35
+      if(!data){
36
+        this.toastr.danger('Unknown character, or no warcraftlogs', "Error", {
37
+          duration: 2000
38
+        })  
39
+        return
40
+      }
35 41
 
36 42
       this.gear = data.gear.map(item => {return <Item>{
37 43
         itemname: item.name,
38 44
         iconname: item.icon.replace('.jpg', ''),
39 45
         quality: item.quality.replace(/^\w/, c => c.toUpperCase()),
40 46
         url: "https://classic.wowhead.com/item="+item.id,
41
-      }})
47
+      }}).filter(item => item.itemname != "Unknown Item")
42 48
     }))
43 49
   }
44 50
 

+ 1
- 6
src/frontend/src/app/frontcraft/pages/character/character.component.html Näytä tiedosto

@@ -35,16 +35,11 @@ status="control">
35 35
         <br />
36 36
         <br />
37 37
         <br />
38
-        <h3>Gear of the last two reported kills <a target="_blank" *ngIf="dataLink != null && dataLink != ''" style="size: 0.5em;" [href]="dataLink">(data)</a></h3>
38
+        <h3>Gear of the last reported kill <a target="_blank" *ngIf="dataLink != null && dataLink != ''" style="size: 0.5em;" [href]="dataLink">(data)</a></h3>
39 39
         <h5>{{boss2.name}} {{boss2.date | date : 'MMM d @ HH : mm'}}</h5>
40 40
         <ng-container *ngFor="let item of gear2">
41 41
             <wowhead [item]="item"></wowhead><br />
42 42
         </ng-container>
43 43
 
44
-        <h5>{{boss1.name}} {{boss1.date | date : 'MMM d @ HH : mm'}}</h5>
45
-        <ng-container *ngFor="let item of gear1">
46
-            <wowhead [item]="item"></wowhead><br />
47
-        </ng-container>
48
-
49 44
     </nb-card-body>
50 45
 </nb-card>

+ 11
- 24
src/frontend/src/app/frontcraft/pages/character/character.component.ts Näytä tiedosto

@@ -48,41 +48,28 @@ export class FrontcraftCharacterComponent implements OnInit{
48 48
 
49 49
           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"
50 50
 
51
-          
52
-
53
-          fetch(this.dataLink).then(raw => raw.json().then((json) => {
51
+          fetch(this.dataLink).then(raw => raw.json().then((json:any[]) => {
54 52
             if(json.length < 1) return
55
-            const data = json[0]
53
+            let data
54
+            let min = -1
56 55
 
57
-            this.boss2 = {
58
-              name: data.encounterName,
59
-              date: data.startTime
56
+            for(let i = json.length-1; i > 0; i--){
57
+              if(json[i].startTime > min && json[i].gear[0].name != "Unknown Item"){
58
+                data = json[i]
59
+                break
60
+              }
60 61
             }
61
-            this.gear2 = data.gear.map(item => {return <Item>{
62
-              itemname: item.name,
63
-              iconname: item.icon.replace('.jpg', ''),
64
-              quality: item.quality.replace(/^\w/, c => c.toUpperCase()),
65
-              url: "https://classic.wowhead.com/item="+item.id,
66
-              tooltip: "unavailable"
67
-            }}).filter(item => item.itemname != "Unknown Item")
68
-          }))
69
-
70
-          fetch(this.dataLink).then(raw => raw.json().then((json) => {
71
-            if(json.length < 2) return
62
+            if(!data) return
72 63
 
73
-            const data = json[1]
74
-
75
-            this.boss1 = {
64
+            this.boss2 = {
76 65
               name: data.encounterName,
77 66
               date: data.startTime
78 67
             }
79
-
80
-            this.gear1 = data.gear.map(item => {return <Item>{
68
+            this.gear2 = data.gear.map(item => {return <Item>{
81 69
               itemname: item.name,
82 70
               iconname: item.icon.replace('.jpg', ''),
83 71
               quality: item.quality.replace(/^\w/, c => c.toUpperCase()),
84 72
               url: "https://classic.wowhead.com/item="+item.id,
85
-              tooltip: "unavailable"
86 73
             }}).filter(item => item.itemname != "Unknown Item")
87 74
           }))
88 75
         }

Loading…
Peruuta
Tallenna