blob: 05f466bc6bc80662476b8281e0351ec442918cb7 [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'
sebdet493c3832019-07-15 17:26:18 +020039import OpenLoopModal from './components/dialogs/OpenLoop/OpenLoopModal';
40import OperationalPolicyModal from './components/dialogs/OperationalPolicy/OperationalPolicyModal';
41import ConfigurationPolicyModal from './components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal';
xuegaoe52d5722019-07-25 15:43:06 +020042import LoopProperties from './components/dialogs/LoopProperties';
43import UserInfo from './components/dialogs/UserInfo';
sebdet83ce0762019-08-02 14:53:59 +020044import LoopService from './api/LoopService';
sebdet81f5cab2019-11-06 11:40:46 +010045import ViewToscaModal from './components/dialogs/ViewToscaModal/ViewToscaModal';
sebdetf9e2cee2019-08-09 18:36:09 +020046import PerformAction from './components/dialogs/PerformActions';
47import RefreshStatus from './components/dialogs/RefreshStatus';
48import DeployLoop from './components/dialogs/DeployLoop';
xuegao0efeb6b2019-10-07 14:36:34 +020049import Alert from 'react-bootstrap/Alert';
sebdetc8d61302019-07-04 15:50:34 +020050
sebdetd0d65632019-08-26 05:47:01 -070051import { Link } from 'react-router-dom';
52
53const StyledMainDiv = styled.div`
54 background-color: ${props => props.theme.backgroundColor};
55`
56
sebdet4946e5b2019-07-10 12:32:36 +020057const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020058 vertical-align: middle;
59 padding-left: 30px;
sebdetd0d65632019-08-26 05:47:01 -070060 font-size: 36px;
61 font-weight: bold;
sebdetc8d61302019-07-04 15:50:34 +020062`
sebdetd0d65632019-08-26 05:47:01 -070063
64const StyledRouterLink = styled(Link)`
65 color: ${props => props.theme.menuFontColor};
66 background-color: ${props => props.theme.backgroundColor};
67`
68
69const StyledLoginInfo = styled.a`
70 color: ${props => props.theme.menuFontColor};
71 background-color: ${props => props.theme.backgroundColor};
72`
73
sebdet4946e5b2019-07-10 12:32:36 +020074const LoopViewDivStyled = styled.div`
sebdet190227a2019-07-19 16:51:19 +020075 height: 100%;
sebdetc8d61302019-07-04 15:50:34 +020076 overflow: hidden;
77 margin-left: 10px;
78 margin-right: 10px;
79 margin-bottom: 10px;
80 color: ${props => props.theme.loopViewerFontColor};
81 background-color: ${props => props.theme.loopViewerBackgroundColor};
82 border: 1px solid transparent;
83 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
84`
85
sebdet4946e5b2019-07-10 12:32:36 +020086const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020087 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
88 padding: 10px 10px;
89 color: ${props => props.theme.loopViewerHeaderFontColor};
90`
91
sebdet4946e5b2019-07-10 12:32:36 +020092const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020093 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
94 padding: 10px 10px;
95 color: ${props => (props.theme.loopViewerHeaderFontColor)};
96 height: 95%;
97`
98
sebdetc8d61302019-07-04 15:50:34 +020099export default class LoopUI extends React.Component {
sebdet493c3832019-07-15 17:26:18 +0200100
sebdet2dacb9b2019-07-17 13:48:44 +0200101 static defaultLoopName="Empty (NO loop loaded yet)";
102
sebdet4946e5b2019-07-10 12:32:36 +0200103 state = {
104 userName: null,
sebdet2dacb9b2019-07-17 13:48:44 +0200105 loopName: LoopUI.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() {
244 this.setState({ loopCache: new LoopCache({}), loopName: LoopUI.defaultLoopName });
245 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">
sebdet81f5cab2019-11-06 11:40:46 +0100251 <Route path="/viewToscaModal" render={(routeProps) => (<ViewToscaModal {...routeProps} />)} />
sebdet493c3832019-07-15 17:26:18 +0200252 <Route path="/operationalPolicyModal"
xuegao0efeb6b2019-10-07 14:36:34 +0200253 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} showAlert={this.showAlert}/>)} />
sebdet83ce0762019-08-02 14:53:59 +0200254 <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
255 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
256 <Route path="/loopProperties" render={(routeProps) => (<LoopProperties {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
xuegaoe52d5722019-07-25 15:43:06 +0200257 <Route path="/userInfo" render={(routeProps) => (<UserInfo {...routeProps} />)} />
xuegao691e2b72019-08-16 11:07:24 +0200258 <Route path="/closeLoop" render={this.closeLoop} />
xuegao0efeb6b2019-10-07 14:36:34 +0200259 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
260 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
261 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
262 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
263 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
264 <Route path="/deploy" render={(routeProps) => (<DeployLoop {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
265 <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
sebdet687b8de2019-08-26 14:29:11 -0700266 <Route path="/logout" render={this.logout} />
267 <GlobalClampStyle />
xuegao0efeb6b2019-10-07 14:36:34 +0200268 {this.renderAlertBar()}
sebdet8a02dd72019-07-31 17:11:11 +0200269 {this.renderNavBar()}
270 {this.renderLoopViewer()}
sebdetd0d65632019-08-26 05:47:01 -0700271 </StyledMainDiv>
sebdetc8d61302019-07-04 15:50:34 +0200272 );
273 }
274}