Skip to content

Commit

Permalink
Merge branch 'master' into 3096-fix-edit-validator
Browse files Browse the repository at this point in the history
  • Loading branch information
shanshanhsieh committed Mar 16, 2022
2 parents 4d82e5d + 72f2fdd commit 8e0cca8
Show file tree
Hide file tree
Showing 28 changed files with 1,823 additions and 1,974 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ module.exports = {
'plugin:react/jsx-runtime',
'plugin:prettier/recommended',
],
parser: 'babel-eslint',
parser: '@babel/eslint-parser',
parserOptions: {
sourceType: 'module',
requireConfigFile: false,
babelOptions: {
presets: ['@babel/preset-react'],
},
},
env: {
browser: true,
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@
}
},
"devDependencies": {
"@babel/core": "^7.15.5",
"@babel/core": "^7.17.7",
"@babel/eslint-parser": "^7.17.0",
"@babel/preset-react": "^7.14.5",
"@electron-forge/cli": "^6.0.0-beta.61",
"@electron-forge/cli": "^6.0.0-beta.63",
"@electron-forge/maker-deb": "^6.0.0-beta.61",
"@electron-forge/maker-rpm": "^6.0.0-beta.61",
"@electron-forge/maker-squirrel": "^6.0.0-beta.61",
"@electron-forge/maker-zip": "^6.0.0-beta.61",
"@electron-forge/plugin-webpack": "6.0.0-beta.61",
"@electron-forge/maker-zip": "^6.0.0-beta.63",
"@electron-forge/plugin-webpack": "6.0.0-beta.63",
"@vercel/webpack-asset-relocator-loader": "1.7.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.2",
"copy-webpack-plugin": "^9.0.1",
"css-loader": "^6.0.0",
"electron": "15.1.0",
"eslint": "^7.32.0",
"electron": "17.1.2",
"eslint": "^8.11.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.26.1",
Expand All @@ -78,16 +78,16 @@
"style-loader": "^3.0.0"
},
"dependencies": {
"@ant-design/compatible": "^1.0.8",
"@ant-design/compatible": "^1.1.0",
"@ant-design/icons": "^4.7.0",
"@babel/polyfill": "^7.8.3",
"@handsontable/react": "^3.1.2",
"@turf/turf": "^6.5.0",
"antd": "^4.0.0",
"axios": "0.25.0",
"antd": "^4.19.2",
"axios": "0.26.1",
"color-interpolate": "^1.0.5",
"connected-react-router": "^6.5.2",
"deck.gl": "7",
"electron-log": "^4.4.3",
"electron-squirrel-startup": "^1.0.0",
"frameless-titlebar": "^2.1.4",
"handsontable": "6",
Expand Down
40 changes: 23 additions & 17 deletions src/main/ceaProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { app, dialog } from 'electron';
let cea;
let timeout;
let interval;
let startupError = '';

export function createCEAProcess(url, BrowserWindow, callback) {
console.log(`createCEAProcess(${url})`);
Expand All @@ -28,24 +29,27 @@ export function createCEAProcess(url, BrowserWindow, callback) {
cea = require('child_process').spawn('cmd.exe', ['/c', scriptPath]);
}

cea.stdout.on('data', function (data) {
console.log(data.toString('utf8'));
});
if (cea) {
// Attach cea output to console
cea.stdout.on('data', function (data) {
console.log(data.toString('utf8').trim());
});

cea.stderr.on('data', function (data) {
console.log(data.toString('utf8'));
});
cea.stderr.on('data', function (data) {
console.error(data.toString('utf8').trim());
});

// Show Error message box when CEA encounters any error on startup
let startupError = '';
cea.stderr.on('data', saveStartupError);
cea.on('exit', showStartupError);
// Show Error message box when CEA encounters any error on startup
cea.stderr.on('data', saveStartupError);
cea.on('exit', showStartupError);
}

function saveStartupError(message) {
startupError += message.toString('utf8');
}

function showStartupError() {
dialog.showMessageBox(BrowserWindow, {
dialog.showMessageBoxSync(BrowserWindow, {
type: 'error',
title: 'CEA Error',
message: 'CEA has encounted an error on startup',
Expand All @@ -57,8 +61,10 @@ export function createCEAProcess(url, BrowserWindow, callback) {

checkCEAStarted(url, () => {
// Remove Error message box listener after successful startup
cea.stderr.removeListener('data', saveStartupError);
cea.removeListener('exit', showStartupError);
if (cea) {
cea.stderr.removeListener('data', saveStartupError);
cea.removeListener('exit', showStartupError);
}
callback();
});

Expand All @@ -76,18 +82,18 @@ export function killCEAProcess() {
}

export async function isCEAAlive(url) {
console.log(`isCEAAlive(${url})`);
console.debug(`isCEAAlive(${url})`);
try {
const resp = await axios.get(`${url}/server/alive`);
return resp.status == 200;
} catch (error) {
console.log(error.response || 'No Response');
console.error(error.response || 'No Response');
return false;
}
}

function checkCEAStarted(url, callback) {
console.log(`checkCEAStarted(${url})`);
console.debug(`checkCEAStarted(${url})`);
const runCallbackOnce = (() => {
let executed = false;
return () => {
Expand All @@ -100,7 +106,7 @@ function checkCEAStarted(url, callback) {

// Check every 1 seconds
var bound_url = url;
console.log(`checkCEAStarted(bound_url=${bound_url})`);
console.debug(`checkCEAStarted(bound_url=${bound_url})`);
interval = setInterval(async () => {
const alive = await isCEAAlive(bound_url);
if (alive) {
Expand Down
15 changes: 13 additions & 2 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ import axios from 'axios';
import ini from 'ini';
import os from 'os';
import fs from 'fs';
import log from 'electron-log';

// Setup logging
process.env.LOG_PATH = path.join(app.getPath('logs'), 'console.log');
log.transports.file.resolvePath = () => {
return process.env.LOG_PATH;
};
const mainLog = log.scope('main');
console.log = mainLog.log;
console.debug = mainLog.debug;
console.error = mainLog.error;

const isDevelopment = process.env.NODE_ENV !== 'production';

Expand Down Expand Up @@ -184,9 +195,9 @@ app.on('will-quit', (event) => {
const shutdown = async () => {
try {
const resp = await axios.post(`${CEA_URL}/server/shutdown`);
console.log(resp);
console.log(resp?.data);
} catch (error) {
console.log(error);
console.error(error);
}
app.exit();
};
Expand Down
8 changes: 5 additions & 3 deletions src/renderer/actions/inputEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const setSelected = (selected) => ({
export const fetchInputData = () =>
httpAction({ url: '/inputs/all-inputs', type: REQUEST_INPUTDATA });

export const saveChanges = () => (dispatch, getState) => {
export const saveChanges = () => async (dispatch, getState) => {
dispatch({ type: SAVE_INPUTDATA });

const { tables, geojsons, crs, schedules } = getState().inputData;
Expand All @@ -56,10 +56,12 @@ export const saveChanges = () => (dispatch, getState) => {
})
.catch((error) => {
const errorPayload = error?.response || error?.request || error;
console.error(errorPayload);
dispatch({
type: SAVE_INPUTDATA_FAILED,
payload: errorPayload,
});
throw errorPayload;
});
};

Expand Down Expand Up @@ -156,7 +158,7 @@ export const fetchMapData = () => {
axios
.get(`${process.env.CEA_URL}${inputEndpoints[type]}`)
.catch((error) => {
console.log(error.response.data);
console.error(error.response.data);
})
);
return axios
Expand All @@ -173,6 +175,6 @@ export const fetchMapData = () => {
payload: { geojsons: data, isFetchingMapData: false },
});
})
.catch((error) => console.log(error));
.catch((error) => console.error(error));
};
};
6 changes: 3 additions & 3 deletions src/renderer/components/Dashboard/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const useDashboardData = () => {
const resp = await axios.get(`${process.env.CEA_URL}/api/dashboards/`);
setDashboards(resp.data);
} catch (error) {
console.log(error);
console.error(error);
}
};
const fetchCategories = async () => {
Expand All @@ -204,7 +204,7 @@ const useDashboardData = () => {
);
setCategories(resp.data);
} catch (error) {
console.log(error);
console.error(error);
}
};

Expand Down Expand Up @@ -266,7 +266,7 @@ export const usePlotDependencies = () => {
mountNodes(...dependency, scriptPromises)
);
// eslint-disable-next-line
Promise.all(scriptPromises).then(values => {
Promise.all(scriptPromises).then((values) => {
// Return true only once all scripts have been loaded
setIsMounted(true);
});
Expand Down
18 changes: 9 additions & 9 deletions src/renderer/components/Dashboard/Modals.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const ModalNewDashboard = ({
})
.catch((error) => {
setConfirmLoading(false);
console.log(error.response);
console.error(error.response);
});
}
});
Expand Down Expand Up @@ -151,7 +151,7 @@ export const ModalDuplicateDashboard = ({
})
.catch((error) => {
setConfirmLoading(false);
console.log(error.response);
console.error(error.response);
});
}
});
Expand Down Expand Up @@ -304,7 +304,7 @@ export const ModalDeleteDashboard = ({
})
.catch((error) => {
setConfirmLoading(false);
console.log(error.response);
console.error(error.response);
});
};

Expand Down Expand Up @@ -356,7 +356,7 @@ const ModalAddPlotTemplate = ({
console.log(params.data);
setParameters(params.data);
} catch (error) {
console.log(error);
console.error(error);
}
};

Expand All @@ -380,7 +380,7 @@ const ModalAddPlotTemplate = ({
})
.catch((error) => {
setConfirmLoading(false);
console.log(error.response);
console.error(error.response);
});
}
});
Expand Down Expand Up @@ -551,7 +551,7 @@ export const ModalEditParameters = ({
console.log(params.data);
setParameters(params.data);
} catch (error) {
console.log(error);
console.error(error);
}
};

Expand All @@ -575,7 +575,7 @@ export const ModalEditParameters = ({
})
.catch((error) => {
setConfirmLoading(false);
console.log(error.response);
console.error(error.response);
});
}
});
Expand Down Expand Up @@ -661,7 +661,7 @@ export const ModalDeletePlot = ({
})
.catch((error) => {
setConfirmLoading(false);
console.log(error.response);
console.error(error.response);
});
};

Expand Down Expand Up @@ -773,7 +773,7 @@ export const ModalPlotFiles = ({ dashIndex, activePlotRef }) => {
data: groupFilesOnParent(data.data),
});
} catch (err) {
console.log(err);
console.error(err);
} finally {
setLoading(false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/DatabaseEditor/DatabaseEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const SaveDatabaseButton = () => {
setSuccess(true);
dispatch(resetDatabaseChanges());
} catch (err) {
console.log(err.response);
console.error(err.response);
setError(err.response);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const ExportDatabaseModal = ({ visible, setVisible }) => {
});
message.success('Database succesfully exported');
} catch (err) {
console.log(err.response);
console.error(err.response);
setConfirmLoading(false);
message.config({
top: 120,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/HomePage/SearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const useGlossaryData = () => {
const result = await axios.get(`${process.env.CEA_URL}/api/glossary`);
setData(result.data);
} catch (error) {
console.log(error);
console.error(error);
}
};
getSearchResults();
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/InputEditor/InputEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const InputTable = () => {
const [tab, setTab] = useState('zone');

if (typeof tables == 'undefined') return null;
console.log(tables);
console.debug(tables);
const TabPanes = [...Object.keys(tables), 'schedules'].map((key) => (
<Tabs.TabPane key={key} tab={key} />
));
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/InputEditor/ScheduleEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const ScheduleEditor = ({ selected, schedules, tabulator }) => {
timeoutRef.current = setTimeout(() => {
dispatch(fetchBuildingSchedule(missingSchedules))
.catch((error) => {
console.log(error);
console.error(error);
setErrors(error);
})
.finally(() => {
Expand Down Expand Up @@ -412,7 +412,7 @@ const getScheduleTypes = (schedules) => {
try {
return Object.keys(schedules[buildings[0]].SCHEDULES);
} catch (error) {
console.log(error);
console.error(error);
return [];
}
};
Expand Down
Loading

0 comments on commit 8e0cca8

Please sign in to comment.