Skip to content

Commit

Permalink
Merge pull request #297 from OpenEnergyDashboard/development
Browse files Browse the repository at this point in the history
Update master to 0.3.0
  • Loading branch information
johndiiorio authored Feb 13, 2018
2 parents 28001d3 + a60f1b3 commit c404da6
Show file tree
Hide file tree
Showing 94 changed files with 3,426 additions and 944 deletions.
1,550 changes: 1,204 additions & 346 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "Open-Energy-Dashboard",
"version": "0.2.0",
"version": "0.3.0",
"private": false,
"license": "MPL-2.0",
"scripts": {
"start": "node ./src/bin/www",
"dev": "webpack -d --watch --color --progress",
"build": "cross-env NODE_ENV=production webpack -p",
"checkHeader": "./src/scripts/checkHeader.sh",
"lint": "./node_modules/.bin/eslint src/client/app/**/*.js src/client/app/**/*.jsx src/server/**/*.js src/server/**/*.jsx",
"lint": "./node_modules/.bin/eslint src/client/app/**/*.js src/client/app/**/*.jsx src/server/**/*.js src/server/*.js",
"test": "./node_modules/.bin/mocha \"src/server/test/**/*.js\"",
"createdb": "node ./src/server/services/createDB.js",
"addMamacMeters": "node ./src/server/services/addMamacMeters.js",
Expand All @@ -25,6 +25,7 @@
"babel-preset-react": "~6.24.1",
"bcryptjs": "~2.4.3",
"body-parser": "~1.15.1",
"bootstrap": "~4.0.0",
"chart.js": "~2.7.0",
"chartjs-plugin-datalabels": "~0.1.0",
"cookie-parser": "~1.4.3",
Expand All @@ -39,23 +40,26 @@
"lodash-webpack-plugin": "~0.11.4",
"moment": "~2.19.1",
"morgan": "~1.7.0",
"multer": "~1.3.0",
"nodemailer": "~2.6.4",
"pg-promise": "~5.9.7",
"prop-types": "~15.5.10",
"react": "~15.6.1",
"react-bootstrap": "~0.31.3",
"react-chartjs-2": "~2.6.2",
"react-dom": "~15.6.1",
"react-dropzone": "~4.2.3",
"react-notification-system": "~0.2.15",
"react-rangeslider": "~2.2.0",
"react-redux": "~5.0.6",
"react-router": "~3.0.5",
"react-select": "~1.0.0-rc.10",
"reactstrap": "~5.0.0-alpha.4",
"redux": "~3.7.2",
"redux-thunk": "~2.2.0",
"request": "~2.83.0",
"request-promise-native": "~1.0.5",
"serve-favicon": "~2.3.0",
"stream-buffers": "~3.0.1",
"webpack": "~3.7.1",
"xml2js": "~0.4.19"
},
Expand Down
8 changes: 4 additions & 4 deletions src/bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

const app = require('../server/app');
const http = require('http');
const log = require('../server/log');
const { log } = require('../server/log');

const serverPort = require('../server/config').serverPort;

