blob: efd02b41f03b23b370d1ed749cdb2e9d667835ca [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';
drveerendra50320952020-03-04 20:30:44 -050052import ManageDictionaries from './components/dialogs/ManageDictionaries/ManageDictionaries';
sebdetf9e2cee2019-08-09 18:36:09 +020053import PerformAction from './components/dialogs/PerformActions';
54import RefreshStatus from './components/dialogs/RefreshStatus';
sebdet2e9ae122019-11-15 16:28:55 +010055import DeployLoopModal from './components/dialogs/Loop/DeployLoopModal';
xuegao0efeb6b2019-10-07 14:36:34 +020056import Alert from 'react-bootstrap/Alert';
sebdetc8d61302019-07-04 15:50:34 +020057
sebdetd0d65632019-08-26 05:47:01 -070058import { Link } from 'react-router-dom';
59
60const StyledMainDiv = styled.div`
61 background-color: ${props => props.theme.backgroundColor};
62`
63
sebdet4946e5b2019-07-10 12:32:36 +020064const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020065 vertical-align: middle;
66 padding-left: 30px;
sebdetd0d65632019-08-26 05:47:01 -070067 font-size: 36px;
68 font-weight: bold;
sebdetc8d61302019-07-04 15:50:34 +020069`
sebdetd0d65632019-08-26 05:47:01 -070070
71const StyledRouterLink = styled(Link)`
72 color: ${props => props.theme.menuFontColor};
73 background-color: ${props => props.theme.backgroundColor};
74`
75
76const StyledLoginInfo = styled.a`
77 color: ${props => props.theme.menuFontColor};
78 background-color: ${props => props.theme.backgroundColor};
79`
80
sebdet4946e5b2019-07-10 12:32:36 +020081const LoopViewDivStyled = styled.div`
sebdet190227a2019-07-19 16:51:19 +020082 height: 100%;
sebdetc8d61302019-07-04 15:50:34 +020083 overflow: hidden;
84 margin-left: 10px;
85 margin-right: 10px;
86 margin-bottom: 10px;
87 color: ${props => props.theme.loopViewerFontColor};
88 background-color: ${props => props.theme.loopViewerBackgroundColor};
89 border: 1px solid transparent;
90 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
91`
92
sebdet4946e5b2019-07-10 12:32:36 +020093const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020094 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
95 padding: 10px 10px;
96 color: ${props => props.theme.loopViewerHeaderFontColor};
97`
98
sebdet4946e5b2019-07-10 12:32:36 +020099const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +0200100 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
101 padding: 10px 10px;
102 color: ${props => (props.theme.loopViewerHeaderFontColor)};
103 height: 95%;
104`
105
sebdetc8d61302019-07-04 15:50:34 +0200106export default class LoopUI extends React.Component {
sebdet493c3832019-07-15 17:26:18 +0200107
sebdet4946e5b2019-07-10 12:32:36 +0200108 state = {
109 userName: null,
Ted Humphrey01e5fde2020-01-27 18:57:39 -0500110 loopName: OnapConstants.defaultLoopName,
xuegao0efeb6b2019-10-07 14:36:34 +0200111 loopCache: new LoopCache({}),
xuegaocc5fe512020-04-06 13:13:52 +0200112 showSucAlert: false,
113 showFailAlert: false
sebdet4946e5b2019-07-10 12:32:36 +0200114 };
xuegao7c7323d2019-07-09 11:52:20 +0200115
sebdet4946e5b2019-07-10 12:32:36 +0200116 constructor() {
117 super();
118 this.getUser = this.getUser.bind(this);
sebdet687b8de2019-08-26 14:29:11 -0700119 this.logout = this.logout.bind(this);
sebdet493c3832019-07-15 17:26:18 +0200120 this.updateLoopCache = this.updateLoopCache.bind(this);
sebdet83ce0762019-08-02 14:53:59 +0200121 this.loadLoop = this.loadLoop.bind(this);
xuegao691e2b72019-08-16 11:07:24 +0200122 this.closeLoop = this.closeLoop.bind(this);
xuegaocc5fe512020-04-06 13:13:52 +0200123 this.showSucAlert = this.showSucAlert.bind(this);
124 this.showFailAlert = this.showFailAlert.bind(this);
xuegao0efeb6b2019-10-07 14:36:34 +0200125 this.disableAlert = this.disableAlert.bind(this);
sebdet4946e5b2019-07-10 12:32:36 +0200126 }
sebdet493c3832019-07-15 17:26:18 +0200127
sebdet2dacb9b2019-07-17 13:48:44 +0200128 componentWillMount() {
sebdet493c3832019-07-15 17:26:18 +0200129 this.getUser();
130 }
sebdet4946e5b2019-07-10 12:32:36 +0200131
132 getUser() {
sebdet493c3832019-07-15 17:26:18 +0200133 UserService.login().then(user => {
134 this.setState({ userName: user })
sebdet4946e5b2019-07-10 12:32:36 +0200135 });
136 }
sebdet687b8de2019-08-26 14:29:11 -0700137
138 logout() {
139 UserService.logout().then(user => {
140 this.setState({ userName: user });
141 window.location.reload();
142 });
143
144 }
sebdet493c3832019-07-15 17:26:18 +0200145
sebdetc8d61302019-07-04 15:50:34 +0200146 renderMenuNavBar() {
147 return (
xuegao691e2b72019-08-16 11:07:24 +0200148 <MenuBar loopName={this.state.loopName}/>
sebdetc8d61302019-07-04 15:50:34 +0200149 );
150 }
sebdet4946e5b2019-07-10 12:32:36 +0200151
sebdetc8d61302019-07-04 15:50:34 +0200152 renderUserLoggedNavBar() {
153 return (
154 <Navbar.Text>
sebdetd0d65632019-08-26 05:47:01 -0700155 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
156 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
157 <StyledRouterLink to="/logout/"> (logout)</StyledRouterLink>
sebdetc8d61302019-07-04 15:50:34 +0200158 </Navbar.Text>
159 );
160 }
sebdet4946e5b2019-07-10 12:32:36 +0200161
sebdetc8d61302019-07-04 15:50:34 +0200162 renderLogoNavBar() {
163 return (
164 <Navbar.Brand>
sebdet493c3832019-07-15 17:26:18 +0200165 <img height="50px" width="234px" src={logo} alt="" />
sebdet4946e5b2019-07-10 12:32:36 +0200166 <ProjectNameStyled>CLAMP</ProjectNameStyled>
sebdetc8d61302019-07-04 15:50:34 +0200167 </Navbar.Brand>
168 );
169 }
sebdet4946e5b2019-07-10 12:32:36 +0200170
xuegao0efeb6b2019-10-07 14:36:34 +0200171 renderAlertBar() {
172 return (
xuegaocc5fe512020-04-06 13:13:52 +0200173 <div>
174 <Alert variant="success" show={this.state.showSucAlert} onClose={this.disableAlert} dismissible>
xuegao0efeb6b2019-10-07 14:36:34 +0200175 {this.state.showMessage}
176 </Alert>
xuegaocc5fe512020-04-06 13:13:52 +0200177 <Alert variant="danger" show={this.state.showFailAlert} onClose={this.disableAlert} dismissible>
178 {this.state.showMessage}
179 </Alert>
180 </div>
xuegao0efeb6b2019-10-07 14:36:34 +0200181 );
182 }
183
sebdetc8d61302019-07-04 15:50:34 +0200184 renderNavBar() {
185 return (
sebdetd0d65632019-08-26 05:47:01 -0700186 <Navbar >
sebdet493c3832019-07-15 17:26:18 +0200187 {this.renderLogoNavBar()}
sebdetd0d65632019-08-26 05:47:01 -0700188 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
sebdet493c3832019-07-15 17:26:18 +0200189 {this.renderMenuNavBar()}
190 {this.renderUserLoggedNavBar()}
191 </Navbar>
192 );
sebdetc8d61302019-07-04 15:50:34 +0200193 }
sebdet493c3832019-07-15 17:26:18 +0200194
sebdetc8d61302019-07-04 15:50:34 +0200195 renderLoopViewHeader() {
196 return (
sebdet4946e5b2019-07-10 12:32:36 +0200197 <LoopViewHeaderDivStyled>
sebdetedaf4f92020-04-16 00:43:48 +0200198 Loop Viewer - {this.state.loopName} - ({this.state.loopCache.getTemplateName()})
sebdet4946e5b2019-07-10 12:32:36 +0200199 </LoopViewHeaderDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200200 );
201 }
sebdet493c3832019-07-15 17:26:18 +0200202
sebdetc8d61302019-07-04 15:50:34 +0200203 renderLoopViewBody() {
204 return (
sebdet4946e5b2019-07-10 12:32:36 +0200205 <LoopViewBodyDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200206 <LoopSvg loopCache={this.state.loopCache} />
sebdet190227a2019-07-19 16:51:19 +0200207 <LoopStatus loopCache={this.state.loopCache}/>
sebdetc1ccc542019-07-19 09:50:33 +0200208 <LoopLogs loopCache={this.state.loopCache} />
sebdet4946e5b2019-07-10 12:32:36 +0200209 </LoopViewBodyDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200210 );
211 }
sebdet493c3832019-07-15 17:26:18 +0200212
xuegaoe52d5722019-07-25 15:43:06 +0200213 getLoopCache() {
214 return this.state.loopCache;
215
216 }
xuegao5fe750c2019-08-06 13:03:53 +0200217
sebdetc8d61302019-07-04 15:50:34 +0200218 renderLoopViewer() {
219 return (
sebdet4946e5b2019-07-10 12:32:36 +0200220 <LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200221 {this.renderLoopViewHeader()}
222 {this.renderLoopViewBody()}
sebdet4946e5b2019-07-10 12:32:36 +0200223 </LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200224 );
sebdetc8d61302019-07-04 15:50:34 +0200225 }
sebdet493c3832019-07-15 17:26:18 +0200226
227 updateLoopCache(loopJson) {
xuegao52432d62019-10-04 16:11:22 +0200228 this.setState({ loopCache: new LoopCache(loopJson) });
229 this.setState({ loopName: this.state.loopCache.getLoopName() });
sebdet83ce0762019-08-02 14:53:59 +0200230 console.info(this.state.loopName+" loop loaded successfully");
231 }
xuegao5fe750c2019-08-06 13:03:53 +0200232
xuegaocc5fe512020-04-06 13:13:52 +0200233 showSucAlert(message) {
234 this.setState ({ showSucAlert: true, showMessage:message });
xuegao0efeb6b2019-10-07 14:36:34 +0200235 }
236
xuegaocc5fe512020-04-06 13:13:52 +0200237 showFailAlert(message) {
238 this.setState ({ showFailAlert: true, showMessage:message });
239 }
240
xuegao0efeb6b2019-10-07 14:36:34 +0200241 disableAlert() {
xuegaocc5fe512020-04-06 13:13:52 +0200242 this.setState ({ showSucAlert: false, showFailAlert: false });
xuegao0efeb6b2019-10-07 14:36:34 +0200243 }
244
sebdet83ce0762019-08-02 14:53:59 +0200245 loadLoop(loopName) {
246 LoopService.getLoop(loopName).then(loop => {
247 console.debug("Updating loopCache");
xuegaoac42c4b2019-10-09 16:12:37 +0200248 LoopActionService.refreshStatus(loopName).then(data => {
249 this.updateLoopCache(data);
250 this.props.history.push('/');
251 })
252 .catch(error => {
253 this.updateLoopCache(loop);
254 this.props.history.push('/');
255 });
sebdet83ce0762019-08-02 14:53:59 +0200256 });
sebdet493c3832019-07-15 17:26:18 +0200257 }
258
xuegao691e2b72019-08-16 11:07:24 +0200259 closeLoop() {
Ted Humphrey01e5fde2020-01-27 18:57:39 -0500260 this.setState({ loopCache: new LoopCache({}), loopName: OnapConstants.defaultLoopName });
xuegao691e2b72019-08-16 11:07:24 +0200261 this.props.history.push('/');
262 }
sebdet687b8de2019-08-26 14:29:11 -0700263
264 render() {
sebdetc8d61302019-07-04 15:50:34 +0200265 return (
sebdetd0d65632019-08-26 05:47:01 -0700266 <StyledMainDiv id="main_div">
ash742683a83e2a2020-01-31 15:40:15 +0000267 <Route path="/uploadToscaPolicyModal" render={(routeProps) => (<UploadToscaPolicyModal {...routeProps} />)} />
drveerendra684057e2019-11-11 19:37:39 -0500268 <Route path="/viewToscaPolicyModal" render={(routeProps) => (<ViewToscaPolicyModal {...routeProps} />)} />
sebdet3b7f6692020-02-17 06:03:31 -0800269 <Route path="/ViewLoopTemplatesModal" render={(routeProps) => (<ViewLoopTemplatesModal {...routeProps} />)} />
drveerendra50320952020-03-04 20:30:44 -0500270 <Route path="/ManageDictionaries" render={(routeProps) => (<ManageDictionaries {...routeProps} />)} />
sebdet493c3832019-07-15 17:26:18 +0200271 <Route path="/operationalPolicyModal"
xuegaocc5fe512020-04-06 13:13:52 +0200272 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
sebdetc11160e2020-02-25 15:13:31 -0800273 <Route path="/policyModal/:policyInstanceType/:policyName" render={(routeProps) => (<PolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
274 <Route path="/configurationPolicyModal/:policyName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
sebdetd2a4df02020-02-26 15:47:30 -0800275 <Route path="/createLoop" render={(routeProps) => (<CreateLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
sebdet83ce0762019-08-02 14:53:59 +0200276 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
sebdetb13a7902019-11-15 17:26:45 +0100277 <Route path="/loopProperties" render={(routeProps) => (<LoopPropertiesModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
sebdetaa486be2020-02-18 02:00:11 -0800278 <Route path="/modifyLoop" render={(routeProps) => (<ModifyLoopModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
279
sebdet4dc849f2019-11-15 17:49:42 +0100280 <Route path="/userInfo" render={(routeProps) => (<UserInfoModal {...routeProps} />)} />
xuegao691e2b72019-08-16 11:07:24 +0200281 <Route path="/closeLoop" render={this.closeLoop} />
xuegaocc5fe512020-04-06 13:13:52 +0200282 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
283 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
284 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
285 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
286 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
287 <Route path="/deploy" render={(routeProps) => (<DeployLoopModal {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
288 <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 -0700289 <Route path="/logout" render={this.logout} />
290 <GlobalClampStyle />
xuegao0efeb6b2019-10-07 14:36:34 +0200291 {this.renderAlertBar()}
sebdet8a02dd72019-07-31 17:11:11 +0200292 {this.renderNavBar()}
293 {this.renderLoopViewer()}
sebdetd0d65632019-08-26 05:47:01 -0700294 </StyledMainDiv>
sebdetc8d61302019-07-04 15:50:34 +0200295 );
296 }
297}