mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-11-04 05:27:04 +08:00
refactoring (page): standalone page
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import React, { useState, useEffect, useRef } from "react";
|
||||
import { FormBuilder, Loader, Button, Icon } from "../../components/";
|
||||
import { FormBuilder, Loader, Button } from "../../components/";
|
||||
import { Config, Log } from "../../model/";
|
||||
import { FormObjToJSON, notify, format, nop } from "../../helpers/";
|
||||
import { t } from "../../locales/";
|
||||
@ -12,14 +12,14 @@ export function LogPage({ isSaving = nop }) {
|
||||
const [config, setConfig] = useState({});
|
||||
const $log = useRef();
|
||||
const filename = () => {
|
||||
const t = new Date().toISOString().substring(0,10).replace(/-/g, "");
|
||||
const t = new Date().toISOString().substring(0, 10).replace(/-/g, "");
|
||||
return `access_${t}.log`;
|
||||
};
|
||||
const onChange = (r) => {
|
||||
const c = Object.assign({}, config)
|
||||
const c = Object.assign({}, config);
|
||||
c["log"] = r[""]["params"];
|
||||
c["connections"] = window.CONFIG.connections;
|
||||
delete c["constant"]
|
||||
delete c["constant"];
|
||||
isSaving(true);
|
||||
Config.save(c, true, () => {
|
||||
isSaving(false);
|
||||
@ -31,7 +31,7 @@ export function LogPage({ isSaving = nop }) {
|
||||
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) {
|
||||
if ($log.current.scrollTop === 0) {
|
||||
$log.current.scrollTop = $log.current.scrollHeight;
|
||||
}
|
||||
}).catch((err) => {
|
||||
@ -41,18 +41,18 @@ export function LogPage({ isSaving = nop }) {
|
||||
|
||||
useEffect(() => {
|
||||
Config.all().then((config) => {
|
||||
setForm({"":{"params":config["log"]}});
|
||||
setForm({ "": { "params": config["log"] } });
|
||||
setConfig(FormObjToJSON(config));
|
||||
});
|
||||
fetchLogs();
|
||||
const id = setInterval(fetchLogs, 5000);
|
||||
return () => clearInterval(id)
|
||||
return () => clearInterval(id);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="component_logpage">
|
||||
<h2>Logging</h2>
|
||||
<div style={{minHeight: "150px"}}>
|
||||
<div style={{ minHeight: "150px" }}>
|
||||
<FormBuilder
|
||||
form={form}
|
||||
onChange={onChange}
|
||||
@ -62,26 +62,30 @@ export function LogPage({ isSaving = nop }) {
|
||||
<span>
|
||||
{ format(struct.label) }:
|
||||
</span>
|
||||
<div style={{width: "100%"}}>
|
||||
<div style={{ width: "100%" }}>
|
||||
{ $input }
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<span className="nothing"></span>
|
||||
<div style={{width: "100%"}}>
|
||||
<div style={{ width: "100%" }}>
|
||||
{
|
||||
struct.description ? (<div className="description">{struct.description}</div>) : null
|
||||
struct.description && (
|
||||
<div className="description">{struct.description}</div>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
)} />
|
||||
</div>
|
||||
<pre style={{height: "350px"}} ref={$log}>
|
||||
<pre style={{ height: "350px" }} ref={$log}>
|
||||
{ log === "" ? <Loader/> : log }
|
||||
</pre>
|
||||
<div>
|
||||
<a href={Log.url()} download={filename()}><Button className="primary">{ t("Download") }</Button></a>
|
||||
<a href={Log.url()} download={filename()}>
|
||||
<Button className="primary">{ t("Download") }</Button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@ -10,10 +10,10 @@ export function HomePage() {
|
||||
useEffect(() => {
|
||||
Session.currentUser().then((res) => {
|
||||
if (res && res.is_authenticated === true) {
|
||||
setRedirection(res.home ? "/files" + res.home : "/files");
|
||||
} else {
|
||||
setRedirection("/login");
|
||||
setRedirection(res.home ? `/files${res.home}` : "/files");
|
||||
return;
|
||||
}
|
||||
setRedirection("/login");
|
||||
}).catch((err) => setRedirection("/login"));
|
||||
}, []);
|
||||
|
||||
|
||||
@ -4,24 +4,19 @@ import { Session } from "../model/";
|
||||
import { Loader, ErrorPage } from "../components/";
|
||||
import { cache } from "../helpers/";
|
||||
|
||||
@ErrorPage
|
||||
export class LogoutPage extends React.Component {
|
||||
constructor(props){
|
||||
super(props);
|
||||
}
|
||||
|
||||
componentDidMount(){
|
||||
function LogoutPageComponent({ error, history }) {
|
||||
useEffect(() => {
|
||||
Session.logout().then((res) => {
|
||||
cache.destroy();
|
||||
CONFIG["logout"] ?
|
||||
window.CONFIG["logout"] ?
|
||||
location.href = CONFIG["logout"] :
|
||||
this.props.history.push("/");
|
||||
}).catch((err) => this.props.error(err));
|
||||
}
|
||||
history.push("/");
|
||||
}).catch((err) => error(err));
|
||||
}, []);
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div> <Loader /> </div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const LogoutPage = ErrorPage(LogoutPageComponent);
|
||||
|
||||
Reference in New Issue
Block a user