blob: eb4ff6a50886e13b7b0de7fd86e39ddfed348b36 [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';
sebdetc8d61302019-07-04 15:50:34 +020030
sebdet493c3832019-07-15 17:26:18 +020031import LoopSvg from './components/loop_viewer/svg/LoopSvg';
32import LoopLogs from './components/loop_viewer/logs/LoopLogs';
33import LoopStatus from './components/loop_viewer/status/LoopStatus';
sebdete44fdb12019-07-12 12:25:56 +020034import UserService from './api/UserService';
sebdet493c3832019-07-15 17:26:18 +020035import LoopCache from './api/LoopCache';
xuegaoac42c4b2019-10-09 16:12:37 +020036import LoopActionService from './api/LoopActionService';
sebdet493c3832019-07-15 17:26:18 +020037
xuegao691e2b72019-08-16 11:07:24 +020038import { Route } from 'react-router-dom'
sebdet67c76a42019-11-15 17:33:44 +010039import OpenLoopModal from './components/dialogs/Loop/OpenLoopModal';
sebdet493c3832019-07-15 17:26:18 +020040import OperationalPolicyModal from './components/dialogs/OperationalPolicy/OperationalPolicyModal';
41import ConfigurationPolicyModal from './components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal';
sebdetb13a7902019-11-15 17:26:45 +010042import LoopPropertiesModal from './components/dialogs/Loop/LoopPropertiesModal';
sebdet4dc849f2019-11-15 17:49:42 +010043import UserInfoModal from './components/dialogs/UserInfoModal';
sebdet83ce0762019-08-02 14:53:59 +020044import LoopService from './api/LoopService';
drveerendra684057e2019-11-11 19:37:39 -050045import ViewToscaPolicyModal from './components/dialogs/Tosca/ViewToscaPolicyModal';
46import ViewBlueprintMicroServiceTemplatesModal from './components/dialogs/Tosca/ViewBlueprintMicroServiceTemplatesModal';
sebdetf9e2cee2019-08-09 18:36:09 +020047import PerformAction from './components/dialogs/PerformActions';
48import RefreshStatus from './components/dialogs/RefreshStatus';
sebdet2e9ae122019-11-15 16:28:55 +010049import DeployLoopModal from './components/dialogs/Loop/DeployLoopModal';
xuegao0efeb6b2019-10-07 14:36:34 +020050import Alert from 'react-bootstrap/Alert';
sebdetc8d61302019-07-04 15:50:34 +020051
sebdetd0d65632019-08-26 05:47:01 -070052import { Link } from 'react-router-dom';
53
54const StyledMainDiv = styled.div`
55 background-color: ${props => props.theme.backgroundColor};
56`
57
sebdet4946e5b2019-07-10 12:32:36 +020058const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020059 vertical-align: middle;
60 padding-left: 30px;
sebdetd0d65632019-08-26 05:47:01 -070061 font-size: 36px;
62 font-weight: bold;
sebdetc8d61302019-07-04 15:50:34 +020063`
sebdetd0d65632019-08-26 05:47:01 -070064
65const StyledRouterLink = styled(Link)`
66 color: ${props => props.theme.menuFontColor};
67 background-color: ${props => props.theme.backgroundColor};
68`
69
70const StyledLoginInfo = styled.a`
71 color: ${props => props.theme.menuFontColor};
72 background-color: ${props => props.theme.backgroundColor};
73`
74
sebdet4946e5b2019-07-10 12:32:36 +020075const LoopViewDivStyled = styled.div`
sebdet190227a2019-07-19 16:51:19 +020076 height: 100%;
sebdetc8d61302019-07-04 15:50:34 +020077 overflow: hidden;
78 margin-left: 10px;
79 margin-right: 10px;
80 margin-bottom: 10px;
81 color: ${props => props.theme.loopViewerFontColor};
82 background-color: ${props => props.theme.loopViewerBackgroundColor};
83 border: 1px solid transparent;
84 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
85`
86
sebdet4946e5b2019-07-10 12:32:36 +020087const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020088 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
89 padding: 10px 10px;
90 color: ${props => props.theme.loopViewerHeaderFontColor};
91`
92
sebdet4946e5b2019-07-10 12:32:36 +020093const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020094 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
95 padding: 10px 10px;
96 color: ${props => (props.theme.loopViewerHeaderFontColor)};
97 height: 95%;
98`
99
sebdetc8d61302019-07-04 15:50:34 +0200100export default class LoopUI extends React.Component {
sebdet493c3832019-07-15 17:26:18 +0200101
sebdet2dacb9b2019-07-17 13:48:44 +0200102 static defaultLoopName="Empty (NO loop loaded yet)";
103
sebdet4946e5b2019-07-10 12:32:36 +0200104 state = {
105 userName: null,
sebdet2dacb9b2019-07-17 13:48:44 +0200106 loopName: LoopUI.defaultLoopName,
xuegao0efeb6b2019-10-07 14:36:34 +0200107 loopCache: new LoopCache({}),
108 showAlert: false
sebdet4946e5b2019-07-10 12:32:36 +0200109 };
xuegao7c7323d2019-07-09 11:52:20 +0200110
sebdet4946e5b2019-07-10 12:32:36 +0200111 constructor() {
112 super();
113 this.getUser = this.getUser.bind(this);
sebdet687b8de2019-08-26 14:29:11 -0700114 this.logout = this.logout.bind(this);
sebdet493c3832019-07-15 17:26:18 +0200115 this.updateLoopCache = this.updateLoopCache.bind(this);
sebdet83ce0762019-08-02 14:53:59 +0200116 this.loadLoop = this.loadLoop.bind(this);
xuegao691e2b72019-08-16 11:07:24 +0200117 this.closeLoop = this.closeLoop.bind(this);
xuegao0efeb6b2019-10-07 14:36:34 +0200118 this.showAlert = this.showAlert.bind(this);
119 this.disableAlert = this.disableAlert.bind(this);
sebdet4946e5b2019-07-10 12:32:36 +0200120 }
sebdet493c3832019-07-15 17:26:18 +0200121
sebdet2dacb9b2019-07-17 13:48:44 +0200122 componentWillMount() {
sebdet493c3832019-07-15 17:26:18 +0200123 this.getUser();
124 }
sebdet4946e5b2019-07-10 12:32:36 +0200125
126 getUser() {
sebdet493c3832019-07-15 17:26:18 +0200127 UserService.login().then(user => {
128 this.setState({ userName: user })
sebdet4946e5b2019-07-10 12:32:36 +0200129 });
130 }
sebdet687b8de2019-08-26 14:29:11 -0700131
132 logout() {
133 UserService.logout().then(user => {
134 this.setState({ userName: user });
135 window.location.reload();
136 });
137
138 }
sebdet493c3832019-07-15 17:26:18 +0200139
sebdetc8d61302019-07-04 15:50:34 +0200140 renderMenuNavBar() {
141 return (
xuegao691e2b72019-08-16 11:07:24 +0200142 <MenuBar loopName={this.state.loopName}/>
sebdetc8d61302019-07-04 15:50:34 +0200143 );
144 }
sebdet4946e5b2019-07-10 12:32:36 +0200145
sebdetc8d61302019-07-04 15:50:34 +0200146 renderUserLoggedNavBar() {
147 return (
148 <Navbar.Text>
sebdetd0d65632019-08-26 05:47:01 -0700149 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
150 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
151 <StyledRouterLink to="/logout/"> (logout)</StyledRouterLink>
sebdetc8d61302019-07-04 15:50:34 +0200152 </Navbar.Text>
153 );
154 }
sebdet4946e5b2019-07-10 12:32:36 +0200155
sebdetc8d61302019-07-04 15:50:34 +0200156 renderLogoNavBar() {
157 return (
158 <Navbar.Brand>
sebdet493c3832019-07-15 17:26:18 +0200159 <img height="50px" width="234px" src={logo} alt="" />
sebdet4946e5b2019-07-10 12:32:36 +0200160 <ProjectNameStyled>CLAMP</ProjectNameStyled>
sebdetc8d61302019-07-04 15:50:34 +0200161 </Navbar.Brand>
162 );
163 }
sebdet4946e5b2019-07-10 12:32:36 +0200164
xuegao0efeb6b2019-10-07 14:36:34 +0200165 renderAlertBar() {
166 return (
167 <Alert variant="danger" show={this.state.showAlert} onClose={this.disableAlert} dismissible>
168 {this.state.showMessage}
169 </Alert>
170 );
171 }
172
sebdetc8d61302019-07-04 15:50:34 +0200173 renderNavBar() {
174 return (
sebdetd0d65632019-08-26 05:47:01 -0700175 <Navbar >
sebdet493c3832019-07-15 17:26:18 +0200176 {this.renderLogoNavBar()}
sebdetd0d65632019-08-26 05:47:01 -0700177 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
sebdet493c3832019-07-15 17:26:18 +0200178 {this.renderMenuNavBar()}
179 {this.renderUserLoggedNavBar()}
180 </Navbar>
181 );
sebdetc8d61302019-07-04 15:50:34 +0200182 }
sebdet493c3832019-07-15 17:26:18 +0200183
sebdetc8d61302019-07-04 15:50:34 +0200184 renderLoopViewHeader() {
185 return (
sebdet4946e5b2019-07-10 12:32:36 +0200186 <LoopViewHeaderDivStyled>
sebdet190227a2019-07-19 16:51:19 +0200187 Loop Viewer - {this.state.loopName}
sebdet4946e5b2019-07-10 12:32:36 +0200188 </LoopViewHeaderDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200189 );
190 }
sebdet493c3832019-07-15 17:26:18 +0200191
sebdetc8d61302019-07-04 15:50:34 +0200192 renderLoopViewBody() {
193 return (
sebdet4946e5b2019-07-10 12:32:36 +0200194 <LoopViewBodyDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200195 <LoopSvg loopCache={this.state.loopCache} />
sebdet190227a2019-07-19 16:51:19 +0200196 <LoopStatus loopCache={this.state.loopCache}/>
sebdetc1ccc542019-07-19 09:50:33 +0200197 <LoopLogs loopCache={this.state.loopCache} />
sebdet4946e5b2019-07-10 12:32:36 +0200198 </LoopViewBodyDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200199 );
200 }
sebdet493c3832019-07-15 17:26:18 +0200201
xuegaoe52d5722019-07-25 15:43:06 +0200202 getLoopCache() {
203 return this.state.loopCache;
204
205 }
xuegao5fe750c2019-08-06 13:03:53 +0200206
sebdetc8d61302019-07-04 15:50:34 +0200207 renderLoopViewer() {
208 return (
sebdet4946e5b2019-07-10 12:32:36 +0200209 <LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200210 {this.renderLoopViewHeader()}
211 {this.renderLoopViewBody()}
sebdet4946e5b2019-07-10 12:32:36 +0200212 </LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200213 );
sebdetc8d61302019-07-04 15:50:34 +0200214 }
sebdet493c3832019-07-15 17:26:18 +0200215
216 updateLoopCache(loopJson) {
xuegao52432d62019-10-04 16:11:22 +0200217 this.setState({ loopCache: new LoopCache(loopJson) });
218 this.setState({ loopName: this.state.loopCache.getLoopName() });
sebdet83ce0762019-08-02 14:53:59 +0200219 console.info(this.state.loopName+" loop loaded successfully");
220 }
xuegao5fe750c2019-08-06 13:03:53 +0200221
xuegao0efeb6b2019-10-07 14:36:34 +0200222 showAlert(message) {
223 this.setState ({ showAlert: true, showMessage:message });
224 }
225
226 disableAlert() {
227 this.setState ({ showAlert: false });
228 }
229
sebdet83ce0762019-08-02 14:53:59 +0200230 loadLoop(loopName) {
231 LoopService.getLoop(loopName).then(loop => {
232 console.debug("Updating loopCache");
xuegaoac42c4b2019-10-09 16:12:37 +0200233 LoopActionService.refreshStatus(loopName).then(data => {
234 this.updateLoopCache(data);
235 this.props.history.push('/');
236 })
237 .catch(error => {
238 this.updateLoopCache(loop);
239 this.props.history.push('/');
240 });
sebdet83ce0762019-08-02 14:53:59 +0200241 });
sebdet493c3832019-07-15 17:26:18 +0200242 }
243
xuegao691e2b72019-08-16 11:07:24 +0200244 closeLoop() {
245 this.setState({ loopCache: new LoopCache({}), loopName: LoopUI.defaultLoopName });
246 this.props.history.push('/');
247 }
sebdet687b8de2019-08-26 14:29:11 -0700248
249 render() {
sebdetc8d61302019-07-04 15:50:34 +0200250 return (
sebdetd0d65632019-08-26 05:47:01 -0700251 <StyledMainDiv id="main_div">
drveerendra684057e2019-11-11 19:37:39 -0500252 <Route path="/viewToscaPolicyModal" render={(routeProps) => (<ViewToscaPolicyModal {...routeProps} />)} />
253 <Route path="/viewBlueprintMicroServiceTemplatesModal" render={(routeProps) => (<ViewBlueprintMicroServiceTemplatesModal {...routeProps} />)} />
sebdet493c3832019-07-15 17:26:18 +0200254 <Route path="/operationalPolicyModal"
xuegao2f5b2cd2020-01-06 16:13:46 +0100255 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
sebdet83ce0762019-08-02 14:53:59 +0200256 <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
257 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
sebdetb13a7902019-11-15 17:26:45 +0100258 <Route path="/loopProperties" render={(routeProps) => (<LoopPropertiesModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
sebdet4dc849f2019-11-15 17:49:42 +0100259 <Route path="/userInfo" render={(routeProps) => (<UserInfoModal {...routeProps} />)} />
xuegao691e2b72019-08-16 11:07:24 +0200260 <Route path="/closeLoop" render={this.closeLoop} />
xuegao0efeb6b2019-10-07 14:36:34 +0200261 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
262 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
263 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
264 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
265 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
sebdet2e9ae122019-11-15 16:28:55 +0100266 <Route path="/deploy" render={(routeProps) => (<DeployLoopModal {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
xuegao0efeb6b2019-10-07 14:36:34 +0200267 <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
sebdet687b8de2019-08-26 14:29:11 -0700268 <Route path="/logout" render={this.logout} />
269 <GlobalClampStyle />
xuegao0efeb6b2019-10-07 14:36:34 +0200270 {this.renderAlertBar()}
sebdet8a02dd72019-07-31 17:11:11 +0200271 {this.renderNavBar()}
272 {this.renderLoopViewer()}
sebdetd0d65632019-08-26 05:47:01 -0700273 </StyledMainDiv>
sebdetc8d61302019-07-04 15:50:34 +0200274 );
275 }
276}