Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Fixup wizard init based on changes in #367
Browse files Browse the repository at this point in the history
  • Loading branch information
CloudNiner committed Dec 22, 2017
1 parent e71a31e commit 5147a6f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class IdentifyStepComponent extends WizardStepComponent<Risk> implements

ngOnInit() {
super.ngOnInit();
const risk = this.session.getData() || new Risk({});
const risk = this.session.getData();
this.setupForm(this.fromModel(risk));
}

Expand All @@ -39,7 +39,7 @@ export class IdentifyStepComponent extends WizardStepComponent<Risk> implements

fromModel(risk: Risk): IdentifyStepFormModel {
return {
hazard: risk.impactDescription,
hazard: risk.weatherEvent.name,
communitySystem: risk.communitySystem.name
};
}
Expand All @@ -60,7 +60,7 @@ export class IdentifyStepComponent extends WizardStepComponent<Risk> implements
}

toModel(data: IdentifyStepFormModel, risk: Risk) {
risk.hazard = data.hazard;
risk.weatherEvent.name = data.hazard;
risk.communitySystem.name = data.communitySystem;
return risk;
}
Expand Down
8 changes: 7 additions & 1 deletion src/angular/planit/src/app/shared/models/risk.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 5147a6f

Please sign in to comment.