Admin is mostly working

This commit is contained in:
Luke Berndt
2021-01-04 22:22:39 -05:00
parent 0deadc385f
commit c8b4f02d06
158 changed files with 17683 additions and 3661 deletions

36
admin-old/.gitignore vendored Normal file
View File

@@ -0,0 +1,36 @@
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
lib
uploads/
# Dependency directory
node_modules
assets
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history

0
admin-old/README.md Normal file
View File

94
admin-old/package.json Normal file
View File

@@ -0,0 +1,94 @@
{
"name": "react-passport-redux-example",
"version": "1.0.0",
"description": "Demonstration of PassportJS authentication in React w/ Redux.",
"main": "devStart.js",
"scripts": {
"build:lib": "babel src/server --out-dir lib/server",
"build:umd": "webpack --config webpack/webpack.config.dev.js",
"build:umd:min": "webpack --config webpack/webpack.config.prod.js",
"build": "npm run clean && npm run build:lib && npm run build:umd && npm run build:umd:min",
"postinstall": "npm run build",
"clean": "rimraf lib public/assets",
"server": "better-npm-run server",
"server:dev": "better-npm-run server:dev",
"start": "npm run server",
"start:dev": "npm run server:dev"
},
"betterScripts": {
"server": {
"command": "node lib/server/index.js",
"env": {
"NODE_ENV": "production",
"MIN_EXT": ".min"
}
},
"server:dev": {
"command": "node devStart.js",
"env": {
"NODE_ENV": "development"
}
}
},
"dependencies": {
"@babel/runtime": "7.3.1",
"@vx/axis": "^0.0.184",
"@vx/curve": "^0.0.182",
"@vx/glyph": "^0.0.183",
"@vx/group": "^0.0.183",
"@vx/legend": "^0.0.183",
"@vx/mock-data": "^0.0.185",
"@vx/responsive": "0.0.184",
"@vx/scale": "0.0.182",
"@vx/shape": "0.0.184",
"@vx/tooltip": "0.0.184",
"axios": "^0.18.0",
"babel-loader": "8.0.5",
"bcrypt-nodejs": "^0.0.3",
"better-npm-run": "^0.1.0",
"body-parser": "^1.18.2",
"connect-mongo": "^2.0.1",
"connected-react-router": "6.3.1",
"csv-parse": "^4.3.3",
"d3-time-format": "^2.1.3",
"express": "^4.16.2",
"express-session": "^1.15.6",
"fs-extra": "^7.0.1",
"lodash": "4.17.11",
"mongoose": "^5.4",
"multer": "^1.3.0",
"node-mailjet": "*",
"node-uuid": "^1.4.8",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"react": "16.8.2",
"react-dom": "16.8.2",
"react-redux": "^6.0.0",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"redux": "^4.0.1",
"redux-thunk": "^2.2.0",
"semantic-ui-react": "^0.85.0"
},
"devDependencies": {
"@babel/cli": "7.2.3",
"@babel/core": "7.3.3",
"@babel/plugin-proposal-class-properties": "7.3.3",
"@babel/plugin-proposal-export-default-from": "7.2.0",
"@babel/plugin-proposal-object-rest-spread": "7.3.2",
"@babel/plugin-transform-runtime": "7.2.0",
"@babel/preset-env": "7.3.1",
"@babel/preset-react": "^7.0.0",
"@babel/preset-stage-1": "^7.0.0",
"@babel/register": "^7.0.0",
"babel-plugin-lodash": "3.3.4",
"detect-node": "2.0.4",
"redux-logger": "^3.0.6",
"rimraf": "2.6.3",
"uglifyjs-webpack-plugin": "2.1.1",
"webpack": "4.29.5",
"webpack-cli": "3.2.3",
"webpack-dev-middleware": "3.5.2",
"webpack-hot-middleware": "2.24.3"
}
}

4896
admin-old/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

12
admin/.env Normal file
View File

