Newer
Older
piotr.kupczyk@id.ethz.ch
committed
import _ from 'lodash'
piotr.kupczyk@id.ethz.ch
committed
import { withStyles } from '@material-ui/core/styles'
piotr.kupczyk@id.ethz.ch
committed
import logger from '@src/js/common/logger.js'
import util from '@src/js/common/util.js'
import pages from '@src/js/common/consts/pages.js'
piotr.kupczyk@id.ethz.ch
committed
import Loading from '@src/js/components/common/loading/Loading.jsx'
import Error from '@src/js/components/common/error/Error.jsx'
import Menu from '@src/js/components/common/menu/Menu.jsx'
piotr.kupczyk@id.ethz.ch
committed
import Login from '@src/js/components/login/Login.jsx'
piotr.kupczyk@id.ethz.ch
committed
import Database from '@src/js/components/database/Database.jsx'
piotr.kupczyk@id.ethz.ch
committed
import Users from '@src/js/components/users/Users.jsx'
import Types from '@src/js/components/types/Types.jsx'
piotr.kupczyk@id.ethz.ch
committed
import Tools from '@src/js/components/tools/Tools.jsx'
piotr.kupczyk@id.ethz.ch
committed
import AppController from '@src/js/components/AppController.js'
import ComponentContext from '@src/js/components/common/ComponentContext.js'
import { library } from '@fortawesome/fontawesome-svg-core'
import { fab } from '@fortawesome/free-brands-svg-icons'
import { faFolder, faFile, faFileArchive, faFileAudio, faFileImage, faFileText,
faFileVideo, faFileCode, faFilePdf, faFileWord, faFileExcel,
faFilePowerpoint } from '@fortawesome/free-regular-svg-icons'
library.add(fab, faFolder, faFile, faFileAudio, faFileText, faFileVideo,
faFileCode, faFileImage, faFileArchive, faFilePdf, faFileWord, faFileExcel,
piotr.kupczyk@id.ethz.ch
committed
const styles = {
piotr.kupczyk@id.ethz.ch
committed
container: {
height: '100%',
display: 'flex',
flexDirection: 'column'
},
page: {
flex: '1 1 100%',
display: 'flex',
overflow: 'hidden'
},
piotr.kupczyk@id.ethz.ch
committed
visible: {
piotr.kupczyk@id.ethz.ch
committed
display: 'flex'
piotr.kupczyk@id.ethz.ch
committed
},
hidden: {
piotr.kupczyk@id.ethz.ch
committed
display: 'none'
piotr.kupczyk@id.ethz.ch
committed
}
piotr.kupczyk@id.ethz.ch
committed
}
const pageToComponent = {
piotr.kupczyk@id.ethz.ch
committed
[pages.DATABASE]: Database,
piotr.kupczyk@id.ethz.ch
committed
[pages.TYPES]: Types,
piotr.kupczyk@id.ethz.ch
committed
[pages.USERS]: Users,
[pages.TOOLS]: Tools
piotr.kupczyk@id.ethz.ch
committed
}
constructor(props) {
super(props)
this.state = {}
if (this.props.controller) {
this.controller = this.props.controller
} else {
this.controller = AppController.getInstance()
}
this.controller.init(new ComponentContext(this))
}
piotr.kupczyk@id.ethz.ch
committed
componentDidMount() {
this.controller.load()
}
handleErrorClosed() {
AppController.getInstance().errorChange(null)
piotr.kupczyk@id.ethz.ch
committed
logger.log(logger.DEBUG, 'App.render')
<AppController.AppContext.Provider value={this.state}>
<Loading loading={AppController.getInstance().getLoading()}>
error={AppController.getInstance().getError()}
errorClosed={this.handleErrorClosed}
>
{AppController.getInstance().getLoaded() && this.renderPage()}
</Error>
</Loading>
</AppController.AppContext.Provider>
piotr.kupczyk@id.ethz.ch
committed
renderPage() {
piotr.kupczyk@id.ethz.ch
committed
const classes = this.props.classes
if (AppController.getInstance().getSession()) {
piotr.kupczyk@id.ethz.ch
committed
<div className={classes.container}>
piotr.kupczyk@id.ethz.ch
committed
{_.map(pageToComponent, (PageComponent, page) => {
let visible = AppController.getInstance().getCurrentPage() === page
piotr.kupczyk@id.ethz.ch
committed
return (
<div
key={page}
className={util.classNames(
classes.page,
visible ? classes.visible : classes.hidden
)}
>
<PageComponent />
</div>
)
})}
piotr.kupczyk@id.ethz.ch
committed
} else {
return <Login disabled={AppController.getInstance().getLoading()} />
export default _.flow(
withStyles(styles),
AppController.getInstance().withState()
)(App)