Rework the structure
[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 ClosedLoopSvg from './components/loop_viewer/svg/ClosedLoopSvg';
32 import ClosedLoopLogs from './components/loop_viewer/logs/ClosedLoopLogs';
33 import ClosedLoopStatus from './components/loop_viewer/status/ClosedLoopStatus';
34 import UserService from './api/UserService';
35
36 const ProjectNameStyled = styled.a`
37         vertical-align: middle;
38         padding-left: 30px;
39         font-size: 30px;
40
41 `
42 const LoopViewDivStyled = styled.div`
43         height: 90vh;
44         overflow: hidden;
45         margin-left: 10px;
46         margin-right: 10px;
47         margin-bottom: 10px;
48         color: ${props => props.theme.loopViewerFontColor};
49         background-color: ${props => props.theme.loopViewerBackgroundColor};
50         border: 1px solid transparent;
51         border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
52 `
53
54 const LoopViewHeaderDivStyled = styled.div`
55         background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
56         padding: 10px 10px;
57         color: ${props => props.theme.loopViewerHeaderFontColor};
58 `
59
60 const LoopViewBodyDivStyled = styled.div`
61         background-color: ${props => (props.theme.loopViewerBackgroundColor)};
62         padding: 10px 10px;
63         color: ${props => (props.theme.loopViewerHeaderFontColor)};
64         height: 95%;
65 `
66
67 const LoopViewLoopNameSpanStyled = styled.span`
68         font-weight: bold;
69         color: ${props => (props.theme.loopViewerHeaderFontColor)};
70         background-color: ${props => (props.theme.loopViewerHeaderBackgroundColor)};
71 `
72
73 export default class LoopUI extends React.Component {
74         state = {
75                 userName: null,
76                 loopName: "Empty (NO loop loaded yet)",
77         };
78
79         constructor() {
80                 super();
81                 this.getUser = this.getUser.bind(this);
82         }
83         
84         componentDidMount() {
85                  this.getUser();
86          }
87
88         getUser() {
89                 UserService.LOGIN().then(user => {
90                         this.setState({userName:user})
91                 });
92         }
93                 
94         renderMenuNavBar() {
95                 return (
96                         <MenuBar />
97                 );
98         }
99
100         renderUserLoggedNavBar() {
101                 return (
102                         <Navbar.Text>
103                                 Signed in as: <a href="/login">{this.state.userName}</a>
104                         </Navbar.Text>
105                 );
106         }
107
108         renderLogoNavBar() {
109                 return (
110                         <Navbar.Brand>
111                                 <img height="50px" width="234px" src={logo} alt=""/>
112                                 <ProjectNameStyled>CLAMP</ProjectNameStyled>
113                         </Navbar.Brand>
114                 );
115         }
116
117         renderNavBar() {
118                 return (
119                 <Navbar expand="lg">
120                         {this.renderLogoNavBar()}
121                         {this.renderMenuNavBar()}
122                         {this.renderUserLoggedNavBar()}
123                 </Navbar>
124         );
125         }
126         
127         renderLoopViewHeader() {
128                 return (
129                         <LoopViewHeaderDivStyled>
130                                 Loop Viewer - <LoopViewLoopNameSpanStyled id="loop_name">{this.state.loopName}</LoopViewLoopNameSpanStyled> 
131                         </LoopViewHeaderDivStyled>
132                 );
133         }
134         
135         renderLoopViewBody() {
136                 return (
137                         <LoopViewBodyDivStyled>
138                                 <ClosedLoopSvg />
139                                 <ClosedLoopLogs />
140                                 <ClosedLoopStatus />
141                         </LoopViewBodyDivStyled>
142                 );
143         }
144         
145         renderLoopViewer() {
146                 return (
147                         <LoopViewDivStyled>
148                                         {this.renderLoopViewHeader()}
149                                         {this.renderLoopViewBody()}
150                         </LoopViewDivStyled>
151                         );
152         }
153         
154         render() {
155                 return (
156                         <div id="main_div">
157                                         <GlobalClampStyle />
158                                         {this.renderNavBar()}
159                                         {this.renderLoopViewer()}
160                                 </div>
161                 );
162         }
163 }