blob: 9eea0be953af442b02195c05cc45b224961e5aea [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';
sebdet493c3832019-07-15 17:26:18 +020041import OperationalPolicyModal from './components/dialogs/OperationalPolicy/OperationalPolicyModal';
42import ConfigurationPolicyModal from './components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal';
sebdetb13a7902019-11-15 17:26:45 +010043import LoopPropertiesModal from './components/dialogs/Loop/LoopPropertiesModal';
sebdet4dc849f2019-11-15 17:49:42 +010044import UserInfoModal from './components/dialogs/UserInfoModal';
sebdet83ce0762019-08-02 14:53:59 +020045import LoopService from './api/LoopService';
drveerendra684057e2019-11-11 19:37:39 -050046import ViewToscaPolicyModal from './components/dialogs/Tosca/ViewToscaPolicyModal';
47import ViewBlueprintMicroServiceTemplatesModal from './components/dialogs/Tosca/ViewBlueprintMicroServiceTemplatesModal';
sebdetf9e2cee2019-08-09 18:36:09 +020048import PerformAction from './components/dialogs/PerformActions';
49import RefreshStatus from './components/dialogs/RefreshStatus';
sebdet2e9ae122019-11-15 16:28:55 +010050import DeployLoopModal from './components/dialogs/Loop/DeployLoopModal';
xuegao0efeb6b2019-10-07 14:36:34 +020051import Alert from 'react-bootstrap/Alert';
sebdetc8d61302019-07-04 15:50:34 +020052
sebdetd0d65632019-08-26 05:47:01 -070053import { Link } from 'react-router-dom';
54
55const StyledMainDiv = styled.div`
56 background-color: ${props => props.theme.backgroundColor};
57`
58
sebdet4946e5b2019-07-10 12:32:36 +020059const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020060 vertical-align: middle;
61 padding-left: 30px;
sebdetd0d65632019-08-26 05:47:01 -070062 font-size: 36px;
63 font-weight: bold;
sebdetc8d61302019-07-04 15:50:34 +020064`
sebdetd0d65632019-08-26 05:47:01 -070065
66const StyledRouterLink = styled(Link)`
67 color: ${props => props.theme.menuFontColor};
68 background-color: ${props => props.theme.backgroundColor};
69`
70
71const StyledLoginInfo = styled.a`
72 color: ${props => props.theme.menuFontColor};
73 background-color: ${props => props.theme.backgroundColor};
74`
75
sebdet4946e5b2019-07-10 12:32:36 +020076const LoopViewDivStyled = styled.div`
sebdet190227a2019-07-19 16:51:19 +020077 height: 100%;
sebdetc8d61302019-07-04 15:50:34 +020078 overflow: hidden;
79 margin-left: 10px;
80 margin-right: 10px;
81 margin-bottom: 10px;
82 color: ${props => props.theme.loopViewerFontColor};
83 background-color: ${props => props.theme.loopViewerBackgroundColor};
84 border: 1px solid transparent;
85 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
86`
87
sebdet4946e5b2019-07-10 12:32:36 +020088const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020089 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
90 padding: 10px 10px;
91 color: ${props => props.theme.loopViewerHeaderFontColor};
92`
93
sebdet4946e5b2019-07-10 12:32:36 +020094const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020095 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
96 padding: 10px 10px;
97 color: ${props => (props.theme.loopViewerHeaderFontColor)};
98 height: 95%;
99`
100
sebdetc8d61302019-07-04 15:50:34 +0200101export default class LoopUI extends React.Component {
sebdet493c3832019-07-15 17:26:18 +0200102
sebdet4946e5b2019-07-10 12:32:36 +0200103 state = {
104 userName: null,
Ted Humphrey01e5fde2020-01-27 18:57:39 -0500105 loopName: OnapConstants.defaultLoopName,
xuegao0efeb6b2019-10-07 14:36:34 +0200106 loopCache: new LoopCache({}),
107 showAlert: false
sebdet4946e5b2019-07-10 12:32:36 +0200108 };
xuegao7c7323d2019-07-09 11:52:20 +0200109
sebdet4946e5b2019-07-10 12:32:36 +0200110 constructor() {
111 super();
112 this.getUser = this.getUser.bind(this);
sebdet687b8de2019-08-26 14:29:11 -0700113 this.logout = this.logout.bind(this);
sebdet493c3832019-07-15 17:26:18 +0200114 this.updateLoopCache = this.updateLoopCache.bind(this);
sebdet83ce0762019-08-02 14:53:59 +0200115 this.loadLoop = this.loadLoop.bind(this);
xuegao691e2b72019-08-16 11:07:24 +0200116 this.closeLoop = this.closeLoop.bind(this);
xuegao0efeb6b2019-10-07 14:36:34 +0200117 this.showAlert = this.showAlert.bind(this);
118 this.disableAlert = this.disableAlert.bind(this);
sebdet4946e5b2019-07-10 12:32:36 +0200119 }
sebdet493c3832019-07-15 17:26:18 +0200120
sebdet2dacb9b2019-07-17 13:48:44 +0200121 componentWillMount() {
sebdet493c3832019-07-15 17:26:18 +0200122 this.getUser();
123 }
sebdet4946e5b2019-07-10 12:32:36 +0200124
125 getUser() {
sebdet493c3832019-07-15 17:26:18 +0200126 UserService.login().then(user => {
127 this.setState({ userName: user })
sebdet4946e5b2019-07-10 12:32:36 +0200128 });
129 }
sebdet687b8de2019-08-26 14:29:11 -0700130
131 logout() {
132 UserService.logout().then(user => {
133 this.setState({ userName: user });
134 window.location.reload();
135 });
136
137 }
sebdet493c3832019-07-15 17:26:18 +0200138
sebdetc8d61302019-07-04 15:50:34 +0200139 renderMenuNavBar() {
140 return (
xuegao691e2b72019-08-16 11:07:24 +0200141 <MenuBar loopName={this.state.loopName}/>
sebdetc8d61302019-07-04 15:50:34 +0200142 );
143 }
sebdet4946e5b2019-07-10 12:32:36 +0200144
sebdetc8d61302019-07-04 15:50:34 +0200145 renderUserLoggedNavBar() {
146 return (
147 <Navbar.Text>
sebdetd0d65632019-08-26 05:47:01 -0700148 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
149 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
150 <StyledRouterLink to="/logout/"> (logout)</StyledRouterLink>
sebdetc8d61302019-07-04 15:50:34 +0200151 </Navbar.Text>
152 );
153 }
sebdet4946e5b2019-07-10 12:32:36 +0200154
sebdetc8d61302019-07-04 15:50:34 +0200155 renderLogoNavBar() {
156 return (
157 <Navbar.Brand>
sebdet493c3832019-07-15 17:26:18 +0200158 <img height="50px" width="234px" src={logo} alt="" />
sebdet4946e5b2019-07-10 12:32:36 +0200159 <ProjectNameStyled>CLAMP</ProjectNameStyled>
sebdetc8d61302019-07-04 15:50:34 +0200160 </Navbar.Brand>
161 );
162 }
sebdet4946e5b2019-07-10 12:32:36 +0200163
xuegao0efeb6b2019-10-07 14:36:34 +0200164 renderAlertBar() {
165 return (
166 <Alert variant="danger" show={this.state.showAlert} onClose={this.disableAlert} dismissible>
167 {this.state.showMessage}
168 </Alert>
169 );
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>
sebdet190227a2019-07-19 16:51:19 +0200186 Loop Viewer - {this.state.loopName}
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>
sebdet493c3832019-07-15 17:26:18 +0200194 <LoopSvg loopCache={this.state.loopCache} />
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
xuegao0efeb6b2019-10-07 14:36:34 +0200221 showAlert(message) {
222 this.setState ({ showAlert: true, showMessage:message });
223 }
224
225 disableAlert() {
226 this.setState ({ showAlert: false });
227 }
228
sebdet83ce0762019-08-02 14:53:59 +0200229 loadLoop(loopName) {
230 LoopService.getLoop(loopName).then(loop => {
231 console.debug("Updating loopCache");
xuegaoac42c4b2019-10-09 16:12:37 +0200232 LoopActionService.refreshStatus(loopName).then(data => {
233 this.updateLoopCache(data);
234 this.props.history.push('/');
235 })
236 .catch(error => {
237 this.updateLoopCache(loop);
238 this.props.history.push('/');
239 });
sebdet83ce0762019-08-02 14:53:59 +0200240 });
sebdet493c3832019-07-15 17:26:18 +0200241 }
242
xuegao691e2b72019-08-16 11:07:24 +0200243 closeLoop() {
Ted Humphrey01e5fde2020-01-27 18:57:39 -0500244 this.setState({ loopCache: new LoopCache({}), loopName: OnapConstants.defaultLoopName });
xuegao691e2b72019-08-16 11:07:24 +0200245 this.props.history.push('/');
246 }
sebdet687b8de2019-08-26 14:29:11 -0700247
248 render() {
sebdetc8d61302019-07-04 15:50:34 +0200249 return (
sebdetd0d65632019-08-26 05:47:01 -0700250 <StyledMainDiv id="main_div">
drveerendra684057e2019-11-11 19:37:39 -0500251 <Route path="/viewToscaPolicyModal" render={(routeProps) => (<ViewToscaPolicyModal {...routeProps} />)} />
252 <Route path="/viewBlueprintMicroServiceTemplatesModal" render={(routeProps) => (<ViewBlueprintMicroServiceTemplatesModal {...routeProps} />)} />
sebdet493c3832019-07-15 17:26:18 +0200253 <Route path="/operationalPolicyModal"
xuegao2f5b2cd2020-01-06 16:13:46 +0100254 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
sebdet83ce0762019-08-02 14:53:59 +0200255 <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
256 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
sebdetb13a7902019-11-15 17:26:45 +0100257 <Route path="/loopProperties" render={(routeProps) => (<LoopPropertiesModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
sebdet4dc849f2019-11-15 17:49:42 +0100258 <Route path="/userInfo" render={(routeProps) => (<UserInfoModal {...routeProps} />)} />
xuegao691e2b72019-08-16 11:07:24 +0200259 <Route path="/closeLoop" render={this.closeLoop} />
xuegao0efeb6b2019-10-07 14:36:34 +0200260 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
261 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
262 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
263 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
264 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
sebdet2e9ae122019-11-15 16:28:55 +0100265 <Route path="/deploy" render={(routeProps) => (<DeployLoopModal {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
xuegao0efeb6b2019-10-07 14:36:34 +0200266 <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
sebdet687b8de2019-08-26 14:29:11 -0700267 <Route path="/logout" render={this.logout} />
268 <GlobalClampStyle />
xuegao0efeb6b2019-10-07 14:36:34 +0200269 {this.renderAlertBar()}
sebdet8a02dd72019-07-31 17:11:11 +0200270 {this.renderNavBar()}
271 {this.renderLoopViewer()}
sebdetd0d65632019-08-26 05:47:01 -0700272 </StyledMainDiv>
sebdetc8d61302019-07-04 15:50:34 +0200273 );
274 }
275}