2019-12-23 05:18:29 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2019-06-29 05:49:08 +00:00
|
|
|
import { NavLink, Route, RouteComponentProps, Switch } from 'react-router-dom';
|
2019-06-29 05:17:29 +00:00
|
|
|
import NavigationBar from '@/components/NavigationBar';
|
|
|
|
import ServerConsole from '@/components/server/ServerConsole';
|
|
|
|
import TransitionRouter from '@/TransitionRouter';
|
2019-06-29 23:14:32 +00:00
|
|
|
import Spinner from '@/components/elements/Spinner';
|
|
|
|
import WebsocketHandler from '@/components/server/WebsocketHandler';
|
2019-07-10 04:25:57 +00:00
|
|
|
import { ServerContext } from '@/state/server';
|
2019-07-10 05:00:29 +00:00
|
|
|
import DatabasesContainer from '@/components/server/databases/DatabasesContainer';
|
2019-07-28 03:23:44 +00:00
|
|
|
import FileManagerContainer from '@/components/server/files/FileManagerContainer';
|
|
|
|
import { CSSTransition } from 'react-transition-group';
|
2019-09-28 21:59:05 +00:00
|
|
|
import SuspenseSpinner from '@/components/elements/SuspenseSpinner';
|
2019-10-19 22:31:02 +00:00
|
|
|
import FileEditContainer from '@/components/server/files/FileEditContainer';
|
2019-12-07 23:58:37 +00:00
|
|
|
import SettingsContainer from '@/components/server/settings/SettingsContainer';
|
2020-02-08 23:23:08 +00:00
|
|
|
import ScheduleContainer from '@/components/server/schedules/ScheduleContainer';
|
2020-03-18 06:33:53 +00:00
|
|
|
import ScheduleEditContainer from '@/components/server/schedules/ScheduleEditContainer';
|
2020-03-26 04:58:37 +00:00
|
|
|
import UsersContainer from '@/components/server/users/UsersContainer';
|
2020-03-29 00:25:04 +00:00
|
|
|
import Can from '@/components/elements/Can';
|
2020-04-04 17:59:25 +00:00
|
|
|
import BackupContainer from '@/components/server/backups/BackupContainer';
|
2019-06-29 05:17:29 +00:00
|
|
|
|
2019-07-10 04:25:57 +00:00
|
|
|
const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>) => {
|
|
|
|
const server = ServerContext.useStoreState(state => state.server.data);
|
|
|
|
const getServer = ServerContext.useStoreActions(actions => actions.server.getServer);
|
|
|
|
const clearServerState = ServerContext.useStoreActions(actions => actions.clearServerState);
|
2019-06-29 23:14:32 +00:00
|
|
|
|
|
|
|
if (!server) {
|
|
|
|
getServer(match.params.id);
|
|
|
|
}
|
|
|
|
|
2019-10-19 22:31:02 +00:00
|
|
|
useEffect(() => () => clearServerState(), [ clearServerState ]);
|
2019-06-29 23:14:32 +00:00
|
|
|
|
|
|
|
return (
|
2020-04-10 17:11:15 +00:00
|
|
|
<React.Fragment key={'server-router'}>
|
2019-06-29 23:14:32 +00:00
|
|
|
<NavigationBar/>
|
2019-07-28 03:23:44 +00:00
|
|
|
<CSSTransition timeout={250} classNames={'fade'} appear={true} in={true}>
|
|
|
|
<div id={'sub-navigation'}>
|
2019-12-23 05:18:29 +00:00
|
|
|
<div className={'items'}>
|
|
|
|
<NavLink to={`${match.url}`} exact>Console</NavLink>
|
2020-03-29 00:25:04 +00:00
|
|
|
<Can action={'file.*'}>
|
|
|
|
<NavLink to={`${match.url}/files`}>File Manager</NavLink>
|
|
|
|
</Can>
|
|
|
|
<Can action={'database.*'}>
|
|
|
|
<NavLink to={`${match.url}/databases`}>Databases</NavLink>
|
|
|
|
</Can>
|
|
|
|
<Can action={'schedule.*'}>
|
|
|
|
<NavLink to={`${match.url}/schedules`}>Schedules</NavLink>
|
|
|
|
</Can>
|
|
|
|
<Can action={'user.*'}>
|
|
|
|
<NavLink to={`${match.url}/users`}>Users</NavLink>
|
|
|
|
</Can>
|
2020-04-04 17:59:25 +00:00
|
|
|
<Can action={'backup.*'}>
|
|
|
|
<NavLink to={`${match.url}/backups`}>Backups</NavLink>
|
|
|
|
</Can>
|
2020-04-10 17:11:15 +00:00
|
|
|
<Can action={[ 'settings.*', 'file.sftp' ]} matchAny={true}>
|
2020-03-29 00:25:04 +00:00
|
|
|
<NavLink to={`${match.url}/settings`}>Settings</NavLink>
|
|
|
|
</Can>
|
2019-06-29 23:14:32 +00:00
|
|
|
</div>
|
2019-06-29 05:49:08 +00:00
|
|
|
</div>
|
2019-07-28 03:23:44 +00:00
|
|
|
</CSSTransition>
|
2020-02-23 04:07:56 +00:00
|
|
|
<WebsocketHandler/>
|
|
|
|
<TransitionRouter>
|
|
|
|
{!server ?
|
|
|
|
<div className={'flex justify-center m-20'}>
|
|
|
|
<Spinner size={'large'}/>
|
|
|
|
</div>
|
|
|
|
:
|
2020-04-10 17:11:15 +00:00
|
|
|
<Switch location={location} key={'server-switch'}>
|
|
|
|
<Route path={`${match.path}`} component={ServerConsole} exact/>
|
|
|
|
<Route path={`${match.path}/files`} component={FileManagerContainer} exact/>
|
|
|
|
<Route
|
|
|
|
path={`${match.path}/files/:action(edit|new)`}
|
|
|
|
render={props => (
|
|
|
|
<SuspenseSpinner>
|
|
|
|
<FileEditContainer {...props as any}/>
|
|
|
|
</SuspenseSpinner>
|
|
|
|
)}
|
|
|
|
exact
|
|
|
|
/>
|
|
|
|
<Route path={`${match.path}/databases`} component={DatabasesContainer} exact/>
|
|
|
|
<Route path={`${match.path}/schedules`} component={ScheduleContainer} exact/>
|
|
|
|
<Route path={`${match.path}/schedules/:id`} component={ScheduleEditContainer} exact/>
|
|
|
|
<Route path={`${match.path}/users`} component={UsersContainer} exact/>
|
|
|
|
<Route path={`${match.path}/backups`} component={BackupContainer} exact/>
|
|
|
|
<Route path={`${match.path}/settings`} component={SettingsContainer} exact/>
|
|
|
|
</Switch>
|
2020-02-23 04:07:56 +00:00
|
|
|
}
|
|
|
|
</TransitionRouter>
|
2019-06-29 23:14:32 +00:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
};
|
2019-07-10 04:25:57 +00:00
|
|
|
|
|
|
|
export default (props: RouteComponentProps<any>) => (
|
|
|
|
<ServerContext.Provider>
|
|
|
|
<ServerRouter {...props}/>
|
|
|
|
</ServerContext.Provider>
|
|
|
|
);
|