Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes for visualize v3.0 feed #111

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions website/src/pages/Visualization.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ const transformRequest = (url = '', resourceType = '') => {
}

onMounted(() => {
// When specifying ?url=https://example.com/gbfs.json, start
// directly a validation
const url_query_param = new URL(location.href).searchParams.get('url')
if (url_query_param) {
set(url, url_query_param)
visualize()
}

const initialState = { lng: 2.349014, lat: 48.864716, zoom: 11 }

mapInstance = new Map({
Expand All @@ -72,7 +64,14 @@ onMounted(() => {

mapInstance.addControl(new NavigationControl())

populateData()
// When specifying ?url=https://example.com/gbfs.json, start
// directly a validation
const url_query_param = new URL(location.href).searchParams.get('url')

if (url_query_param) {
set(url, url_query_param)
return visualize()
}
})

onUnmounted(() => {
Expand Down Expand Up @@ -120,7 +119,7 @@ function updateURL() {
function dataFromArray(f) {
if (f?.body) {
if (Array.isArray(f.body)) {
return f.body[0].body?.data
return f.body.length && f.body[0].body?.data
} else {
return f.body.data
}
Expand All @@ -131,11 +130,13 @@ function dataFromArray(f) {

const vehicles = computed(() => {
if (get(result).length) {
const vehiclesFile = get(result).find(
(f) => f.file === 'free_bike_status.json'
const vehiclesFile = get(result).find((f) =>
['free_bike_status', 'vehicle_status'].includes(f.type)
)

return dataFromArray(vehiclesFile)?.bikes
const data = dataFromArray(vehiclesFile)

return data?.bikes || data?.vehicles
} else {
return null
}
Expand Down Expand Up @@ -166,7 +167,7 @@ const vehiclesCountByType = computed(() => {
const stations = computed(() => {
if (get(result).length) {
const stationsFile = get(result).find(
(f) => f.file === 'station_information.json'
(f) => f.type === 'station_information'
)

return dataFromArray(stationsFile)?.stations
Expand Down Expand Up @@ -201,9 +202,7 @@ const vehiclesInStations = computed(() => {

const vehicleTypes = computed(() => {
if (get(result)) {
const vehicleTypesFile = get(result).find(
(f) => f.file === 'vehicle_types.json'
)
const vehicleTypesFile = get(result).find((f) => f.type === 'vehicle_types')

return dataFromArray(vehicleTypesFile)?.vehicle_types
} else {
Expand Down
Loading