blob: 997f94b18ed3c39197826eb139a496c312bcfc9f [file] [log] [blame]
sebdetc8d61302019-07-04 15:50:34 +02001/*-
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
24import React from 'react';
25import styled from 'styled-components';
sebdete44fdb12019-07-12 12:25:56 +020026import MenuBar from './components/menu/MenuBar';
sebdetc8d61302019-07-04 15:50:34 +020027import Navbar from 'react-bootstrap/Navbar';
28import logo from './logo.png';
sebdete44fdb12019-07-12 12:25:56 +020029import { GlobalClampStyle } from './theme/globalStyle.js';
sebdetc8d61302019-07-04 15:50:34 +020030
sebdete44fdb12019-07-12 12:25:56 +020031import ClosedLoopSvg from './components/loop_viewer/svg/ClosedLoopSvg';
32import ClosedLoopLogs from './components/loop_viewer/logs/ClosedLoopLogs';
33import ClosedLoopStatus from './components/loop_viewer/status/ClosedLoopStatus';
34import UserService from './api/UserService';
sebdetc8d61302019-07-04 15:50:34 +020035
sebdet4946e5b2019-07-10 12:32:36 +020036const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020037 vertical-align: middle;
38 padding-left: 30px;
39 font-size: 30px;
40
41`
sebdet4946e5b2019-07-10 12:32:36 +020042const LoopViewDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020043 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
sebdet4946e5b2019-07-10 12:32:36 +020054const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020055 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
56 padding: 10px 10px;
57 color: ${props => props.theme.loopViewerHeaderFontColor};
58`
59
sebdet4946e5b2019-07-10 12:32:36 +020060const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020061 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
62 padding: 10px 10px;
63 color: ${props => (props.theme.loopViewerHeaderFontColor)};
64 height: 95%;
65`
66
sebdet4946e5b2019-07-10 12:32:36 +020067const LoopViewLoopNameSpanStyled = styled.span`
sebdetc8d61302019-07-04 15:50:34 +020068 font-weight: bold;
69 color: ${props => (props.theme.loopViewerHeaderFontColor)};
70 background-color: ${props => (props.theme.loopViewerHeaderBackgroundColor)};
71`
72
73export default class LoopUI extends React.Component {
sebdet4946e5b2019-07-10 12:32:36 +020074 state = {
75 userName: null,
76 loopName: "Empty (NO loop loaded yet)",
77 };
xuegao7c7323d2019-07-09 11:52:20 +020078
sebdet4946e5b2019-07-10 12:32:36 +020079 constructor() {
80 super();
81 this.getUser = this.getUser.bind(this);
82 }
sebdete44fdb12019-07-12 12:25:56 +020083
sebdet4946e5b2019-07-10 12:32:36 +020084 componentDidMount() {
85 this.getUser();
86 }
87
88 getUser() {
89 UserService.LOGIN().then(user => {
90 this.setState({userName:user})
91 });
92 }
sebdetc8d61302019-07-04 15:50:34 +020093
94 renderMenuNavBar() {
95 return (
96 <MenuBar />
97 );
98 }
sebdet4946e5b2019-07-10 12:32:36 +020099
sebdetc8d61302019-07-04 15:50:34 +0200100 renderUserLoggedNavBar() {
101 return (
102 <Navbar.Text>
sebdet4946e5b2019-07-10 12:32:36 +0200103 Signed in as: <a href="/login">{this.state.userName}</a>
sebdetc8d61302019-07-04 15:50:34 +0200104 </Navbar.Text>
105 );
106 }
sebdet4946e5b2019-07-10 12:32:36 +0200107
sebdetc8d61302019-07-04 15:50:34 +0200108 renderLogoNavBar() {
109 return (
110 <Navbar.Brand>
111 <img height="50px" width="234px" src={logo} alt=""/>
sebdet4946e5b2019-07-10 12:32:36 +0200112 <ProjectNameStyled>CLAMP</ProjectNameStyled>
sebdetc8d61302019-07-04 15:50:34 +0200113 </Navbar.Brand>
114 );
115 }
sebdet4946e5b2019-07-10 12:32:36 +0200116
sebdetc8d61302019-07-04 15:50:34 +0200117 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 (
sebdet4946e5b2019-07-10 12:32:36 +0200129 <LoopViewHeaderDivStyled>
130 Loop Viewer - <LoopViewLoopNameSpanStyled id="loop_name">{this.state.loopName}</LoopViewLoopNameSpanStyled>
131 </LoopViewHeaderDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200132 );
133 }
134
135 renderLoopViewBody() {
136 return (
sebdet4946e5b2019-07-10 12:32:36 +0200137 <LoopViewBodyDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200138 <ClosedLoopSvg />
139 <ClosedLoopLogs />
140 <ClosedLoopStatus />
sebdet4946e5b2019-07-10 12:32:36 +0200141 </LoopViewBodyDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200142 );
143 }
144
145 renderLoopViewer() {
146 return (
sebdet4946e5b2019-07-10 12:32:36 +0200147 <LoopViewDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200148 {this.renderLoopViewHeader()}
149 {this.renderLoopViewBody()}
sebdet4946e5b2019-07-10 12:32:36 +0200150 </LoopViewDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200151 );
152 }
153
154 render() {
155 return (
sebdet4946e5b2019-07-10 12:32:36 +0200156 <div id="main_div">
sebdetc8d61302019-07-04 15:50:34 +0200157 <GlobalClampStyle />
158 {this.renderNavBar()}
159 {this.renderLoopViewer()}
160 </div>
161 );
162 }
163}