Skip to content

Commit

Permalink
frontend overhaul -> master (#138)
Browse files Browse the repository at this point in the history
* updates to webpack

* fix for #132

* pm2 config watch changes

* shrinkwrap swap

* added antd, broke the frontend
just a regular day in the IDE

* LiveVideo and FileStats

* multi-deprecation

* group by hours for fileStats

* more v2 stuff

* summary scrubber

* more updates

* updates

* updates

* updates

* updates

* updates

* more updates and hooks

* updates to listing

* updates to process list

* updates

* updates, adding hooks

* updates

* updates

* npm start prepare auth 3 minute timeout (#137)

* fixing date deletion, glob was very incorrect

* responsive main

* updates

* updates

* updates

* delete old app

* multi fix commit
cron tasks destroy not a function due to npm dep change
hooks fix
task listing works
scheduling processes

* updates

* updates to views

* updates

* updates

* updates to status for #136

* more for #136

* updates for livestream command

* updates to gateway, helmet

* adding to env

* the big v5 release prep

* extra line removed
  • Loading branch information
jjjpanda authored Feb 2, 2022
1 parent d847a09 commit 26134be
Show file tree
Hide file tree
Showing 93 changed files with 33,483 additions and 25,264 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@ sudo apt-get install motion ffmpeg postgresql
*Or however you need to download it on your machine*

Then, set up a conf for **motion** with all of your cameras. Then, set up **postgres** with a database, port, user, and password of your choosing. **Motion** will also need postgres details in it's conf as well. [*See storage for details.*](storage)
### 2. Installing NPM dependencies

```
npm install --no-optional
```

### 3. Create Environment Variables File
### 2. Create Environment Variables File

Copy the example env into an .env dotfile:
```
Expand All @@ -45,7 +40,19 @@ cp env.example .env

Fill in the .env with all the info listed ( for optional fields, leave blank after the "=" ).

### 4. Start Chimera
### 3. Installing NPM dependencies

```
npm install --no-optional
```

### 4. Run Build

```
npm run build-with-env
```

### 5. Start Chimera

If running all or more than one service(s)
```
Expand Down
8 changes: 6 additions & 2 deletions chimera/splitAndValidateEnvVars.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ env.gateway += writeVarLine("command_PROXY_ON")
env.gateway += writeVarLine("schedule_PROXY_ON")
env.gateway += writeVarLine("storage_PROXY_ON")
env.gateway += writeVarLine("livestream_PROXY_ON")
env.gateway += writeVarLine("object_PROXY_ON")

env.gateway += writeVarLine("gateway_ON")
env.gateway += writeVarLine("gateway_PORT")
Expand Down Expand Up @@ -135,8 +136,11 @@ env.gateway += writeVarLine("livestream_HOST")
env.livestream += writeVarLine("livestream_FOLDERPATH")
confirmPath("livestream_FOLDERPATH", true)

writeVarLine("object_os")
writeVarLine("OBJECT_CONF_FOLDERPATH")
writeVarLine("object_ON")
writeVarLine("object_PORT")
env.gateway += writeVarLine("object_HOST")
writeVarLine("object_minimumConfidence")
writeVarLine("object_alertUrls")

env.memory += writeVarLine("memory_ON")
env.memory += writeVarLine("memory_PORT")
Expand Down
1 change: 0 additions & 1 deletion command/babel.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"@babel/preset-react"
],
"plugins": [
["import", {"libraryName": "antd-mobile", "style": true}, "antd-mobile" ],
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime"
],
Expand Down
158 changes: 38 additions & 120 deletions command/frontend/App.jsx
Original file line number Diff line number Diff line change
@@ -1,148 +1,66 @@
import React from "react"
import React, {useEffect, useState} from "react"
import ReactDOM from "react-dom"
import {
BrowserRouter as Router,
Route,
Routes,
Navigate
} from "react-router-dom"
import Main from "./app/Main.jsx"
import ResponsiveMain from "./app_v2/ResponsiveMain.jsx"

import "./css/style.less"
import Cookies from "js-cookie"
import LoadingIcon from "./app/LoadingIcon.jsx"
import LoginPage from "./app/LoginPage.jsx"

import { request } from "./js/request.js"

const timeout = 750
import LoadingIcon from "./app_v2/LoadingIcon.jsx"
import LoginPage from "./app_v2/LoginPage.jsx"
import ThemeProvider from "./app_v2/ThemeProvider.jsx"

import * as FastClick from "fastclick"
import useAuth from "./hooks/useAuth.js"

if ("addEventListener" in document) {
document.addEventListener("DOMContentLoaded", () => {
FastClick.attach(document.body)
}, false)
}

class App extends React.Component{
constructor(props){
super(props)
this.state = {
loaded: false,
loggedIn: false,
key: 1,
timestamp: new Date()
}
}

attemptLogin = (password, url="/authorization/login", body={password}) => {
return request(url, {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
},
credentials: "include",
body: JSON.stringify(body)
}, (prom) => {
return prom.then(res => {
return res.json()
}, (err)=> {
return {error: true}
})
})
}

attemptVerification = () => {
return request("/authorization/verify", {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
},
}, (prom) => {
return prom.then(res => {
return res.json()
}, (err)=> {
return {error: true}
})
})
}
const App = () => {
const [loaded, loggedIn, tryLogin] = useAuth()
const [key, setKey] = useState(0)

handleLoginAttempt = (res, timestamp, callback=()=>{}) => {
console.log("login attempt", res)
callback(res.error)
setTimeout(() => this.setState(() => ({loaded: true, loggedIn: !res.error}), () => {
setTimeout(() => {
this.setState((oldState) => ({
key: oldState.key + 1
}), () => console.log("APP KEY", this.state.key))
}, Math.max(0, timeout - (new Date() - timestamp)))
}), 500)
}
useEffect(() => {
console.log("UPDATED CHIMERA KEY: ", key)
setKey((k) => k+1)
}, [loggedIn])

componentDidMount() {
if(Cookies.get("bearertoken") != undefined){
this.attemptVerification().then(res => {
this.handleLoginAttempt(res, this.state.timestamp)
})
}
else{
this.setState(() => ({
loaded: true,
loggedIn: false
}))
}
}

render() {
const loginProps = {
loginReq: this.attemptLogin,
handler: this.handleLoginAttempt,
timestamp: this.state.timestamp
}
return (
<Router>
{this.state.loaded ? <Routes>
<Route path="/login/:password" element={this.state.loggedIn ? <Navigate to="/" /> : <LoginPage withPassword {...loginProps} />}
return (
<ThemeProvider>
<Router key={`ROUTER-${key}`}>
{loaded ? <Routes>
<Route
key={`ROUTE-${key}-1`}
path="/login/:password"
element={loggedIn ? <Navigate to="/" /> : <LoginPage withPassword tryLogin={tryLogin} />}
/>
<Route
key={`ROUTE-${key}-2`}
path="/login"
element={loggedIn ? <Navigate to="/" /> : <LoginPage tryLogin={tryLogin} />}
/>
<Route path="/login" element={this.state.loggedIn ? <Navigate to="/" /> : <LoginPage {...loginProps} />}
<Route
key={`ROUTE-${key}-3`}
path="/:route"
element={loggedIn ? <ResponsiveMain /> : <Navigate to="/login" />}
/>
<Route
key={`ROUTE-${key}-4`}
path="/"
element={loggedIn ? <ResponsiveMain /> : <Navigate to="/login" />}
/>
<Route path="/:route" element={this.state.loggedIn ? <Main /> : <Navigate to="/login" />}/>
<Route path="/" element={this.state.loggedIn ? <Main /> : <Navigate to="/login" />}/>
</Routes> : <LoadingIcon />}
</Router>
)
}
</ThemeProvider>
)
}

ReactDOM.render(<App />,
document.getElementById("root"),
)

/*
const [key, value] = location.search.split('=')
console.log(key, value, this.state.loggedIn)
if(key == "?loginForm") {
if(this.state.loggedIn){
return <div>bruh</div>//this.props.history.push({pathname: "/"})
}
else{
if(value == undefined){
return <LoginForm />
}
else{
return <div>bruh</div>//this.props.history.push({pathname: "/", state: { otp: value }})
}
}
}
else {
if(this.state.loggedIn) {
return <Main />
}
else{
return <div>bruh</div>//this.props.history.push({pathname: "/?loginForm"})
}
}
*/
)
11 changes: 0 additions & 11 deletions command/frontend/app/Alert.jsx

This file was deleted.

63 changes: 0 additions & 63 deletions command/frontend/app/CameraDatePicker.jsx

This file was deleted.

Loading

0 comments on commit 26134be

Please sign in to comment.