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'; |
Ted Humphrey | 01e5fde | 2020-01-27 18:57:39 -0500 | [diff] [blame] | 30 | import OnapConstants from './utils/OnapConstants'; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 31 | |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame] | 32 | import SvgGenerator from './components/loop_viewer/svg/SvgGenerator'; |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 33 | import LoopLogs from './components/loop_viewer/logs/LoopLogs'; |
| 34 | import LoopStatus from './components/loop_viewer/status/LoopStatus'; |
sebdet | e44fdb1 | 2019-07-12 12:25:56 +0200 | [diff] [blame] | 35 | import UserService from './api/UserService'; |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 36 | import LoopCache from './api/LoopCache'; |
xuegao | ac42c4b | 2019-10-09 16:12:37 +0200 | [diff] [blame] | 37 | import LoopActionService from './api/LoopActionService'; |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 38 | |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 39 | import { Route } from 'react-router-dom' |
sebdet | d2a4df0 | 2020-02-26 15:47:30 -0800 | [diff] [blame] | 40 | import CreateLoopModal from './components/dialogs/Loop/CreateLoopModal'; |
sebdet | 67c76a4 | 2019-11-15 17:33:44 +0100 | [diff] [blame] | 41 | import OpenLoopModal from './components/dialogs/Loop/OpenLoopModal'; |
sebdet | aa486be | 2020-02-18 02:00:11 -0800 | [diff] [blame] | 42 | import ModifyLoopModal from './components/dialogs/Loop/ModifyLoopModal'; |
sebdet | d2a4df0 | 2020-02-26 15:47:30 -0800 | [diff] [blame] | 43 | import PolicyModal from './components/dialogs/Policy/PolicyModal'; |
sebdet | b13a790 | 2019-11-15 17:26:45 +0100 | [diff] [blame] | 44 | import LoopPropertiesModal from './components/dialogs/Loop/LoopPropertiesModal'; |
sebdet | 4dc849f | 2019-11-15 17:49:42 +0100 | [diff] [blame] | 45 | import UserInfoModal from './components/dialogs/UserInfoModal'; |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 46 | import LoopService from './api/LoopService'; |
ash74268 | 3a83e2a | 2020-01-31 15:40:15 +0000 | [diff] [blame] | 47 | import UploadToscaPolicyModal from './components/dialogs/Tosca/UploadToscaPolicyModal'; |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 48 | import ViewToscaPolicyModal from './components/dialogs/Tosca/ViewToscaPolicyModal'; |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 49 | import ViewLoopTemplatesModal from './components/dialogs/Tosca/ViewLoopTemplatesModal'; |
drveerendra | 5032095 | 2020-03-04 20:30:44 -0500 | [diff] [blame] | 50 | import ManageDictionaries from './components/dialogs/ManageDictionaries/ManageDictionaries'; |
sebdet | f9e2cee | 2019-08-09 18:36:09 +0200 | [diff] [blame] | 51 | import PerformAction from './components/dialogs/PerformActions'; |
| 52 | import RefreshStatus from './components/dialogs/RefreshStatus'; |
sebdet | 2e9ae12 | 2019-11-15 16:28:55 +0100 | [diff] [blame] | 53 | import DeployLoopModal from './components/dialogs/Loop/DeployLoopModal'; |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame] | 54 | import Alert from 'react-bootstrap/Alert'; |
Ted Humphrey | 4fb3239 | 2020-07-06 16:59:47 -0400 | [diff] [blame^] | 55 | import Spinner from 'react-bootstrap/Spinner'; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 56 | |
sebdet | d0d6563 | 2019-08-26 05:47:01 -0700 | [diff] [blame] | 57 | import { Link } from 'react-router-dom'; |
| 58 | |
| 59 | const StyledMainDiv = styled.div` |
| 60 | background-color: ${props => props.theme.backgroundColor}; |
| 61 | ` |
| 62 | |
Ted Humphrey | 4fb3239 | 2020-07-06 16:59:47 -0400 | [diff] [blame^] | 63 | const StyledSpinnerDiv = styled.div` |
| 64 | justify-content: center !important; |
| 65 | display: flex !important; |
| 66 | `; |
| 67 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 68 | const ProjectNameStyled = styled.a` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 69 | vertical-align: middle; |
| 70 | padding-left: 30px; |
sebdet | d0d6563 | 2019-08-26 05:47:01 -0700 | [diff] [blame] | 71 | font-size: 36px; |
| 72 | font-weight: bold; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 73 | ` |
sebdet | d0d6563 | 2019-08-26 05:47:01 -0700 | [diff] [blame] | 74 | |
| 75 | const StyledRouterLink = styled(Link)` |
| 76 | color: ${props => props.theme.menuFontColor}; |
| 77 | background-color: ${props => props.theme.backgroundColor}; |
| 78 | ` |
| 79 | |
| 80 | const StyledLoginInfo = styled.a` |
| 81 | color: ${props => props.theme.menuFontColor}; |
| 82 | background-color: ${props => props.theme.backgroundColor}; |
| 83 | ` |
| 84 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 85 | const LoopViewDivStyled = styled.div` |
sebdet | 190227a | 2019-07-19 16:51:19 +0200 | [diff] [blame] | 86 | height: 100%; |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 87 | overflow: hidden; |
| 88 | margin-left: 10px; |
| 89 | margin-right: 10px; |
| 90 | margin-bottom: 10px; |
| 91 | color: ${props => props.theme.loopViewerFontColor}; |
| 92 | background-color: ${props => props.theme.loopViewerBackgroundColor}; |
| 93 | border: 1px solid transparent; |
| 94 | border-color: ${props => props.theme.loopViewerHeaderBackgroundColor}; |
| 95 | ` |
| 96 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 97 | const LoopViewHeaderDivStyled = styled.div` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 98 | background-color: ${props => props.theme.loopViewerHeaderBackgroundColor}; |
| 99 | padding: 10px 10px; |
| 100 | color: ${props => props.theme.loopViewerHeaderFontColor}; |
| 101 | ` |
| 102 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 103 | const LoopViewBodyDivStyled = styled.div` |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 104 | background-color: ${props => (props.theme.loopViewerBackgroundColor)}; |
| 105 | padding: 10px 10px; |
| 106 | color: ${props => (props.theme.loopViewerHeaderFontColor)}; |
| 107 | height: 95%; |
| 108 | ` |
| 109 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 110 | export default class LoopUI extends React.Component { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 111 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 112 | state = { |
| 113 | userName: null, |
Ted Humphrey | 01e5fde | 2020-01-27 18:57:39 -0500 | [diff] [blame] | 114 | loopName: OnapConstants.defaultLoopName, |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame] | 115 | loopCache: new LoopCache({}), |
xuegao | cc5fe51 | 2020-04-06 13:13:52 +0200 | [diff] [blame] | 116 | showSucAlert: false, |
Ted Humphrey | 4fb3239 | 2020-07-06 16:59:47 -0400 | [diff] [blame^] | 117 | showFailAlert: false, |
| 118 | busyLoadingCount: 0 |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 119 | }; |
xuegao | 7c7323d | 2019-07-09 11:52:20 +0200 | [diff] [blame] | 120 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 121 | constructor() { |
| 122 | super(); |
| 123 | this.getUser = this.getUser.bind(this); |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 124 | this.updateLoopCache = this.updateLoopCache.bind(this); |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 125 | this.loadLoop = this.loadLoop.bind(this); |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 126 | this.closeLoop = this.closeLoop.bind(this); |
xuegao | cc5fe51 | 2020-04-06 13:13:52 +0200 | [diff] [blame] | 127 | this.showSucAlert = this.showSucAlert.bind(this); |
| 128 | this.showFailAlert = this.showFailAlert.bind(this); |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame] | 129 | this.disableAlert = this.disableAlert.bind(this); |
Ted Humphrey | 4fb3239 | 2020-07-06 16:59:47 -0400 | [diff] [blame^] | 130 | this.setBusyLoading = this.setBusyLoading.bind(this); |
| 131 | this.clearBusyLoading = this.clearBusyLoading.bind(this); |
| 132 | this.isBusyLoading = this.isBusyLoading.bind(this); |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 133 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 134 | |
sebdet | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 135 | componentWillMount() { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 136 | this.getUser(); |
| 137 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 138 | |
| 139 | getUser() { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 140 | UserService.login().then(user => { |
| 141 | this.setState({ userName: user }) |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 142 | }); |
| 143 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 144 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 145 | renderMenuNavBar() { |
| 146 | return ( |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 147 | <MenuBar loopName={this.state.loopName}/> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 148 | ); |
| 149 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 150 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 151 | renderUserLoggedNavBar() { |
| 152 | return ( |
| 153 | <Navbar.Text> |
sebdet | d0d6563 | 2019-08-26 05:47:01 -0700 | [diff] [blame] | 154 | <StyledLoginInfo>Signed in as: </StyledLoginInfo> |
| 155 | <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 156 | </Navbar.Text> |
| 157 | ); |
| 158 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 159 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 160 | renderLogoNavBar() { |
| 161 | return ( |
| 162 | <Navbar.Brand> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 163 | <img height="50px" width="234px" src={logo} alt="" /> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 164 | <ProjectNameStyled>CLAMP</ProjectNameStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 165 | </Navbar.Brand> |
| 166 | ); |
| 167 | } |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 168 | |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame] | 169 | renderAlertBar() { |
| 170 | return ( |
xuegao | cc5fe51 | 2020-04-06 13:13:52 +0200 | [diff] [blame] | 171 | <div> |
| 172 | <Alert variant="success" show={this.state.showSucAlert} onClose={this.disableAlert} dismissible> |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame] | 173 | {this.state.showMessage} |
| 174 | </Alert> |
xuegao | cc5fe51 | 2020-04-06 13:13:52 +0200 | [diff] [blame] | 175 | <Alert variant="danger" show={this.state.showFailAlert} onClose={this.disableAlert} dismissible> |
| 176 | {this.state.showMessage} |
| 177 | </Alert> |
| 178 | </div> |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame] | 179 | ); |
| 180 | } |
| 181 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 182 | renderNavBar() { |
| 183 | return ( |
sebdet | d0d6563 | 2019-08-26 05:47:01 -0700 | [diff] [blame] | 184 | <Navbar > |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 185 | {this.renderLogoNavBar()} |
sebdet | d0d6563 | 2019-08-26 05:47:01 -0700 | [diff] [blame] | 186 | <Navbar.Toggle aria-controls="responsive-navbar-nav" /> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 187 | {this.renderMenuNavBar()} |
| 188 | {this.renderUserLoggedNavBar()} |
| 189 | </Navbar> |
| 190 | ); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 191 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 192 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 193 | renderLoopViewHeader() { |
| 194 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 195 | <LoopViewHeaderDivStyled> |
sebdet | edaf4f9 | 2020-04-16 00:43:48 +0200 | [diff] [blame] | 196 | Loop Viewer - {this.state.loopName} - ({this.state.loopCache.getTemplateName()}) |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 197 | </LoopViewHeaderDivStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 198 | ); |
| 199 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 200 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 201 | renderLoopViewBody() { |
| 202 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 203 | <LoopViewBodyDivStyled> |
Ted Humphrey | 4fb3239 | 2020-07-06 16:59:47 -0400 | [diff] [blame^] | 204 | <SvgGenerator loopCache={this.state.loopCache} clickable={true} generatedFrom={SvgGenerator.GENERATED_FROM_INSTANCE} isBusyLoading={this.isBusyLoading}/> |
sebdet | 190227a | 2019-07-19 16:51:19 +0200 | [diff] [blame] | 205 | <LoopStatus loopCache={this.state.loopCache}/> |
sebdet | c1ccc54 | 2019-07-19 09:50:33 +0200 | [diff] [blame] | 206 | <LoopLogs loopCache={this.state.loopCache} /> |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 207 | </LoopViewBodyDivStyled> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 208 | ); |
| 209 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 210 | |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 211 | getLoopCache() { |
| 212 | return this.state.loopCache; |
| 213 | |
| 214 | } |
xuegao | 5fe750c | 2019-08-06 13:03:53 +0200 | [diff] [blame] | 215 | |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 216 | renderLoopViewer() { |
| 217 | return ( |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 218 | <LoopViewDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 219 | {this.renderLoopViewHeader()} |
| 220 | {this.renderLoopViewBody()} |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 221 | </LoopViewDivStyled> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 222 | ); |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 223 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 224 | |
| 225 | updateLoopCache(loopJson) { |
xuegao | 52432d6 | 2019-10-04 16:11:22 +0200 | [diff] [blame] | 226 | this.setState({ loopCache: new LoopCache(loopJson) }); |
| 227 | this.setState({ loopName: this.state.loopCache.getLoopName() }); |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 228 | console.info(this.state.loopName+" loop loaded successfully"); |
| 229 | } |
xuegao | 5fe750c | 2019-08-06 13:03:53 +0200 | [diff] [blame] | 230 | |
xuegao | cc5fe51 | 2020-04-06 13:13:52 +0200 | [diff] [blame] | 231 | showSucAlert(message) { |
| 232 | this.setState ({ showSucAlert: true, showMessage:message }); |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame] | 233 | } |
| 234 | |
xuegao | cc5fe51 | 2020-04-06 13:13:52 +0200 | [diff] [blame] | 235 | showFailAlert(message) { |
| 236 | this.setState ({ showFailAlert: true, showMessage:message }); |
| 237 | } |
Ted Humphrey | 4fb3239 | 2020-07-06 16:59:47 -0400 | [diff] [blame^] | 238 | |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame] | 239 | disableAlert() { |
xuegao | cc5fe51 | 2020-04-06 13:13:52 +0200 | [diff] [blame] | 240 | this.setState ({ showSucAlert: false, showFailAlert: false }); |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame] | 241 | } |
| 242 | |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 243 | loadLoop(loopName) { |
Ted Humphrey | 4fb3239 | 2020-07-06 16:59:47 -0400 | [diff] [blame^] | 244 | this.setBusyLoading(); |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 245 | LoopService.getLoop(loopName).then(loop => { |
| 246 | console.debug("Updating loopCache"); |
xuegao | ac42c4b | 2019-10-09 16:12:37 +0200 | [diff] [blame] | 247 | LoopActionService.refreshStatus(loopName).then(data => { |
| 248 | this.updateLoopCache(data); |
Ted Humphrey | 4fb3239 | 2020-07-06 16:59:47 -0400 | [diff] [blame^] | 249 | this.clearBusyLoading(); |
xuegao | ac42c4b | 2019-10-09 16:12:37 +0200 | [diff] [blame] | 250 | this.props.history.push('/'); |
| 251 | }) |
| 252 | .catch(error => { |
| 253 | this.updateLoopCache(loop); |
Ted Humphrey | 4fb3239 | 2020-07-06 16:59:47 -0400 | [diff] [blame^] | 254 | this.clearBusyLoading(); |
xuegao | ac42c4b | 2019-10-09 16:12:37 +0200 | [diff] [blame] | 255 | this.props.history.push('/'); |
| 256 | }); |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 257 | }); |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 258 | } |
| 259 | |
Ted Humphrey | 4fb3239 | 2020-07-06 16:59:47 -0400 | [diff] [blame^] | 260 | setBusyLoading() { |
| 261 | this.setState((state,props) => ({ busyLoadingCount: ++state.busyLoadingCount })); |
| 262 | } |
| 263 | |
| 264 | clearBusyLoading() { |
| 265 | this.setState((state,props) => ({ busyLoadingCount: --state.busyLoadingCount })); |
| 266 | } |
| 267 | |
| 268 | isBusyLoading() { |
| 269 | if (this.state.busyLoadingCount === 0) { |
| 270 | return false; |
| 271 | } else { |
| 272 | return true; |
| 273 | } |
| 274 | } |
| 275 | |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 276 | closeLoop() { |
Ted Humphrey | 01e5fde | 2020-01-27 18:57:39 -0500 | [diff] [blame] | 277 | this.setState({ loopCache: new LoopCache({}), loopName: OnapConstants.defaultLoopName }); |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 278 | this.props.history.push('/'); |
| 279 | } |
sebdet | 687b8de | 2019-08-26 14:29:11 -0700 | [diff] [blame] | 280 | |
Ted Humphrey | 4fb3239 | 2020-07-06 16:59:47 -0400 | [diff] [blame^] | 281 | renderRoutes() { |
| 282 | return( |
| 283 | <React.Fragment> |
ash74268 | 3a83e2a | 2020-01-31 15:40:15 +0000 | [diff] [blame] | 284 | <Route path="/uploadToscaPolicyModal" render={(routeProps) => (<UploadToscaPolicyModal {...routeProps} />)} /> |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 285 | <Route path="/viewToscaPolicyModal" render={(routeProps) => (<ViewToscaPolicyModal {...routeProps} />)} /> |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 286 | <Route path="/ViewLoopTemplatesModal" render={(routeProps) => (<ViewLoopTemplatesModal {...routeProps} />)} /> |
drveerendra | 5032095 | 2020-03-04 20:30:44 -0500 | [diff] [blame] | 287 | <Route path="/ManageDictionaries" render={(routeProps) => (<ManageDictionaries {...routeProps} />)} /> |
Ted Humphrey | 4fb3239 | 2020-07-06 16:59:47 -0400 | [diff] [blame^] | 288 | |
| 289 | <Route path="/policyModal/:policyInstanceType/:policyName" render={(routeProps) => (<PolicyModal {...routeProps} |
| 290 | loopCache={this.getLoopCache()} |
| 291 | loadLoopFunction={this.loadLoop}/>)} |
| 292 | /> |
| 293 | <Route path="/createLoop" render={(routeProps) => (<CreateLoopModal {...routeProps} |
| 294 | loadLoopFunction={this.loadLoop} />)} |
| 295 | /> |
| 296 | <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} |
| 297 | loadLoopFunction={this.loadLoop} />)} |
| 298 | /> |
| 299 | <Route path="/loopProperties" render={(routeProps) => (<LoopPropertiesModal {...routeProps} |
| 300 | loopCache={this.getLoopCache()} |
| 301 | loadLoopFunction={this.loadLoop}/>)} |
| 302 | /> |
| 303 | <Route path="/modifyLoop" render={(routeProps) => (<ModifyLoopModal {...routeProps} |
| 304 | loopCache={this.getLoopCache()} |
| 305 | loadLoopFunction={this.loadLoop}/>)} |
| 306 | /> |
sebdet | aa486be | 2020-02-18 02:00:11 -0800 | [diff] [blame] | 307 | |
sebdet | 4dc849f | 2019-11-15 17:49:42 +0100 | [diff] [blame] | 308 | <Route path="/userInfo" render={(routeProps) => (<UserInfoModal {...routeProps} />)} /> |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 309 | <Route path="/closeLoop" render={this.closeLoop} /> |
Ted Humphrey | 4fb3239 | 2020-07-06 16:59:47 -0400 | [diff] [blame^] | 310 | |
| 311 | <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} |
| 312 | loopAction="submit" |
| 313 | loopCache={this.getLoopCache()} |
| 314 | updateLoopFunction={this.updateLoopCache} |
| 315 | showSucAlert={this.showSucAlert} |
| 316 | showFailAlert={this.showFailAlert} |
| 317 | setBusyLoading={this.setBusyLoading} |
| 318 | clearBusyLoading={this.clearBusyLoading}/>)} |
| 319 | /> |
| 320 | <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} |
| 321 | loopAction="stop" |
| 322 | loopCache={this.getLoopCache()} |
| 323 | updateLoopFunction={this.updateLoopCache} |
| 324 | showSucAlert={this.showSucAlert} |
| 325 | showFailAlert={this.showFailAlert} |
| 326 | setBusyLoading={this.setBusyLoading} |
| 327 | clearBusyLoading={this.clearBusyLoading}/>)} |
| 328 | /> |
| 329 | <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} |
| 330 | loopAction="restart" |
| 331 | loopCache={this.getLoopCache()} |
| 332 | updateLoopFunction={this.updateLoopCache} |
| 333 | showSucAlert={this.showSucAlert} |
| 334 | showFailAlert={this.showFailAlert} |
| 335 | setBusyLoading={this.setBusyLoading} |
| 336 | clearBusyLoading={this.clearBusyLoading}/>)} |
| 337 | /> |
| 338 | <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} |
| 339 | loopAction="delete" |
| 340 | loopCache={this.getLoopCache()} |
| 341 | updateLoopFunction={this.updateLoopCache} |
| 342 | showSucAlert={this.showSucAlert} |
| 343 | showFailAlert={this.showFailAlert} |
| 344 | setBusyLoading={this.setBusyLoading} |
| 345 | clearBusyLoading={this.clearBusyLoading}/>)} |
| 346 | /> |
| 347 | <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} |
| 348 | loopAction="undeploy" |
| 349 | loopCache={this.getLoopCache()} |
| 350 | updateLoopFunction={this.updateLoopCache} |
| 351 | showSucAlert={this.showSucAlert} |
| 352 | showFailAlert={this.showFailAlert} |
| 353 | setBusyLoading={this.setBusyLoading} |
| 354 | clearBusyLoading={this.clearBusyLoading}/>)} |
| 355 | /> |
| 356 | <Route path="/deploy" render={(routeProps) => (<DeployLoopModal {...routeProps} |
| 357 | loopCache={this.getLoopCache()} |
| 358 | updateLoopFunction={this.updateLoopCache} |
| 359 | showSucAlert={this.showSucAlert} |
| 360 | showFailAlert={this.showFailAlert}/>)} |
| 361 | /> |
| 362 | <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} |
| 363 | loopCache={this.getLoopCache()} |
| 364 | updateLoopFunction={this.updateLoopCache} |
| 365 | showSucAlert={this.showSucAlert} |
| 366 | showFailAlert={this.showFailAlert}/>)} |
| 367 | /> |
| 368 | </React.Fragment> |
| 369 | ); |
| 370 | } |
| 371 | |
| 372 | renderSpinner() { |
| 373 | if (this.isBusyLoading()) { |
| 374 | return ( |
| 375 | <StyledSpinnerDiv> |
| 376 | <Spinner animation="border" role="status"> |
| 377 | <span className="sr-only">Loading...</span> |
| 378 | </Spinner> |
| 379 | </StyledSpinnerDiv> |
| 380 | ); |
| 381 | } else { |
| 382 | return (<div></div>); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | render() { |
| 387 | return ( |
| 388 | <StyledMainDiv id="main_div"> |
| 389 | <GlobalClampStyle /> |
| 390 | {this.renderRoutes()} |
| 391 | {this.renderSpinner()} |
xuegao | 0efeb6b | 2019-10-07 14:36:34 +0200 | [diff] [blame] | 392 | {this.renderAlertBar()} |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 393 | {this.renderNavBar()} |
| 394 | {this.renderLoopViewer()} |
sebdet | d0d6563 | 2019-08-26 05:47:01 -0700 | [diff] [blame] | 395 | </StyledMainDiv> |
sebdet | c8d6130 | 2019-07-04 15:50:34 +0200 | [diff] [blame] | 396 | ); |
| 397 | } |
| 398 | } |