Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: entities #1938

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import {
} from 'src/app/analytics/analytics.enum';
import { AnalyticsService } from 'src/app/analytics/analytics.service';
import { LayerControlInfoPopoverComponent } from 'src/app/components/layer-control-info-popover/layer-control-info-popover.component';
import { AREAS_OF_FOCUS } from 'src/app/models/area-of-focus.const';
import {
Country,
CountryDisasterSettings,
DisasterType,
} from 'src/app/models/country.model';
import { PlaceCode } from 'src/app/models/place-code.model';
import { ApiService } from 'src/app/services/api.service';
import { CountryService } from 'src/app/services/country.service';
import { DisasterTypeService } from 'src/app/services/disaster-type.service';
import { EapActionsService } from 'src/app/services/eap-actions.service';
import { EventService } from 'src/app/services/event.service';
import { PlaceCodeService } from 'src/app/services/place-code.service';
import { AreaOfFocus } from 'src/app/types/area-of-focus';
import { EapAction } from 'src/app/types/eap-action';
import { EventState } from 'src/app/types/event-state';
import { TriggeredArea } from 'src/app/types/triggered-area';

Expand All @@ -40,15 +41,14 @@ export class AreasOfFocusSummaryComponent implements OnInit, OnDestroy {
public country: Country;
public disasterType: DisasterType;
public countryDisasterSettings: CountryDisasterSettings;
public areasOfFocus: AreaOfFocus[];
public areasOfFocus: AreaOfFocus[] = AREAS_OF_FOCUS;
public triggeredAreas: TriggeredArea[];
public trigger: boolean;
public eventState: EventState;
public placeCode: PlaceCode;

constructor(
private eapActionsService: EapActionsService,
private apiService: ApiService,
public eventService: EventService,
private placeCodeService: PlaceCodeService,
private changeDetectorRef: ChangeDetectorRef,
Expand Down Expand Up @@ -116,22 +116,24 @@ export class AreasOfFocusSummaryComponent implements OnInit, OnDestroy {
this.calculateEAPActionStatus(this.triggeredAreas);
};

private onEachEAPAction = (areaOfFocus) => (action) => {
// And count the total # of (checked) tasks this way
if (areaOfFocus.id === action.aof) {
areaOfFocus.count += 1;
if (action.checked) {
areaOfFocus.countChecked += 1;
private onEachEAPAction =
(areaOfFocus: AreaOfFocus) => (action: EapAction) => {
// And count the total # of (checked) tasks this way
if (areaOfFocus.id === action.aof) {
areaOfFocus.count += 1;
if (action.checked) {
areaOfFocus.countChecked += 1;
}
}
}
};
};

private onEachTriggeredArea = (areaOfFocus) => (area) => {
// And at each action within the area ..
area.eapActions.forEach(this.onEachEAPAction(areaOfFocus));
};
private onEachTriggeredArea =
(areaOfFocus: AreaOfFocus) => (area: TriggeredArea) => {
// And at each action within the area ..
area.eapActions.forEach(this.onEachEAPAction(areaOfFocus));
};

private calculateEAPActionStatus(triggeredAreas): void {
private calculateEAPActionStatus(triggeredAreas: TriggeredArea[]): void {
if (this.placeCode) {
triggeredAreas = triggeredAreas.filter(
(a) => a.placeCode === this.placeCode?.placeCode,
Expand All @@ -144,21 +146,12 @@ export class AreasOfFocusSummaryComponent implements OnInit, OnDestroy {
triggeredAreas.forEach(this.onEachTriggeredArea(areaOfFocus));
};

const onAreasOfFocusChange = (areasOfFocus: AreaOfFocus[]) => {
this.areasOfFocus = areasOfFocus;

// Start calculation only when last area has eapActions attached to it
if (triggeredAreas[triggeredAreas.length - 1]?.eapActions) {
// For each area of focus ..
this.areasOfFocus.forEach(onEachAreaOfFocus);
}
this.changeDetectorRef.detectChanges();
};

// Get areas of focus from db
if (triggeredAreas.length) {
this.apiService.getAreasOfFocus().subscribe(onAreasOfFocusChange);
// Start calculation only when last area has eapActions attached to it
if (triggeredAreas[triggeredAreas.length - 1]?.eapActions) {
// For each area of focus ..
this.areasOfFocus.forEach(onEachAreaOfFocus);
}
this.changeDetectorRef.detectChanges();
}

private onEventStateChange = (eventState: EventState) => {
Expand Down Expand Up @@ -191,7 +184,7 @@ export class AreasOfFocusSummaryComponent implements OnInit, OnDestroy {
component: this.constructor.name,
});

popover.present();
void popover.present();
}

public showAreasOfFocusSummary(): boolean {
Expand Down
54 changes: 54 additions & 0 deletions interfaces/IBF-dashboard/src/app/models/area-of-focus.const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { AreaOfFocus } from 'src/app/types/area-of-focus';

// ##TODO: exact same const as in back-end. Is this good practice? Better than via endpoint.
export const AREAS_OF_FOCUS: AreaOfFocus[] = [
{
id: 'drr',
label: 'Disaster Risk Reduction',
description:
'(DRR) is a systematic approach to identifying, assessing and reducing the risks of disaster.<br><br>It aims to reduce socio-economic vulnerabilities to disaster as well as dealing with the environmental and other hazards that trigger them.',
icon: 'Disaster risk reduction.svg',
},
{
id: 'shelter',
label: 'Shelter',
description:
'Shelter and Non-Food Items includes provision of shelter materials and non-food household item packages.<br><br>The theme also covers Camp Coordination and Camp Management.<br><br>Long-term/permanent reconstruction/rebuilding of housing is not covered by this area of focus.',
icon: 'Shelter.svg',
},
{
id: 'livelihood',
label: 'Livelihoods & Basic Needs',
description:
"Disasters can take a devastating toll on people's food security livelihoods and their basic needs.<br><br>They can increase people's socio-economic vulnerability and seriously impact their ability to recover, which in turn affects their ability to cope with future shocks and stresses.<br><br>These actions are aimed at protecting these needs as preparation for forecasted hazards.",
icon: 'Livelihood.svg',
},
{
id: 'health',
label: 'Health',
description:
'Health includes emergency medical services, equipment and supplies; reproductive health; psycho-social support; mobile medical clinics; and disease control and surveillance.',
icon: 'Health.svg',
},
{
id: 'wash',
label: 'WASH',
description:
'Water, Sanitation, and Hygiene includes emergency provision of safe drinking water, hygiene and sanitation services, environmental sanitation and water supply, as well as hygiene promotion campaigns.',
icon: 'Water-Sanitation-and-Hygiene.svg',
},
{
id: 'inclusion',
label: 'Protection, Gender and Inclusion',
description:
"People affected by disasters can have very different experiences.<br>A person's sex, gender identity, age, physical ability, race, nationality and many other factors can influence how they are vulnerable to, and affected by disasters, conflicts and crises. They can also affect how they respond and recover.<br><br>Emergencies can also make existing inequalities worse. This can be seen in the increase in incidences of sexual and gender-based violence (SGBV), violence against children and trafficking in human beings during and after emergencies.<br><ul><li><strong>Protection</strong> - addressing violence and keeping people safe from harm</li><li><strong>Gender and diversity</strong> - addressing discrimination and understanding people's different needs, risks and capacities</li><li><strong>Inclusion</strong> - actively addressing exclusion by meaningfully involving and engaging excluded people in our work</li></ul>",
icon: 'Gender.svg',
},
{
id: 'migration',
label: 'Migration',
description:
'Migration and displacement pose some of the biggest humanitarian challenges of our time.<br><br>These actions are aimed at supporting people on the move with saving lives and preventing suffering, help people cope with the risks and challenges of migration and work to protect and restore their dignity.',
icon: 'Internally-displaced.svg',
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ApiService } from 'src/app/services/api.service';
import { DisasterTypeService } from 'src/app/services/disaster-type.service';
import { DisasterTypeKey } from 'src/app/types/disaster-type-key';

type ActivationLogRecord = Record<string, boolean | number | string>;
export type ActivationLogRecord = Record<string, boolean | number | string>;

@Component({
selector: 'app-activation-log',
Expand Down Expand Up @@ -89,15 +89,15 @@ export class ActivationLogPage implements OnInit, OnDestroy {
this.presentToast(
this.translate.instant(
'activation-page.' + this.getEapKey() + '.copy-success',
),
) as string,
'ibf-primary',
),
)
.catch(() =>
this.presentToast(
this.translate.instant(
'activation-page.' + this.getEapKey() + '.copy-fail',
),
) as string,
'alert',
),
);
Expand Down
Loading
Loading