diff --git a/.eslintrc.json b/.eslintrc.json index 6f8a3d23..22beac4c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,6 +21,7 @@ ], "@typescript-eslint/no-non-null-assertion": "off", "no-console": "warn", - "@typescript-eslint/ban-ts-ignore": "off" + "@typescript-eslint/ban-ts-ignore": "off", + "guard-for-in": "off" } } diff --git a/src/main/webapp/app/entities/force/force.component.ts b/src/main/webapp/app/entities/force/force.component.ts index 86e82540..800939c8 100644 --- a/src/main/webapp/app/entities/force/force.component.ts +++ b/src/main/webapp/app/entities/force/force.component.ts @@ -34,54 +34,46 @@ export class ForceComponent implements OnInit { } ngOnInit(): void { - this.getArmyId(); + this.loadArmy().then(); } - getArmyId(): void { - if (this.forceList[0] && this.forceList[0].unit.id) { - const armyIdOrNull: Observable> = this.unitArmyService.getArmy(this.forceList[0].unit.id); - armyIdOrNull.toPromise().then( - res => { - Promise.resolve(res.body); - this.armyId = res.body? res.body : 0; - } - ) - } - } - - getArmyIdPromise(): Promise | null { - if (this.forceList[0] && this.forceList[0].unit.id) { - const armyIdOrNull: Observable> = this.unitArmyService.getArmy(this.forceList[0].unit.id); - return armyIdOrNull.toPromise().then( - res => { - Promise.resolve(res.body); - } - ); - } - return null; - } - - getArmyPromise(): Promise> { - this.getArmyId(); - const armyObs: Observable> = this.armyService.find(this.armyId); - const armyPromise: Promise> = armyObs.toPromise().then( + async loadArmy(): Promise> { + // @ts-ignore + const armyIdPromise: Observable> = this.unitArmyService.getArmy(this.forceList[0].unit.id); + await armyIdPromise.toPromise().then( res => { Promise.resolve(res.body); - return res; + if (res.body) { + this.armyId = res.body; + } } - ) - return armyPromise; - } + ); - loadArmy(): void { - this.getArmyId(); - const armyObs: Observable> = this.armyService.find(this.armyId); - armyObs.toPromise().then( + const armyPromise: Observable> = this.armyService.find(this.armyId); + await armyPromise.toPromise().then( res => { Promise.resolve(res.body); this.army = res.body; } - ) + ); + + for (let i = 0; i < this.forceList.length; i++) { + if (this.army && this.army.units) { + this.army.units.forEach( + armyyUnit => { + if (this.forceList[i].unit.id === armyyUnit.id) { + for (const key in armyyUnit) { + if (key !== "army") { + this.forceList[i].unit[key] = armyyUnit[key]; + } + } + } + } + ) + } + } + localStorage.setItem('forceAddedListStored', JSON.stringify(this.forceList)); + return armyIdPromise.toPromise(); } resetAll(): void { @@ -141,17 +133,7 @@ export class ForceComponent implements OnInit { localStorage.setItem('forceAddedListStored', JSON.stringify(this.forceList)); } - async saveList(): Promise { - const armyPromise: Promise> = this.getArmyPromise(); - - await armyPromise.then( - res => { - Promise.resolve(res.body); - this.army = res.body; - return this.army; - } - ) - + saveList(): void { for (const fu of this.forceList) { let newExperience: number let newUnitsDestroyed: number @@ -194,6 +176,7 @@ export class ForceComponent implements OnInit { fu.unit.enemyUnitsDestroyed = newUnitsDestroyed; fu.unit.experiencePoints = newExperience; + // console.log(fu.unit); this.unitArmyService.update(fu.unit).toPromise().then(); } @@ -216,6 +199,7 @@ export class ForceComponent implements OnInit { } if (this.army) { + // console.log(this.army) this.armyService.update(this.army).toPromise().then() }