blob: 8624726bed0f491253c983f75fc2db52a81dcab8 [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';
sebdetc8d61302019-07-04 15:50:34 +020055
sebdetd0d65632019-08-26 05:47:01 -070056import { Link } from 'react-router-dom';
57
58const StyledMainDiv = styled.div`
59 background-color: ${props => props.theme.backgroundColor};
60`
61
sebdet4946e5b2019-07-10 12:32:36 +020062const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020063 vertical-align: middle;
64 padding-left: 30px;
sebdetd0d65632019-08-26 05:47:01 -070065 font-size: 36px;
66 font-weight: bold;
sebdetc8d61302019-07-04 15:50:34 +020067`
sebdetd0d65632019-08-26 05:47:01 -070068
69const StyledRouterLink = styled(Link)`
70 color: ${props => props.theme.menuFontColor};
71 background-color: ${props => props.theme.backgroundColor};
72`
73
74const StyledLoginInfo = styled.a`
75 color: ${props => props.theme.menuFontColor};
76 background-color: ${props => props.theme.backgroundColor};
77`
78
sebdet4946e5b2019-07-10 12:32:36 +020079const LoopViewDivStyled = styled.div`
sebdet190227a2019-07-19 16:51:19 +020080 height: 100%;
sebdetc8d61302019-07-04 15:50:34 +020081 overflow: hidden;
82 margin-left: 10px;
83 margin-right: 10px;
84 margin-bottom: 10px;
85 color: ${props => props.theme.loopViewerFontColor};
86 background-color: ${props => props.theme.loopViewerBackgroundColor};
87 border: 1px solid transparent;
88 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
89`
90
sebdet4946e5b2019-07-10 12:32:36 +020091const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020092 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
93 padding: 10px 10px;
94 color: ${props => props.theme.loopViewerHeaderFontColor};
95`
96
sebdet4946e5b2019-07-10 12:32:36 +020097const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020098 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
99 padding: 10px 10px;
100 color: ${props => (props.theme.loopViewerHeaderFontColor)};
101 height: 95%;
102`
103
sebdetc8d61302019-07-04 15:50:34 +0200104export default class LoopUI extends React.Component {
sebdet493c3832019-07-15 17:26:18 +0200105
sebdet4946e5b2019-07-10 12:32:36 +0200106 state = {
107 userName: null,
Ted Humphrey01e5fde2020-01-27 18:57:39 -0500108 loopName: OnapConstants.defaultLoopName,
xuegao0efeb6b2019-10-07 14:36:34 +0200109 loopCache: new LoopCache({}),
xuegaocc5fe512020-04-06 13:13:52 +0200110 showSucAlert: false,
111 showFailAlert: false
sebdet4946e5b2019-07-10 12:32:36 +0200112 };
xuegao7c7323d2019-07-09 11:52:20 +0200113
sebdet4946e5b2019-07-10 12:32:36 +0200114 constructor() {
115 super();
116 this.getUser = this.getUser.bind(this);
sebdet493c3832019-07-15 17:26:18 +0200117 this.updateLoopCache = this.updateLoopCache.bind(this);
sebdet83ce0762019-08-02 14:53:59 +0200118 this.loadLoop = this.loadLoop.bind(this);
xuegao691e2b72019-08-16 11:07:24 +0200119 this.closeLoop = this.closeLoop.bind(this);
xuegaocc5fe512020-04-06 13:13:52 +0200120 this.showSucAlert = this.showSucAlert.bind(this);
121 this.showFailAlert = this.showFailAlert.bind(this);
xuegao0efeb6b2019-10-07 14:36:34 +0200122 this.disableAlert = this.disableAlert.bind(this);
sebdet4946e5b2019-07-10 12:32:36 +0200123 }
sebdet493c3832019-07-15 17:26:18 +0200124
sebdet2dacb9b2019-07-17 13:48:44 +0200125 componentWillMount() {
sebdet493c3832019-07-15 17:26:18 +0200126 this.getUser();
127 }
sebdet4946e5b2019-07-10 12:32:36 +0200128
129 getUser() {
sebdet493c3832019-07-15 17:26:18 +0200130 UserService.login().then(user => {
131 this.setState({ userName: user })
sebdet4946e5b2019-07-10 12:32:36 +0200132 });
133 }
sebdet493c3832019-07-15 17:26:18 +0200134
sebdetc8d61302019-07-04 15:50:34 +0200135 renderMenuNavBar() {
136 return (
xuegao691e2b72019-08-16 11:07:24 +0200137 <MenuBar loopName={this.state.loopName}/>
sebdetc8d61302019-07-04 15:50:34 +0200138 );
139 }
sebdet4946e5b2019-07-10 12:32:36 +0200140
sebdetc8d61302019-07-04 15:50:34 +0200141 renderUserLoggedNavBar() {
142 return (
143 <Navbar.Text>
sebdetd0d65632019-08-26 05:47:01 -0700144 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
145 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
sebdetc8d61302019-07-04 15:50:34 +0200146 </Navbar.Text>
147 );
148 }
sebdet4946e5b2019-07-10 12:32:36 +0200149
sebdetc8d61302019-07-04 15:50:34 +0200150 renderLogoNavBar() {
151 return (
152 <Navbar.Brand>
sebdet493c3832019-07-15 17:26:18 +0200153 <img height="50px" width="234px" src={logo} alt="" />
sebdet4946e5b2019-07-10 12:32:36 +0200154 <ProjectNameStyled>CLAMP</ProjectNameStyled>
sebdetc8d61302019-07-04 15:50:34 +0200155 </Navbar.Brand>
156 );
157 }
sebdet4946e5b2019-07-10 12:32:36 +0200158
xuegao0efeb6b2019-10-07 14:36:34 +0200159 renderAlertBar() {
160 return (
xuegaocc5fe512020-04-06 13:13:52 +0200161 <div>
162 <Alert variant="success" show={this.state.showSucAlert} onClose={this.disableAlert} dismissible>
xuegao0efeb6b2019-10-07 14:36:34 +0200163 {this.state.showMessage}
164 </Alert>
xuegaocc5fe512020-04-06 13:13:52 +0200165 <Alert variant="danger" show={this.state.showFailAlert} onClose={this.disableAlert} dismissible>
166 {this.state.showMessage}
167 </Alert>
168 </div>
xuegao0efeb6b2019-10-07 14:36:34 +0200169 );
170 }
171
sebdetc8d61302019-07-04 15:50:34 +0200172 renderNavBar() {
173 return (
sebdetd0d65632019-08-26 05:47:01 -0700174 <Navbar >
sebdet493c3832019-07-15 17:26:18 +0200175 {this.renderLogoNavBar()}
sebdetd0d65632019-08-26 05:47:01 -0700176 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
sebdet493c3832019-07-15 17:26:18 +0200177 {this.renderMenuNavBar()}
178 {this.renderUserLoggedNavBar()}
179 </Navbar>
180 );
sebdetc8d61302019-07-04 15:50:34 +0200181 }
sebdet493c3832019-07-15 17:26:18 +0200182
sebdetc8d61302019-07-04 15:50:34 +0200183 renderLoopViewHeader() {
184 return (
sebdet4946e5b2019-07-10 12:32:36 +0200185 <LoopViewHeaderDivStyled>
sebdetedaf4f92020-04-16 00:43:48 +0200186 Loop Viewer - {this.state.loopName} - ({this.state.loopCache.getTemplateName()})
sebdet4946e5b2019-07-10 12:32:36 +0200187 </LoopViewHeaderDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200188 );
189 }
sebdet493c3832019-07-15 17:26:18 +0200190
sebdetc8d61302019-07-04 15:50:34 +0200191 renderLoopViewBody() {
192 return (
sebdet4946e5b2019-07-10 12:32:36 +0200193 <LoopViewBodyDivStyled>
sebdetc0ec0fc2020-05-18 12:31:11 +0200194 <SvgGenerator loopCache={this.state.loopCache} clickable={true} generatedFrom={SvgGenerator.GENERATED_FROM_INSTANCE}/>
sebdet190227a2019-07-19 16:51:19 +0200195 <LoopStatus loopCache={this.state.loopCache}/>
sebdetc1ccc542019-07-19 09:50:33 +0200196 <LoopLogs loopCache={this.state.loopCache} />
sebdet4946e5b2019-07-10 12:32:36 +0200197 </LoopViewBodyDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200198 );
199 }
sebdet493c3832019-07-15 17:26:18 +0200200
xuegaoe52d5722019-07-25 15:43:06 +0200201 getLoopCache() {
202 return this.state.loopCache;
203
204 }
xuegao5fe750c2019-08-06 13:03:53 +0200205
sebdetc8d61302019-07-04 15:50:34 +0200206 renderLoopViewer() {
207 return (
sebdet4946e5b2019-07-10 12:32:36 +0200208 <LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200209 {this.renderLoopViewHeader()}
210 {this.renderLoopViewBody()}
sebdet4946e5b2019-07-10 12:32:36 +0200211 </LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200212 );
sebdetc8d61302019-07-04 15:50:34 +0200213 }
sebdet493c3832019-07-15 17:26:18 +0200214
215 updateLoopCache(loopJson) {
xuegao52432d62019-10-04 16:11:22 +0200216 this.setState({ loopCache: new LoopCache(loopJson) });
217 this.setState({ loopName: this.state.loopCache.getLoopName() });
sebdet83ce0762019-08-02 14:53:59 +0200218 console.info(this.state.loopName+" loop loaded successfully");
219 }
xuegao5fe750c2019-08-06 13:03:53 +0200220
xuegaocc5fe512020-04-06 13:13:52 +0200221 showSucAlert(message) {
222 this.setState ({ showSucAlert: true, showMessage:message });
xuegao0efeb6b2019-10-07 14:36:34 +0200223 }
224
xuegaocc5fe512020-04-06 13:13:52 +0200225 showFailAlert(message) {
226 this.setState ({ showFailAlert: true, showMessage:message });
227 }
228
xuegao0efeb6b2019-10-07 14:36:34 +0200229 disableAlert() {
xuegaocc5fe512020-04-06 13:13:52 +0200230 this.setState ({ showSucAlert: false, showFailAlert: false });
xuegao0efeb6b2019-10-07 14:36:34 +0200231 }
232
sebdet83ce0762019-08-02 14:53:59 +0200233 loadLoop(loopName) {
234 LoopService.getLoop(loopName).then(loop => {
235 console.debug("Updating loopCache");
xuegaoac42c4b2019-10-09 16:12:37 +0200236 LoopActionService.refreshStatus(loopName).then(data => {
237 this.updateLoopCache(data);
238 this.props.history.push('/');
239 })
240 .catch(error => {
241 this.updateLoopCache(loop);
242 this.props.history.push('/');
243 });
sebdet83ce0762019-08-02 14:53:59 +0200244 });
sebdet493c3832019-07-15 17:26:18 +0200245 }
246
xuegao691e2b72019-08-16 11:07:24 +0200247 closeLoop() {
Ted Humphrey01e5fde2020-01-27 18:57:39 -0500248 this.setState({ loopCache: new LoopCache({}), loopName: OnapConstants.defaultLoopName });
xuegao691e2b72019-08-16 11:07:24 +0200249 this.props.history.push('/');
250 }
sebdet687b8de2019-08-26 14:29:11 -0700251
252 render() {
sebdetc8d61302019-07-04 15:50:34 +0200253 return (
sebdetd0d65632019-08-26 05:47:01 -0700254 <StyledMainDiv id="main_div">
ash742683a83e2a2020-01-31 15:40:15 +0000255 <Route path="/uploadToscaPolicyModal" render={(routeProps) => (<UploadToscaPolicyModal {...routeProps} />)} />
drveerendra684057e2019-11-11 19:37:39 -0500256 <Route path="/viewToscaPolicyModal" render={(routeProps) => (<ViewToscaPolicyModal {...routeProps} />)} />
sebdet3b7f6692020-02-17 06:03:31 -0800257 <Route path="/ViewLoopTemplatesModal" render={(routeProps) => (<ViewLoopTemplatesModal {...routeProps} />)} />
drveerendra50320952020-03-04 20:30:44 -0500258 <Route path="/ManageDictionaries" render={(routeProps) => (<ManageDictionaries {...routeProps} />)} />
sebdetc11160e2020-02-25 15:13:31 -0800259 <Route path="/policyModal/:policyInstanceType/:policyName" render={(routeProps) => (<PolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
sebdetd2a4df02020-02-26 15:47:30 -0800260 <Route path="/createLoop" render={(routeProps) => (<CreateLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
sebdet83ce0762019-08-02 14:53:59 +0200261 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
sebdetb13a7902019-11-15 17:26:45 +0100262 <Route path="/loopProperties" render={(routeProps) => (<LoopPropertiesModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
sebdetaa486be2020-02-18 02:00:11 -0800263 <Route path="/modifyLoop" render={(routeProps) => (<ModifyLoopModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
264
sebdet4dc849f2019-11-15 17:49:42 +0100265 <Route path="/userInfo" render={(routeProps) => (<UserInfoModal {...routeProps} />)} />
xuegao691e2b72019-08-16 11:07:24 +0200266 <Route path="/closeLoop" render={this.closeLoop} />
xuegaocc5fe512020-04-06 13:13:52 +0200267 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
268 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
269 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
270 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
271 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
272 <Route path="/deploy" render={(routeProps) => (<DeployLoopModal {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
273 <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
sebdet687b8de2019-08-26 14:29:11 -0700274 <GlobalClampStyle />
xuegao0efeb6b2019-10-07 14:36:34 +0200275 {this.renderAlertBar()}
sebdet8a02dd72019-07-31 17:11:11 +0200276 {this.renderNavBar()}
277 {this.renderLoopViewer()}
sebdetd0d65632019-08-26 05:47:01 -0700278 </StyledMainDiv>
sebdetc8d61302019-07-04 15:50:34 +0200279 );
280 }
281}