feat: adjust map popup

This commit is contained in:
dancingCycle 2022-09-26 19:56:30 +02:00
parent 1dd8d7921c
commit 48044b9e0b
2 changed files with 34 additions and 3 deletions

View File

@ -1,16 +1,21 @@
import React from 'react';
import PropTypes from 'prop-types';
import {Popup} from 'react-leaflet';
import seconds2dmhs from '../../utils/seconds2dhms';
const PopupMsg = ({index,message,ptByIfleet}) => {
const vehicleAge=seconds2dmhs(Math.round(((Date.now()-message.tsMsgCreationVehicle*1000)/1000).toFixed(0)));
const itcsAge=seconds2dmhs(Math.round(((Date.now()-message.tsMsgCreationItcs*1000)/1000).toFixed(0)));
const clientAge=seconds2dmhs(Math.round(((Date.now()-message.tsMsgReception*1000)/1000).toFixed(0)));
return (
<>
<Popup
index={index}>
id: {message.id} <br/>
vehicle id: {message.vehicleId} <br/>
ts creation vehicle: {message.tsMsgCreationVehicle} <br/>
ts creation ITCS: {message.tsMsgCreationItcs} <br/>
ts reception client; {message.tsMsgReception} <br/>
creation time at vehicle: ts:{message.tsMsgCreationVehicle}, age:{vehicleAge} <br/>
creation time at ITCS: ts:{message.tsMsgCreationItcs}, age:{itcsAge} <br/>
reception time at client: ts:{message.tsMsgReception}, age:{clientAge} <br/>
trip id: {ptByIfleet.trip_id} <br/>
trip name: {ptByIfleet.trip_short_name} <br/>
trip destination: {ptByIfleet.trip_headsign} <br/>

26
app/utils/seconds2dhms.js Normal file
View File

@ -0,0 +1,26 @@
function seconds2dhms (seconds) {
seconds = Number(seconds);
var d = Math.floor(seconds / (3600 * 24));
var h = Math.floor((seconds % (3600 * 24)) / 3600);
var m = Math.floor((seconds % 3600) / 60);
var s = Math.floor(seconds % 60);
/*var dDisplay = d > 0 ? d + (d === 1 ? ' day, ' : ' days, ') : '';
var hDisplay = h > 0 ? h + (h === 1 ? ' hour, ' : ' hours, ') : '';
var mDisplay = m > 0 ? m + (m === 1 ? ' minute, ' : ' minutes, ') : '';
var sDisplay = s > 0 ? s + (s === 1 ? ' second' : ' seconds') : '';*/
var dDisplay = d > 0 ? d + 'd, ' : '';
var hDisplay = h > 0 ? h + 'h, ' : '';
var mDisplay = m > 0 ? m + 'm, ' : '';
var sDisplay = s > 0 ? s + 's' : '';
/*return without trailing commas*/
return (dDisplay + hDisplay + mDisplay + sDisplay).replace(/,\s*$/, '');
}
export default seconds2dhms;