Expand Down Expand Up @@ -66,11 +66,11 @@ function onError(error) {
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
log(`${bind} requires elevated privileges`, 'error', true);
log.error(`${bind} requires elevated privileges`);
process.exit(1);
break;
case 'EADDRINUSE':
log(`${bind} is already in use`, 'error', true);
log.error(`${bind} is already in use`);
process.exit(1);
break;
default:
Expand All @@ -87,7 +87,7 @@ function onListening() {
const bind = typeof addr === 'string'
? `pipe ${addr}`
: `port ${addr.port}`;
log(`Listening on ${bind}`);
log.info(`Listening on ${bind}`);
}


Expand Down
116 changes: 116 additions & 0 deletions src/client/app/actions/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import axios from 'axios';
import { changeBarStacking, changeChartToRender } from './graph';
import { showErrorNotification, showSuccessNotification } from '../utils/notifications';
import { getToken } from '../utils/token';

export const UPDATE_IMPORT_METER = 'UPDATE_IMPORT_METER';
export const UPDATE_DISPLAY_TITLE = 'UPDATE_DISPLAY_TITLE';
export const UPDATE_DEFAULT_CHART_TO_RENDER = 'UPDATE_DEFAULT_CHART_TO_RENDER';
export const TOGGLE_DEFAULT_BAR_STACKING = 'TOGGLE_DEFAULT_BAR_STACKING';
export const REQUEST_PREFERENCES = 'REQUEST_PREFERENCES';
export const RECEIVE_PREFERENCES = 'RECEIVE_PREFERENCES';
export const MARK_PREFERENCES_NOT_SUBMITTED = 'MARK_PREFERENCES_NOT_SUBMITTED';
export const MARK_PREFERENCES_SUBMITTED = 'MARK_PREFERENCES_SUBMITTED';

export function updateDisplayTitle(displayTitle) {
return { type: UPDATE_DISPLAY_TITLE, displayTitle };
}

export function updateDefaultChartToRender(defaultChartToRender) {
return { type: UPDATE_DEFAULT_CHART_TO_RENDER, defaultChartToRender };
}

export function toggleDefaultBarStacking() {
return { type: TOGGLE_DEFAULT_BAR_STACKING };
}

function requestPreferences() {
return { type: REQUEST_PREFERENCES };
}

function receivePreferences(data) {
return { type: RECEIVE_PREFERENCES, data };
}

function markPreferencesSubmitted() {
return { type: MARK_PREFERENCES_SUBMITTED };
}

function markPreferencesNotSubmitted() {
return { type: MARK_PREFERENCES_NOT_SUBMITTED };
}

function fetchPreferences() {
return (dispatch, getState) => {
dispatch(requestPreferences());
return axios.get('/api/preferences')
.then(response => {
dispatch(receivePreferences(response.data));
const state = getState();
if (!state.graph.hotlinked) {
dispatch(changeChartToRender(state.admin.defaultChartToRender));
if (response.data.defaultBarStacking !== state.graph.barStacking) {
dispatch(changeBarStacking());
}
}
});
};
}

function submitPreferences() {
return (dispatch, getState) => {
const state = getState();
dispatch(markPreferencesSubmitted());
return axios.post('/api/preferences',
{
token: getToken(),
preferences: {
displayTitle: state.admin.displayTitle,
defaultChartToRender: state.admin.defaultChartToRender,
defaultBarStacking: state.admin.defaultBarStacking
}
})
.then(() => {
showSuccessNotification('Updated preferences');
})
.catch(() => {
dispatch(markPreferencesNotSubmitted());
showErrorNotification('Failed to submit changes');
}
);
};
}

function shouldFetchPreferenceData(state) {
return !state.admin.isFetching;
}

function shouldSubmitPreferenceData(state) {
return !state.admin.submitted;
}

export function fetchPreferencesIfNeeded() {
return (dispatch, getState) => {
if (shouldFetchPreferenceData(getState())) {
return dispatch(fetchPreferences());
}
return Promise.resolve();
};
}

export function submitPreferencesIfNeeded() {
return (dispatch, getState) => {
if (shouldSubmitPreferenceData(getState())) {
return dispatch(submitPreferences());
}
return Promise.resolve();
};
}

export function updateSelectedMeter(meterID) {
return { type: UPDATE_IMPORT_METER, meterID };
}
6 changes: 3 additions & 3 deletions src/client/app/actions/barReadings.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function fetchCompareReadings(meterIDs, timeInterval) {
dispatch(requestMeterBarReadings(meterIDs, timeInterval, compareDuration));
const stringifiedMeterIDs = meterIDs.join(',');
return axios.get(`/api/readings/bar/meters/${stringifiedMeterIDs}`, {
params: { timeInterval: timeInterval.toString(), barDuration: compareDuration.toISOString() }
params: { timeInterval: timeInterval, barDuration: compareDuration.toISOString() }
}).then(response => dispatch(receiveMeterBarReadings(meterIDs, timeInterval, compareDuration, response.data)));
};
}
Expand All @@ -133,11 +133,11 @@ function fetchGroupCompareReadings(groupIDs, timeInterval) {
return (dispatch, getState) => {
const compareDuration = getState().graph.compareDuration;
dispatch(requestGroupBarReadings(groupIDs, timeInterval, compareDuration));
// API expectes a comma-seperated string of IDs
// API expects a comma-separated string of IDs
const stringifiedIDs = groupIDs.join(',');

return axios.get(`/api/readings/bar/groups/${stringifiedIDs}`, {
params: { timeInterval: timeInterval.toString(), barDuration: compareDuration.toISOString() }
params: { timeInterval: timeInterval, barDuration: compareDuration.toISOString() }
}).then(response => dispatch(receiveGroupBarReadings(groupIDs, timeInterval, compareDuration, response.data)));
};
}
Expand Down
27 changes: 26 additions & 1 deletion src/client/app/actions/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export const UPDATE_BAR_DURATION = 'UPDATE_BAR_DURATION';
export const CHANGE_CHART_TO_RENDER = 'CHANGE_CHART_TO_RENDER';
export const CHANGE_BAR_STACKING = 'CHANGE_BAR_STACKING';
export const CHANGE_GRAPH_ZOOM = 'CHANGE_GRAPH_ZOOM';
export const UPDATE_COMPARE_INTERVAL = 'UPDATE_COMPARE_INTERVAL';
export const UPDATE_COMPARE_DURATION = 'UPDATE_COMPARE_DURATION';
export const TOGGLE_HOTLINKED = 'TOGGLE_HOTLINKED';


