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