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 | |
sebdet | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 37 | import { Route, Redirect } from 'react-router-dom' |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 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 | 190227a | 2019-07-19 16:51:19 +0200 | [diff] [blame^] | 49 | height: 100%; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 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 | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 81 | static defaultLoopName="Empty (NO loop loaded yet)"; |
| 82 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 83 | state = { |
| 84 | userName: null, |
sebdet | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 85 | loopName: LoopUI.defaultLoopName, |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 86 | loopCache: new LoopCache({}), |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 87 | }; |
xuegao | 7c7323d | 2019-07-09 11:52:20 +0200 | [diff] [blame] | 88 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 89 | constructor() { |
| 90 | super(); |
| 91 | this.getUser = this.getUser.bind(this); |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 92 | this.updateLoopCache = this.updateLoopCache.bind(this); |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 93 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 94 | |
sebdet | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 95 | componentWillMount() { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 96 | this.getUser(); |
| 97 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 98 | |
| 99 | getUser() { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 100 | UserService.login().then(user => { |
| 101 | this.setState({ userName: user }) |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 102 | }); |
| 103 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 104 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 105 | renderMenuNavBar() { |
| 106 | return ( |
| 107 | <MenuBar /> |
| 108 | ); |
| 109 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 110 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 111 | renderUserLoggedNavBar() { |
| 112 | return ( |
| 113 | <Navbar.Text> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 114 | Signed in as: <a href="/login">{this.state.userName}</a> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 115 | </Navbar.Text> |
| 116 | ); |
| 117 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 118 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 119 | renderLogoNavBar() { |
| 120 | return ( |
| 121 | <Navbar.Brand> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 122 | <img height="50px" width="234px" src={logo} alt="" /> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 123 | <ProjectNameStyled>CLAMP</ProjectNameStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 124 | </Navbar.Brand> |
| 125 | ); |
| 126 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 127 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 128 | renderNavBar() { |
| 129 | return ( |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 130 | <Navbar expand="lg"> |
| 131 | {this.renderLogoNavBar()} |
| 132 | {this.renderMenuNavBar()} |
| 133 | {this.renderUserLoggedNavBar()} |
| 134 | </Navbar> |
| 135 | ); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 136 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 137 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 138 | renderLoopViewHeader() { |
| 139 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 140 | <LoopViewHeaderDivStyled> |
sebdet | 190227a | 2019-07-19 16:51:19 +0200 | [diff] [blame^] | 141 | Loop Viewer - {this.state.loopName} |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 142 | </LoopViewHeaderDivStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 143 | ); |
| 144 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 145 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 146 | renderLoopViewBody() { |
| 147 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 148 | <LoopViewBodyDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 149 | <LoopSvg loopCache={this.state.loopCache} /> |
sebdet | 190227a | 2019-07-19 16:51:19 +0200 | [diff] [blame^] | 150 | <LoopStatus loopCache={this.state.loopCache}/> |
sebdet | c1ccc54 | 2019-07-19 09:50:33 +0200 | [diff] [blame] | 151 | <LoopLogs loopCache={this.state.loopCache} /> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 152 | </LoopViewBodyDivStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 153 | ); |
| 154 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 155 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 156 | renderLoopViewer() { |
| 157 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 158 | <LoopViewDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 159 | {this.renderLoopViewHeader()} |
| 160 | {this.renderLoopViewBody()} |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 161 | </LoopViewDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 162 | ); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 163 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 164 | |
| 165 | updateLoopCache(loopJson) { |
| 166 | this.setState({ loopCache: new LoopCache(loopJson) }); |
sebdet | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 167 | this.setState({ loopName: this.state.loopCache.getLoopName() }); |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 168 | } |
| 169 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 170 | render() { |
| 171 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 172 | <div id="main_div"> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 173 | <GlobalClampStyle /> |
| 174 | {this.renderNavBar()} |
| 175 | {this.renderLoopViewer()} |
| 176 | <Route path="/operationalPolicyModal" |
| 177 | render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.state.loopCache} />)} /> |
sebdet | 5f6c178 | 2019-07-18 15:23:13 +0200 | [diff] [blame] | 178 | <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.state.loopCache} />)} /> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 179 | <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} updateLoopCacheFunction={this.updateLoopCache} />)} /> |
sebdet | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 180 | <Route path="/closeLoop" render={(routeProps) => (<Redirect to='/'/>)} /> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 181 | </div> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 182 | ); |
| 183 | } |
| 184 | } |