-
+
{
struct.description ? (
{struct.description}
) : null
}
@@ -224,7 +222,7 @@ export class BackendPage extends React.Component {
}
:
You need to enable a backend first.
- }
+ }
);
}
diff --git a/client/pages/adminpage/backend.scss b/client/pages/adminpage/backend.scss
index 57a7fda5..ccb9b5c4 100644
--- a/client/pages/adminpage/backend.scss
+++ b/client/pages/adminpage/backend.scss
@@ -1,5 +1,4 @@
.component_dashboard{
-
.alert { margin-top: -15px; }
.box-container {
display: flex;
@@ -41,6 +40,7 @@
text-shadow: none;
background: var(--emphasis-primary);
padding: 18px 0;
+ @media (max-width: 750px){ padding: 8px 0; }
margin: 6px;
opacity: 0.95;
.icon{
diff --git a/client/pages/adminpage/home.js b/client/pages/adminpage/home.js
index 9d597250..d86a403a 100644
--- a/client/pages/adminpage/home.js
+++ b/client/pages/adminpage/home.js
@@ -1,15 +1,6 @@
-import React from 'react';
-import { Redirect } from 'react-router-dom';
+import React from "react";
+import { Redirect } from "react-router-dom";
-export class HomePage extends React.Component {
- constructor(props){
- super(props);
- this.state = {
- stage: "loading"
- }
- }
-
- render(){
- return (
);
- }
+export function HomePage() {
+ return (
);
}
diff --git a/client/pages/adminpage/logger.js b/client/pages/adminpage/logger.js
index 7751c8ed..a8430529 100644
--- a/client/pages/adminpage/logger.js
+++ b/client/pages/adminpage/logger.js
@@ -1,91 +1,86 @@
-import React from 'react';
-import { FormBuilder, Loader, Button, Icon } from '../../components/';
-import { Config, Log } from '../../model/';
-import { FormObjToJSON, notify, format } from '../../helpers/';
-import { t } from '../../locales/';
+import React, { useState, useEffect, useRef } from "react";
+import { FormBuilder, Loader, Button, Icon } from "../../components/";
+import { Config, Log } from "../../model/";
+import { FormObjToJSON, notify, format, nop } from "../../helpers/";
+import { t } from "../../locales/";
import "./logger.scss";
-export class LogPage extends React.Component {
- constructor(props){
- super(props);
- this.state = {
- form: {},
- log: "",
- config: {}
- };
- }
-
- componentDidMount(){
- Config.all().then((config) => {
- this.setState({
- form: {"":{"params":config["log"]}},
- config: FormObjToJSON(config)
- });
- });
- Log.get(1024*100).then((log) => { // get only the last 100kb of log
- this.setState({log: log}, () => {
- this.refs.$log.scrollTop = this.refs.$log.scrollHeight;
- });
- });
- }
-
- onChange(r){
- this.state.config["log"] = r[""].params;
- this.state.config["connections"] = window.CONFIG.connections;
- this.props.isSaving(true);
- Config.save(this.state.config, true, () => {
- this.props.isSaving(false);
+export function LogPage({ isSaving = nop }) {
+ const [log, setLog] = useState("");
+ const [form, setForm] = useState({});
+ const [config, setConfig] = useState({});
+ const $log = useRef();
+ const filename = () => {
+ const t = new Date().toISOString().substring(0,10).replace(/-/g, "");
+ return `access_${t}.log`;
+ };
+ const onChange = (r) => {
+ const c = Object.assign({}, config)
+ c["log"] = r[""]["params"];
+ c["connections"] = window.CONFIG.connections;
+ delete c["constant"]
+ isSaving(true);
+ Config.save(c, true, () => {
+ isSaving(false);
}, () => {
- notify.send(err && err.message || t('Oops'), 'error');
- this.props.isSaving(false);
+ isSaving(false);
+ notify.send(err && err.message || t("Oops"), "error");
});
- }
+ };
+ const fetchLogs = () => {
+ Log.get(1024*100).then((log) => { // get only the last 100kb of log
+ setLog(log + "\n\n\n\n\n");
+ if($log.current.scrollTop === 0) {
+ $log.current.scrollTop = $log.current.scrollHeight;
+ }
+ });
+ };
- render(){
- const filename = () => {
- let tmp = "access_";
- tmp += new Date().toISOString().substring(0,10).replace(/-/g, "");
- tmp += ".log";
- };
- return (
-
-
Logging
-
-
{
- return (
-
- );
- }} />
-
+ useEffect(() => {
+ Config.all().then((config) => {
+ setForm({"":{"params":config["log"]}});
+ setConfig(FormObjToJSON(config));
+ });
+ fetchLogs();
+ const id = setInterval(fetchLogs, 5000);
+ return () => clearInterval(id)
+ }, []);
-
- {
- this.state.log === "" ? : this.state.log + "\n\n\n\n\n"
- }
-
-
+ return (
+
+
Logging
+
+
(
+
+ )} />
- );
- }
+
+ { log === "" ? : log }
+
+
+
+ );
}
diff --git a/client/pages/adminpage/loginpage.js b/client/pages/adminpage/loginpage.js
index c7589998..074e102c 100644
--- a/client/pages/adminpage/loginpage.js
+++ b/client/pages/adminpage/loginpage.js
@@ -1,54 +1,44 @@
-import React from 'react';
-import { Redirect } from 'react-router';
+import React, { useState, useRef } from "react";
+import { Redirect } from "react-router";
-import { Input, Button, Container, Icon, Loader } from '../../components/';
-import { Config, Admin } from '../../model/';
-import { t } from '../../locales/';
-import ReactCSSTransitionGroup from 'react-addons-css-transition-group';
+import { Input, Button, Container, Icon } from "../../components/";
+import { Admin } from "../../model/";
+import { nop } from "../../helpers/";
+import { t } from "../../locales/";
-export class LoginPage extends React.Component {
- constructor(props){
- super(props);
- this.state = {
- loading: false,
- error: null
- };
- }
-
- componentDidMount(){
- this.refs.$input.ref.focus();
- }
-
- authenticate(e){
+export function LoginPage({ reload = nop }) {
+ const [isLoading, setIsLoading] = useState(false);
+ const [hasError, setHasError] = useState(false);
+ const $input = useRef();
+ const marginTop = () => ({ marginTop: `${parseInt(window.innerHeight / 3)}px` })
+ const authenticate = (e) => {
e.preventDefault();
- this.setState({loading: true});
- Admin.login(this.refs.$input.ref.value)
- .then(() => this.props.reload())
- .catch(() => {
- this.refs.$input.ref.value = "";
- this.setState({
- loading: false,
- error: true
- }, () => {
- window.setTimeout(() => {
- this.setState({error: false});
- }, 500);
- });
+ setIsLoading(true);
+ Admin.login($input.current.ref.value)
+ .then(() => reload())
+ .catch(() => {
+ $input.current.ref.value = "";
+ setIsLoading(false)
+ setHasError(true);
+ setTimeout(() => {
+ setHasError(false);
+ }, 500);
});
}
- render(){
- const marginTop = () => { return {marginTop: parseInt(window.innerHeight / 3)+'px'};};
+ useRef(() => {
+ $input.current.ref.focus();
+ }, []);
- return (
-
-
+
+ )
}
diff --git a/client/pages/adminpage/settings.js b/client/pages/adminpage/settings.js
index 0e50ef02..ebfd7540 100644
--- a/client/pages/adminpage/settings.js
+++ b/client/pages/adminpage/settings.js
@@ -1,26 +1,12 @@
-import React from 'react';
-import { FormBuilder } from '../../components/';
-import { Config } from '../../model/';
-import { format, notify } from '../../helpers';
-import { t } from '../../locales/';
+import React, { useState, useEffect } from "react";
+import { FormBuilder } from "../../components/";
+import { Config } from "../../model/";
+import { format, notify, nop } from "../../helpers";
+import { t } from "../../locales/";
-export class SettingsPage extends React.Component {
- constructor(props){
- super(props);
- this.state = {
- form: {}
- };
- }
-
- componentDidMount(){
- Config.all().then((c) => {
- delete c.constant; // The constant key contains read only global variable that are
- // application wide truth => not editable from the admin area
- this.setState({form: c});
- });
- }
-
- format(name){
+export function SettingsPage({ isSaving = nop }) {
+ const [form, setForm] = useState({});
+ const format = (name) => {
if(typeof name !== "string"){
return "N/A";
}
@@ -34,45 +20,52 @@ export class SettingsPage extends React.Component {
})
.join(" ");
}
-
- onChange(form){
- form.connections = window.CONFIG.connections;
- this.props.isSaving(true);
- Config.save(form, true, () => {
- this.props.isSaving(false);
+ const onChange = (_form) => {
+ _form.connections = window.CONFIG.connections;
+ delete _form.constant;
+ refresh(Math.random())
+ isSaving(true)
+ Config.save(_form, true, () => {
+ isSaving(false)
}, (err) => {
- notify.send(err && err.message || t('Oops'), 'error');
- this.props.isSaving(false);
+ isSaving(false)
+ notify.send(err && err.message || t("Oops"), "error");
});
}
+ const [_, refresh] = useState(null);
- render(){
- return (
-