Skip to content

Commit

Permalink
Merge pull request #1679 from rodekruis/fix.filter-area-list-exposed-…
Browse files Browse the repository at this point in the history
…only

Fix.filter area list exposed only
  • Loading branch information
jannisvisser authored Nov 4, 2024
2 parents 5d28207 + 17fb63a commit 3579792
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,19 @@
@if (
filteredStoppedAreas.length === 0 && filteredActiveAreas.length === 0
) {
@if (activeAreas.length) {
<app-event-speech-bubble
[type]="'active'"
[event]="event"
[selectedEvent]="eventState?.event?.eventName"
[disasterTypeLabel]="disasterType?.label"
[disasterTypeName]="disasterType?.disasterType"
[clearOutMessage]="getClearOutMessage(event)"
[countryCodeISO3]="country?.countryCodeISO3"
[areas]="activeAreas"
[adminAreaLabelPlural]="adminAreaLabelPlural"
[actionIndicatorLabel]="actionIndicatorLabel"
[actionIndicatorNumberFormat]="actionIndicatorNumberFormat"
></app-event-speech-bubble>
}
<app-event-speech-bubble
[type]="'active'"
[event]="event"
[selectedEvent]="eventState?.event?.eventName"
[disasterTypeLabel]="disasterType?.label"
[disasterTypeName]="disasterType?.disasterType"
[clearOutMessage]="getClearOutMessage(event)"
[countryCodeISO3]="country?.countryCodeISO3"
[areas]="activeAreas"
[adminAreaLabelPlural]="adminAreaLabelPlural"
[actionIndicatorLabel]="actionIndicatorLabel"
[actionIndicatorNumberFormat]="actionIndicatorNumberFormat"
></app-event-speech-bubble>
@if (stoppedAreas.length) {
<app-event-speech-bubble
[type]="'stopped'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,35 +133,33 @@
>
}
</p>
@if (event.affectedAreas) {
<p>
<strong
>{{
'chat-component.' + disasterTypeName + '.alertLevel.exposed-areas'
| translate: { adminAreaLabelPlural: adminAreaLabelPlural }
}}
</strong>
<span>{{ event.affectedAreas + ' ' }}</span>
@if (event.thresholdReached) {
<span>{{
<p>
<strong
>{{
'chat-component.' + disasterTypeName + '.alertLevel.exposed-areas'
| translate: { adminAreaLabelPlural: adminAreaLabelPlural }
}}
</strong>
<span>{{ event.nrAffectedAreas + ' ' }}</span>
@if (event.thresholdReached) {
<span>{{
'(' +
(actionIndicatorLabel | titlecase) +
' ' +
(event.actionsValueSum | compact) +
')'
}}</span>
} @else {
<span>
{{
'(' +
(actionIndicatorLabel | titlecase) +
' ' +
(event.actionsValueSum | compact) +
('chat-component.' + disasterTypeName + '.alertLevel.no-data'
| translate) +
')'
}}</span>
} @else {
<span>
{{
'(' +
('chat-component.' + disasterTypeName + '.alertLevel.no-data'
| translate) +
')'
}}
</span>
}
</p>
}
}}
</span>
}
</p>
}

