sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 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'; |
sebdet | e44fdb1 | 2019-07-12 12:25:56 +0200 | [diff] [blame^] | 26 | import MenuBar from './components/menu/MenuBar'; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 27 | import Navbar from 'react-bootstrap/Navbar'; |
| 28 | import logo from './logo.png'; |
sebdet | e44fdb1 | 2019-07-12 12:25:56 +0200 | [diff] [blame^] | 29 | import { GlobalClampStyle } from './theme/globalStyle.js'; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 30 | |
sebdet | e44fdb1 | 2019-07-12 12:25:56 +0200 | [diff] [blame^] | 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'; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 35 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 36 | const ProjectNameStyled = styled.a` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 37 | vertical-align: middle; |
| 38 | padding-left: 30px; |
| 39 | font-size: 30px; |
| 40 | |
| 41 | ` |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 42 | const LoopViewDivStyled = styled.div` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 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 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 54 | const LoopViewHeaderDivStyled = styled.div` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 55 | background-color: ${props => props.theme.loopViewerHeaderBackgroundColor}; |
| 56 | padding: 10px 10px; |
| 57 | color: ${props => props.theme.loopViewerHeaderFontColor}; |
| 58 | ` |
| 59 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 60 | const LoopViewBodyDivStyled = styled.div` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 61 | background-color: ${props => (props.theme.loopViewerBackgroundColor)}; |
| 62 | padding: 10px 10px; |
| 63 | color: ${props => (props.theme.loopViewerHeaderFontColor)}; |
| 64 | height: 95%; |
| 65 | ` |
| 66 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 67 | const LoopViewLoopNameSpanStyled = styled.span` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 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 { |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 74 | state = { |
| 75 | userName: null, |
| 76 | loopName: "Empty (NO loop loaded yet)", |
| 77 | }; |
xuegao | 7c7323d | 2019-07-09 11:52:20 +0200 | [diff] [blame] | 78 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 79 | constructor() { |
| 80 | super(); |
| 81 | this.getUser = this.getUser.bind(this); |
| 82 | } |
sebdet | e44fdb1 | 2019-07-12 12:25:56 +0200 | [diff] [blame^] | 83 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 84 | componentDidMount() { |
| 85 | this.getUser(); |
| 86 | } |
| 87 | |
| 88 | getUser() { |
| 89 | UserService.LOGIN().then(user => { |
| 90 | this.setState({userName:user}) |
| 91 | }); |
| 92 | } |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 93 | |
| 94 | renderMenuNavBar() { |
| 95 | return ( |
| 96 | <MenuBar /> |
| 97 | ); |
| 98 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 99 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 100 | renderUserLoggedNavBar() { |
| 101 | return ( |
| 102 | <Navbar.Text> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 103 | Signed in as: <a href="/login">{this.state.userName}</a> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 104 | </Navbar.Text> |
| 105 | ); |
| 106 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 107 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 108 | renderLogoNavBar() { |
| 109 | return ( |
| 110 | <Navbar.Brand> |
| 111 | <img height="50px" width="234px" src={logo} alt=""/> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 112 | <ProjectNameStyled>CLAMP</ProjectNameStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 113 | </Navbar.Brand> |
| 114 | ); |
| 115 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 116 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 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 ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 129 | <LoopViewHeaderDivStyled> |
| 130 | Loop Viewer - <LoopViewLoopNameSpanStyled id="loop_name">{this.state.loopName}</LoopViewLoopNameSpanStyled> |
| 131 | </LoopViewHeaderDivStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 132 | ); |
| 133 | } |
| 134 | |
| 135 | renderLoopViewBody() { |
| 136 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 137 | <LoopViewBodyDivStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 138 | <ClosedLoopSvg /> |
| 139 | <ClosedLoopLogs /> |
| 140 | <ClosedLoopStatus /> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 141 | </LoopViewBodyDivStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 142 | ); |
| 143 | } |
| 144 | |
| 145 | renderLoopViewer() { |
| 146 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 147 | <LoopViewDivStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 148 | {this.renderLoopViewHeader()} |
| 149 | {this.renderLoopViewBody()} |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 150 | </LoopViewDivStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 151 | ); |
| 152 | } |
| 153 | |
| 154 | render() { |
| 155 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 156 | <div id="main_div"> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 157 | <GlobalClampStyle /> |
| 158 | {this.renderNavBar()} |
| 159 | {this.renderLoopViewer()} |
| 160 | </div> |
| 161 | ); |
| 162 | } |
| 163 | } |