function toggleHotlinked() {
return { type: 'TOGGLE_HOTLINKED' };
}

/**
* @param {string} chartType is one of chartTypes
Expand Down Expand Up @@ -48,6 +56,23 @@ export function changeBarDuration(barDuration) {
};
}

function updateCompareTimeInterval(compareTimeInterval) {
return { type: UPDATE_COMPARE_INTERVAL, compareTimeInterval };
}

function updateCompareDuration(compareDuration) {
return { type: UPDATE_COMPARE_DURATION, compareDuration };
}

export function changeCompareTimeInterval(compareTimeInterval, compareDuration) {
return (dispatch, getState) => {
dispatch(updateCompareTimeInterval(compareTimeInterval));
dispatch(updateCompareDuration(compareDuration));
dispatch(fetchNeededCompareReadings(getState().graph.compareTimeInterval));
return Promise.resolve();
};
}

export function changeSelectedMeters(meterIDs) {
return (dispatch, getState) => {
dispatch(updateSelectedMeters(meterIDs));
Expand Down Expand Up @@ -104,7 +129,7 @@ export function changeGraphZoomIfNeeded(timeInterval) {
* @returns {function(*)}
*/
export function changeOptionsFromLink(options) {
const dispatchFirst = [];
const dispatchFirst = [toggleHotlinked()];
const dispatchSecond = [];
if (options.meterIDs) {
dispatchFirst.push(fetchMetersDetailsIfNeeded());
Expand Down
19 changes: 13 additions & 6 deletions src/client/app/actions/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/

import axios from 'axios';
import getToken from '../utils/getToken';
import { getToken } from '../utils/token';
import { showErrorNotification } from '../utils/notifications';

// View and fetching actions
export const REQUEST_GROUPS_DETAILS = 'REQUEST_GROUPS_DETAILS';
Expand Down Expand Up @@ -277,9 +278,9 @@ function submitNewGroup(group) {
dispatch2(changeDisplayMode(DISPLAY_MODE.VIEW));
});
})
.catch(error => {
.catch(() => {
dispatch(markGroupInEditingNotSubmitted());
console.error(error);
showErrorNotification('Failed to create a new group');
});
};
}
Expand All @@ -296,9 +297,13 @@ function submitGroupEdits(group) {
dispatch2(changeDisplayMode(DISPLAY_MODE.VIEW));
});
})
.catch(error => {
.catch(e => {
dispatch(markGroupInEditingNotSubmitted());
console.error(error);
if (e.response.data.message && e.response.data.message === 'Cyclic group detected') {
showErrorNotification('You cannot create a cyclic group');
} else {
showErrorNotification('Failed to edit group');
}
});
};
}
Expand Down Expand Up @@ -354,6 +359,8 @@ export function deleteGroup() {
dispatch2(changeDisplayMode('view'));
});
})
.catch(console.error);
.catch(() => {
showErrorNotification('Failed to delete group');
});
};
}
2 changes: 1 addition & 1 deletion src/client/app/actions/meters.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function fetchMetersDetails() {
}

/**
* @param {State} state
* @param {State} Redux state
*/
function shouldFetchMetersDetails(state) {
return !state.meters.isFetching && state.meters.meters === undefined;
Expand Down
Loading

0 comments on commit c404da6

Please sign in to comment.