blob: 0ee6e6e24c41bbba224a376dd111ecf07faa6938 [file] [log] [blame]
sebdetc8d61302019-07-04 15:50:34 +02001/*-
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
24import React from 'react';
25import styled from 'styled-components';
sebdete44fdb12019-07-12 12:25:56 +020026import MenuBar from './components/menu/MenuBar';
sebdetc8d61302019-07-04 15:50:34 +020027import Navbar from 'react-bootstrap/Navbar';
28import logo from './logo.png';
sebdete44fdb12019-07-12 12:25:56 +020029import { GlobalClampStyle } from './theme/globalStyle.js';
Ted Humphrey01e5fde2020-01-27 18:57:39 -050030import OnapConstants from './utils/OnapConstants';
sebdetc8d61302019-07-04 15:50:34 +020031
sebdetc0ec0fc2020-05-18 12:31:11 +020032import SvgGenerator from './components/loop_viewer/svg/SvgGenerator';
sebdet493c3832019-07-15 17:26:18 +020033import LoopLogs from './components/loop_viewer/logs/LoopLogs';
34import LoopStatus from './components/loop_viewer/status/LoopStatus';
sebdete44fdb12019-07-12 12:25:56 +020035import UserService from './api/UserService';
sebdet493c3832019-07-15 17:26:18 +020036import LoopCache from './api/LoopCache';
xuegaoac42c4b2019-10-09 16:12:37 +020037import LoopActionService from './api/LoopActionService';
sebdet493c3832019-07-15 17:26:18 +020038
xuegao691e2b72019-08-16 11:07:24 +020039import { Route } from 'react-router-dom'
sebdetd2a4df02020-02-26 15:47:30 -080040import CreateLoopModal from './components/dialogs/Loop/CreateLoopModal';
sebdet67c76a42019-11-15 17:33:44 +010041import OpenLoopModal from './components/dialogs/Loop/OpenLoopModal';
sebdetaa486be2020-02-18 02:00:11 -080042import ModifyLoopModal from './components/dialogs/Loop/ModifyLoopModal';
sebdetd2a4df02020-02-26 15:47:30 -080043import PolicyModal from './components/dialogs/Policy/PolicyModal';
sebdetb13a7902019-11-15 17:26:45 +010044import LoopPropertiesModal from './components/dialogs/Loop/LoopPropertiesModal';
sebdet4dc849f2019-11-15 17:49:42 +010045import UserInfoModal from './components/dialogs/UserInfoModal';
sebdet83ce0762019-08-02 14:53:59 +020046import LoopService from './api/LoopService';
ash742683a83e2a2020-01-31 15:40:15 +000047import UploadToscaPolicyModal from './components/dialogs/Tosca/UploadToscaPolicyModal';
drveerendra684057e2019-11-11 19:37:39 -050048import ViewToscaPolicyModal from './components/dialogs/Tosca/ViewToscaPolicyModal';
sebdet3b7f6692020-02-17 06:03:31 -080049import ViewLoopTemplatesModal from './components/dialogs/Tosca/ViewLoopTemplatesModal';
drveerendra50320952020-03-04 20:30:44 -050050import ManageDictionaries from './components/dialogs/ManageDictionaries/ManageDictionaries';
sebdetf9e2cee2019-08-09 18:36:09 +020051import PerformAction from './components/dialogs/PerformActions';
52import RefreshStatus from './components/dialogs/RefreshStatus';
sebdet2e9ae122019-11-15 16:28:55 +010053import DeployLoopModal from './components/dialogs/Loop/DeployLoopModal';
xuegao0efeb6b2019-10-07 14:36:34 +020054import Alert from 'react-bootstrap/Alert';
Ted Humphrey4fb32392020-07-06 16:59:47 -040055import Spinner from 'react-bootstrap/Spinner';
sebdetc8d61302019-07-04 15:50:34 +020056
sebdetd0d65632019-08-26 05:47:01 -070057import { Link } from 'react-router-dom';
58
59const StyledMainDiv = styled.div`
60 background-color: ${props => props.theme.backgroundColor};
61`
62
Ted Humphrey4fb32392020-07-06 16:59:47 -040063const StyledSpinnerDiv = styled.div`
64 justify-content: center !important;
65 display: flex !important;
66`;
67
sebdet4946e5b2019-07-10 12:32:36 +020068const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020069 vertical-align: middle;
70 padding-left: 30px;
sebdetd0d65632019-08-26 05:47:01 -070071 font-size: 36px;
72 font-weight: bold;
sebdetc8d61302019-07-04 15:50:34 +020073`
sebdetd0d65632019-08-26 05:47:01 -070074
75const StyledRouterLink = styled(Link)`
76 color: ${props => props.theme.menuFontColor};
77 background-color: ${props => props.theme.backgroundColor};
78`
79
80const StyledLoginInfo = styled.a`
81 color: ${props => props.theme.menuFontColor};
82 background-color: ${props => props.theme.backgroundColor};
83`
84
sebdet4946e5b2019-07-10 12:32:36 +020085const LoopViewDivStyled = styled.div`
sebdet190227a2019-07-19 16:51:19 +020086 height: 100%;
sebdetc8d61302019-07-04 15:50:34 +020087 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
sebdet4946e5b2019-07-10 12:32:36 +020097const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020098 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
99 padding: 10px 10px;
100 color: ${props => props.theme.loopViewerHeaderFontColor};
101`
102
sebdet4946e5b2019-07-10 12:32:36 +0200103const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +0200104 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
105 padding: 10px 10px;
106 color: ${props => (props.theme.loopViewerHeaderFontColor)};
107 height: 95%;
108`
109
sebdetc8d61302019-07-04 15:50:34 +0200110export default class LoopUI extends React.Component {
sebdet493c3832019-07-15 17:26:18 +0200111
sebdet4946e5b2019-07-10 12:32:36 +0200112 state = {
113 userName: null,
Ted Humphrey01e5fde2020-01-27 18:57:39 -0500114 loopName: OnapConstants.defaultLoopName,
xuegao0efeb6b2019-10-07 14:36:34 +0200115 loopCache: new LoopCache({}),
xuegaocc5fe512020-04-06 13:13:52 +0200116 showSucAlert: false,
Ted Humphrey4fb32392020-07-06 16:59:47 -0400117 showFailAlert: false,
118 busyLoadingCount: 0
sebdet4946e5b2019-07-10 12:32:36 +0200119 };
xuegao7c7323d2019-07-09 11:52:20 +0200120
sebdet4946e5b2019-07-10 12:32:36 +0200121 constructor() {
122 super();
123 this.getUser = this.getUser.bind(this);
sebdet493c3832019-07-15 17:26:18 +0200124 this.updateLoopCache = this.updateLoopCache.bind(this);
sebdet83ce0762019-08-02 14:53:59 +0200125 this.loadLoop = this.loadLoop.bind(this);
xuegao691e2b72019-08-16 11:07:24 +0200126 this.closeLoop = this.closeLoop.bind(this);
xuegaocc5fe512020-04-06 13:13:52 +0200127 this.showSucAlert = this.showSucAlert.bind(this);
128 this.showFailAlert = this.showFailAlert.bind(this);
xuegao0efeb6b2019-10-07 14:36:34 +0200129 this.disableAlert = this.disableAlert.bind(this);
Ted Humphrey4fb32392020-07-06 16:59:47 -0400130 this.setBusyLoading = this.setBusyLoading.bind(this);
131 this.clearBusyLoading = this.clearBusyLoading.bind(this);
132 this.isBusyLoading = this.isBusyLoading.bind(this);
sebdet4946e5b2019-07-10 12:32:36 +0200133 }
sebdet493c3832019-07-15 17:26:18 +0200134
sebdet2dacb9b2019-07-17 13:48:44 +0200135 componentWillMount() {
sebdet493c3832019-07-15 17:26:18 +0200136 this.getUser();
137 }
sebdet4946e5b2019-07-10 12:32:36 +0200138
139 getUser() {
sebdet493c3832019-07-15 17:26:18 +0200140 UserService.login().then(user => {
141 this.setState({ userName: user })
sebdet4946e5b2019-07-10 12:32:36 +0200142 });
143 }
sebdet493c3832019-07-15 17:26:18 +0200144
sebdetc8d61302019-07-04 15:50:34 +0200145 renderMenuNavBar() {
146 return (
xuegao691e2b72019-08-16 11:07:24 +0200147 <MenuBar loopName={this.state.loopName}/>
sebdetc8d61302019-07-04 15:50:34 +0200148 );
149 }
sebdet4946e5b2019-07-10 12:32:36 +0200150
sebdetc8d61302019-07-04 15:50:34 +0200151 renderUserLoggedNavBar() {
152 return (
153 <Navbar.Text>
sebdetd0d65632019-08-26 05:47:01 -0700154 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
155 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
sebdetc8d61302019-07-04 15:50:34 +0200156 </Navbar.Text>
157 );
158 }
sebdet4946e5b2019-07-10 12:32:36 +0200159
sebdetc8d61302019-07-04 15:50:34 +0200160 renderLogoNavBar() {
161 return (
162 <Navbar.Brand>
sebdet493c3832019-07-15 17:26:18 +0200163 <img height="50px" width="234px" src={logo} alt="" />
sebdet4946e5b2019-07-10 12:32:36 +0200164 <ProjectNameStyled>CLAMP</ProjectNameStyled>
sebdetc8d61302019-07-04 15:50:34 +0200165 </Navbar.Brand>
166 );
167 }
sebdet4946e5b2019-07-10 12:32:36 +0200168
xuegao0efeb6b2019-10-07 14:36:34 +0200169 renderAlertBar() {
170 return (
xuegaocc5fe512020-04-06 13:13:52 +0200171 <div>
172 <Alert variant="success" show={this.state.showSucAlert} onClose={this.disableAlert} dismissible>
xuegao0efeb6b2019-10-07 14:36:34 +0200173 {this.state.showMessage}
174 </Alert>
xuegaocc5fe512020-04-06 13:13:52 +0200175 <Alert variant="danger" show={this.state.showFailAlert} onClose={this.disableAlert} dismissible>
176 {this.state.showMessage}
177 </Alert>
178 </div>
xuegao0efeb6b2019-10-07 14:36:34 +0200179 );
180 }
181
sebdetc8d61302019-07-04 15:50:34 +0200182 renderNavBar() {
183 return (
sebdetd0d65632019-08-26 05:47:01 -0700184 <Navbar >
sebdet493c3832019-07-15 17:26:18 +0200185 {this.renderLogoNavBar()}
sebdetd0d65632019-08-26 05:47:01 -0700186 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
sebdet493c3832019-07-15 17:26:18 +0200187 {this.renderMenuNavBar()}
188 {this.renderUserLoggedNavBar()}
189 </Navbar>
190 );
sebdetc8d61302019-07-04 15:50:34 +0200191 }
sebdet493c3832019-07-15 17:26:18 +0200192
sebdetc8d61302019-07-04 15:50:34 +0200193 renderLoopViewHeader() {
194 return (
sebdet4946e5b2019-07-10 12:32:36 +0200195 <LoopViewHeaderDivStyled>
sebdetedaf4f92020-04-16 00:43:48 +0200196 Loop Viewer - {this.state.loopName} - ({this.state.loopCache.getTemplateName()})
sebdet4946e5b2019-07-10 12:32:36 +0200197 </LoopViewHeaderDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200198 );
199 }
sebdet493c3832019-07-15 17:26:18 +0200200
sebdetc8d61302019-07-04 15:50:34 +0200201 renderLoopViewBody() {
202 return (
sebdet4946e5b2019-07-10 12:32:36 +0200203 <LoopViewBodyDivStyled>
Ted Humphrey4fb32392020-07-06 16:59:47 -0400204 <SvgGenerator loopCache={this.state.loopCache} clickable={true} generatedFrom={SvgGenerator.GENERATED_FROM_INSTANCE} isBusyLoading={this.isBusyLoading}/>
sebdet190227a2019-07-19 16:51:19 +0200205 <LoopStatus loopCache={this.state.loopCache}/>
sebdetc1ccc542019-07-19 09:50:33 +0200206 <LoopLogs loopCache={this.state.loopCache} />
sebdet4946e5b2019-07-10 12:32:36 +0200207 </LoopViewBodyDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200208 );
209 }
sebdet493c3832019-07-15 17:26:18 +0200210
xuegaoe52d5722019-07-25 15:43:06 +0200211 getLoopCache() {
212 return this.state.loopCache;
213
214 }
xuegao5fe750c2019-08-06 13:03:53 +0200215
sebdetc8d61302019-07-04 15:50:34 +0200216 renderLoopViewer() {
217 return (
sebdet4946e5b2019-07-10 12:32:36 +0200218 <LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200219 {this.renderLoopViewHeader()}
220 {this.renderLoopViewBody()}
sebdet4946e5b2019-07-10 12:32:36 +0200221 </LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200222 );
sebdetc8d61302019-07-04 15:50:34 +0200223 }
sebdet493c3832019-07-15 17:26:18 +0200224
225 updateLoopCache(loopJson) {
xuegao52432d62019-10-04 16:11:22 +0200226 this.setState({ loopCache: new LoopCache(loopJson) });
227 this.setState({ loopName: this.state.loopCache.getLoopName() });
sebdet83ce0762019-08-02 14:53:59 +0200228 console.info(this.state.loopName+" loop loaded successfully");
229 }
xuegao5fe750c2019-08-06 13:03:53 +0200230
xuegaocc5fe512020-04-06 13:13:52 +0200231 showSucAlert(message) {
232 this.setState ({ showSucAlert: true, showMessage:message });
xuegao0efeb6b2019-10-07 14:36:34 +0200233 }
234
xuegaocc5fe512020-04-06 13:13:52 +0200235 showFailAlert(message) {
236 this.setState ({ showFailAlert: true, showMessage:message });
237 }
Ted Humphrey4fb32392020-07-06 16:59:47 -0400238
xuegao0efeb6b2019-10-07 14:36:34 +0200239 disableAlert() {
xuegaocc5fe512020-04-06 13:13:52 +0200240 this.setState ({ showSucAlert: false, showFailAlert: false });
xuegao0efeb6b2019-10-07 14:36:34 +0200241 }
242
sebdet83ce0762019-08-02 14:53:59 +0200243 loadLoop(loopName) {
Ted Humphrey4fb32392020-07-06 16:59:47 -0400244 this.setBusyLoading();
sebdet83ce0762019-08-02 14:53:59 +0200245 LoopService.getLoop(loopName).then(loop => {
246 console.debug("Updating loopCache");
xuegaoac42c4b2019-10-09 16:12:37 +0200247 LoopActionService.refreshStatus(loopName).then(data => {
248 this.updateLoopCache(data);
Ted Humphrey4fb32392020-07-06 16:59:47 -0400249 this.clearBusyLoading();
xuegaoac42c4b2019-10-09 16:12:37 +0200250 this.props.history.push('/');
251 })
252 .catch(error => {
253 this.updateLoopCache(loop);
Ted Humphrey4fb32392020-07-06 16:59:47 -0400254 this.clearBusyLoading();
xuegaoac42c4b2019-10-09 16:12:37 +0200255 this.props.history.push('/');
256 });
sebdet83ce0762019-08-02 14:53:59 +0200257 });
sebdet493c3832019-07-15 17:26:18 +0200258 }
259
Ted Humphrey4fb32392020-07-06 16:59:47 -0400260 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
xuegao691e2b72019-08-16 11:07:24 +0200276 closeLoop() {
Ted Humphrey01e5fde2020-01-27 18:57:39 -0500277 this.setState({ loopCache: new LoopCache({}), loopName: OnapConstants.defaultLoopName });
xuegao691e2b72019-08-16 11:07:24 +0200278 this.props.history.push('/');
279 }
sebdet687b8de2019-08-26 14:29:11 -0700280
Ted Humphrey4fb32392020-07-06 16:59:47 -0400281 renderRoutes() {
282 return(
283 <React.Fragment>
ash742683a83e2a2020-01-31 15:40:15 +0000284 <Route path="/uploadToscaPolicyModal" render={(routeProps) => (<UploadToscaPolicyModal {...routeProps} />)} />
drveerendra684057e2019-11-11 19:37:39 -0500285 <Route path="/viewToscaPolicyModal" render={(routeProps) => (<ViewToscaPolicyModal {...routeProps} />)} />
sebdet3b7f6692020-02-17 06:03:31 -0800286 <Route path="/ViewLoopTemplatesModal" render={(routeProps) => (<ViewLoopTemplatesModal {...routeProps} />)} />
drveerendra50320952020-03-04 20:30:44 -0500287 <Route path="/ManageDictionaries" render={(routeProps) => (<ManageDictionaries {...routeProps} />)} />
Ted Humphrey4fb32392020-07-06 16:59:47 -0400288
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 />
sebdetaa486be2020-02-18 02:00:11 -0800307
sebdet4dc849f2019-11-15 17:49:42 +0100308 <Route path="/userInfo" render={(routeProps) => (<UserInfoModal {...routeProps} />)} />
xuegao691e2b72019-08-16 11:07:24 +0200309 <Route path="/closeLoop" render={this.closeLoop} />
Ted Humphrey4fb32392020-07-06 16:59:47 -0400310
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()}
xuegao0efeb6b2019-10-07 14:36:34 +0200392 {this.renderAlertBar()}
sebdet8a02dd72019-07-31 17:11:11 +0200393 {this.renderNavBar()}
394 {this.renderLoopViewer()}
sebdetd0d65632019-08-26 05:47:01 -0700395 </StyledMainDiv>
sebdetc8d61302019-07-04 15:50:34 +0200396 );
397 }
398}