|
| 1 | +export default { |
| 2 | + /** Format time for displaying : YYYYMMDDTHHMMSS -> HH:MM */ |
| 3 | + formatTime(dateTimeString) { |
| 4 | + if (!dateTimeString) return ''; |
| 5 | + return dateTimeString.substring(9, 11) + ':' + dateTimeString.substring(11, 13); |
| 6 | + }, |
| 7 | + |
| 8 | + /** Format duration for displaying : h / min */ |
| 9 | + formatDuration(seconds) { |
| 10 | + if (!seconds && seconds !== 0) return ''; |
| 11 | + const hours = Math.floor(seconds / 3600); |
| 12 | + const minutes = Math.floor((seconds % 3600) / 60); |
| 13 | + |
| 14 | + if (hours > 0) { |
| 15 | + return `${hours} h ${minutes > 0 ? minutes + ' min' : ''}`; |
| 16 | + } |
| 17 | + return `${minutes} min`; |
| 18 | + }, |
| 19 | + |
| 20 | + /** Gets icons according to the nature of the transport */ |
| 21 | + getTransportIcon(section) { |
| 22 | + if (!section.display_informations) return ''; |
| 23 | + |
| 24 | + const mode = section.display_informations.commercial_mode?.toLowerCase() || ''; |
| 25 | + if (mode.includes('bus')) return 'bus'; |
| 26 | + if (mode.includes('tram')) return 'tram'; |
| 27 | + if (mode.includes('métro') || mode.includes('metro')) return 'tram'; |
| 28 | + if (mode.includes('train')) return 'train'; |
| 29 | + if (mode.includes('car')) return 'bus'; |
| 30 | + |
| 31 | + return 'bus'; |
| 32 | + }, |
| 33 | + |
| 34 | + /** Manage different spellings of transports */ |
| 35 | + getTransportClass(section) { |
| 36 | + if (!section.display_informations) return ''; |
| 37 | + |
| 38 | + const mode = section.display_informations.commercial_mode?.toLowerCase() || ''; |
| 39 | + |
| 40 | + if (mode.includes('bus')) return 'bus'; |
| 41 | + if (mode.includes('tram')) return 'tram'; |
| 42 | + if (mode.includes('métro') || mode.includes('metro')) return 'tram'; |
| 43 | + if (mode.includes('train')) return 'train'; |
| 44 | + if (mode.includes('car')) return 'bus'; |
| 45 | + |
| 46 | + return 'bus'; |
| 47 | + }, |
| 48 | + |
| 49 | + /** Method to calculate distance in meters */ |
| 50 | + getDistance(section) { |
| 51 | + if (section.distance) { |
| 52 | + return Math.round(section.distance); |
| 53 | + } |
| 54 | + return section.path && section.path.length > 0 |
| 55 | + ? Math.round(section.path.reduce((acc, step) => acc + (step.length || 0), 0)) |
| 56 | + : 0; |
| 57 | + }, |
| 58 | + |
| 59 | + /** Method to get accessibility icons */ |
| 60 | + getAccessibilityIcon(section) { |
| 61 | + if (!section.display_informations || !section.display_informations.equipments) { |
| 62 | + return { |
| 63 | + bike: false, |
| 64 | + wheelchair: false, |
| 65 | + }; |
| 66 | + } |
| 67 | + |
| 68 | + return { |
| 69 | + bike: section.display_informations.equipments.includes('has_bike_accepted'), |
| 70 | + wheelchair: section.display_informations.equipments.includes('has_wheelchair'), |
| 71 | + }; |
| 72 | + }, |
| 73 | + |
| 74 | + /** Each route follows the same sequence of colors */ |
| 75 | + getRouteColor(section) { |
| 76 | + if (section.mode === 'walking') return '00008B'; |
| 77 | + if (section.type === 'public_transport' || section.type === 'on_demand_transport') { |
| 78 | + const color = section.display_informations?.color; |
| 79 | + return color === 'FFFFFF' ? '808080' : color || '808080'; |
| 80 | + } |
| 81 | + return '808080'; |
| 82 | + }, |
| 83 | + |
| 84 | + /** Creates the class based on color */ |
| 85 | + getTransportColorClass(section) { |
| 86 | + if (section.display_informations?.color) { |
| 87 | + return 'transport-color-' + section.display_informations.color.replace('#', ''); |
| 88 | + } |
| 89 | + return 'transport-color-default'; |
| 90 | + }, |
| 91 | + |
| 92 | + /** Formats the journey time in minutes and hours */ |
| 93 | + formatJourneyDuration(seconds) { |
| 94 | + if (!seconds && seconds !== 0) return ''; |
| 95 | + |
| 96 | + const hours = Math.floor(seconds / 3600); |
| 97 | + const minutes = Math.floor((seconds % 3600) / 60); |
| 98 | + |
| 99 | + if (hours > 0) { |
| 100 | + return `${hours}h${minutes.toString().padStart(2, '0')}`; |
| 101 | + } |
| 102 | + return `${minutes} min`; |
| 103 | + }, |
| 104 | + |
| 105 | + /** Get section duration directly when available, fallback to 0 */ |
| 106 | + calculateSectionDuration(section) { |
| 107 | + if (section.duration !== undefined && section.duration !== null) { |
| 108 | + return section.duration; |
| 109 | + } |
| 110 | + return 0; |
| 111 | + }, |
| 112 | +}; |
0 commit comments