-
Notifications
You must be signed in to change notification settings - Fork 2
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 #127 from OneBusAway/feature/schedule-visualization
Feature/schedule-visualization
- Loading branch information
Showing
17 changed files
with
538 additions
and
22 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
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
114 changes: 114 additions & 0 deletions
114
src/components/schedule-for-stop/ScheduleAccordionItem.svelte
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,114 @@ | ||
<script> | ||
import { createEventDispatcher } from 'svelte'; | ||
import { AccordionItem } from 'flowbite-svelte'; | ||
import { t } from 'svelte-i18n'; | ||
export let schedule; | ||
export let expanded; | ||
const dispatch = createEventDispatcher(); | ||
function handleToggle() { | ||
dispatch('toggle'); | ||
} | ||
function formatHour(hour) { | ||
const hourInt = +hour; | ||
if (hourInt === 0) return '12'; | ||
if (hourInt > 12) return hourInt - 12; | ||
return hourInt; | ||
} | ||
function renderScheduleTable(schedule) { | ||
const stopTimes = Object.entries(schedule.stopTimes); | ||
const amTimes = stopTimes.filter(([hour]) => +hour < 12); | ||
const pmTimes = stopTimes.filter(([hour]) => +hour >= 12); | ||
return { | ||
amTimes, | ||
pmTimes | ||
}; | ||
} | ||
function extractMinutes(arrivalTime) { | ||
return arrivalTime.replace(/[AP]M/, '').split(':')[1]; | ||
} | ||
</script> | ||
|
||
<AccordionItem open={expanded} on:click={handleToggle}> | ||
<span slot="header" class="text-lg font-semibold text-gray-800"> | ||
{schedule.tripHeadsign} | ||
</span> | ||
<div class="overflow-x-auto"> | ||
<table class="mt-4 w-full table-auto rounded-lg border border-gray-200 shadow-lg"> | ||
<thead class="bg-gray-100 text-gray-800"> | ||
<tr> | ||
<th class="cursor-pointer px-6 py-3 text-left">{$t('schedule_for_stop.hour')}</th> | ||
<th class="cursor-pointer px-6 py-3 text-left">{$t('schedule_for_stop.minutes')}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr class="bg-gray-50 hover:bg-gray-100"> | ||
<td colspan="2" class="px-6 py-3 font-semibold text-gray-700">AM</td> | ||
</tr> | ||
{#if renderScheduleTable(schedule).amTimes.length === 0} | ||
<tr> | ||
<td colspan="2" class="border px-6 py-3 text-center text-gray-500"> | ||
{$t('schedule_for_stop.no_am_schedules_available')} | ||
</td> | ||
</tr> | ||
{:else} | ||
{#each renderScheduleTable(schedule).amTimes as [hour, times]} | ||
<tr class="hover:bg-gray-100"> | ||
<td | ||
class="border px-6 py-3 text-center text-lg font-semibold" | ||
title="Full Time: {hour}:{extractMinutes(times[0].arrivalTime)}" | ||
> | ||
{formatHour(hour)} <span class="text-sm text-gray-600">AM</span> | ||
</td> | ||
<td class="border px-6 py-3 text-lg"> | ||
{#each times as stopTime, index (index)} | ||
<span> | ||
{extractMinutes(stopTime.arrivalTime)} | ||
{index < times.length - 1 ? ', ' : ''} | ||
</span> | ||
{/each} | ||
</td> | ||
</tr> | ||
{/each} | ||
{/if} | ||
|
||
<tr class="bg-gray-50 hover:bg-gray-100"> | ||
<td colspan="2" class="px-6 py-3 font-semibold text-gray-700">PM</td> | ||
</tr> | ||
{#if renderScheduleTable(schedule).pmTimes.length === 0} | ||
<tr> | ||
<td colspan="2" class="border px-6 py-3 text-center text-gray-500"> | ||
{$t('schedule_for_stop.no_pm_schedules_available')} | ||
</td> | ||
</tr> | ||
{:else} | ||
{#each renderScheduleTable(schedule).pmTimes as [hour, times]} | ||
<tr class="hover:bg-gray-100"> | ||
<td | ||
class="border px-6 py-3 text-center text-lg font-semibold" | ||
title="Full Time: {hour}:{extractMinutes(times[0].arrivalTime)}" | ||
> | ||
{formatHour(hour)} <span class="text-sm text-gray-600">PM</span> | ||
</td> | ||
<td class="border px-6 py-3 text-lg"> | ||
{#each times as stopTime, index (index)} | ||
<span> | ||
{extractMinutes(stopTime.arrivalTime)} | ||
{index < times.length - 1 ? ', ' : ''} | ||
</span> | ||
{/each} | ||
</td> | ||
</tr> | ||
{/each} | ||
{/if} | ||
</tbody> | ||
</table> | ||
</div> | ||
</AccordionItem> |
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,35 @@ | ||
<script> | ||
import { faBus, faMapMarkerAlt, faArrowRight } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/svelte-fontawesome'; | ||
import { t } from 'svelte-i18n'; | ||
export let stopName; | ||
export let stopId; | ||
export let stopDirection; | ||
</script> | ||
|
||
<div class="mb-6 rounded-lg bg-white p-6 text-center shadow-lg"> | ||
<h1 class="flex items-center justify-center gap-2 text-3xl font-bold text-green-700"> | ||
<FontAwesomeIcon icon={faBus} /> | ||
{$t('schedule_for_stop.stop_details')} | ||
</h1> | ||
<p class="mt-2 flex items-center justify-center gap-2 text-lg text-gray-700"> | ||
<FontAwesomeIcon icon={faMapMarkerAlt} /> | ||
<strong>{$t('schedule_for_stop.stop_name')}:</strong> | ||
{stopName} | <strong>{$t('schedule_for_stop.stop_id')}:</strong> | ||
{stopId} | ||
</p> | ||
<p class="mt-2 flex items-center justify-center gap-2 text-lg text-gray-700"> | ||
<FontAwesomeIcon icon={faArrowRight} /> | ||
<strong>{$t('schedule_for_stop.direction')}:</strong> | ||
{stopDirection} | ||
</p> | ||
<div class="mt-4 flex justify-center"> | ||
<a | ||
href={`/stops/${stopId}`} | ||
class="flex items-center justify-center gap-2 rounded-lg bg-green-500 px-3 py-1 text-white shadow hover:bg-green-600" | ||
> | ||
<FontAwesomeIcon icon={faMapMarkerAlt} /> | ||
{$t('schedule_for_stop.click_for_realtime')} | ||
</a> | ||
</div> | ||
</div> |
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 |
---|---|---|
@@ -1,15 +1,21 @@ | ||
import { init, register, getLocaleFromNavigator } from 'svelte-i18n'; | ||
|
||
register('en', () => import('./../locales/en.json')); // English | ||
register('es', () => import('./../locales/es.json')); // Spanish | ||
register('pl', () => import('./../locales/pl.json')); // Polish | ||
register('vi', () => import('./../locales/vi.json')); // Vietnamese | ||
register('tl', () => import('./../locales/tl.json')); // Tagalog | ||
register('so', () => import('./../locales/so.json')); // Somali | ||
register('am', () => import('./../locales/am.json')); // Amharic | ||
register('ar', () => import('./../locales/ar.json')); // Arabic | ||
async function setup() { | ||
register('en', () => import('./../locales/en.json')); // English | ||
register('es', () => import('./../locales/es.json')); // Spanish | ||
register('pl', () => import('./../locales/pl.json')); // Polish | ||
register('vi', () => import('./../locales/vi.json')); // Vietnamese | ||
register('tl', () => import('./../locales/tl.json')); // Tagalog | ||
register('so', () => import('./../locales/so.json')); // Somali | ||
register('am', () => import('./../locales/am.json')); // Amharic | ||
register('ar', () => import('./../locales/ar.json')); // Arabic | ||
|
||
init({ | ||
fallbackLocale: 'en', | ||
initialLocale: getLocaleFromNavigator() | ||
}); | ||
return await Promise.allSettled([ | ||
init({ | ||
fallbackLocale: 'en', | ||
initialLocale: getLocaleFromNavigator() | ||
}) | ||
]); | ||
} | ||
|
||
await setup(); |
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
Oops, something went wrong.