From 5147a6f48069934d97a92c102fd870c71076ddb6 Mon Sep 17 00:00:00 2001 From: CloudNiner Date: Fri, 22 Dec 2017 11:23:33 -0500 Subject: [PATCH] Fixup wizard init based on changes in #367 --- .../planit/src/app/risk-wizard/risk-wizard.component.ts | 8 ++++++-- .../src/app/risk-wizard/steps/identify-step.component.ts | 6 +++--- src/angular/planit/src/app/shared/models/risk.model.ts | 8 +++++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/angular/planit/src/app/risk-wizard/risk-wizard.component.ts b/src/angular/planit/src/app/risk-wizard/risk-wizard.component.ts index dc362f260..6d8a12361 100644 --- a/src/angular/planit/src/app/risk-wizard/risk-wizard.component.ts +++ b/src/angular/planit/src/app/risk-wizard/risk-wizard.component.ts @@ -29,8 +29,12 @@ export class RiskWizardComponent implements AfterViewInit, OnDestroy, OnInit { ngOnInit() { // TODO: Set initial risk from API - this.session.setData(new Risk({})); - this.session.data.subscribe(risk => this.riskModelChanged(risk)); + const risk = new Risk({ + communitySystem: { name: '' }, + weatherEvent: { name: '' } + }); + this.session.setData(risk); + this.session.data.subscribe(r => this.riskModelChanged(r)); } ngOnDestroy() { diff --git a/src/angular/planit/src/app/risk-wizard/steps/identify-step.component.ts b/src/angular/planit/src/app/risk-wizard/steps/identify-step.component.ts index ecdc93c05..9411a86fd 100644 --- a/src/angular/planit/src/app/risk-wizard/steps/identify-step.component.ts +++ b/src/angular/planit/src/app/risk-wizard/steps/identify-step.component.ts @@ -29,7 +29,7 @@ export class IdentifyStepComponent extends WizardStepComponent implements ngOnInit() { super.ngOnInit(); - const risk = this.session.getData() || new Risk({}); + const risk = this.session.getData(); this.setupForm(this.fromModel(risk)); } @@ -39,7 +39,7 @@ export class IdentifyStepComponent extends WizardStepComponent implements fromModel(risk: Risk): IdentifyStepFormModel { return { - hazard: risk.impactDescription, + hazard: risk.weatherEvent.name, communitySystem: risk.communitySystem.name }; } @@ -60,7 +60,7 @@ export class IdentifyStepComponent extends WizardStepComponent implements } toModel(data: IdentifyStepFormModel, risk: Risk) { - risk.hazard = data.hazard; + risk.weatherEvent.name = data.hazard; risk.communitySystem.name = data.communitySystem; return risk; } diff --git a/src/angular/planit/src/app/shared/models/risk.model.ts b/src/angular/planit/src/app/shared/models/risk.model.ts index a48fbab38..55e86569c 100644 --- a/src/angular/planit/src/app/shared/models/risk.model.ts +++ b/src/angular/planit/src/app/shared/models/risk.model.ts @@ -17,7 +17,13 @@ export class Risk { intensity: OrgRiskDirectionalOption = OrgRiskDirectionalOption.Unsure; probability: OrgRiskRelativeOption = OrgRiskRelativeOption.Unsure; - constructor(object: Object) { + constructor(object: any) { Object.assign(this, object); + if (object.communitySystem) { + this.communitySystem = Object.assign({}, object.communitySystem); + } + if (object.weatherEvent) { + this.weatherEvent = Object.assign({}, object.weatherEvent); + } } }