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 | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 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'; |
sebdet | e44fdb1 | 2019-07-12 12:25:56 +0200 | [diff] [blame] | 34 | import UserService from './api/UserService'; |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 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'; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 41 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 42 | const ProjectNameStyled = styled.a` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 43 | vertical-align: middle; |
| 44 | padding-left: 30px; |
| 45 | font-size: 30px; |
| 46 | |
| 47 | ` |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 48 | const LoopViewDivStyled = styled.div` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 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 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 60 | const LoopViewHeaderDivStyled = styled.div` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 61 | background-color: ${props => props.theme.loopViewerHeaderBackgroundColor}; |
| 62 | padding: 10px 10px; |
| 63 | color: ${props => props.theme.loopViewerHeaderFontColor}; |
| 64 | ` |
| 65 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 66 | const LoopViewBodyDivStyled = styled.div` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 67 | background-color: ${props => (props.theme.loopViewerBackgroundColor)}; |
| 68 | padding: 10px 10px; |
| 69 | color: ${props => (props.theme.loopViewerHeaderFontColor)}; |
| 70 | height: 95%; |
| 71 | ` |
| 72 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 73 | const LoopViewLoopNameSpanStyled = styled.span` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 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 { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 80 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 81 | state = { |
| 82 | userName: null, |
| 83 | loopName: "Empty (NO loop loaded yet)", |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 84 | loopCache: new LoopCache({}), |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 85 | }; |
xuegao | 7c7323d | 2019-07-09 11:52:20 +0200 | [diff] [blame] | 86 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 87 | constructor() { |
| 88 | super(); |
| 89 | this.getUser = this.getUser.bind(this); |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 90 | this.updateLoopCache = this.updateLoopCache.bind(this); |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 91 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 92 | |
| 93 | componentDidMount() { |
| 94 | this.getUser(); |
| 95 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 96 | |
| 97 | getUser() { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 98 | UserService.login().then(user => { |
| 99 | this.setState({ userName: user }) |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 100 | }); |
| 101 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 102 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 103 | renderMenuNavBar() { |
| 104 | return ( |
| 105 | <MenuBar /> |
| 106 | ); |
| 107 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 108 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 109 | renderUserLoggedNavBar() { |
| 110 | return ( |
| 111 | <Navbar.Text> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 112 | Signed in as: <a href="/login">{this.state.userName}</a> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 113 | </Navbar.Text> |
| 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 | renderLogoNavBar() { |
| 118 | return ( |
| 119 | <Navbar.Brand> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 120 | <img height="50px" width="234px" src={logo} alt="" /> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 121 | <ProjectNameStyled>CLAMP</ProjectNameStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 122 | </Navbar.Brand> |
| 123 | ); |
| 124 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 125 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 126 | renderNavBar() { |
| 127 | return ( |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 128 | <Navbar expand="lg"> |
| 129 | {this.renderLogoNavBar()} |
| 130 | {this.renderMenuNavBar()} |
| 131 | {this.renderUserLoggedNavBar()} |
| 132 | </Navbar> |
| 133 | ); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 134 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 135 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 136 | renderLoopViewHeader() { |
| 137 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 138 | <LoopViewHeaderDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 139 | Loop Viewer - <LoopViewLoopNameSpanStyled id="loop_name">{this.state.loopName}</LoopViewLoopNameSpanStyled> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 140 | </LoopViewHeaderDivStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 141 | ); |
| 142 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 143 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 144 | renderLoopViewBody() { |
| 145 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 146 | <LoopViewBodyDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 147 | <LoopSvg loopCache={this.state.loopCache} /> |
| 148 | <LoopLogs /> |
| 149 | <LoopStatus /> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 150 | </LoopViewBodyDivStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 151 | ); |
| 152 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 153 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 154 | renderLoopViewer() { |
| 155 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 156 | <LoopViewDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 157 | {this.renderLoopViewHeader()} |
| 158 | {this.renderLoopViewBody()} |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 159 | </LoopViewDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 160 | ); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 161 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 162 | |
| 163 | updateLoopCache(loopJson) { |
| 164 | this.setState({ loopCache: new LoopCache(loopJson) }); |
| 165 | } |
| 166 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 167 | render() { |
| 168 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 169 | <div id="main_div"> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame^] | 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> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 178 | ); |
| 179 | } |
| 180 | } |