Update ODLUX
[ccsdk/features.git] / sdnr / wt / odlux / framework / src / views / frame.tsx
1 /**\r
2  * ============LICENSE_START========================================================================\r
3  * ONAP : ccsdk feature sdnr wt odlux\r
4  * =================================================================================================\r
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.\r
6  * =================================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
8  * in compliance with the License. You may obtain a copy of the License at\r
9  *\r
10  * http://www.apache.org/licenses/LICENSE-2.0\r
11  *\r
12  * Unless required by applicable law or agreed to in writing, software distributed under the License\r
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
14  * or implied. See the License for the specific language governing permissions and limitations under\r
15  * the License.\r
16  * ============LICENSE_END==========================================================================\r
17  */\r
18 import * as React from 'react';\r
19 import { HashRouter as Router, Route, Redirect, Switch } from 'react-router-dom';\r
20 \r
21 import { withStyles, WithStyles, createStyles, Theme } from '@material-ui/core/styles';\r
22 import { faHome, faAddressBook, faSignInAlt, faCog } from '@fortawesome/free-solid-svg-icons';\r
23 \r
24 import { SnackbarProvider } from 'notistack';\r
25 import { ConfirmProvider } from 'material-ui-confirm';\r
26 \r
27 import AppFrame from '../components/routing/appFrame';\r
28 import TitleBar from '../components/titleBar';\r
29 import Menu from '../components/navigationMenu';\r
30 import ErrorDisplay from '../components/errorDisplay';\r
31 import SnackDisplay from '../components/material-ui/snackDisplay';\r
32 \r
33 import Home from '../views/home';\r
34 import Login from '../views/login';\r
35 import About from '../views/about';\r
36 import Test from '../views/test';\r
37 import UserSettings from '../views/settings';\r
38 \r
39 import applicationService from '../services/applicationManager';\r
40 \r
41 \r
42 const styles = (theme: Theme) => createStyles({\r
43   root: {\r
44     flexGrow: 1,\r
45     height: '100%',\r
46     zIndex: 1,\r
47     overflow: 'hidden',\r
48     position: 'relative',\r
49     display: 'flex',\r
50   },\r
51   content: {\r
52     flexGrow: 1,\r
53     display: "flex",\r
54     flexDirection: "column",\r
55     backgroundColor: theme.palette.background.default,\r
56     padding: theme.spacing(3),\r
57     minWidth: 0, // So the Typography noWrap works\r
58   },\r
59   toolbar: theme.mixins.toolbar as any\r
60 });\r
61 \r
62 \r
63 \r
64 type FrameProps = WithStyles<typeof styles>;\r
65 \r
66 class FrameComponent extends React.Component<FrameProps>{\r
67 \r
68   render() {\r
69     const registrations = applicationService.applications;\r
70     const { classes } = this.props;\r
71     return (\r
72       <ConfirmProvider>\r
73         <SnackbarProvider maxSnack={3}>\r
74             <Router>\r
75             <div className={classes.root}>\r
76                 <SnackDisplay />\r
77                 <ErrorDisplay />\r
78                 <TitleBar />\r
79                 <Menu />\r
80                 <main className={classes.content}>\r
81                 {\r
82                     <div className={classes.toolbar} /> //needed for margins, don't remove!\r
83                 }\r
84                 <Switch>\r
85                     <Route exact path="/" component={() => (\r
86                       <AppFrame title={"Home"} icon={faHome} >\r
87                           <Home />\r
88                       </AppFrame>\r
89                     )} />\r
90                     <Route path="/about" component={() => (\r
91                       <AppFrame title={"About"} icon={faAddressBook} >\r
92                           <About />\r
93                       </AppFrame>\r
94                     )} />\r
95                     <Route path="/settings" component={() => (\r
96                       <AppFrame title={"Settings"} icon={faCog} >\r
97                           <UserSettings />\r
98                       </AppFrame>\r
99                     )} />\r
100                     {process.env.NODE_ENV === "development" ? <Route path="/test" component={() => (\r
101                       <AppFrame title={"Test"} icon={faAddressBook} >\r
102                           <Test />\r
103                       </AppFrame>\r
104                     )} /> : null}\r
105                     <Route path="/login" component={() => (\r
106                       <AppFrame title={"Login"} icon={faSignInAlt} >\r
107                           <Login />\r
108                       </AppFrame>\r
109                       )} />\r
110                     { Object.keys(registrations).map(p => {\r
111                       const application = registrations[p];\r
112                       return (<Route key={application.name} path={application.path || `/${application.name}`} component={() => (\r
113                           <AppFrame title={application.title || (typeof application.menuEntry === 'string' && application.menuEntry) || application.name} icon={application.icon} appId={application.name} >\r
114                           <application.rootComponent />\r
115                           </AppFrame>\r
116                       )} />)\r
117                     })}\r
118                     <Redirect to="/" />\r
119                 </Switch>\r
120                 </main>\r
121             </div>\r
122             </Router>\r
123         </SnackbarProvider>\r
124       </ConfirmProvider>  \r
125     );\r
126   }\r
127 }\r
128 \r
129 export const Frame = withStyles(styles)(FrameComponent);\r
130 export default Frame;\r