-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from dataforgoodfr/ctiss-dashboard-call-backend
feat: Display backend data on Dashboard page
- Loading branch information
Showing
10 changed files
with
226 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
NEXT_PUBLIC_MAPTILER_TO=3IWed9ZbNv0p8UVD6Ogv | ||
NEXT_PUBLIC_DOMAIN=http://localhost:3000 | ||
|
||
NEXT_PUBLIC_BACKEND_BASE_URL=http://localhost:8000 | ||
NEXT_PUBLIC_BACKEND_BASE_URL=http://localhost:8000/api/v1 | ||
NEXT_PUBLIC_BACKEND_API_KEY=bloom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
import { Temporal } from '@js-temporal/polyfill'; | ||
|
||
export function convertDurationInHours(durationPattern: string): number { | ||
const duration = Temporal.Duration.from(durationPattern); | ||
const durationHours = duration.total({ relativeTo: Temporal.Now.plainDateISO(), unit: "hours"}) | ||
return ~~durationHours; // round without decimals | ||
} | ||
|
||
// format date like: 2023-07-15T17:16:27 | ||
export function format(date: Date) { | ||
return ( | ||
[ | ||
date.getFullYear(), | ||
padTwoDigits(date.getMonth() + 1), | ||
padTwoDigits(date.getDate()), | ||
].join("-") + | ||
"T" + | ||
[ | ||
padTwoDigits(date.getHours()), | ||
padTwoDigits(date.getMinutes()), | ||
padTwoDigits(date.getSeconds()), | ||
].join(":") | ||
); | ||
} | ||
|
||
function padTwoDigits(num: number) { | ||
return num.toString().padStart(2, "0"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Item } from "@/types/item"; | ||
import { VesselTrackingTimeDto } from "@/types/vessel"; | ||
import { ZoneVisitTimeDto } from "@/types/zone"; | ||
|
||
import { convertDurationInHours } from "@/libs/dateUtils"; | ||
|
||
export function convertVesselDtoToItem(vesselDtos: VesselTrackingTimeDto[]): Item[] { | ||
return vesselDtos?.map((vesselDto: VesselTrackingTimeDto) => { | ||
return { | ||
id: `${vesselDto.vessel_id}`, | ||
title: vesselDto.vessel_ship_name, | ||
description: `IMO ${vesselDto.vessel_imo} / MMSI ${vesselDto.vessel_mmsi} / ${vesselDto.vessel_length} mètres`, | ||
value: `${convertDurationInHours(vesselDto.total_time_at_sea)}h`, | ||
type: "vessel" | ||
} | ||
}); | ||
} | ||
|
||
export function convertZoneDtoToItem(zoneDtos: ZoneVisitTimeDto[]): Item[] { | ||
return zoneDtos?.map((zoneDto: ZoneVisitTimeDto) => { | ||
return { | ||
id: `${zoneDto.zone_id}`, | ||
title: zoneDto.zone_name, | ||
description: zoneDto.zone_sub_category, | ||
value: `${convertDurationInHours(zoneDto.visiting_duration)}h`, | ||
type: "amp" | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
export type ZoneVisitTimeDto = { | ||
zone_id: number; | ||
zone_category: string; | ||
zone_sub_category: string; | ||
zone_name: string; | ||
visiting_duration: string; | ||
} |