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 | |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 37 | import { Route } 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 | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 43 | import LoopService from './api/LoopService'; |
sebdet | f9e2cee | 2019-08-09 18:36:09 +0200 | [diff] [blame] | 44 | import PerformAction from './components/dialogs/PerformActions'; |
| 45 | import RefreshStatus from './components/dialogs/RefreshStatus'; |
| 46 | import DeployLoop from './components/dialogs/DeployLoop'; |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame^] | 47 | import Alert from 'react-bootstrap/Alert'; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 48 | |
sebdet | d0d6563 | 2019-08-26 05:47:01 -0700 | [diff] [blame] | 49 | import { Link } from 'react-router-dom'; |
| 50 | |
| 51 | const StyledMainDiv = styled.div` |
| 52 | background-color: ${props => props.theme.backgroundColor}; |
| 53 | ` |
| 54 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 55 | const ProjectNameStyled = styled.a` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 56 | vertical-align: middle; |
| 57 | padding-left: 30px; |
sebdet | d0d6563 | 2019-08-26 05:47:01 -0700 | [diff] [blame] | 58 | font-size: 36px; |
| 59 | font-weight: bold; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 60 | ` |
sebdet | d0d6563 | 2019-08-26 05:47:01 -0700 | [diff] [blame] | 61 | |
| 62 | const StyledRouterLink = styled(Link)` |
| 63 | color: ${props => props.theme.menuFontColor}; |
| 64 | background-color: ${props => props.theme.backgroundColor}; |
| 65 | ` |
| 66 | |
| 67 | const StyledLoginInfo = styled.a` |
| 68 | color: ${props => props.theme.menuFontColor}; |
| 69 | background-color: ${props => props.theme.backgroundColor}; |
| 70 | ` |
| 71 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 72 | const LoopViewDivStyled = styled.div` |
sebdet | 190227a | 2019-07-19 16:51:19 +0200 | [diff] [blame] | 73 | height: 100%; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 74 | overflow: hidden; |
| 75 | margin-left: 10px; |
| 76 | margin-right: 10px; |
| 77 | margin-bottom: 10px; |
| 78 | color: ${props => props.theme.loopViewerFontColor}; |
| 79 | background-color: ${props => props.theme.loopViewerBackgroundColor}; |
| 80 | border: 1px solid transparent; |
| 81 | border-color: ${props => props.theme.loopViewerHeaderBackgroundColor}; |
| 82 | ` |
| 83 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 84 | const LoopViewHeaderDivStyled = styled.div` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 85 | background-color: ${props => props.theme.loopViewerHeaderBackgroundColor}; |
| 86 | padding: 10px 10px; |
| 87 | color: ${props => props.theme.loopViewerHeaderFontColor}; |
| 88 | ` |
| 89 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 90 | const LoopViewBodyDivStyled = styled.div` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 91 | background-color: ${props => (props.theme.loopViewerBackgroundColor)}; |
| 92 | padding: 10px 10px; |
| 93 | color: ${props => (props.theme.loopViewerHeaderFontColor)}; |
| 94 | height: 95%; |
| 95 | ` |
| 96 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 97 | export default class LoopUI extends React.Component { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 98 | |
sebdet | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 99 | static defaultLoopName="Empty (NO loop loaded yet)"; |
| 100 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 101 | state = { |
| 102 | userName: null, |
sebdet | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 103 | loopName: LoopUI.defaultLoopName, |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame^] | 104 | loopCache: new LoopCache({}), |
| 105 | showAlert: false |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 106 | }; |
xuegao | 7c7323d | 2019-07-09 11:52:20 +0200 | [diff] [blame] | 107 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 108 | constructor() { |
| 109 | super(); |
| 110 | this.getUser = this.getUser.bind(this); |
sebdet | 687b8de | 2019-08-26 14:29:11 -0700 | [diff] [blame] | 111 | this.logout = this.logout.bind(this); |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 112 | this.updateLoopCache = this.updateLoopCache.bind(this); |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 113 | this.loadLoop = this.loadLoop.bind(this); |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 114 | this.closeLoop = this.closeLoop.bind(this); |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame^] | 115 | this.showAlert = this.showAlert.bind(this); |
| 116 | this.disableAlert = this.disableAlert.bind(this); |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 117 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 118 | |
sebdet | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 119 | componentWillMount() { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 120 | this.getUser(); |
| 121 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 122 | |
| 123 | getUser() { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 124 | UserService.login().then(user => { |
| 125 | this.setState({ userName: user }) |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 126 | }); |
| 127 | } |
sebdet | 687b8de | 2019-08-26 14:29:11 -0700 | [diff] [blame] | 128 | |
| 129 | logout() { |
| 130 | UserService.logout().then(user => { |
| 131 | this.setState({ userName: user }); |
| 132 | window.location.reload(); |
| 133 | }); |
| 134 | |
| 135 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 136 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 137 | renderMenuNavBar() { |
| 138 | return ( |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 139 | <MenuBar loopName={this.state.loopName}/> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 140 | ); |
| 141 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 142 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 143 | renderUserLoggedNavBar() { |
| 144 | return ( |
| 145 | <Navbar.Text> |
sebdet | d0d6563 | 2019-08-26 05:47:01 -0700 | [diff] [blame] | 146 | <StyledLoginInfo>Signed in as: </StyledLoginInfo> |
| 147 | <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink> |
| 148 | <StyledRouterLink to="/logout/"> (logout)</StyledRouterLink> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 149 | </Navbar.Text> |
| 150 | ); |
| 151 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 152 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 153 | renderLogoNavBar() { |
| 154 | return ( |
| 155 | <Navbar.Brand> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 156 | <img height="50px" width="234px" src={logo} alt="" /> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 157 | <ProjectNameStyled>CLAMP</ProjectNameStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 158 | </Navbar.Brand> |
| 159 | ); |
| 160 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 161 | |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame^] | 162 | renderAlertBar() { |
| 163 | return ( |
| 164 | <Alert variant="danger" show={this.state.showAlert} onClose={this.disableAlert} dismissible> |
| 165 | {this.state.showMessage} |
| 166 | </Alert> |
| 167 | ); |
| 168 | } |
| 169 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 170 | renderNavBar() { |
| 171 | return ( |
sebdet | d0d6563 | 2019-08-26 05:47:01 -0700 | [diff] [blame] | 172 | <Navbar > |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 173 | {this.renderLogoNavBar()} |
sebdet | d0d6563 | 2019-08-26 05:47:01 -0700 | [diff] [blame] | 174 | <Navbar.Toggle aria-controls="responsive-navbar-nav" /> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 175 | {this.renderMenuNavBar()} |
| 176 | {this.renderUserLoggedNavBar()} |
| 177 | </Navbar> |
| 178 | ); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 179 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 180 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 181 | renderLoopViewHeader() { |
| 182 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 183 | <LoopViewHeaderDivStyled> |
sebdet | 190227a | 2019-07-19 16:51:19 +0200 | [diff] [blame] | 184 | Loop Viewer - {this.state.loopName} |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 185 | </LoopViewHeaderDivStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 186 | ); |
| 187 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 188 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 189 | renderLoopViewBody() { |
| 190 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 191 | <LoopViewBodyDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 192 | <LoopSvg loopCache={this.state.loopCache} /> |
sebdet | 190227a | 2019-07-19 16:51:19 +0200 | [diff] [blame] | 193 | <LoopStatus loopCache={this.state.loopCache}/> |
sebdet | c1ccc54 | 2019-07-19 09:50:33 +0200 | [diff] [blame] | 194 | <LoopLogs loopCache={this.state.loopCache} /> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 195 | </LoopViewBodyDivStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 196 | ); |
| 197 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 198 | |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 199 | getLoopCache() { |
| 200 | return this.state.loopCache; |
| 201 | |
| 202 | } |
xuegao | 5fe750c | 2019-08-06 13:03:53 +0200 | [diff] [blame] | 203 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 204 | renderLoopViewer() { |
| 205 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 206 | <LoopViewDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 207 | {this.renderLoopViewHeader()} |
| 208 | {this.renderLoopViewBody()} |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 209 | </LoopViewDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 210 | ); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 211 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 212 | |
| 213 | updateLoopCache(loopJson) { |
xuegao | 52432d6 | 2019-10-04 16:11:22 +0200 | [diff] [blame] | 214 | this.setState({ loopCache: new LoopCache(loopJson) }); |
| 215 | this.setState({ loopName: this.state.loopCache.getLoopName() }); |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 216 | console.info(this.state.loopName+" loop loaded successfully"); |
| 217 | } |
xuegao | 5fe750c | 2019-08-06 13:03:53 +0200 | [diff] [blame] | 218 | |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame^] | 219 | showAlert(message) { |
| 220 | this.setState ({ showAlert: true, showMessage:message }); |
| 221 | } |
| 222 | |
| 223 | disableAlert() { |
| 224 | this.setState ({ showAlert: false }); |
| 225 | } |
| 226 | |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 227 | loadLoop(loopName) { |
| 228 | LoopService.getLoop(loopName).then(loop => { |
| 229 | console.debug("Updating loopCache"); |
| 230 | this.updateLoopCache(loop); |
| 231 | }); |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 232 | } |
| 233 | |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 234 | closeLoop() { |
| 235 | this.setState({ loopCache: new LoopCache({}), loopName: LoopUI.defaultLoopName }); |
| 236 | this.props.history.push('/'); |
| 237 | } |
sebdet | 687b8de | 2019-08-26 14:29:11 -0700 | [diff] [blame] | 238 | |
| 239 | render() { |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 240 | return ( |
sebdet | d0d6563 | 2019-08-26 05:47:01 -0700 | [diff] [blame] | 241 | <StyledMainDiv id="main_div"> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 242 | <Route path="/operationalPolicyModal" |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame^] | 243 | render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} showAlert={this.showAlert}/>)} /> |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 244 | <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} /> |
| 245 | <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} /> |
| 246 | <Route path="/loopProperties" render={(routeProps) => (<LoopProperties {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} /> |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 247 | <Route path="/userInfo" render={(routeProps) => (<UserInfo {...routeProps} />)} /> |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 248 | <Route path="/closeLoop" render={this.closeLoop} /> |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame^] | 249 | <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} /> |
| 250 | <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} /> |
| 251 | <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} /> |
| 252 | <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} /> |
| 253 | <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} /> |
| 254 | <Route path="/deploy" render={(routeProps) => (<DeployLoop {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} /> |
| 255 | <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} /> |
sebdet | 687b8de | 2019-08-26 14:29:11 -0700 | [diff] [blame] | 256 | <Route path="/logout" render={this.logout} /> |
| 257 | <GlobalClampStyle /> |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame^] | 258 | {this.renderAlertBar()} |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 259 | {this.renderNavBar()} |
| 260 | {this.renderLoopViewer()} |
sebdet | d0d6563 | 2019-08-26 05:47:01 -0700 | [diff] [blame] | 261 | </StyledMainDiv> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 262 | ); |
| 263 | } |
| 264 | } |