blob: 7f07f34385ea1d2de53732f8251e04238c38a03a [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
sebdet493c3832019-07-15 17:26:18 +020032import LoopSvg from './components/loop_viewer/svg/LoopSvg';
33import 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'
sebdet67c76a42019-11-15 17:33:44 +010040import OpenLoopModal from './components/dialogs/Loop/OpenLoopModal';
sebdetaa486be2020-02-18 02:00:11 -080041import ModifyLoopModal from './components/dialogs/Loop/ModifyLoopModal';
sebdet493c3832019-07-15 17:26:18 +020042import OperationalPolicyModal from './components/dialogs/OperationalPolicy/OperationalPolicyModal';
43import ConfigurationPolicyModal from './components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal';
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';
sebdetf9e2cee2019-08-09 18:36:09 +020050import PerformAction from './components/dialogs/PerformActions';
51import RefreshStatus from './components/dialogs/RefreshStatus';
sebdet2e9ae122019-11-15 16:28:55 +010052import DeployLoopModal from './components/dialogs/Loop/DeployLoopModal';
xuegao0efeb6b2019-10-07 14:36:34 +020053import Alert from 'react-bootstrap/Alert';
sebdetc8d61302019-07-04 15:50:34 +020054
sebdetd0d65632019-08-26 05:47:01 -070055import { Link } from 'react-router-dom';
56
57const StyledMainDiv = styled.div`
58 background-color: ${props => props.theme.backgroundColor};
59`
60
sebdet4946e5b2019-07-10 12:32:36 +020061const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020062 vertical-align: middle;
63 padding-left: 30px;
sebdetd0d65632019-08-26 05:47:01 -070064 font-size: 36px;
65 font-weight: bold;
sebdetc8d61302019-07-04 15:50:34 +020066`
sebdetd0d65632019-08-26 05:47:01 -070067
68const StyledRouterLink = styled(Link)`
69 color: ${props => props.theme.menuFontColor};
70 background-color: ${props => props.theme.backgroundColor};
71`
72
73const StyledLoginInfo = styled.a`
74 color: ${props => props.theme.menuFontColor};
75 background-color: ${props => props.theme.backgroundColor};
76`
77
sebdet4946e5b2019-07-10 12:32:36 +020078const LoopViewDivStyled = styled.div`
sebdet190227a2019-07-19 16:51:19 +020079 height: 100%;
sebdetc8d61302019-07-04 15:50:34 +020080 overflow: hidden;
81 margin-left: 10px;
82 margin-right: 10px;
83 margin-bottom: 10px;
84 color: ${props => props.theme.loopViewerFontColor};
85 background-color: ${props => props.theme.loopViewerBackgroundColor};
86 border: 1px solid transparent;
87 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
88`
89
sebdet4946e5b2019-07-10 12:32:36 +020090const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020091 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
92 padding: 10px 10px;
93 color: ${props => props.theme.loopViewerHeaderFontColor};
94`
95
sebdet4946e5b2019-07-10 12:32:36 +020096const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020097 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
98 padding: 10px 10px;
99 color: ${props => (props.theme.loopViewerHeaderFontColor)};
100 height: 95%;
101`
102
sebdetc8d61302019-07-04 15:50:34 +0200103export default class LoopUI extends React.Component {
sebdet493c3832019-07-15 17:26:18 +0200104
sebdet4946e5b2019-07-10 12:32:36 +0200105 state = {
106 userName: null,
Ted Humphrey01e5fde2020-01-27 18:57:39 -0500107 loopName: OnapConstants.defaultLoopName,
xuegao0efeb6b2019-10-07 14:36:34 +0200108 loopCache: new LoopCache({}),
109 showAlert: false
sebdet4946e5b2019-07-10 12:32:36 +0200110 };
xuegao7c7323d2019-07-09 11:52:20 +0200111
sebdet4946e5b2019-07-10 12:32:36 +0200112 constructor() {
113 super();
114 this.getUser = this.getUser.bind(this);
sebdet687b8de2019-08-26 14:29:11 -0700115 this.logout = this.logout.bind(this);
sebdet493c3832019-07-15 17:26:18 +0200116 this.updateLoopCache = this.updateLoopCache.bind(this);
sebdet83ce0762019-08-02 14:53:59 +0200117 this.loadLoop = this.loadLoop.bind(this);
xuegao691e2b72019-08-16 11:07:24 +0200118 this.closeLoop = this.closeLoop.bind(this);
xuegao0efeb6b2019-10-07 14:36:34 +0200119 this.showAlert = this.showAlert.bind(this);
120 this.disableAlert = this.disableAlert.bind(this);
sebdet4946e5b2019-07-10 12:32:36 +0200121 }
sebdet493c3832019-07-15 17:26:18 +0200122
sebdet2dacb9b2019-07-17 13:48:44 +0200123 componentWillMount() {
sebdet493c3832019-07-15 17:26:18 +0200124 this.getUser();
125 }
sebdet4946e5b2019-07-10 12:32:36 +0200126
127 getUser() {
sebdet493c3832019-07-15 17:26:18 +0200128 UserService.login().then(user => {
129 this.setState({ userName: user })
sebdet4946e5b2019-07-10 12:32:36 +0200130 });
131 }
sebdet687b8de2019-08-26 14:29:11 -0700132
133 logout() {
134 UserService.logout().then(user => {
135 this.setState({ userName: user });
136 window.location.reload();
137 });
138
139 }
sebdet493c3832019-07-15 17:26:18 +0200140
sebdetc8d61302019-07-04 15:50:34 +0200141 renderMenuNavBar() {
142 return (
xuegao691e2b72019-08-16 11:07:24 +0200143 <MenuBar loopName={this.state.loopName}/>
sebdetc8d61302019-07-04 15:50:34 +0200144 );
145 }
sebdet4946e5b2019-07-10 12:32:36 +0200146
sebdetc8d61302019-07-04 15:50:34 +0200147 renderUserLoggedNavBar() {
148 return (
149 <Navbar.Text>
sebdetd0d65632019-08-26 05:47:01 -0700150 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
151 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
152 <StyledRouterLink to="/logout/"> (logout)</StyledRouterLink>
sebdetc8d61302019-07-04 15:50:34 +0200153 </Navbar.Text>
154 );
155 }
sebdet4946e5b2019-07-10 12:32:36 +0200156
sebdetc8d61302019-07-04 15:50:34 +0200157 renderLogoNavBar() {
158 return (
159 <Navbar.Brand>
sebdet493c3832019-07-15 17:26:18 +0200160 <img height="50px" width="234px" src={logo} alt="" />
sebdet4946e5b2019-07-10 12:32:36 +0200161 <ProjectNameStyled>CLAMP</ProjectNameStyled>
sebdetc8d61302019-07-04 15:50:34 +0200162 </Navbar.Brand>
163 );
164 }
sebdet4946e5b2019-07-10 12:32:36 +0200165
xuegao0efeb6b2019-10-07 14:36:34 +0200166 renderAlertBar() {
167 return (
168 <Alert variant="danger" show={this.state.showAlert} onClose={this.disableAlert} dismissible>
169 {this.state.showMessage}
170 </Alert>
171 );
172 }
173
sebdetc8d61302019-07-04 15:50:34 +0200174 renderNavBar() {
175 return (
sebdetd0d65632019-08-26 05:47:01 -0700176 <Navbar >
sebdet493c3832019-07-15 17:26:18 +0200177 {this.renderLogoNavBar()}
sebdetd0d65632019-08-26 05:47:01 -0700178 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
sebdet493c3832019-07-15 17:26:18 +0200179 {this.renderMenuNavBar()}
180 {this.renderUserLoggedNavBar()}
181 </Navbar>
182 );
sebdetc8d61302019-07-04 15:50:34 +0200183 }
sebdet493c3832019-07-15 17:26:18 +0200184
sebdetc8d61302019-07-04 15:50:34 +0200185 renderLoopViewHeader() {
186 return (
sebdet4946e5b2019-07-10 12:32:36 +0200187 <LoopViewHeaderDivStyled>
sebdet190227a2019-07-19 16:51:19 +0200188 Loop Viewer - {this.state.loopName}
sebdet4946e5b2019-07-10 12:32:36 +0200189 </LoopViewHeaderDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200190 );
191 }
sebdet493c3832019-07-15 17:26:18 +0200192
sebdetc8d61302019-07-04 15:50:34 +0200193 renderLoopViewBody() {
194 return (
sebdet4946e5b2019-07-10 12:32:36 +0200195 <LoopViewBodyDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200196 <LoopSvg loopCache={this.state.loopCache} />
sebdet190227a2019-07-19 16:51:19 +0200197 <LoopStatus loopCache={this.state.loopCache}/>
sebdetc1ccc542019-07-19 09:50:33 +0200198 <LoopLogs loopCache={this.state.loopCache} />
sebdet4946e5b2019-07-10 12:32:36 +0200199 </LoopViewBodyDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200200 );
201 }
sebdet493c3832019-07-15 17:26:18 +0200202
xuegaoe52d5722019-07-25 15:43:06 +0200203 getLoopCache() {
204 return this.state.loopCache;
205
206 }
xuegao5fe750c2019-08-06 13:03:53 +0200207
sebdetc8d61302019-07-04 15:50:34 +0200208 renderLoopViewer() {
209 return (
sebdet4946e5b2019-07-10 12:32:36 +0200210 <LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200211 {this.renderLoopViewHeader()}
212 {this.renderLoopViewBody()}
sebdet4946e5b2019-07-10 12:32:36 +0200213 </LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200214 );
sebdetc8d61302019-07-04 15:50:34 +0200215 }
sebdet493c3832019-07-15 17:26:18 +0200216
217 updateLoopCache(loopJson) {
xuegao52432d62019-10-04 16:11:22 +0200218 this.setState({ loopCache: new LoopCache(loopJson) });
219 this.setState({ loopName: this.state.loopCache.getLoopName() });
sebdet83ce0762019-08-02 14:53:59 +0200220 console.info(this.state.loopName+" loop loaded successfully");
221 }
xuegao5fe750c2019-08-06 13:03:53 +0200222
xuegao0efeb6b2019-10-07 14:36:34 +0200223 showAlert(message) {
224 this.setState ({ showAlert: true, showMessage:message });
225 }
226
227 disableAlert() {
228 this.setState ({ showAlert: false });
229 }
230
sebdet83ce0762019-08-02 14:53:59 +0200231 loadLoop(loopName) {
232 LoopService.getLoop(loopName).then(loop => {
233 console.debug("Updating loopCache");
xuegaoac42c4b2019-10-09 16:12:37 +0200234 LoopActionService.refreshStatus(loopName).then(data => {
235 this.updateLoopCache(data);
236 this.props.history.push('/');
237 })
238 .catch(error => {
239 this.updateLoopCache(loop);
240 this.props.history.push('/');
241 });
sebdet83ce0762019-08-02 14:53:59 +0200242 });
sebdet493c3832019-07-15 17:26:18 +0200243 }
244
xuegao691e2b72019-08-16 11:07:24 +0200245 closeLoop() {
Ted Humphrey01e5fde2020-01-27 18:57:39 -0500246 this.setState({ loopCache: new LoopCache({}), loopName: OnapConstants.defaultLoopName });
xuegao691e2b72019-08-16 11:07:24 +0200247 this.props.history.push('/');
248 }
sebdet687b8de2019-08-26 14:29:11 -0700249
250 render() {
sebdetc8d61302019-07-04 15:50:34 +0200251 return (
sebdetd0d65632019-08-26 05:47:01 -0700252 <StyledMainDiv id="main_div">
ash742683a83e2a2020-01-31 15:40:15 +0000253 <Route path="/uploadToscaPolicyModal" render={(routeProps) => (<UploadToscaPolicyModal {...routeProps} />)} />
drveerendra684057e2019-11-11 19:37:39 -0500254 <Route path="/viewToscaPolicyModal" render={(routeProps) => (<ViewToscaPolicyModal {...routeProps} />)} />
sebdet3b7f6692020-02-17 06:03:31 -0800255 <Route path="/ViewLoopTemplatesModal" render={(routeProps) => (<ViewLoopTemplatesModal {...routeProps} />)} />
sebdet493c3832019-07-15 17:26:18 +0200256 <Route path="/operationalPolicyModal"
xuegao2f5b2cd2020-01-06 16:13:46 +0100257 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
sebdet83ce0762019-08-02 14:53:59 +0200258 <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
259 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
sebdetb13a7902019-11-15 17:26:45 +0100260 <Route path="/loopProperties" render={(routeProps) => (<LoopPropertiesModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
sebdetaa486be2020-02-18 02:00:11 -0800261 <Route path="/modifyLoop" render={(routeProps) => (<ModifyLoopModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
262
sebdet4dc849f2019-11-15 17:49:42 +0100263 <Route path="/userInfo" render={(routeProps) => (<UserInfoModal {...routeProps} />)} />
xuegao691e2b72019-08-16 11:07:24 +0200264 <Route path="/closeLoop" render={this.closeLoop} />
xuegao0efeb6b2019-10-07 14:36:34 +0200265 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
266 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
267 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
268 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
269 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
sebdet2e9ae122019-11-15 16:28:55 +0100270 <Route path="/deploy" render={(routeProps) => (<DeployLoopModal {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
xuegao0efeb6b2019-10-07 14:36:34 +0200271 <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
sebdet687b8de2019-08-26 14:29:11 -0700272 <Route path="/logout" render={this.logout} />
273 <GlobalClampStyle />
xuegao0efeb6b2019-10-07 14:36:34 +0200274 {this.renderAlertBar()}
sebdet8a02dd72019-07-31 17:11:11 +0200275 {this.renderNavBar()}
276 {this.renderLoopViewer()}
sebdetd0d65632019-08-26 05:47:01 -0700277 </StyledMainDiv>
sebdetc8d61302019-07-04 15:50:34 +0200278 );
279 }
280}