forked from City-of-Helsinki/parkkihubi
-
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.
Dashboard: Implement initial version of the app
Following features are currently implemented: * A Map showing parking regions (ParkingRegionMap) - Map shows usage of each region by a color from green to red - Map shows more info about a region by clicking a region - Regions can be selected by clicking them on the map * Region can be selected or deselected from a dropdown (RegionSelector) * Possibility to select a date and time of interest; by default uses the current time (TimeSelect) - Time updates automatically every 5 minutes There is also some static non-updating dummy UI components shown to demonstrate features that will be implemented in the future: * A table that will list currently active parkings * A bar diagram that will show histogram of the parking counts from last 24h (or whatever time range is selected) Layout is implemented with Bootstrap 4. Map is implemented using Leaflet. API communication is done with Axios.
- Loading branch information
1 parent
b9ca90f
commit 1823f9e
Showing
34 changed files
with
1,790 additions
and
68 deletions.
There are no files selected for viewing
Empty file.
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017-2018, City of Helsinki | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,65 @@ | ||
import { Moment } from 'moment'; | ||
|
||
import { RegionList, RegionStatsList } from './api/types'; | ||
import { MapViewport } from './components/types'; | ||
|
||
interface SetMapViewportAction { | ||
type: 'SET_MAP_VIEWPORT'; | ||
viewport: MapViewport; | ||
} | ||
export function setMapViewport(viewport: MapViewport): SetMapViewportAction { | ||
return {type: 'SET_MAP_VIEWPORT', viewport}; | ||
} | ||
|
||
interface SetDataTimeAction { | ||
type: 'SET_DATA_TIME'; | ||
time: Moment; | ||
} | ||
export function setDataTime(time: Moment): SetDataTimeAction { | ||
return {type: 'SET_DATA_TIME', time}; | ||
} | ||
|
||
interface SetAutoUpdateAction { | ||
type: 'SET_AUTO_UPDATE'; | ||
value: boolean; | ||
} | ||
export function setAutoUpdate(value: boolean): SetAutoUpdateAction { | ||
return {type: 'SET_AUTO_UPDATE', value}; | ||
} | ||
|
||
interface SetSelectedRegionAction { | ||
type: 'SET_SELECTED_REGION'; | ||
regionId: string|null; | ||
} | ||
export function setSelectedRegion(regionId: string|null): | ||
SetSelectedRegionAction { | ||
return {type: 'SET_SELECTED_REGION', regionId}; | ||
} | ||
|
||
interface ReceiveRegionStatsAction { | ||
type: 'RECEIVE_REGION_STATS'; | ||
data: RegionStatsList; | ||
time: Moment; | ||
} | ||
export function receiveRegionStats( | ||
data: RegionStatsList, | ||
time: Moment | ||
): ReceiveRegionStatsAction { | ||
return {type: 'RECEIVE_REGION_STATS', data, time}; | ||
} | ||
|
||
interface ReceiveRegionInfoAction { | ||
type: 'RECEIVE_REGION_INFO'; | ||
data: RegionList; | ||
} | ||
export function receiveRegionInfo(data: RegionList): ReceiveRegionInfoAction { | ||
return {type: 'RECEIVE_REGION_INFO', data}; | ||
} | ||
|
||
export type Action = | ||
SetMapViewportAction | | ||
SetDataTimeAction | | ||
SetAutoUpdateAction | | ||
SetSelectedRegionAction | | ||
ReceiveRegionStatsAction | | ||
ReceiveRegionInfoAction; |
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,66 @@ | ||
import * as axios from 'axios'; | ||
import { Moment } from 'moment'; | ||
|
||
import { RegionList, RegionStatsList } from './types'; | ||
|
||
interface SuccessCallback<T> { | ||
(response: axios.AxiosResponse<T>): void; | ||
} | ||
|
||
interface ErrorHandler { | ||
(error: axios.AxiosError): void; | ||
} | ||
|
||
export class Api { | ||
public endpoints = { | ||
regions: '/monitoring/v1/region/', | ||
regionStats: '/monitoring/v1/region_statistics/', | ||
}; | ||
|
||
private axios: axios.AxiosInstance; | ||
|
||
constructor(baseUrl?: string) { | ||
this.axios = axios.default.create({baseURL: baseUrl}); | ||
} | ||
|
||
setBaseUrl(baseUrl: string) { | ||
this.axios.defaults.baseURL = baseUrl; | ||
} | ||
|
||
fetchRegions( | ||
callback: SuccessCallback<RegionList>, | ||
errorHandler: ErrorHandler | ||
) { | ||
this._fetchAllPages(this.endpoints.regions, callback, errorHandler); | ||
} | ||
|
||
fetchRegionStats( | ||
time: Moment, | ||
callback: SuccessCallback<RegionStatsList>, | ||
errorHandler: ErrorHandler | ||
) { | ||
const timeParam = (time) ? '?time=' + time.toISOString() : ''; | ||
this._fetchAllPages(this.endpoints.regionStats + timeParam, | ||
callback, errorHandler); | ||
} | ||
|
||
private _fetchAllPages( | ||
url: string, | ||
callback: SuccessCallback<{}>, | ||
errorHandler: ErrorHandler | ||
) { | ||
this.axios.get(url) | ||
.then((response) => { | ||
callback(response); | ||
const nextUrl = response.data.next; | ||
if (nextUrl) { | ||
this._fetchAllPages(nextUrl, callback, errorHandler); | ||
} | ||
}) | ||
.catch(errorHandler); | ||
} | ||
} | ||
|
||
const api = new Api(); | ||
|
||
export default api; |
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,60 @@ | ||
import * as geojson from 'geojson'; | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// Primitive types | ||
|
||
type Url = string; | ||
type ParkingAreaId = string; | ||
type RegionId = string; | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// Helper interfaces | ||
|
||
interface PaginatedList { | ||
count: number; | ||
next: Url|null; | ||
previous: Url|null; | ||
} | ||
|
||
// Type of the Features returned by the API | ||
interface ApiFeature<I extends string, P> extends | ||
geojson.Feature<geojson.MultiPolygon, P> { | ||
type: 'Feature'; | ||
geometry: geojson.MultiPolygon; | ||
id: I; | ||
properties: P|null; | ||
} | ||
|
||
// Type of the Feature Collections returned by the API | ||
interface ApiFeatureCollection<I extends string, P> extends | ||
geojson.FeatureCollection<geojson.MultiPolygon, P> { | ||
type: 'FeatureCollection'; | ||
features: Array<ApiFeature<I, P>>; | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// Exported API interfaces | ||
|
||
export type Region = ApiFeature<RegionId, RegionProperties>; | ||
|
||
export interface RegionList extends | ||
ApiFeatureCollection<RegionId, RegionProperties>, | ||
PaginatedList { | ||
} | ||
|
||
export interface RegionProperties { | ||
name: string; | ||
capacity_estimate: number; | ||
area_km2: number; | ||
spots_per_km2: number; | ||
parking_areas: ParkingAreaId[]; | ||
} | ||
|
||
export interface RegionStatsList extends PaginatedList { | ||
results: RegionStats[]; | ||
} | ||
|
||
export interface RegionStats { | ||
id: RegionId; | ||
parking_count: number; | ||
} |
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,12 @@ | ||
declare module 'react-datetime/src/CalendarContainer' { | ||
import * as React from 'react'; | ||
|
||
interface Props { | ||
view: string; // 'years'|'months'|'days'|'time'; | ||
viewProps: any; | ||
onClickOutside: () => void; | ||
} | ||
|
||
export default class CalendarContainer extends React.Component<Props> { | ||
} | ||
} |
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,3 @@ | ||
.leaflet-container { | ||
min-height: 10rem; | ||
} |
Oops, something went wrong.