@if (typhoonLandfallText) {
Expand Down Expand Up @@ -208,29 +206,27 @@
"
></p>
}
@for (class of alertClasses; track class.alertClass) {
<div>
<ul class="list-inside list-disc text-xs">
@for (area of class.areas; track area.eventPlaceCodeId) {
<li
class="my-1 cursor-pointer hover:underline"
(click)="selectArea(area)"
>
{{ area.name }}
@if (area.nameParent) {
<span>({{ area.nameParent }})</span>
}
@if (area.actionsValue && area.actionsValue > 0) {
{{ ' - ' }}
<span>{{
area.actionsValue | compact: actionIndicatorNumberFormat
}}</span>
}
</li>
}
</ul>
</div>
}
<div>
<ul class="list-inside list-disc text-xs">
@for (area of areas; track area.eventPlaceCodeId) {
<li
class="my-1 cursor-pointer hover:underline"
(click)="selectArea(area)"
>
{{ area.name }}
@if (area.nameParent) {
<span>({{ area.nameParent }})</span>
}
@if (area.actionsValue && area.actionsValue > 0) {
{{ ' - ' }}
<span>{{
area.actionsValue | compact: actionIndicatorNumberFormat
}}</span>
}
</li>
}
</ul>
</div>
@if (event.thresholdReached) {
<p
[translate]="
Expand Down Expand Up @@ -261,32 +257,25 @@
}
"
></p>
@for (class of alertClasses; track class.alertClass) {
<div>
@if (class.alertClass !== 'undefined') {
<p class="ion-padding-top">
<strong>{{ class.alertClass }}</strong>
</p>
<div>
<ul class="list-inside list-disc text-xs">
@for (area of areas; track area.eventPlaceCodeId) {
<li
class="my-1 cursor-pointer hover:underline"
(click)="selectArea(area)"
>
{{ area.name }}
@if (area.nameParent) {
<span>({{ area.nameParent }})</span>
}
-
<span>{{
area.actionsValue | compact: actionIndicatorNumberFormat
}}</span>
</li>
}
<ul class="list-inside list-disc text-xs">
@for (area of class.areas; track area.eventPlaceCodeId) {
<li
class="my-1 cursor-pointer hover:underline"
(click)="selectArea(area)"
>
{{ area.name }}
@if (area.nameParent) {
<span>({{ area.nameParent }})</span>
}
-
<span>{{
area.actionsValue | compact: actionIndicatorNumberFormat
}}</span>
</li>
}
</ul>
</div>
}
</ul>
</div>
<p
[translate]="
'chat-component.' + disasterTypeName + '.stopped-event.instruction'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class EventSpeechBubbleComponent implements AfterViewChecked, OnDestroy {
public isStopped: boolean;
private placeCodeHoverSubscription: Subscription;
public placeCodeHover: PlaceCode;
public alertClasses: { alertClass: string; areas: TriggeredArea[] }[];

constructor(
private authService: AuthService,
Expand All @@ -71,8 +70,6 @@ export class EventSpeechBubbleComponent implements AfterViewChecked, OnDestroy {
this.displayName = this.authService.displayName;
}

this.alertClasses = this.splitAreasByAlertClass(this.areas);

this.placeCodeHoverSubscription = this.placeCodeService
.getPlaceCodeHoverSubscription()
.subscribe(this.onPlaceCodeHoverChange);
Expand All @@ -88,24 +85,6 @@ export class EventSpeechBubbleComponent implements AfterViewChecked, OnDestroy {
this.placeCodeHoverSubscription.unsubscribe();
}

public splitAreasByAlertClass(
areas: TriggeredArea[] = [],
): { alertClass: string; areas: TriggeredArea[] }[] {
const areasByAlertClass = {};

for (const area of areas) {
if (!areasByAlertClass[area.alertClass]) {
areasByAlertClass[area.alertClass] = [];
}
areasByAlertClass[area.alertClass].push(area);
}

return Object.keys(areasByAlertClass).map((alertClass) => ({
alertClass: alertClass,
areas: areasByAlertClass[alertClass],
}));
}

public selectArea(area) {
this.adminLevelService.zoomInAdminLevel();
this.placeCodeService.setPlaceCode({
Expand Down
15 changes: 0 additions & 15 deletions interfaces/IBF-dashboard/src/app/services/eap-actions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,6 @@ export class EapActionsService {
};

private mapTriggerValueToAlertClass = (triggeredArea: TriggeredArea) => {
// If no match is found, then no alertClass will be shown
if (this.countryDisasterSettings.eapAlertClasses) {
for (const alertClass of Object.keys(
this.countryDisasterSettings.eapAlertClasses,
)) {
if (
triggeredArea.triggerValue ===
this.countryDisasterSettings.eapAlertClasses[alertClass].value
) {
triggeredArea.alertClass =
this.countryDisasterSettings.eapAlertClasses[alertClass].label;
}
}
}

if (triggeredArea.triggerValue === 1) {
triggeredArea.alertLabel = AlertLabel.trigger;
} else if (triggeredArea.triggerValue > 0) {
Expand Down
2 changes: 1 addition & 1 deletion interfaces/IBF-dashboard/src/app/services/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class EventSummary {
duration?: number;
disasterSpecificProperties: DisasterSpecificProperties;
header?: string;
affectedAreas?: number;
nrAffectedAreas?: number;
actionsValueSum?: number;
}

Expand Down
1 change: 0 additions & 1 deletion interfaces/IBF-dashboard/src/app/types/triggered-area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export class TriggeredArea {
stopped: boolean;
stoppedDate: string;
submitDisabled: boolean;
alertClass?: string;
alertLabel?: AlertLabel;
}

Expand Down
15 changes: 5 additions & 10 deletions services/API-service/src/api/event/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class EventService {
'to_char(MIN("startDate") , \'yyyy-mm-dd\') AS "startDate"',
'to_char(MAX("endDate") , \'yyyy-mm-dd\') AS "endDate"',
'MAX(event."thresholdReached"::int)::boolean AS "thresholdReached"',
'count(event."adminAreaId")::int AS "affectedAreas"',
'SUM(CASE WHEN event."actionsValue" > 0 OR event."triggerValue" > 0 THEN 1 ELSE 0 END) AS "nrAffectedAreas"', // This count is needed here, because the portal also needs the count of other events when in event view, which it cannot get any more from the triggeredAreas array length, which is then filtered on selected event only
'MAX(event."triggerValue")::float AS "triggerValue"',
'sum(event."actionsValue")::int AS "actionsValueSum"',
])
Expand Down Expand Up @@ -354,7 +354,7 @@ export class EventService {
if (eventName) {
whereFiltersEvent['eventName'] = eventName;
}
const triggeredAreasQuery = this.eventPlaceCodeRepo
const triggeredAreas = await this.eventPlaceCodeRepo
.createQueryBuilder('event')
.select([
'area."placeCode" AS "placeCode"',
Expand All @@ -380,14 +380,9 @@ export class EventService {
.andWhere('area."countryCodeISO3" = :countryCodeISO3', {
countryCodeISO3: countryCodeISO3,
})
.orderBy('event."actionsValue"', 'DESC');

if (triggeredPlaceCodes.length) {
triggeredAreasQuery.andWhere('area."placeCode" IN(:...placeCodes)', {
placeCodes: triggeredPlaceCodes,
});
}
const triggeredAreas = await triggeredAreasQuery.getRawMany();
.andWhere('(event."actionsValue" > 0 OR event."triggerValue" > 0)')
.orderBy('event."actionsValue"', 'DESC')
.getRawMany();

for (const area of triggeredAreas) {
if (triggeredPlaceCodes.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,17 @@ const getMjmlEventAdminAreaTable = ({
},
});

const adminAreaList = event.triggeredAreas
.filter(({ actionsValue }) => actionsValue)
.map((triggeredArea) => {
return {
exposed: toCompactNumber(
triggeredArea.actionsValue,
indicatorMetadata.numberFormatMap,
),
name: `${triggeredArea.name} ${
triggeredArea.nameParent ? `(${triggeredArea.nameParent})` : ''
}`,
};
});
const adminAreaList = event.triggeredAreas.map((triggeredArea) => {
return {
exposed: toCompactNumber(
triggeredArea.actionsValue,
indicatorMetadata.numberFormatMap,
),
name: `${triggeredArea.name} ${
triggeredArea.nameParent ? `(${triggeredArea.nameParent})` : ''
}`,
};
});

const adminAreaTable = getAdminAreaTable({
adminAreaList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,7 @@ export class NotificationContentService {
disasterType,
event,
);
data.nrOfTriggeredAreas = await this.getNrOfTriggeredAreas(
data.triggeredAreas,
data.triggerStatusLabel,
disasterType,
);
data.nrOfTriggeredAreas = data.triggeredAreas.length;
// This looks weird, but as far as I understand the startDate of the event is the day it was first issued
data.issuedDate = new Date(event.startDate);
data.firstLeadTimeString = await this.getFirstLeadTimeString(
Expand All @@ -204,28 +200,6 @@ export class NotificationContentService {
return data;
}

private async getNrOfTriggeredAreas(
triggeredAreas: TriggeredArea[],
statusLabel: TriggerStatusLabelEnum,
disasterType: DisasterType,
): Promise<number> {
// This filters out the areas that are affected by the event but do not have any affect action units
// Affected action units are for example people_affected, houses_affected, etc (differs per disaster type)
// We are not sure why this is done, but it is done in the original code
// For warning flood events this is not done, because there are no flood extens for warning events so we do not know any actions values
if (
disasterType === DisasterType.Floods &&
statusLabel === TriggerStatusLabelEnum.Warning
) {
return triggeredAreas.length;
} else {
const triggeredAreasWithoutActionValue = triggeredAreas.filter(
(a) => a.actionsValue > 0,
);
return triggeredAreasWithoutActionValue.length;
}
}

private async getSortedTriggeredAreas(
country: CountryEntity,
disasterType: DisasterType,
Expand Down
2 changes: 1 addition & 1 deletion services/API-service/src/shared/data.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,5 @@ export class EventSummaryCountry {
public triggerValue: number;

@ApiProperty({ example: 5 })
public affectedAreas: number;
public nrAffectedAreas: number;
}

0 comments on commit 3579792

Please sign in to comment.