SVG Rendering
[clamp.git] / ui-react / src / LoopUI.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  *
22  */
23
24 import React from 'react';
25 import styled from 'styled-components';
26 import MenuBar from './components/menu/MenuBar';
27 import Navbar from 'react-bootstrap/Navbar';
28 import logo from './logo.png';
29 import { GlobalClampStyle } from './theme/globalStyle.js';
30
31 import LoopSvg from './components/loop_viewer/svg/LoopSvg';
32 import LoopLogs from './components/loop_viewer/logs/LoopLogs';
33 import LoopStatus from './components/loop_viewer/status/LoopStatus';
34 import UserService from './api/UserService';
35 import LoopCache from './api/LoopCache';
36
37 import { Route } from 'react-router-dom'
38 import OpenLoopModal from './components/dialogs/OpenLoop/OpenLoopModal';
39 import OperationalPolicyModal from './components/dialogs/OperationalPolicy/OperationalPolicyModal';
40 import ConfigurationPolicyModal from './components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal';
41
42 const ProjectNameStyled = styled.a`
43         vertical-align: middle;
44         padding-left: 30px;
45         font-size: 30px;
46
47 `
48 const LoopViewDivStyled = styled.div`
49         height: 90vh;
50         overflow: hidden;
51         margin-left: 10px;
52         margin-right: 10px;
53         margin-bottom: 10px;
54         color: ${props => props.theme.loopViewerFontColor};
55         background-color: ${props => props.theme.loopViewerBackgroundColor};
56         border: 1px solid transparent;
57         border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
58 `
59
60 const LoopViewHeaderDivStyled = styled.div`
61         background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
62         padding: 10px 10px;
63         color: ${props => props.theme.loopViewerHeaderFontColor};
64 `
65
66 const LoopViewBodyDivStyled = styled.div`
67         background-color: ${props => (props.theme.loopViewerBackgroundColor)};
68         padding: 10px 10px;
69         color: ${props => (props.theme.loopViewerHeaderFontColor)};
70         height: 95%;
71 `
72
73 const LoopViewLoopNameSpanStyled = styled.span`
74         font-weight: bold;
75         color: ${props => (props.theme.loopViewerHeaderFontColor)};
76         background-color: ${props => (props.theme.loopViewerHeaderBackgroundColor)};
77 `
78
79 export default class LoopUI extends React.Component {
80
81         state = {
82                 userName: null,
83                 loopName: "Empty (NO loop loaded yet)",
84                 loopCache: new LoopCache({}),
85         };
86
87         constructor() {
88                 super();
89                 this.getUser = this.getUser.bind(this);
90                 this.updateLoopCache = this.updateLoopCache.bind(this);
91         }
92
93         componentDidMount() {
94                 this.getUser();
95         }
96
97         getUser() {
98                 UserService.login().then(user => {
99                         this.setState({ userName: user })
100                 });
101         }
102
103         renderMenuNavBar() {
104                 return (
105                         <MenuBar />
106                 );
107         }
108
109         renderUserLoggedNavBar() {
110                 return (
111                         <Navbar.Text>
112                                 Signed in as: <a href="/login">{this.state.userName}</a>
113                         </Navbar.Text>
114                 );
115         }
116
117         renderLogoNavBar() {
118                 return (
119                         <Navbar.Brand>
120                                 <img height="50px" width="234px" src={logo} alt="" />
121                                 <ProjectNameStyled>CLAMP</ProjectNameStyled>
122                         </Navbar.Brand>
123                 );
124         }
125
126         renderNavBar() {
127                 return (
128                         <Navbar expand="lg">
129                                 {this.renderLogoNavBar()}
130                                 {this.renderMenuNavBar()}
131                                 {this.renderUserLoggedNavBar()}
132                         </Navbar>
133                 );
134         }
135
136         renderLoopViewHeader() {
137                 return (
138                         <LoopViewHeaderDivStyled>
139                                 Loop Viewer - <LoopViewLoopNameSpanStyled id="loop_name">{this.state.loopName}</LoopViewLoopNameSpanStyled>
140                         </LoopViewHeaderDivStyled>
141                 );
142         }
143
144         renderLoopViewBody() {
145                 return (
146                         <LoopViewBodyDivStyled>
147                                 <LoopSvg loopCache={this.state.loopCache} />
148                                 <LoopLogs />
149                                 <LoopStatus />
150                         </LoopViewBodyDivStyled>
151                 );
152         }
153
154         renderLoopViewer() {
155                 return (
156                         <LoopViewDivStyled>
157                                 {this.renderLoopViewHeader()}
158                                 {this.renderLoopViewBody()}
159                         </LoopViewDivStyled>
160                 );
161         }
162
163         updateLoopCache(loopJson) {
164                 this.setState({ loopCache: new LoopCache(loopJson) });
165         }
166
167         render() {
168                 return (
169                         <div id="main_div">
170                                 <GlobalClampStyle />
171                                 {this.renderNavBar()}
172                                 {this.renderLoopViewer()}
173                                 <Route path="/operationalPolicyModal"
174                                         render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.state.loopCache} />)} />
175                                 <Route path="/configurationPolicyModal" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.state.loopCache} />)} />
176                                 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} updateLoopCacheFunction={this.updateLoopCache} />)} />
177                         </div>
178                 );
179         }
180 }