@@ -0,0 +1,12 @@
REACT_APP_BACKEND_SERVER=https://api.openmhz.com
REACT_APP_FRONTEND_SERVER=https://openmhz.com
REACT_APP_SOCKET_SERVER=wss://api.openmhz.com
REACT_APP_ACCOUNT_SERVER=https://account.openmhz.com
REACT_APP_ADMIN_SERVER=localhost:3000
REACT_APP_ADMIN_EMAIL=luke@robotastic.com
REACT_APP_SITE_NAME=OpenMHz
REACT_APP_ARCHIVE_DAYS=30
REACT_APP_PRO_PLAN=1
REACT_APP_FREE_PLAN=0
REACT_APP_PRO_PLAN_ARCHIVE=30
REACT_APP_FREE_PLAN_ARCHIVE=7

1
admin/.eslintcache Normal file

File diff suppressed because one or more lines are too long

59
admin/.gitignore vendored
View File

@@ -1,36 +1,23 @@
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
lib
uploads/
# Dependency directory
node_modules
assets
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

View File

@@ -0,0 +1,68 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app), using the [Redux](https://redux.js.org/) and [Redux Toolkit](https://redux-toolkit.js.org/) template.
## Available Scripts
In the project directory, you can run:
### `yarn start`
Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.<br />
You will also see any lint errors in the console.
### `yarn test`
Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `yarn build`
Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `yarn eject`
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
### Analyzing the Bundle Size
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
### Making a Progressive Web App
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
### Advanced Configuration
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
### Deployment
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
### `yarn build` fails to minify
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

12
admin/env-example Normal file
View File

@@ -0,0 +1,12 @@
REACT_APP_BACKEND_SERVER=https://api.openmhz.com
REACT_APP_FRONTEND_SERVER=https://openmhz.com
REACT_APP_SOCKET_SERVER=wss://api.openmhz.com
REACT_ACCOUNT_SERVER=https://account.openmhz.com
REACT_ADMIN_SERVER=https://admin.openmhz.com
REACT_ADMIN_EMAIL=luke@robotastic.com
REACT_APP_SITE_NAME=OpenMHz
REACT_APP_ARCHIVE_DAYS=30
REACT_APP_PRO_PLAN=1
REACT_APP_FREE_PLAN=0
REACT_APP_PRO_PLAN_ARCHIVE=30
REACT_APP_FREE_PLAN_ARCHIVE=7

10
admin/notes.md Normal file
View File

@@ -0,0 +1,10 @@
## Base
start using `npx create-react-app admin --template redux`
## Packages used:
- [connected-react-router](https://github.com/supasate/connected-react-router): Synchronize router state with redux store through
- [Redux Thunk](https://github.com/reduxjs/redux-thunk): lets you do AJAX calls
- [axios](https://github.com/axios/axios) - library for doing HTTP requests
- [react-router-dom](https://reactrouter.com/web/guides/quick-start) - Adds routes to React
- [Semantic UI](https://react.semantic-ui.com/usage) - The UI frontend

View File

@@ -1,94 +1,42 @@
{
"name": "react-passport-redux-example",
"version": "1.0.0",
"description": "Demonstration of PassportJS authentication in React w/ Redux.",
"main": "devStart.js",
"scripts": {
"build:lib": "babel src/server --out-dir lib/server",
"build:umd": "webpack --config webpack/webpack.config.dev.js",
"build:umd:min": "webpack --config webpack/webpack.config.prod.js",
"build": "npm run clean && npm run build:lib && npm run build:umd && npm run build:umd:min",
"postinstall": "npm run build",
"clean": "rimraf lib public/assets",
"server": "better-npm-run server",
"server:dev": "better-npm-run server:dev",
"start": "npm run server",
"start:dev": "npm run server:dev"
},
"betterScripts": {
"server": {
"command": "node lib/server/index.js",
"env": {
"NODE_ENV": "production",
"MIN_EXT": ".min"
}
},
"server:dev": {
"command": "node devStart.js",
"env": {
"NODE_ENV": "development"
}
}
},
"name": "admin",
"version": "0.1.0",
"private": true,
"dependencies": {
"@babel/runtime": "7.3.1",
"@vx/axis": "^0.0.184",
"@vx/curve": "^0.0.182",
"@vx/glyph": "^0.0.183",
"@vx/group": "^0.0.183",
"@vx/legend": "^0.0.183",
"@vx/mock-data": "^0.0.185",
"@vx/responsive": "0.0.184",
"@vx/scale": "0.0.182",
"@vx/shape": "0.0.184",
"@vx/tooltip": "0.0.184",
"axios": "^0.18.0",
"babel-loader": "8.0.5",
"bcrypt-nodejs": "^0.0.3",
"better-npm-run": "^0.1.0",
"body-parser": "^1.18.2",
"connect-mongo": "^2.0.1",
"connected-react-router": "6.3.1",
"csv-parse": "^4.3.3",
"d3-time-format": "^2.1.3",
"express": "^4.16.2",
"express-session": "^1.15.6",
"fs-extra": "^7.0.1",
"lodash": "4.17.11",
"mongoose": "^5.4",
"multer": "^1.3.0",
"node-mailjet": "*",
"node-uuid": "^1.4.8",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"react": "16.8.2",
"react-dom": "16.8.2",
"react-redux": "^6.0.0",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"redux": "^4.0.1",
"redux-thunk": "^2.2.0",
"semantic-ui-react": "^0.85.0"
"@reduxjs/toolkit": "^1.1.0",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"axios": "0.21.1",
"connected-react-router": "6.8.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-redux": "^7.1.3",
"react-router-dom": "5.2.0",
"react-scripts": "4.0.1",
"redux-thunk": "2.3.0",
"semantic-ui-css": "2.4.1",
"semantic-ui-react": "2.0.1"
},
"devDependencies": {
"@babel/cli": "7.2.3",
"@babel/core": "7.3.3",
"@babel/plugin-proposal-class-properties": "7.3.3",
"@babel/plugin-proposal-export-default-from": "7.2.0",
"@babel/plugin-proposal-object-rest-spread": "7.3.2",
"@babel/plugin-transform-runtime": "7.2.0",
"@babel/preset-env": "7.3.1",
"@babel/preset-react": "^7.0.0",
"@babel/preset-stage-1": "^7.0.0",
"@babel/register": "^7.0.0",
"babel-plugin-lodash": "3.3.4",
"detect-node": "2.0.4",
"redux-logger": "^3.0.6",
"rimraf": "2.6.3",
"uglifyjs-webpack-plugin": "2.1.1",
"webpack": "4.29.5",
"webpack-cli": "3.2.3",
"webpack-dev-middleware": "3.5.2",
"webpack-hot-middleware": "2.24.3"
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

BIN
admin/public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

43
admin/public/index.html Normal file
View File

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
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 Redux App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

BIN
admin/public/logo192.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
admin/public/logo512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

2
admin/public/robots.txt Normal file
View File

@@ -0,0 +1,2 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *

39
admin/src/App.css Normal file
View File

@@ -0,0 +1,39 @@
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-float infinite 3s ease-in-out;
}
}
.App-header {
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
}
.App-link {
color: rgb(112, 76, 182);
}
@keyframes App-logo-float {
0% {
transform: translateY(0);
}
50% {
transform: translateY(10px)
}
100% {
transform: translateY(0px)
}
}

58
admin/src/App.js Normal file
View File

@@ -0,0 +1,58 @@
import React from 'react';
import logo from './logo.svg';
import { Counter } from './features/counter/Counter';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<Counter />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<span>
<span>Learn </span>
<a
className="App-link"
href="https://reactjs.org/"
target="_blank"
rel="noopener noreferrer"
>
React
</a>
<span>, </span>
<a
className="App-link"
href="https://redux.js.org/"
target="_blank"
rel="noopener noreferrer"
>
Redux
</a>
<span>, </span>
<a
className="App-link"
href="https://redux-toolkit.js.org/"
target="_blank"
rel="noopener noreferrer"
>
Redux Toolkit
</a>
,<span> and </span>
<a
className="App-link"
href="https://react-redux.js.org/"
target="_blank"
rel="noopener noreferrer"
>
React Redux
</a>
</span>
</header>
</div>
);
}
export default App;

15
admin/src/App.test.js Normal file
View File

@@ -0,0 +1,15 @@
import React from 'react';
import { render } from '@testing-library/react';
import { Provider } from 'react-redux';
import store from './app/store';
import App from './App';
test('renders learn react link', () => {
const { getByText } = render(
<Provider store={store}>
<App />
</Provider>
);
expect(getByText(/learn/i)).toBeInTheDocument();
});

15
admin/src/App/App.js Normal file
View File

@@ -0,0 +1,15 @@
import React, { Component } from "react"
import NavigationContainer from "./NavigationContainer"
class App extends Component {
render() {
return(
<div>
<NavigationContainer />
{this.props.children}
</div>
)
}
}
export default App

View File

@@ -0,0 +1,55 @@
import React, { Component } from "react";
import { Link } from "react-router-dom";
import { Menu, Dropdown } from "semantic-ui-react";
const navStyle = {
marginBottom: "30px"
};
const blankStyle = {
marginBottom: "50px"
};
class Navigation extends Component {
constructor(props) {
super(props);
this._logout = this._logout.bind(this);
}
_logout = event => {
event.preventDefault();
this.props.manualLogout();
};
render() {
var profileLink = process.env.REACT_APP_ACCOUNT_SERVER + "/profile";
return (
<div>
{this.props.user.authenticated ? (
<Menu style={navStyle}>
<Menu.Item name="systems" header>
{ process.env.REACT_APP_SITE_NAME}
</Menu.Item>
<Menu.Menu position="right">
<Link to="/list-systems">
<Menu.Item name="systems"> Systems</Menu.Item>
</Link>
<Link to="/about">
<Menu.Item name="about">About</Menu.Item>
</Link>
<Dropdown item text={this.props.user.email}>
<Dropdown.Menu>
<Dropdown.Item href={profileLink}>Profile</Dropdown.Item>
<Dropdown.Item onClick={this._logout}>Logout</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
</Menu.Menu>
</Menu>
) : (
<div style={blankStyle} />
)}
</div>
);
}
}
export default Navigation;

View File

@@ -0,0 +1,21 @@
import { connect } from "react-redux"
import * as userActions from "../User/user-actions"
import Navigation from "./Navigation"
// Function passed in to `connect` to subscribe to Redux store updates.
// Any time it updates, mapStateToProps is called.
const mapStateToProps = (state) => {
return {
user: state.user
}
}
// Connects React component to the redux store
// It does not modify the component class passed to it
// Instead, it returns a new, connected component class, for you to use.
export default connect(
mapStateToProps,
userActions
)(Navigation)

View File

@@ -0,0 +1,56 @@
// in src/restricted.js
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
import * as types from "../User/user-constants";
import axios from "axios";
/**
* Higher-order component (HOC) to wrap restricted pages
*/
const restricted = (BaseComponent, store) => {
class Restricted extends Component {
componentWillMount() {
this.checkAuthentication(this.props);
}
componentWillReceiveProps(nextProps) {
if (nextProps.location !== this.props.location) {
this.checkAuthentication(nextProps);
}
}
checkAuthentication(params) {
const { history } = params;
const authenticated = store.getState().user.authenticated;
if (!authenticated) {
axios
.get(process.env.REACT_APP_ACCOUNT_SERVER + "/authenticated", {withCredentials: true})
.then(response => {
if (response.data.success) {
const user = response.data.user
store.dispatch({
type: types.LOGIN_SUCCESS_USER,
data: user
});
} else {
window.location = process.env.REACT_APP_ACCOUNT_SERVER + "/login?nextLocation=admin";
/*history.replace({ pathname: '/login',
state: { nextPathname: params.location.pathname } });*/
}
})
.catch(response => {
if (response instanceof Error) {
window.location = process.env.REACT_APP_ACCOUNT_SERVER + "/login?nextLocation=admin";
// Something happened during logout that triggered an Error
console.log("Error", response.message);
}
});
}
}
render() {
return <BaseComponent {...this.props} />;
}
}
return withRouter(Restricted);
}
export default restricted

Some files were not shown because too many files have changed in this diff Show More