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 | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 48 | const ProjectNameStyled = styled.a` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 49 | vertical-align: middle; |
| 50 | padding-left: 30px; |
| 51 | font-size: 30px; |
| 52 | |
| 53 | ` |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 54 | const LoopViewDivStyled = styled.div` |
sebdet | 190227a | 2019-07-19 16:51:19 +0200 | [diff] [blame] | 55 | height: 100%; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 56 | overflow: hidden; |
| 57 | margin-left: 10px; |
| 58 | margin-right: 10px; |
| 59 | margin-bottom: 10px; |
| 60 | color: ${props => props.theme.loopViewerFontColor}; |
| 61 | background-color: ${props => props.theme.loopViewerBackgroundColor}; |
| 62 | border: 1px solid transparent; |
| 63 | border-color: ${props => props.theme.loopViewerHeaderBackgroundColor}; |
| 64 | ` |
| 65 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 66 | const LoopViewHeaderDivStyled = styled.div` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 67 | background-color: ${props => props.theme.loopViewerHeaderBackgroundColor}; |
| 68 | padding: 10px 10px; |
| 69 | color: ${props => props.theme.loopViewerHeaderFontColor}; |
| 70 | ` |
| 71 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 72 | const LoopViewBodyDivStyled = styled.div` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 73 | background-color: ${props => (props.theme.loopViewerBackgroundColor)}; |
| 74 | padding: 10px 10px; |
| 75 | color: ${props => (props.theme.loopViewerHeaderFontColor)}; |
| 76 | height: 95%; |
| 77 | ` |
| 78 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 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, |
xuegao | 5fe750c | 2019-08-06 13:03:53 +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 | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 93 | this.loadLoop = this.loadLoop.bind(this); |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 94 | this.closeLoop = this.closeLoop.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 | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 109 | <MenuBar loopName={this.state.loopName}/> |
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 | 190227a | 2019-07-19 16:51:19 +0200 | [diff] [blame] | 143 | Loop Viewer - {this.state.loopName} |
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 | 190227a | 2019-07-19 16:51:19 +0200 | [diff] [blame] | 152 | <LoopStatus loopCache={this.state.loopCache}/> |
sebdet | c1ccc54 | 2019-07-19 09:50:33 +0200 | [diff] [blame] | 153 | <LoopLogs loopCache={this.state.loopCache} /> |
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 | } |
xuegao | 5fe750c | 2019-08-06 13:03:53 +0200 | [diff] [blame] | 162 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 163 | renderLoopViewer() { |
| 164 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 165 | <LoopViewDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 166 | {this.renderLoopViewHeader()} |
| 167 | {this.renderLoopViewBody()} |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 168 | </LoopViewDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 169 | ); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 170 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 171 | |
| 172 | updateLoopCache(loopJson) { |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 173 | this.setState({ loopCache: new LoopCache(loopJson), loopName: this.state.loopCache.getLoopName() }); |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 174 | console.info(this.state.loopName+" loop loaded successfully"); |
| 175 | } |
xuegao | 5fe750c | 2019-08-06 13:03:53 +0200 | [diff] [blame] | 176 | |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 177 | loadLoop(loopName) { |
| 178 | LoopService.getLoop(loopName).then(loop => { |
| 179 | console.debug("Updating loopCache"); |
| 180 | this.updateLoopCache(loop); |
| 181 | }); |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 182 | } |
| 183 | |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 184 | closeLoop() { |
| 185 | this.setState({ loopCache: new LoopCache({}), loopName: LoopUI.defaultLoopName }); |
| 186 | this.props.history.push('/'); |
| 187 | } |
sebdet | f9e2cee | 2019-08-09 18:36:09 +0200 | [diff] [blame] | 188 | |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 189 | render() { |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 190 | return ( |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 191 | <div id="main_div"> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 192 | <Route path="/operationalPolicyModal" |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 193 | render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} /> |
| 194 | <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} /> |
| 195 | <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} /> |
| 196 | <Route path="/loopProperties" render={(routeProps) => (<LoopProperties {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} /> |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 197 | <Route path="/userInfo" render={(routeProps) => (<UserInfo {...routeProps} />)} /> |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 198 | <Route path="/closeLoop" render={this.closeLoop} /> |
xuegao | 5fe750c | 2019-08-06 13:03:53 +0200 | [diff] [blame] | 199 | <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} /> |
| 200 | <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} /> |
| 201 | <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} /> |
| 202 | <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} /> |
| 203 | <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] | 204 | <Route path="/deploy" render={(routeProps) => (<DeployLoop {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} /> |
xuegao | 5fe750c | 2019-08-06 13:03:53 +0200 | [diff] [blame] | 205 | <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} /> |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 206 | <GlobalClampStyle /> |
| 207 | {this.renderNavBar()} |
| 208 | {this.renderLoopViewer()} |
| 209 | </div> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 210 | ); |
| 211 | } |
| 212 | } |