ada78b90f22ed46cc0cf11662f0a0bcaf06657bb
[ccsdk/features.git] / sdnr / wt / odlux / framework / src / app.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 \r
19 import * as React from 'react';\r
20 import * as ReactDOM from 'react-dom';\r
21 \r
22 import { MuiThemeProvider } from '@material-ui/core/styles';\r
23 \r
24 import { Frame } from './views/frame';\r
25 \r
26 import { User } from './models/authentication';\r
27 \r
28 import { AddErrorInfoAction } from './actions/errorActions';\r
29 import { UpdateUser } from './actions/authentication';\r
30 \r
31 import { applicationStoreCreator } from './store/applicationStore';\r
32 import { ApplicationStoreProvider } from './flux/connect';\r
33 \r
34 import { startHistoryListener } from './middleware/navigation';\r
35 import { startRestService } from './services/restService';\r
36 \r
37 import { startForceLogoutService } from './services/forceLogoutService';\r
38 import { startNotificationService } from './services/notificationService';\r
39 \r
40 import theme from './design/default';\r
41 import '!style-loader!css-loader!./app.css';\r
42 \r
43 declare module '@material-ui/core/styles/createMuiTheme' {\r
44 \r
45   interface IDesign {\r
46     id: string,\r
47     name: string,\r
48     url: string,        // image url of a company logo, which will be presented in the ui header\r
49     height: number,     // image height [px] as delivered by the url\r
50     width: number,      // image width [px] as delivered by the url\r
51     logoHeight: number  // height in [px] of the logo (see url) within the ui header\r
52   }\r
53 \r
54   interface Theme {\r
55     design?: IDesign\r
56   }\r
57   interface ThemeOptions {\r
58     design?: IDesign\r
59   }\r
60 }\r
61 \r
62 export { configureApplication } from "./handlers/applicationStateHandler";\r
63 \r
64 export const transportPCEUrl = "transportPCEUrl";\r
65 \r
66 export const runApplication = () => {\r
67 \r
68   const initialToken = localStorage.getItem("userToken");\r
69   const applicationStore = applicationStoreCreator();\r
70 \r
71   if (initialToken) {\r
72     applicationStore.dispatch(new UpdateUser(User.fromString(initialToken) || undefined));\r
73   }\r
74 \r
75   window.onerror = function (msg: string, url: string, line: number, col: number, error: Error) {\r
76     // Note that col & error are new to the HTML 5 spec and may not be\r
77     // supported in every browser.  It worked for me in Chrome.\r
78     var extra = !col ? '' : '\ncolumn: ' + col;\r
79     extra += !error ? '' : '\nerror: ' + error;\r
80 \r
81     // You can view the information in an alert to see things working like this:\r
82     applicationStore.dispatch(new AddErrorInfoAction({ error, message: msg, url, line, col, info: { extra } }));\r
83 \r
84     var suppressErrorAlert = true;\r
85     // If you return true, then error alerts (like in older versions of\r
86     // Internet Explorer) will be suppressed.\r
87     return suppressErrorAlert;\r
88   };\r
89 \r
90   startRestService(applicationStore);\r
91   startHistoryListener(applicationStore);\r
92   startForceLogoutService(applicationStore);\r
93   startNotificationService(applicationStore);\r
94 \r
95   const App = (): JSX.Element => (\r
96     <ApplicationStoreProvider applicationStore={applicationStore} >\r
97       <MuiThemeProvider theme={theme}>\r
98         <Frame />\r
99       </MuiThemeProvider>\r
100     </ApplicationStoreProvider>\r
101   );\r
102 \r
103   ReactDOM.render(<App />, document.getElementById('app'));\r
104 \r
105   \r
106 \r
107 };\r