blob: 471e87200c76b024f2ab424e26cfb5c8fa1cda5c [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'
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';
sebdet493c3832019-07-15 17:26:18 +020043import OperationalPolicyModal from './components/dialogs/OperationalPolicy/OperationalPolicyModal';
44import ConfigurationPolicyModal from './components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal';
sebdetd2a4df02020-02-26 15:47:30 -080045import PolicyModal from './components/dialogs/Policy/PolicyModal';
sebdetb13a7902019-11-15 17:26:45 +010046import LoopPropertiesModal from './components/dialogs/Loop/LoopPropertiesModal';
sebdet4dc849f2019-11-15 17:49:42 +010047import UserInfoModal from './components/dialogs/UserInfoModal';
sebdet83ce0762019-08-02 14:53:59 +020048import LoopService from './api/LoopService';
ash742683a83e2a2020-01-31 15:40:15 +000049import UploadToscaPolicyModal from './components/dialogs/Tosca/UploadToscaPolicyModal';
drveerendra684057e2019-11-11 19:37:39 -050050import ViewToscaPolicyModal from './components/dialogs/Tosca/ViewToscaPolicyModal';
sebdet3b7f6692020-02-17 06:03:31 -080051import ViewLoopTemplatesModal from './components/dialogs/Tosca/ViewLoopTemplatesModal';
sebdetf9e2cee2019-08-09 18:36:09 +020052import PerformAction from './components/dialogs/PerformActions';
53import RefreshStatus from './components/dialogs/RefreshStatus';
sebdet2e9ae122019-11-15 16:28:55 +010054import DeployLoopModal from './components/dialogs/Loop/DeployLoopModal';
xuegao0efeb6b2019-10-07 14:36:34 +020055import Alert from 'react-bootstrap/Alert';
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
sebdet4946e5b2019-07-10 12:32:36 +020063const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020064 vertical-align: middle;
65 padding-left: 30px;
sebdetd0d65632019-08-26 05:47:01 -070066 font-size: 36px;
67 font-weight: bold;
sebdetc8d61302019-07-04 15:50:34 +020068`
sebdetd0d65632019-08-26 05:47:01 -070069
70const StyledRouterLink = styled(Link)`
71 color: ${props => props.theme.menuFontColor};
72 background-color: ${props => props.theme.backgroundColor};
73`
74
75const StyledLoginInfo = styled.a`
76 color: ${props => props.theme.menuFontColor};
77 background-color: ${props => props.theme.backgroundColor};
78`
79
sebdet4946e5b2019-07-10 12:32:36 +020080const LoopViewDivStyled = styled.div`
sebdet190227a2019-07-19 16:51:19 +020081 height: 100%;
sebdetc8d61302019-07-04 15:50:34 +020082 overflow: hidden;
83 margin-left: 10px;
84 margin-right: 10px;
85 margin-bottom: 10px;
86 color: ${props => props.theme.loopViewerFontColor};
87 background-color: ${props => props.theme.loopViewerBackgroundColor};
88 border: 1px solid transparent;
89 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
90`
91
sebdet4946e5b2019-07-10 12:32:36 +020092const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020093 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
94 padding: 10px 10px;
95 color: ${props => props.theme.loopViewerHeaderFontColor};
96`
97
sebdet4946e5b2019-07-10 12:32:36 +020098const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020099 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
100 padding: 10px 10px;
101 color: ${props => (props.theme.loopViewerHeaderFontColor)};
102 height: 95%;
103`
104
sebdetc8d61302019-07-04 15:50:34 +0200105export default class LoopUI extends React.Component {
sebdet493c3832019-07-15 17:26:18 +0200106
sebdet4946e5b2019-07-10 12:32:36 +0200107 state = {
108 userName: null,
Ted Humphrey01e5fde2020-01-27 18:57:39 -0500109 loopName: OnapConstants.defaultLoopName,
xuegao0efeb6b2019-10-07 14:36:34 +0200110 loopCache: new LoopCache({}),
111 showAlert: 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);
sebdet687b8de2019-08-26 14:29:11 -0700117 this.logout = this.logout.bind(this);
sebdet493c3832019-07-15 17:26:18 +0200118 this.updateLoopCache = this.updateLoopCache.bind(this);
sebdet83ce0762019-08-02 14:53:59 +0200119 this.loadLoop = this.loadLoop.bind(this);
xuegao691e2b72019-08-16 11:07:24 +0200120 this.closeLoop = this.closeLoop.bind(this);
xuegao0efeb6b2019-10-07 14:36:34 +0200121 this.showAlert = this.showAlert.bind(this);
122 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 }
sebdet687b8de2019-08-26 14:29:11 -0700134
135 logout() {
136 UserService.logout().then(user => {
137 this.setState({ userName: user });
138 window.location.reload();
139 });
140
141 }
sebdet493c3832019-07-15 17:26:18 +0200142
sebdetc8d61302019-07-04 15:50:34 +0200143 renderMenuNavBar() {
144 return (
xuegao691e2b72019-08-16 11:07:24 +0200145 <MenuBar loopName={this.state.loopName}/>
sebdetc8d61302019-07-04 15:50:34 +0200146 );
147 }
sebdet4946e5b2019-07-10 12:32:36 +0200148
sebdetc8d61302019-07-04 15:50:34 +0200149 renderUserLoggedNavBar() {
150 return (
151 <Navbar.Text>
sebdetd0d65632019-08-26 05:47:01 -0700152 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
153 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
154 <StyledRouterLink to="/logout/"> (logout)</StyledRouterLink>
sebdetc8d61302019-07-04 15:50:34 +0200155 </Navbar.Text>
156 );
157 }
sebdet4946e5b2019-07-10 12:32:36 +0200158
sebdetc8d61302019-07-04 15:50:34 +0200159 renderLogoNavBar() {
160 return (
161 <Navbar.Brand>
sebdet493c3832019-07-15 17:26:18 +0200162 <img height="50px" width="234px" src={logo} alt="" />
sebdet4946e5b2019-07-10 12:32:36 +0200163 <ProjectNameStyled>CLAMP</ProjectNameStyled>
sebdetc8d61302019-07-04 15:50:34 +0200164 </Navbar.Brand>
165 );
166 }
sebdet4946e5b2019-07-10 12:32:36 +0200167
xuegao0efeb6b2019-10-07 14:36:34 +0200168 renderAlertBar() {
169 return (
170 <Alert variant="danger" show={this.state.showAlert} onClose={this.disableAlert} dismissible>
171 {this.state.showMessage}
172 </Alert>
173 );
174 }
175
sebdetc8d61302019-07-04 15:50:34 +0200176 renderNavBar() {
177 return (
sebdetd0d65632019-08-26 05:47:01 -0700178 <Navbar >
sebdet493c3832019-07-15 17:26:18 +0200179 {this.renderLogoNavBar()}
sebdetd0d65632019-08-26 05:47:01 -0700180 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
sebdet493c3832019-07-15 17:26:18 +0200181 {this.renderMenuNavBar()}
182 {this.renderUserLoggedNavBar()}
183 </Navbar>
184 );
sebdetc8d61302019-07-04 15:50:34 +0200185 }
sebdet493c3832019-07-15 17:26:18 +0200186
sebdetc8d61302019-07-04 15:50:34 +0200187 renderLoopViewHeader() {
188 return (
sebdet4946e5b2019-07-10 12:32:36 +0200189 <LoopViewHeaderDivStyled>
sebdet190227a2019-07-19 16:51:19 +0200190 Loop Viewer - {this.state.loopName}
sebdet4946e5b2019-07-10 12:32:36 +0200191 </LoopViewHeaderDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200192 );
193 }
sebdet493c3832019-07-15 17:26:18 +0200194
sebdetc8d61302019-07-04 15:50:34 +0200195 renderLoopViewBody() {
196 return (
sebdet4946e5b2019-07-10 12:32:36 +0200197 <LoopViewBodyDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200198 <LoopSvg loopCache={this.state.loopCache} />
sebdet190227a2019-07-19 16:51:19 +0200199 <LoopStatus loopCache={this.state.loopCache}/>
sebdetc1ccc542019-07-19 09:50:33 +0200200 <LoopLogs loopCache={this.state.loopCache} />
sebdet4946e5b2019-07-10 12:32:36 +0200201 </LoopViewBodyDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200202 );
203 }
sebdet493c3832019-07-15 17:26:18 +0200204
xuegaoe52d5722019-07-25 15:43:06 +0200205 getLoopCache() {
206 return this.state.loopCache;
207
208 }
xuegao5fe750c2019-08-06 13:03:53 +0200209
sebdetc8d61302019-07-04 15:50:34 +0200210 renderLoopViewer() {
211 return (
sebdet4946e5b2019-07-10 12:32:36 +0200212 <LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200213 {this.renderLoopViewHeader()}
214 {this.renderLoopViewBody()}
sebdet4946e5b2019-07-10 12:32:36 +0200215 </LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200216 );
sebdetc8d61302019-07-04 15:50:34 +0200217 }
sebdet493c3832019-07-15 17:26:18 +0200218
219 updateLoopCache(loopJson) {
xuegao52432d62019-10-04 16:11:22 +0200220 this.setState({ loopCache: new LoopCache(loopJson) });
221 this.setState({ loopName: this.state.loopCache.getLoopName() });
sebdet83ce0762019-08-02 14:53:59 +0200222 console.info(this.state.loopName+" loop loaded successfully");
223 }
xuegao5fe750c2019-08-06 13:03:53 +0200224
xuegao0efeb6b2019-10-07 14:36:34 +0200225 showAlert(message) {
226 this.setState ({ showAlert: true, showMessage:message });
227 }
228
229 disableAlert() {
230 this.setState ({ showAlert: false });
231 }
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} />)} />
sebdet493c3832019-07-15 17:26:18 +0200258 <Route path="/operationalPolicyModal"
xuegao2f5b2cd2020-01-06 16:13:46 +0100259 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
sebdetc11160e2020-02-25 15:13:31 -0800260 <Route path="/policyModal/:policyInstanceType/:policyName" render={(routeProps) => (<PolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
261 <Route path="/configurationPolicyModal/:policyName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
sebdetd2a4df02020-02-26 15:47:30 -0800262 <Route path="/createLoop" render={(routeProps) => (<CreateLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
sebdet83ce0762019-08-02 14:53:59 +0200263 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
sebdetb13a7902019-11-15 17:26:45 +0100264 <Route path="/loopProperties" render={(routeProps) => (<LoopPropertiesModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
sebdetaa486be2020-02-18 02:00:11 -0800265 <Route path="/modifyLoop" render={(routeProps) => (<ModifyLoopModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
266
sebdet4dc849f2019-11-15 17:49:42 +0100267 <Route path="/userInfo" render={(routeProps) => (<UserInfoModal {...routeProps} />)} />
xuegao691e2b72019-08-16 11:07:24 +0200268 <Route path="/closeLoop" render={this.closeLoop} />
xuegao0efeb6b2019-10-07 14:36:34 +0200269 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
270 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
271 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
272 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
273 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
sebdet2e9ae122019-11-15 16:28:55 +0100274 <Route path="/deploy" render={(routeProps) => (<DeployLoopModal {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
xuegao0efeb6b2019-10-07 14:36:34 +0200275 <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
sebdet687b8de2019-08-26 14:29:11 -0700276 <Route path="/logout" render={this.logout} />
277 <GlobalClampStyle />
xuegao0efeb6b2019-10-07 14:36:34 +0200278 {this.renderAlertBar()}
sebdet8a02dd72019-07-31 17:11:11 +0200279 {this.renderNavBar()}
280 {this.renderLoopViewer()}
sebdetd0d65632019-08-26 05:47:01 -0700281 </StyledMainDiv>
sebdetc8d61302019-07-04 15:50:34 +0200282 );
283 }
284}