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'; |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame^] | 41 | import LoopProperties from './components/dialogs/LoopProperties'; |
| 42 | import UserInfo from './components/dialogs/UserInfo'; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 43 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 44 | const ProjectNameStyled = styled.a` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 45 | vertical-align: middle; |
| 46 | padding-left: 30px; |
| 47 | font-size: 30px; |
| 48 | |
| 49 | ` |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 50 | const LoopViewDivStyled = styled.div` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 51 | height: 90vh; |
| 52 | overflow: hidden; |
| 53 | margin-left: 10px; |
| 54 | margin-right: 10px; |
| 55 | margin-bottom: 10px; |
| 56 | color: ${props => props.theme.loopViewerFontColor}; |
| 57 | background-color: ${props => props.theme.loopViewerBackgroundColor}; |
| 58 | border: 1px solid transparent; |
| 59 | border-color: ${props => props.theme.loopViewerHeaderBackgroundColor}; |
| 60 | ` |
| 61 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 62 | const LoopViewHeaderDivStyled = styled.div` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 63 | background-color: ${props => props.theme.loopViewerHeaderBackgroundColor}; |
| 64 | padding: 10px 10px; |
| 65 | color: ${props => props.theme.loopViewerHeaderFontColor}; |
| 66 | ` |
| 67 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 68 | const LoopViewBodyDivStyled = styled.div` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 69 | background-color: ${props => (props.theme.loopViewerBackgroundColor)}; |
| 70 | padding: 10px 10px; |
| 71 | color: ${props => (props.theme.loopViewerHeaderFontColor)}; |
| 72 | height: 95%; |
| 73 | ` |
| 74 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 75 | const LoopViewLoopNameSpanStyled = styled.span` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 76 | font-weight: bold; |
| 77 | color: ${props => (props.theme.loopViewerHeaderFontColor)}; |
| 78 | background-color: ${props => (props.theme.loopViewerHeaderBackgroundColor)}; |
| 79 | ` |
| 80 | |
| 81 | export default class LoopUI extends React.Component { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 82 | |
sebdet | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 83 | static defaultLoopName="Empty (NO loop loaded yet)"; |
| 84 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 85 | state = { |
| 86 | userName: null, |
sebdet | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 87 | loopName: LoopUI.defaultLoopName, |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 88 | loopCache: new LoopCache({}), |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 89 | }; |
xuegao | 7c7323d | 2019-07-09 11:52:20 +0200 | [diff] [blame] | 90 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 91 | constructor() { |
| 92 | super(); |
| 93 | this.getUser = this.getUser.bind(this); |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 94 | this.updateLoopCache = this.updateLoopCache.bind(this); |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 95 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 96 | |
sebdet | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 97 | componentWillMount() { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 98 | this.getUser(); |
| 99 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 100 | |
| 101 | getUser() { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 102 | UserService.login().then(user => { |
| 103 | this.setState({ userName: user }) |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 104 | }); |
| 105 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 106 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 107 | renderMenuNavBar() { |
| 108 | return ( |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame^] | 109 | <MenuBar loopCache={this.state.loopCache}/> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 110 | ); |
| 111 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 112 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 113 | renderUserLoggedNavBar() { |
| 114 | return ( |
| 115 | <Navbar.Text> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 116 | Signed in as: <a href="/login">{this.state.userName}</a> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 117 | </Navbar.Text> |
| 118 | ); |
| 119 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 120 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 121 | renderLogoNavBar() { |
| 122 | return ( |
| 123 | <Navbar.Brand> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 124 | <img height="50px" width="234px" src={logo} alt="" /> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 125 | <ProjectNameStyled>CLAMP</ProjectNameStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 126 | </Navbar.Brand> |
| 127 | ); |
| 128 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 129 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 130 | renderNavBar() { |
| 131 | return ( |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 132 | <Navbar expand="lg"> |
| 133 | {this.renderLogoNavBar()} |
| 134 | {this.renderMenuNavBar()} |
| 135 | {this.renderUserLoggedNavBar()} |
| 136 | </Navbar> |
| 137 | ); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 138 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 139 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 140 | renderLoopViewHeader() { |
| 141 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 142 | <LoopViewHeaderDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 143 | Loop Viewer - <LoopViewLoopNameSpanStyled id="loop_name">{this.state.loopName}</LoopViewLoopNameSpanStyled> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 144 | </LoopViewHeaderDivStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 145 | ); |
| 146 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 147 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 148 | renderLoopViewBody() { |
| 149 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 150 | <LoopViewBodyDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 151 | <LoopSvg loopCache={this.state.loopCache} /> |
sebdet | c1ccc54 | 2019-07-19 09:50:33 +0200 | [diff] [blame] | 152 | <LoopLogs loopCache={this.state.loopCache} /> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 153 | <LoopStatus /> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 154 | </LoopViewBodyDivStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 155 | ); |
| 156 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 157 | |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame^] | 158 | getLoopCache() { |
| 159 | return this.state.loopCache; |
| 160 | |
| 161 | } |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 162 | renderLoopViewer() { |
| 163 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 164 | <LoopViewDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 165 | {this.renderLoopViewHeader()} |
| 166 | {this.renderLoopViewBody()} |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 167 | </LoopViewDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 168 | ); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 169 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 170 | |
| 171 | updateLoopCache(loopJson) { |
| 172 | this.setState({ loopCache: new LoopCache(loopJson) }); |
sebdet | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 173 | this.setState({ loopName: this.state.loopCache.getLoopName() }); |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 174 | } |
| 175 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 176 | render() { |
| 177 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 178 | <div id="main_div"> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 179 | <GlobalClampStyle /> |
| 180 | {this.renderNavBar()} |
| 181 | {this.renderLoopViewer()} |
| 182 | <Route path="/operationalPolicyModal" |
| 183 | render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.state.loopCache} />)} /> |
sebdet | 5f6c178 | 2019-07-18 15:23:13 +0200 | [diff] [blame] | 184 | <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.state.loopCache} />)} /> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 185 | <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} updateLoopCacheFunction={this.updateLoopCache} />)} /> |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame^] | 186 | <Route path="/loopProperties" render={(routeProps) => (<LoopProperties {...routeProps} loopCache={this.getLoopCache()} />)} /> |
| 187 | <Route path="/userInfo" render={(routeProps) => (<UserInfo {...routeProps} />)} /> |
sebdet | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 188 | <Route path="/closeLoop" render={(routeProps) => (<Redirect to='/'/>)} /> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 189 | </div> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 190 | ); |
| 191 | } |
| 192 | } |