Skip to content

Commit

Permalink
front: display simulation results in stdcm
Browse files Browse the repository at this point in the history
  • Loading branch information
Akctarus committed Jun 25, 2024
1 parent 24485e2 commit 027c61d
Show file tree
Hide file tree
Showing 11 changed files with 503 additions and 16 deletions.
6 changes: 6 additions & 0 deletions front/public/locales/en/stdcm-simulation-report-sheet.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
"conventionalSign": "conv. sign",
"convoy": "convoy",
"crossedATE": "crossed ATE",
"displayAll": "Display all operational points",
"displayMain": "Display main operational points",
"downloadSimulationSheet": "Download simulation report sheet",
"endStop": "end",
"for": "for",
"formattedDate": "{{year}}/{{month}}/{{day}} at {{hours}}:{{minutes}}",
"from": "from",
"gesicoRequest":"and attach this document to your GESICO DSDM request.",
"maxLength": "max. length",
"maxSpeed": "max. speed",
"maxWeight": "max. weight",
Expand All @@ -21,8 +25,10 @@
"requestedRoute": "requested route",
"scheduledArrival": "scheduled arrival at",
"scheduledDeparture": "scheduled departure at",
"selectThisSimulation": "Select this simulation",
"serviceStop": "Service stop",
"simulation": "Simulation",
"simulationSelected": "You have selected this simulation",
"speedLimitByTag": "speed limit by tag",
"startStop": "start",
"stdcm": "ST DCM",
Expand Down
1 change: 1 addition & 0 deletions front/public/locales/en/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"consist": "Consist",
"tractionEngine": "Traction engine"
},
"formattedCreationDate": "{{month}}/{{day}}/{{year}} {{hours}}:{{minutes}}",
"loaderImageLegend": "The TGV Nord line",
"notificationTitle": "Phase 1: from D-7 to D-1 5pm, on the Perrigny-Miramas axis.",
"pleaseWait": "Please wait…",
Expand Down
6 changes: 6 additions & 0 deletions front/public/locales/fr/stdcm-simulation-report-sheet.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
"conventionalSign": "signe conv.",
"convoy": "convoi",
"crossedATE": "ATE croisé",
"displayAll": "Afficher tous les jalons",
"displayMain": "Afficher les jalons principaux",
"downloadSimulationSheet": "Télécharger la fiche de simulation",
"endStop": "arrivée",
"for": "pour",
"formattedDate": "le {{day}}/{{month}}/{{year}} à {{hours}}:{{minutes}}",
"from": "du",
"gesicoRequest":"et joignez ce document à votre demande GESICO DSDM",
"maxLength": "longueur max.",
"maxSpeed": "vitesse max.",
"maxWeight": "tonnage max.",
Expand All @@ -21,8 +25,10 @@
"requestedRoute": "parcours demandé",
"scheduledArrival": "arrivée prévue à",
"scheduledDeparture": "départ prévu à",
"selectThisSimulation": "Retenir cette simulation",
"serviceStop": "Arrêt de service",
"simulation": "Simulation",
"simulationSelected": "Vous avez retenu cette simulation",
"speedLimitByTag": "code de composition",
"startStop":"départ",
"stdcm": "ST DCM",
Expand Down
1 change: 1 addition & 0 deletions front/public/locales/fr/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"consist": "Convoi",
"tractionEngine": "Engin de traction"
},
"formattedCreationDate": "{{day}}/{{month}}/{{year}} {{hours}}:{{minutes}}",
"loaderImageLegend": "La ligne TGV Nord",
"notificationTitle": "Phase 1 : de J-7 à J-1 17h, sur l’axe Perrigny—Miramas.",
"pleaseWait": "Veuillez patientez…",
Expand Down
6 changes: 5 additions & 1 deletion front/src/applications/stdcm/views/StdcmConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ const StdcmConfig = ({
: 'stdcm-map-noSimulation'
}`}
>
<Map setMapCanvas={setMapCanvas} pathProperties={pathProperties} />
<Map
setMapCanvas={setMapCanvas}
pathProperties={pathProperties}
currentStdcmRequestStatus={currentStdcmRequestStatus}
/>
</div>
)}
</div>
Expand Down
6 changes: 3 additions & 3 deletions front/src/applications/stdcm/views/StdcmResultsV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type StcdmResultsProps = {
creationDate?: Date;
};

const codeNumber = generateCodeNumber();
const simulationReportSheetNumber = generateCodeNumber();

// TODO TS2 : Adapt StdcmResult to trainSchedule v2 (SpaceTimeChart and SpeedSpaceChart)

Expand All @@ -46,12 +46,12 @@ const StcdmResultsV2 = ({
pathProperties={pathProperties}
rollingStockData={rollingStockData}
speedLimitByTag={speedLimitByTag}
simulationReportSheetNumber={codeNumber}
simulationReportSheetNumber={simulationReportSheetNumber}
mapCanvas={mapCanvas}
creationDate={creationDate}
/>
}
fileName={`STDCM-${codeNumber}.pdf`}
fileName={`STDCM-${simulationReportSheetNumber}.pdf`}
>
{t('stdcm:stdcmSimulationReport')}
</PDFDownloadLink>
Expand Down
81 changes: 81 additions & 0 deletions front/src/applications/stdcmV2/components/StdcmResults.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React, { useState } from 'react';

import { CheckCircle } from '@osrd-project/ui-icons';
import { useTranslation } from 'react-i18next';

import type { ManageTrainSchedulePathProperties } from 'applications/operationalStudies/types';
import type { StdcmV2SuccessResponse } from 'applications/stdcm/types';
import { generateCodeNumber } from 'applications/stdcm/utils';
import type { RollingStockWithLiveries } from 'common/api/osrdEditoastApi';
import { Map } from 'modules/trainschedule/components/ManageTrainSchedule';
import { formatDateToString } from 'utils/date';

import StdcmTableResults from './StdcmTableResults';

type StcdmResultsV2Props = {
stdcmData: StdcmV2SuccessResponse;
pathProperties?: ManageTrainSchedulePathProperties;
rollingStockData: RollingStockWithLiveries;
speedLimitByTag?: string;
currentStdcmRequestStatus?: string;
creationDate?: Date;
};

const StcdmViewResultsV2 = ({
stdcmData,
pathProperties,
rollingStockData,
speedLimitByTag,
currentStdcmRequestStatus,
creationDate,
}: StcdmResultsV2Props) => {
const { t } = useTranslation('stdcm');
const date = creationDate && t('formattedCreationDate', formatDateToString(creationDate));

const [isSimulationSelected, setIsSimulationSelected] = useState(false);

const [mapCanvas, setMapCanvas] = useState<string>();

const simulationReportSheetNumber = generateCodeNumber();

return (
<main className="stdcm-v2-results">
<div className="simuation-banner">
<div
className="simulation-validated"
style={{ color: isSimulationSelected ? '#0B723C' : '' }}
>
Simulation n°1
{isSimulationSelected && (
<div className="check-circle">
<CheckCircle variant="fill" />
</div>
)}
</div>
<div className="creation-date">{date}</div>
</div>
<div className="simuation-results">
<StdcmTableResults
stdcmData={stdcmData}
pathProperties={pathProperties}
rollingStockData={rollingStockData}
speedLimitByTag={speedLimitByTag}
creationDate={creationDate}
simulationReportSheetNumber={simulationReportSheetNumber}
setIsSimulationSelected={setIsSimulationSelected}
mapCanvas={mapCanvas}
/>
<div className="osrd-config-item-container osrd-config-item-container-map map-results">
<Map
hideAttribution
setMapCanvas={setMapCanvas}
pathProperties={pathProperties}
currentStdcmRequestStatus={currentStdcmRequestStatus}
/>
</div>
</div>
</main>
);
};

export default StcdmViewResultsV2;
161 changes: 161 additions & 0 deletions front/src/applications/stdcmV2/components/StdcmTableResults.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import React, { useState } from 'react';

import { Button } from '@osrd-project/ui-core';
import { PDFDownloadLink } from '@react-pdf/renderer';
import { useTranslation } from 'react-i18next';

import type { ManageTrainSchedulePathProperties } from 'applications/operationalStudies/types';
import SimulationReportSheetV2 from 'applications/stdcm/components/SimulationReportSheetV2';
import type { SimulationReportSheetProps, StdcmV2SuccessResponse } from 'applications/stdcm/types';
import { getOperationalPointsWithTimes } from 'applications/stdcm/utils';
import type { RollingStockWithLiveries } from 'common/api/osrdEditoastApi';

type SimulationTableProps = {
stdcmData: StdcmV2SuccessResponse;
pathProperties?: ManageTrainSchedulePathProperties;
rollingStockData: RollingStockWithLiveries;
speedLimitByTag?: string;
creationDate?: Date;
simulationReportSheetNumber: string;
mapCanvas?: string;
setIsSimulationSelected?: (simulationSelected: boolean) => void;
};

const StcdmTableResults = ({
stdcmData,
pathProperties,
rollingStockData,
speedLimitByTag,
creationDate,
simulationReportSheetNumber,
mapCanvas,
setIsSimulationSelected,
}: SimulationTableProps) => {
const { t } = useTranslation('stdcm-simulation-report-sheet');

const simulationReport: SimulationReportSheetProps = {
stdcmData,
pathProperties,
rollingStockData,
simulationReportSheetNumber,
speedLimitByTag,
creationDate,
};

const opList = getOperationalPointsWithTimes(simulationReport);

const [showAllPR, setShowAllPR] = useState(false);

const [isSimulation, setIsSimulation] = useState(false);

const handleSimulationClick = () => {
if (setIsSimulationSelected) {
setIsSimulation(true);
setIsSimulationSelected(true);
}
};

const handleShowAllClick = () => {
setShowAllPR((prevState) => !prevState);
};

return (
<div className="table-container">
<table className="table-results">
<thead>
<th aria-label="line-count" />
<th>{t('operationalPoint')}</th>
<th>{t('code')}</th>
<th>{t('endStop')}</th>
<th>{t('passageStop')}</th>
<th>{t('startStop')}</th>
<th className="weight">{t('weight')}</th>
<th>{t('refEngine')}</th>
</thead>
<tbody className="table-results">
{opList.map((step, index) => {
const isFirstStep = index === 0;
const isLastStep = index === opList.length - 1;
const prevStep = opList[index - 1];
const shouldRenderRow = isFirstStep || /* step.stop > '0' || */ isLastStep;
if (showAllPR || shouldRenderRow) {
return (
<tr key={index}>
<td
className="index"
style={{ fontWeight: isFirstStep || isLastStep ? 600 : 'normal' }}
>
{index + 1}
</td>
<td>
{!isFirstStep && !isLastStep && step.name === prevStep.name
? '='
: step.name || 'Unknown'}
</td>
<td className="ch">{step.ch}</td>
<td className="stop">{isLastStep ? step.time : ''}</td>
<td className="stop">{isFirstStep || isLastStep ? '' : step.time}</td>
<td className="stop">{isFirstStep ? step.departureTime : ''}</td>
<td className="weight" style={{ color: isLastStep ? '#797671' : '#312E2B' }}>
{!isFirstStep && !isLastStep
? '='
: `${Math.floor(rollingStockData.mass / 1000)} t`}
</td>
<td style={{ color: isLastStep ? '#797671' : '#312E2B' }}>
{!isFirstStep && !isLastStep ? '=' : rollingStockData.metadata?.reference}
</td>
</tr>
);
}
return null;
})}
</tbody>
</table>
<div className="display-all">
<div className="button-display-all-PR">
<Button
variant="Normal"
label={showAllPR ? t('displayMain') : t('displayAll')}
onClick={handleShowAllClick}
/>
</div>
<div className="button-get-simulation">
{!isSimulation ? (
<Button
label={t('selectThisSimulation')}
onClick={handleSimulationClick}
isDisabled={isSimulation}
/>
) : (
<div className="selected-simulation">{t('simulationSelected')}</div>
)}
</div>
</div>
{isSimulation && (
<div className="get-simulation">
<div className="download-simulation">
<PDFDownloadLink
document={
<SimulationReportSheetV2
stdcmData={stdcmData}
pathProperties={pathProperties}
rollingStockData={rollingStockData}
speedLimitByTag={speedLimitByTag}
simulationReportSheetNumber={simulationReportSheetNumber}
mapCanvas={mapCanvas}
creationDate={creationDate}
/>
}
fileName={`STDCM-${simulationReportSheetNumber}.pdf`}
>
<Button label={t('downloadSimulationSheet')} />
</PDFDownloadLink>
</div>
<div className="gesico-text">{t('gesicoRequest')}</div>
</div>
)}
</div>
);
};

export default StcdmTableResults;
Loading

0 comments on commit 027c61d

Please sign in to comment.