Skip to content

Commit

Permalink
Dashboard: Implement initial version of the app
Browse files Browse the repository at this point in the history
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
suutari-ai committed Feb 14, 2018
1 parent b9ca90f commit 1823f9e
Show file tree
Hide file tree
Showing 34 changed files with 1,790 additions and 68 deletions.
Empty file added dashboard/.indium
Empty file.
21 changes: 21 additions & 0 deletions dashboard/LICENSE
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.
35 changes: 34 additions & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,32 @@
"name": "parkkidash",
"version": "0.1.0",
"private": true,
"license": "MIT",
"dependencies": {
"axios": "^0.17.1",
"bootstrap": "^4.0.0",
"chart.js": "^2.7.1",
"chroma-js": "^1.3.4",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
"leaflet": "^1.3.1",
"lodash": "^4.17.4",
"moment": "^2.20.1",
"popper.js": "^1.12.9",
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-chartjs-2": "^2.7.0",
"react-datetime": "^2.10.3",
"react-dom": "^16.2.0",
"react-scripts-ts": "2.13.0"
"react-leaflet": "^1.8.0",
"react-redux": "^5.0.6",
"react-scripts-ts": "2.13.0",
"react-select": "^1.2.1",
"react-table": "^6.7.6",
"reactstrap": "^5.0.0-beta",
"redux": "^3.7.2",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.2.0"
},
"scripts": {
"start": "react-scripts-ts start",
Expand All @@ -14,10 +36,21 @@
"eject": "react-scripts-ts eject"
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/chart.js": "^2.7.6",
"@types/chroma-js": "^1.3.3",
"@types/jest": "^22.1.1",
"@types/leaflet": "^1.2.5",
"@types/lodash": "^4.14.98",
"@types/node": "^9.4.0",
"@types/react": "^16.0.35",
"@types/react-dom": "^16.0.3",
"@types/react-leaflet": "^1.1.4",
"@types/react-redux": "^5.0.14",
"@types/react-select": "^1.2.0",
"@types/react-table": "^6.7.2",
"@types/reactstrap": "^5.0.12",
"@types/redux-logger": "^3.0.5",
"typescript": "^2.6.2"
}
}
2 changes: 1 addition & 1 deletion dashboard/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>Parkkidash</title>
</head>
<body>
<noscript>
Expand Down
28 changes: 0 additions & 28 deletions dashboard/src/App.css

This file was deleted.

22 changes: 0 additions & 22 deletions dashboard/src/App.tsx

This file was deleted.

65 changes: 65 additions & 0 deletions dashboard/src/actions.ts
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;
66 changes: 66 additions & 0 deletions dashboard/src/api/index.ts
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;
60 changes: 60 additions & 0 deletions dashboard/src/api/types.ts
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;
}
12 changes: 12 additions & 0 deletions dashboard/src/components/CalendarContainer.d.ts
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> {
}
}
3 changes: 3 additions & 0 deletions dashboard/src/components/ParkingRegionsMap.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.leaflet-container {
min-height: 10rem;
}
Loading

0 comments on commit 1823f9e

Please sign in to comment.